Пример #1
0
            [
                robot.enqueue(action)
                for action in commands.process_program(lines, robot)
            ]
    else:
        # Start the telnet control server
        control_server = ControlServer(robot)

        # Define the mechanism for attaching joystick axis events to robot motion
        def joystick_movement(js, axis, value):
            robot.locomote(js.axis_states['x'], js.axis_states['y'])

        # Initialize the joystick
        joystick = Joystick()
        joystick.register(loop)
        joystick.add_axis_callback('x', joystick_movement)
        joystick.add_axis_callback('y', joystick_movement)

    # Initialize the robot's main command processing loop
    consumer = asyncio.ensure_future(robot.consume_queue())
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        print()
        print('Shutting down...')

        async def loop_shutdown():
            consumer.cancel()

        loop.run_until_complete(loop_shutdown())
    finally: