Пример #1
0
def main():
    # test and run the the Robot
    # motor GPIO Pins
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    StdByPin = 14  # this is the common pin
    leftMotorPins = [12, 23, 24]  # fill up with GPIO pins, PWMA, AIn1, AIn2
    rightMotorPins = [13, 25, 26]  # same as above
    leftMotorPins.append(StdByPin)
    rightMotorPins.append(StdByPin)

    #Sensor GPIO Pins
    trig = 4  # common trig pin
    echo_left = 17  #left sensor echo pin
    echo_fwd = 27  #forward sensor echo pin
    echo_right = 22  #right sensor echo pin

    #button pins
    button_pin = 18
    GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

    #set up motors and sensors
    Motors = [
        motors.motor(leftMotorPins, 'Left'),
        motors.motor(rightMotorPins, 'Right')
    ]
    Sensors = [
        sensors.ultrasonic_sensor([trig, echo_left]),
        sensors.ultrasonic_sensor([trig, echo_fwd]),
        sensors.ultrasonic_sensor([trig, echo_right])
    ]

    #set up robot
    PiOde = RobotOne(Motors, Sensors)

    signal.signal(signal.SIGINT, signal_handler)

    GPIO.add_event_detect(button_pin, GPIO.RISING, bouncetime=200)
    GPIO.add_event_callback(button_pin, button_handler)
    #previous_button_state = False
    while True:  # do forever
        #button,previous_button_state = buttons.button_pressed(button_pin,previous_button_state)
        if roaming:
            PiOde.roam()
            print('roaming')
        else:
            PiOde.stop()
            print('stopped')

    GPIO.cleanup()
Пример #2
0
def main(HOST='', PORT=65432):
    #HOST is localhost
    #set up Ctrl C interrupt
    signal.signal(signal.SIGINT, signal_handler)

    #Initialise the Board
    params = load(open('params.yaml').read(), Loader=Loader)
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)

    StdByPin = params['StdByPin']  # this is the common pin
    leftMotorPins = params[
        'leftMotorPins']  # fill up with GPIO pins, PWMA, AIn1, AIn2
    rightMotorPins = params['rightMotorPins']  # same as above
    leftMotorPins.append(StdByPin)
    rightMotorPins.append(StdByPin)

    #set up motors and sensors
    Motors = [
        motors.motor(leftMotorPins, 'Left'),
        motors.motor(rightMotorPins, 'Right')
    ]
    Sensors = [
        sensors.ultrasonic_sensor([params['trig'], params['echo_left']]),
        sensors.ultrasonic_sensor([params['trig'], params['echo_fwd']]),
        sensors.ultrasonic_sensor([params['trig'], params['echo_right']])
    ]

    #set up robot
    PiOde = robots.RobotOne(Motors, Sensors)
    PiOde.test()

    #Buttons
    button_pin = params['button_pin']
    GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

    #set up button handling
    GPIO.add_event_detect(button_pin, GPIO.RISING, bouncetime=200)
    GPIO.add_event_callback(button_pin, PiOde.toggle_roaming)

    d = Driver(PiOde, HOST, PORT)
    sense = threading.Thread(target=d.sense)
    rx_commands = threading.Thread(target=d.rx_commands)
    drive = threading.Thread(target=d.drive)

    sense.start()
    rx_commands.start()
    drive.start()
Пример #3
0
def main():
    #test and drive the the Robot with PS3 Controller
    #set up Ctrl C interrupt
    signal.signal(signal.SIGINT, signal_handler)

    #Initialise the Board
    params = load(open('params.yaml').read(), Loader=Loader)
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)

    StdByPin = params['StdByPin']  # this is the common pin
    leftMotorPins = params[
        'leftMotorPins']  # fill up with GPIO pins, PWMA, AIn1, AIn2
    rightMotorPins = params['rightMotorPins']  # same as above
    leftMotorPins.append(StdByPin)
    rightMotorPins.append(StdByPin)
    #set up motors and sensors
    Motors = [
        motors.motor(leftMotorPins, 'Left'),
        motors.motor(rightMotorPins, 'Right')
    ]
    Sensors = [
        sensors.ultrasonic_sensor([params['trig'], params['echo_left']]),
        sensors.ultrasonic_sensor([params['trig'], params['echo_fwd']]),
        sensors.ultrasonic_sensor([params['trig'], params['echo_right']])
    ]

    #set up robot
    PiOde = robots.RobotOne(Motors, Sensors)
    #PiOde.test()

    #Buttons
    button_pin = params['button_pin']
    GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

    #set up button handling
    #GPIO.add_event_detect(button_pin, GPIO.RISING,callback=lambda x: PiOde.toggle_roaming(), bouncetime = 200)
    #GPIO.add_event_callback(button_pin, button_handler)

    ps3drive(PiOde)
Пример #4
0
trig = 19  # common trig pin
echo_left = 17  #left sensor echo pin
echo_fwd = 4  #forward sensor echo pin
echo_right = 16  #right sensor echo pin

#button pins
button_pin = 18
GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

