def stop():
    global running
    print "Stopping controller"
    xboxController.stop()
    print "Cleanup initio"
    initio.cleanup()
    running = False
    print "Exit"
    sys.exit()
Exemple #2
0
def execute():
    print('Startup')

    initio.init(Motors=True)

    cmd_forwards = 'f'
    cmd_backwards = 'b'
    cmd_left = 'l'
    cmd_right = 'r'
    cmd_stop = 's'
    cmd_query = '?'

    r = redis.Redis(host='192.168.0.1', port=6379,
                    db=0, decode_responses=True)
    p = r.pubsub(ignore_subscribe_messages=True)
    p.subscribe('fernando')

    r.publish('services', 'fernando.on')
    systemd.daemon.notify('READY=1')
    print('Startup complete')

    try:
        initio.stop()
        r.publish('fernando.status', cmd_stop)

        last_cmd = cmd_stop

        for message in p.listen():
            cmd = message['data']

            if cmd == cmd_forwards:
                initio.forward(100)
            elif cmd == cmd_backwards:
                initio.reverse(100)
            elif cmd == cmd_left:
                initio.spinLeft(100)
            elif cmd == cmd_right:
                initio.spinRight(100)
            elif cmd == cmd_stop:
                initio.stop()
            elif cmd == cmd_query:
                # Don't need to do anything in this case
                pass

            if cmd != cmd_query:
                last_cmd = cmd

            r.publish('fernando.status', last_cmd)
    except:
        p.close()

        initio.stop()
        initio.cleanup()

        r.publish('services', 'fernando.off')
        print('Goodbye')
Exemple #3
0
#!/usr/bin/python
import time, initio

initio.stop
initio.cleanup()
Exemple #4
0
def execute():
    print('Startup')

    if len(sys.argv) > 1 and sys.argv[1] == 'line':
        print('Line mode')
        initio.init(Line=True)
        message_prefix = 'line'
        left_sensor = initio.lineLeft
        right_sensor = initio.lineRight
    else:
        print('Obstacle mode')
        initio.init(IR=True)
        message_prefix = 'obstacle'
        left_sensor = initio.irFL
        right_sensor = initio.irFR

    redis_queue = 'redeye.' + message_prefix
    redis_queue_left = redis_queue + '.left'
    redis_queue_right = redis_queue + '.right'

    message_left_off = message_prefix + '.left.off'
    message_left_on = message_prefix + '.left.on'
    message_right_off = message_prefix + '.right.off'
    message_right_on = message_prefix + '.right.on'

    r = redis.Redis(host='192.168.0.1', port=6379, db=0, decode_responses=True)
    p = r.pubsub(ignore_subscribe_messages=True)
    p.subscribe(redis_queue)

    r.publish('services', redis_queue + '.on')
    systemd.daemon.notify('READY=1')
    print('Startup complete')

    try:

        def left_callback(c):
            if GPIO.input(left_sensor):
                r.publish(redis_queue_left, message_left_off)
            else:
                r.publish(redis_queue_left, message_left_on)

        def right_callback(c):
            if GPIO.input(right_sensor):
                r.publish(redis_queue_right, message_right_off)
            else:
                r.publish(redis_queue_right, message_right_on)

        GPIO.add_event_detect(left_sensor,
                              GPIO.BOTH,
                              callback=left_callback,
                              bouncetime=100)
        GPIO.add_event_detect(right_sensor,
                              GPIO.BOTH,
                              callback=right_callback,
                              bouncetime=100)
        left_callback(left_sensor)
        right_callback(right_sensor)

        for message in p.listen():
            # If message is received, send current status
            left_callback(left_sensor)
            right_callback(right_sensor)

    except:
        p.close()

        initio.cleanup()

        r.publish('services', redis_queue + '.off')
        print('Goodbye')
Exemple #5
0
        if keyp == 'w' or ord(keyp) == 16:
            initio.forward(speed)
            print 'Forward', speed
        elif keyp == 'z' or ord(keyp) == 17:
            initio.reverse(speed)
            print 'Reverse', speed
        elif keyp == 's' or ord(keyp) == 18:
            initio.spinRight(speed)
            print 'Spin Right', speed
        elif keyp == 'a' or ord(keyp) == 19:
            initio.spinLeft(speed)
            print 'Spin Left', speed
        elif keyp == '.' or keyp == '>':
            speed = min(100, speed+10)
            print 'Speed+', speed
        elif keyp == ',' or keyp == '<':
            speed = max (0, speed-10)
            print 'Speed-', speed
        elif keyp == ' ':
            initio.stop()
            print 'Stop'
        elif ord(keyp) == 3:
            break

except KeyboardInterrupt:
    print

finally:
    initio.cleanup()
    
Exemple #6
0
def execute():
    print('Startup')

    x = {'init': 0, 'max': 80, 'min': -80}
    y = {'init': 10, 'max': 80, 'min': -25}

    initio.init(Servos=True)
    initio.setServo(0, x['init'])
    initio.setServo(1, y['init'])

    r = redis.Redis(host='192.168.0.1', port=6379,
                    db=0, decode_responses=True)
    p = r.pubsub(ignore_subscribe_messages=True)
    p.subscribe('jaxx')

    r.publish('services', 'jaxx.on')
    systemd.daemon.notify('READY=1')
    print('Startup complete')

    try:
        r.publish('jaxx.head', str(x['init']) + "," + str(y['init']))

        x_angle = x['init']
        y_angle = y['init']

        for message in p.listen():
            cmd = message['data']

            if cmd == '0':
                x_angle = x['init']
                y_angle = y['init']
            elif cmd == '?':
                # Query mode - don't need to update anything - just pass through
                pass
            else:
                angles = cmd.split(',')
                x_angle = int(angles[0])
                y_angle = int(angles[1])

            # Make sure it's valid
            if x_angle > x['max']:
                x_angle = x['max']
            if x_angle < x['min']:
                x_angle = x['min']
            if y_angle > y['max']:
                y_angle = y['max']
            if y_angle < y['min']:
                y_angle = y['min']

            initio.setServo(0, x_angle)
            initio.setServo(1, y_angle)

            r.publish('jaxx.head', str(x_angle) + "," + str(y_angle))
    except:
        p.close()

        initio.setServo(0, x['init'])
        initio.setServo(1, y['init'])
        initio.cleanup()

        r.publish('services', 'jaxx.off')
        print('Goodbye')