コード例 #1
0
interface.initialize()
config = str(sys.argv[1])
Robot = Robot(interface, pid_config_file=config)
bumpers = [None, None]
speeds = [6, 6]
zeros = [0, 0]
Robot.set_speed(speeds)
#Robot.start_debugging()

while True:
    bumpers[0] = Robot.get_bumper("left")
    bumpers[1] = Robot.get_bumper("right")

    if bumpers[0] and bumpers[1]:
        Robot.stop()
        Robot.travel_straight(-3)
        Robot.rotate_right(30)
        Robot.set_speed([-x for x in speeds])

    if not bumpers[0] and bumpers[1]:
        Robot.stop()
        Robot.rotate_left(30)
        Robot.set_speed([-x for x in speeds])

    if bumpers[0] and not bumpers[1]:
        Robot.stop()
        Robot.rotate_right(30)
        Robot.set_speed([-x for x in speeds])

interface.terminate()
コード例 #2
0
#Initialize the interface
interface=brickpi.Interface()
interface.initialize()

NUMBER_OF_PARTICLES = None

OFFSET = 100
DISTANCE_TO_PIXEL = 15

#Draw the square
print "drawLine:" + str((OFFSET,OFFSET,40*DISTANCE_TO_PIXEL+OFFSET,OFFSET))
print "drawLine:" + str((40*DISTANCE_TO_PIXEL+OFFSET,OFFSET,40*DISTANCE_TO_PIXEL+OFFSET,OFFSET+40*DISTANCE_TO_PIXEL))
print "drawLine:" + str((40*DISTANCE_TO_PIXEL+OFFSET,40*DISTANCE_TO_PIXEL+OFFSET,OFFSET,40*DISTANCE_TO_PIXEL+OFFSET))
print "drawLine:" + str((OFFSET,40*DISTANCE_TO_PIXEL+OFFSET,OFFSET,OFFSET))

Robot = Robot(interface, pid_config_file="carpet_config.json")
for i in range(4):
    for j in range(4):
        Robot.travel_straight(10,update_particles=True)
        NUMBER_OF_PARTICLES = Robot.get_state()
        NUMBER_OF_PARTICLES = [(OFFSET+point[0][0]*DISTANCE_TO_PIXEL,OFFSET+point[0][1]*DISTANCE_TO_PIXEL,point[0][2]) for point in NUMBER_OF_PARTICLES]
        print "drawParticles:" + str(NUMBER_OF_PARTICLES)
        time.sleep(5)
    Robot.rotate_right(90,update_particles=True)
    NUMBER_OF_PARTICLES = Robot.get_state()
    NUMBER_OF_PARTICLES = [(OFFSET+point[0][0]*DISTANCE_TO_PIXEL,OFFSET+point[0][1]*DISTANCE_TO_PIXEL,point[0][2]) for point in NUMBER_OF_PARTICLES]
    print "drawParticles:" + str(NUMBER_OF_PARTICLES)
    time.sleep(5)

interface.terminate()
コード例 #3
0
import threading
import time
from src.robot import Robot
import brickpi

#Initialize the interface
interface=brickpi.Interface()
interface.initialize()

Robot = Robot(interface, pid_config_file="carpet_config.json")

Robot.travel_straight(40)
time.sleep(5)
Robot.travel_straight(-40)
time.sleep(5)
Robot.rotate_left(90)
time.sleep(5)
Robot.rotate_right(90)

interface.terminate()
コード例 #4
0
import threading
import time
import sys
from src.robot import Robot
import brickpi

#Initialize the interface
interface = brickpi.Interface()
interface.initialize()
interface.startLogging("motor_position_1.log")

Robot = Robot(interface, 'paper_config.json')

Robot.rotate_right(float(sys.argv[1]))

interface.stopLogging()
interface.terminate()