#set up motors and sensors
Motors = [
    motors.motor(leftMotorPins, 'Left'),
    motors.motor(rightMotorPins, 'Right')
]
Sensors = [
    sensors.ultrasonic_sensor([trig, echo_left]),
    sensors.ultrasonic_sensor([trig, echo_fwd]),
    sensors.ultrasonic_sensor([trig, echo_right])
]

#set up robot
PiOde = robots.RobotOne(Motors, Sensors)

#set up Ctrl C interrupt
signal.signal(signal.SIGINT, signal_handler)

#set up button handling
GPIO.add_event_detect(button_pin, GPIO.RISING, bouncetime=200)
GPIO.add_event_callback(button_pin, button_handler)
time.sleep(1)
PiOde.sense()
Пример #5
0
def main():
    #test and run the the Robot

    parser = argparse.ArgumentParser(description='Driver for RoboKar')
    parser.add_argument('--v', default=1.0)
    parser.add_argument('--w', default=0)
    parser.add_argument('--testing', default=False)
    parser.add_argument('--time', default=10)
    args = parser.parse_args()
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    StdByPin = 22  # this is the common pin
    leftMotorPins = [12, 23, 24]  # fill up with GPIO pins, PWMA, AIn1, AIn2
    rightMotorPins = [13, 25, 5]  # same as above
    leftMotorPins.append(StdByPin)
    rightMotorPins.append(StdByPin)

    # Cleanup done at exit
    @atexit.register
    def cleanup_robot():
        if args.testing != 'True':
            print('EXITING')
            PiOde.stop()
            GPIO.cleanup()
            pass

    #Sensor GPIO Pins
    trig = 19  # common trig pin
    echo_left = 17  #left sensor echo pin
    echo_fwd = 4  #forward sensor echo pin
    echo_right = 16  #right sensor echo pin

    #set up motors and sensors
    Motors = [
        motors.motor(leftMotorPins, 'Left'),
        motors.motor(rightMotorPins, 'Right')
    ]
    Sensors = [
        sensors.ultrasonic_sensor([trig, echo_left]),
        sensors.ultrasonic_sensor([trig, echo_fwd]),
        sensors.ultrasonic_sensor([trig, echo_right])
    ]

    #set up robot
    PiOde = RobotOne(Motors, Sensors)

    #set up Ctrl C interrupt
    signal.signal(signal.SIGINT, signal_handler)

    #button pins
    button_pin = 18
    GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

    #set up button handling
    #GPIO.add_event_detect(button_pin, GPIO.RISING,callback=lambda x: PiOde.toggle_roaming(), bouncetime = 200)
    #GPIO.add_event_callback(button_pin, button_handler)

    # Test the Robot
    #PiOde.set_roaming_on()
    #while PiOde.is_roaming():
    #    PiOde.roam()
    PiOde.command_vel([float(args.v), float(args.w)])
    time.sleep(float(args.time))
Пример #6
0
def main():
    parser = argparse.ArgumentParser(description='Web Driver for RoboKar')
    parser.add_argument('--hostname', default='0.0.0.0')
    parser.add_argument('--port', default=5000)
    parser.add_argument('--testing',default=False)
    args = parser.parse_args()
    # Cleanup done at exit

    @atexit.register
    def cleanup_robot():
        if args.testing != 'True':
            print('EXITING')
            PiOde.stop()
            GPIO.cleanup()
            server.shutdown()
        pass

    if args.testing != 'True':
        # Rpi Sepcific Commands - if not testing
        import RPi.GPIO as GPIO
        import sensors
        import motors
        import robots
        params = load(open('params.yaml').read(), Loader=Loader)
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)

        StdByPin = params['StdByPin']  # this is the common pin
        leftMotorPins = params['leftMotorPins'] # fill up with GPIO pins, PWMA, AIn1, AIn2
        rightMotorPins = params['rightMotorPins'] # same as above
        leftMotorPins.append(StdByPin)
        rightMotorPins.append(StdByPin)

        #set up motors and sensors
        Motors = [motors.motor(leftMotorPins,'Left'),motors.motor(rightMotorPins,'Right')]
        Sensors = [sensors.ultrasonic_sensor([params['trig'],params['echo_left']]), sensors.ultrasonic_sensor([params['trig'],params['echo_fwd']]), sensors.ultrasonic_sensor([params['trig'],params['echo_right']])]

        #set up robot
        PiOde = robots.RobotOne(Motors,Sensors)
        #PiOde.test()

        #Buttons
        button_pin = params['button_pin']
        GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

        #set up button handling
        GPIO.add_event_detect(button_pin, GPIO.RISING, bouncetime = 200)
        GPIO.add_event_callback(button_pin, PiOde.toggle_roaming)
        print('PiOde Set Up Complete')
    else:
        PiOde = None

    # driver instance
    d = Driver(PiOde,args)

    #start the threaded processes
    threading.Thread(target=d.sense,daemon=True).start()

    #start the flask server
    app = Flask(__name__)

    #app.add_url_rule('/','web_interface',d.web_interface)
    #app.add_url_rule('/read_vel','read_vel',d.read_vel)

    app.route("/")(d.web_interface)
    app.route("/read_vel")(d.read_vel)
    app.route("/stop")(d.stop)
    app.route("/exit")(lambda:sys.exit(0))
    server = ServerThread(app,args)
    server.start()