def __init__(self, host=None, rpc_port=8000, verbose=True): """M3RtProxy is the client interface to the M3RtServer. It manages the state of the server using XML_RPC methods. It can query the server state, start/stop the run-time system, create a DataService connection, and publish/subscribe desired components to the DataService. The DataService uses a faster TCP/IP socket on port 10000""" self.stopped = False self.host = host self.verbose = verbose if host is None: self.host = m3t.get_config_hostname() if self.host is None: self.host = m3t.get_local_hostname() self.rpc_port = rpc_port self.data_port = 10000 #Currently hardcoded in M3 self.proxy = None self.data_socket = None self.subscribed = {} self.published_param = {} self.published_command = {} self.available_components = [] self.available_component_types = [] self.log_comps = {} self.log_names = [] self.logname = None self.status_raw = mbs.M3StatusAll() self.command_raw = mbs.M3CommandAll() self.ns = 0 self.nsl = 0 self.data_svc = None self.ros_svc = None self.use_timeout = True self.is_server_started = False try: if self.verbose: print 'Starting M3 RPC Client at ', self.host, 'on Port ', self.rpc_port, '...' self.proxy = xmlrpclib.ServerProxy('http://' + self.host + ':' + str(self.rpc_port)) if self.verbose: print 'M3 RPC Client started at ', self.host, 'on Port ', self.rpc_port #Check that connection made try: self.proxy.system.listMethods() except xmlrpclib.Error, v: self.proxy = None raise m3t.M3Exception( 'Error: ' + v + 'Make sure that the M3 RPC Server is running') except socket.error, msg: self.proxy = None raise m3t.M3Exception( 'Check that server is started. Socket Error: ' + str(msg))
def stop(self, force_safeop=True): """Stop the RtSystem and any running data service on the server. This should be called at client process shutdown Will automatically move all components to SAFEOP by default (for safety)""" try: if self.is_server_started: for comp_name in self.command_raw.name_cmd: try: try: #if bot bot_comp = self.published_command[comp_name][ 'component'] for c in bot_comp.get_available_chains(): bot_comp.set_mode_off(c) except: pass # or just hand, arm etc self.published_command[comp_name][ 'component'].set_mode_off() except: pass self.step() self.make_safe_operational(comp_name) if self.data_svc is not None: self.__stop_data_service() if self.ros_svc is not None: self.__stop_ros_service() if self.proxy is not None: #if not self.proxy.IsDataServiceRunning(): self.proxy.RemoveRtSystem() self.proxy = None self.subscribed = {} self.published_param = {} self.published_command = {} self.available_components = [] self.available_component_types = [] self.status_raw = mbs.M3StatusAll() self.command_raw = mbs.M3CommandAll() except socket.error: pass #Ok because shutting down self.stopped = True self.is_server_started = False