def move_failed(robot, message): robot.wait() robot.stop() def move1_finished(robot, message): robot.subscribe('robot.move.finished', move2_finished) robot.moveby(12, 0, 1) return True def done(robot, message): pass # create our device simulator = Simulator(10, 10, 5.5, 2.4, 45) # create our robot robot = Robot(simulator) # subscribe to things robot.subscribe('robot.ready', ready) robot.subscribe('robot.move.finished', move1_finished) robot.subscribe('robot.move.failed', move_failed) robot.subscribe('robot.done', done) # start things running robot.run()
logger.info('ready') robot.moveby(1, 0.5, 1) return True def move_3_finished(robot, message): logger.info('move 2 finished') robot.end() return True def move_2_finished(robot, message): logger.info('move 2 finished') robot.rotateby(163, 1) robot.subscribe('robot.move.finished', move_3_finished) return True def move_finished(robot, message): logger.info('move finished') robot.moveby(-sqrt(1.25), 0) robot.subscribe('robot.move.finished', move_2_finished) return True roomba = Roomba700('/dev/ttyAMA0') robot = Robot(roomba) robot.subscribe('robot.ready', ready) robot.subscribe('robot.move.finished', move_finished) robot.run()
#!/usr/bin/env python from __future__ import absolute_import, division, print_function, \ unicode_literals from evrobot import Robot, Roomba from math import sqrt from serial import Serial import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(threadName)-10s %(name)-9s ' '%(message)s') logger = logging.getLogger(__name__) serial = Serial('/dev/ttyAMA0', baudrate=115200, timeout=0.5) roomba = Roomba(serial) robot = Robot(roomba) # queue up some commands roomba.move_by(1, 0.5, 2 / 5.0) roomba.move_by(-sqrt(1.25), 0, 0.5) roomba.rotate_by(163) # shutdown robot.shutdown() # wait for things to finish robot.wait()
robot.stop() return True def move_failed(robot, message): robot.wait() robot.stop() def move1_finished(robot, message): robot.subscribe('robot.move.finished', move2_finished) robot.moveby(12, 0, 1) return True def done(robot, message): pass # create our device simulator = Simulator(10, 10, 5.5, 2.4, 45) # create our robot robot = Robot(simulator) # subscribe to things robot.subscribe('robot.ready', ready) robot.subscribe('robot.move.finished', move1_finished) robot.subscribe('robot.move.failed', move_failed) robot.subscribe('robot.done', done) # start things running robot.run()
logger = logging.getLogger(__name__) def ready(robot, message): logger.info('ready') robot.moveby(1, 0.5, 1) return True def move_3_finished(robot, message): logger.info('move 2 finished') robot.end() return True def move_2_finished(robot, message): logger.info('move 2 finished') robot.rotateby(163, 1) robot.subscribe('robot.move.finished', move_3_finished) return True def move_finished(robot, message): logger.info('move finished') robot.moveby(-sqrt(1.25), 0) robot.subscribe('robot.move.finished', move_2_finished) return True roomba = Roomba700('/dev/ttyAMA0') robot = Robot(roomba) robot.subscribe('robot.ready', ready) robot.subscribe('robot.move.finished', move_finished) robot.run()