def start(self, args): try: self.acquire_camera() except CameraUserError as e: raise OpModeError(str(e)) if not self.have_camera(): self.stop(None) raise OpModeError(str(e)) self.begin_stream()
def stop(self, args): if self.have_acquired("Wheels"): self.release_motors("Wheels") if self.connection_active(): try: self.disconnect() except ReceiverError as e: raise OpModeError(str(e))
def stop(self, args): '''Implementation of OpMode abstract method stop(args). Stops the RoboticArm mode.''' if self.have_acquired("Arm"): self.release_motors("Arm") if self.connection_active(): try: self.disconnect() except ReceiverError as e: raise OpModeError(str(e))
def start(self, args): '''port=args[1] will be used as local port. Attached unit will use port+1 so that main and attached units can run on the same computer.''' try: self.attached_unit = args[0] port = args[1] self.connect(port) except (IndexError, TypeError): raise OpModeError( "Invalid arguments to start depcam_offload or need a valid port number" ) try: self.attached_unit_ip = unit.MainService.unit_list[ self.attached_unit][1] except KeyError as e: raise OpModeError( "Could not start depcam_offload: unit probably detached.") self.clisock = ClientSocket() # start attempting connection (poll) to attached unit's Receiver for values Thread(target=self.clisock.connect_polled, args=[self.attached_unit_ip, int(port) + 1]).start() try: # blocking call to start unit's depcamera mode unit.send_command(self.attached_unit, "START DepCamera {}".format(int(port) + 1)) except unit.UnitError as e: raise OpModeError(str(e)) # If this point is reached depcamera mode on unit has started successfully # while self.clisock.is_open() and (self.clisock.check_poll_success() == False): # pass # if not self.clisock.is_open(): # raise OpModeError('Poll socket was closed.') # Thread(target=self.check_alive, args=[]).start() # periodically check for close try: self.begin_receive() except ReceiverError as e: raise OpModeError(str(e)) self.ip = cfg.overall_config.get_connected_ip() # time.sleep(5) dg.print("Starting stream redirection...") redirect.start(self.attached_unit_ip, 5520, self.ip, 5520) dg.print("Stream redirection started.")
def start(self, args): '''Implementation of OpMode abstract method start(args). Starts the RoboticArm mode.''' try: port = args[0] self.connect(port) # wait for connection self.begin_receive() # start receiving values except (IndexError, TypeError): raise OpModeError("Need a valid port number.") except ReceiverError as e: raise OpModeError(str(e)) try: self.acquire_motors("Arm") except ActuatorError as e: self.stop(None) # clean up raise OpModeError(str(e)) if self.have_acquired("Arm"): self.begin_actuate() # start sending received values to motors else: self.stop(None) raise OpModeError('Could not get access to Arm motors.')
def start(self, args): '''Implementation of OpMode abstract method start(args). Starts the Dummy mode.''' try: port = args[0] self.connect(port) self.begin_receive() except(IndexError, TypeError): raise OpModeError("Need a valid port number.") except ReceiverError as e: raise OpModeError(str(e)) try: self.acquire_motors("Wheels") except ActuatorError as e: self.stop(None) raise OpModeError(str(e)) if self.have_acquired("Wheels"): self.begin_actuate() else: self.stop(None) raise OpModeError('Could not get access to Wheels.')
def stop(self, args): mgr.global_resources.release("IPCamera") if self.have_acquired("DeployableCamera"): self.release_motors("DeployableCamera") if self.connection_active(): try: self.disconnect() except ReceiverError as e: raise OpModeError(str(e)) if cfg.overall_config.running_as_unit: with unit.cli_wait: unit.cli_wait.notify()
def goals_initialise(self): '''Look for goals in autonomous directory. Initialise them to register them and add to goals_list.''' for filename in os.listdir('.'): if str(filename) == "auto_mode.py": continue if str(filename).startswith('goal_') and \ str(filename).endswith('.py'): importlib.import_module(str(filename).split('.')[0]) for subcls in Goal.__subclasses__(): try: subcls() except TypeError as e: raise OpModeError(str(e))
def start(self, args): try: port = args[0] self.connect(port) self.begin_receive() except (IndexError, TypeError): raise OpModeError("Need a valid port number.") except ReceiverError as e: raise OpModeError(str(e)) try: self.acquire_motors("DeployableCamera") except ActuatorError as e: self.stop(None) raise OpModeError(str(e)) if self.have_acquired("DeployableCamera"): self.begin_actuate() else: self.stop(None) raise OpModeError( 'Could not get access to deployable camera motors.') mgr.global_resources.get_shared("IPCamera") if cfg.overall_config.running_as_unit: with unit.cli_wait: unit.cli_wait.notify()
def stop(self, args): if self.connection_active(): try: self.disconnect() except ReceiverError as e: raise OpModeError(str(e)) redirect.stop() try: if self.clisock.is_open( ): # only way to check if unit is reachable unit.send_command(self.attached_unit, "STOP DepCamera") self.clisock.close() except unit.UnitError as e: dg.print( "Warning: sending command 'STOP DepCamera' to unit {} failed.". format(self.attached_unit))