def __init__(self, server_address, server_handler, serial_port, brc_pin): super().__init__(server_address, server_handler) self.logger = logging.getLogger('Roomberry') #Initialize camera self.camera_lock = Lock() # self.start_camera() self.last_camera_operation = time() #Wake up an initialize roomba self.roomba = Create2(serial_port, self.logger, brc_pin, enable_quirks=False) self.roomba.logger.disabled = False # boot_message = self.roomba.firmware_version.split('\r\n') self.roomba_lock = Lock() self.distance = 0 self.angle = 0 self.roomba.client = mqtt.Client(socket.gethostname()) #Start watchdog thread self.battery_watchdog_thread = Thread(target=self.battery_watchdog) self.battery_watchdog_thread.setDaemon(True)
def main(): import code import atexit import os import readline import rlcompleter historyPath = os.path.expanduser("~/.pyhistory") def save_history(historyPath=historyPath): import readline readline.write_history_file(historyPath) if os.path.exists(historyPath): readline.read_history_file(historyPath) atexit.register(save_history) del os, atexit, readline, rlcompleter, save_history, historyPath print('Launching REPL') port = input('Serial Port> ') brc_pin = int(input('BRC Pin> ')) print() # give the user a way out before we launch into interactive mode if port.lower() == 'quit()': return try: robot = Create2(port,brc_pin) except RobotConnectionError as e: print(e, '\nInner Exception:', e.__cause__) return except ModeChangeError: print('Failed to enter Passive mode') return # add methods to turn logging to console on/off logger = _configure_logger() def enable_logging(): logger.disabled = False def disable_logging(): logger.disabled = True # determine if we need to handle the issue with angle/distance check_for_quirks(robot) # add our goodies to the scope # I hope the Python powers don't come to get me foe doing this vars = globals().copy() vars.update(locals()) # punch user out to a repl shell = code.InteractiveConsole(vars) shell.interact(banner='Create2 attached as robot on {0}\nMay it serve you well'.format(port))
def connect(): """Connect to the create - must be called before anything else is used.""" global robot global create_initialized create_initialized = True try: robot = Create2(port) except Exception: print('The Create is either not connected or is powered off.') exit(1) robot.oi_mode = MODES.SAFE _set_initial_counts()
def __init__(self, server_address, server_handler, serial_port, brc_pin): super().__init__(server_address, server_handler) self.logger = logging.getLogger('Roomberry') #Initialize camera self.camera_lock = Lock() self.start_camera() self.last_camera_operation = time() #Wake up an initialize roomba self.roomba = Create2(serial_port, brc_pin, enable_quirks=False) self.roomba.logger.disabled = True self.roomba_lock = Lock() self.distance = 0 self.angle = 0 #Start watchdog thread self.battery_watchdog_thread = Thread(target=self.battery_watchdog) self.battery_watchdog_thread.setDaemon(True)
def main(): import code print('Launching REPL') port = input('Serial Port> ') print() # give the user a way out before we launch into interactive mode if port.lower() == 'quit()': return try: robot = Create2(port) except RobotConnectionError as e: print(e, '\nInner Exception:', e.__cause__) return except ModeChangeError: print('Failed to enter Passive mode') return # add methods to turn logging to console on/off logger = _configure_logger() def enable_logging(): logger.disabled = False def disable_logging(): logger.disabled = True # determine if we need to handle the issue with angle/distance check_for_quirks(robot) # add our goodies to the scope # I hope the Python powers don't come to get me foe doing this vars = globals().copy() vars.update(locals()) # punch user out to a repl shell = code.InteractiveConsole(vars) shell.interact(banner='Create2 attached as robot on {0}\nMay it serve you well'.format(port))
print('\t' * level, obj) else: for prop in [prop for prop in dir(obj) if not prop.startswith('_')]: prop_val = getattr(obj, prop) if not hasattr(prop_val, '__dict__'): print('\t' * level, prop + ':', prop_val) else: print('\t' * level, prop + ':') print_properties(prop_val, level + 1) def get_all_sensor_readings(robot): print('Reading all sensors') for p in [ p for p in dir(Create2) if isinstance(getattr(Create2, p), property) and p not in ['enable_quirks', 'enable_logging', 'firmware_version'] ]: print(p) print_properties(getattr(robot, p)) print() sleep(.03) if __name__ == "__main__": print('Launching robots Tests') port = input('Serial Port?> ') robot = Create2(port, enable_quirks=True) get_all_sensor_readings(robot) robot.stop()
from irobot.robots.create2 import Create2 from irobot.openinterface.constants import MODES import time port = '/dev/ttyUSB0' robot = Create2(port) print(robot.left_encoder_counts) robot.ou_mode = MODES.SAFE #robot.seek_dock() robot.wake()
from irobot.robots.create2 import Create2 from irobot.openinterface.constants import MODES # instantiate robot robot = Create2(port='/dev/serial0') robot.set_baud(115200) # read sensor # print(robot.left_encoder_counts) # change mode to drive (SAFE|FULL) robot.oi_mode = MODES.SAFE robot.drive_straight(50) # stop driving robot.drive_straight(0) # return to passive mode robot.oi_mode = MODES.PASSIVE # shutdown OI robot.stop()