def handle_event(type, param):
    if type == 'user':
        if param == 'left':
            print 'Moving left...'
            motor_r.forward()
            motor_l.back()

            sleep(TURN_TIME)
            motor_r.stop()
            motor_l.stop()

        elif param == 'right':
            print 'Moving right...'
            motor_r.back()
            motor_l.forward()

            sleep(TURN_TIME)
            motor_r.stop()
            motor_l.stop()

        elif param == 'forward' or param == 'go':
            print 'Moving forward...'
            motor_r.forward()
            motor_l.forward()

        elif param == 'back' or param == 'reverse':
            print 'Moving back...'
            motor_r.back()
            motor_l.back()

        elif param == 'stop':
            print 'Stopping motors..'
            #turns motors off
            motor_r.stop()
            motor_l.stop()
            print 'Motors stopped'

    elif type == 'internal':
        if param == 'collide':
            print 'Collided!'
            motor_r.back()
            motor_l.back()

            sleep(COLL_REVERSE_TIME)
            motor_r.stop()
            motor_l.stop()

        elif param == 'exit':
            print 'Cleaning up...'
            motor_r.stop()
            motot_l.stop()
            io.cleanup()

            stop_listening()
            print 'Exiting'
            sys.exit(0)
Esempio n. 2
0
def handle_event(type, param):
    if type == 'user':
        if param == 'left':
            print('Moving left...')
            motor_r.forward()
            motor_l.back()

            sleep(TURN_TIME)
            motor_r.stop()
            motor_l.stop()

        elif param == 'right':
            print('Moving right...')
            motor_r.back()
            motor_l.forward()

            sleep(TURN_TIME)
            motor_r.stop()
            motor_l.stop()

        elif param == 'forward' or param == 'go':
            print('Moving forward...')
            motor_r.forward()
            motor_l.forward()

        elif param == 'back' or param == 'reverse':
            print('Moving back...')
            motor_r.back()
            motor_l.back()

        elif param == 'stop':
            print('Stopping motors..')
            #turns motors off
            motor_r.stop()
            motor_l.stop()
            print('Motors stopped')

    elif type == 'internal':
        if param == 'collide':
            print('Collided!')
            motor_r.back()
            motor_l.back()

            sleep(COLL_REVERSE_TIME)
            motor_r.stop()
            motor_l.stop()

        elif param == 'exit':
            print('Cleaning up...')
            motor_r.stop()
            motot_l.stop()
            io.cleanup()

            stop_listening()
            print('Exiting')
            sys.exit(0)