Ejemplo n.º 1
0
    world = World(.0, .1, .0, lock, stepper.pulse_width)
    stopped = threading.Event()

    motor_thread = threading.Thread(name='motor',
                                    target=run_motor,
                                    args=(stepper, world, stopped))
    world_thread = threading.Thread(name='world',
                                    target=update_world,
                                    args=(world, stepper, 0.001, stopped))
    # hopper_thread = threading.Thread(name='hopper', target=hopper, args=(world, 5.0, stopped))

    try:
        motor_thread.start()
        world_thread.start()
        # hopper_thread.start()

        while True:
            state = world.get_state()
            position = stepper.get_position()
            now = time.time()

            print("%f\t%f\t%f\t%f\t%f" % (now, state[2], state[1], state[0],
                                          float(position) / STEPS_PER_10CM))
            time.sleep(0.005)

    except KeyboardInterrupt:
        stopped.set()
        if platform.system() == 'Linux':
            import RPi.GPIO as GPIO
            GPIO.cleanup()