示例#1
0
import time
from src.robot import Robot
import brickpi
import sys
"""
    argv[1]: 1 for wall on the left side
        2 for wall on the right side
"""
#Initialize the interface
interface = brickpi.Interface()
interface.initialize()
config = "carpet_config.json"
Robot = Robot(interface, pid_config_file=config)
speeds = [6, 6]
wall_location = int(sys.argv[1])
Robot.set_speed(speeds)
#Robot.start_debugging()

if (wall_location == 1):
    Robot.set_ultra_pose(90)
elif (wall_location == 2):
    Robot.set_ultra_pose(-90)
else:
    raise Exception("Can not change Ultrasound pose!")

while True:
    Robot.keep_distance(30, 6, wall_location)
    time.sleep(0.5)

interface.terminate()
from __future__ import division
import threading
import time
from src.robot import Robot
from src.drawing import Map, Canvas
import brickpi

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

Robot = Robot(interface,
              pid_config_file="speed_config.json",
              mcl=False,
              threading=False)

speed_l = float(input("Enter left wheel speed:"))
speed_r = float(input("Enter right wheel speed:"))
Robot.set_speed(speeds=[speed_l, speed_r], k=1)
raw_input("Press enter when max speed has been hit.")
Robot.start_obstacle_detection()
time.sleep(10)

Robot.set_speed(speeds=[0, 0])
Robot.stop_threading()
interface.terminate()
raw_input("Press enter to terminate.")