def test_offline(self): import rosservice orig_uri = os.environ['ROS_MASTER_URI'] os.environ['ROS_MASTER_URI'] = 'http://fake_host:12356' try: c = 'rosservice' try: rosservice.get_service_type('/add_two_ints') self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass try: rosservice._rosservice_cmd_list([c, 'list']) self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass try: rosservice._rosservice_cmd_info([c, 'info', '/add_two_ints']) self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass try: rosservice._rosservice_cmd_type([c, 'type', '/add_two_ints']) self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass try: rosservice._rosservice_cmd_uri([c, 'uri', '/add_two_ints']) self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass try: rosservice._rosservice_cmd_find( [c, 'find', 'test_ros/AddTwoInts']) self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass try: rosservice._rosservice_cmd_call( [c, 'call', '/add_two_ints', '1', '2']) self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass finally: os.environ['ROS_MASTER_URI'] = orig_uri
def service_wait_type(self, service_name, retries=5, retrysleep=1): resolved_service_name = rospy.resolve_name(service_name) service_type = rosservice.get_service_type(resolved_service_name) retry = 0 while not service_type and retry < 5: print('Service {service} not found. Retrying...'.format( service=resolved_service_name)) rospy.rostime.wallsleep(retrysleep) retry += 1 service_type = rosservice.get_service_type(resolved_service_name) if retry >= retries: self.fail("service {0} not found ! Failing.".format( resolved_service_name)) return service_type
def _refresh_ctrlers_cb(self): try: # refresh the list of controller managers we can find srv_list = rosservice.get_service_list() ctrlman_ns_list_cur = [] for srv_name in srv_list: if 'controller_manager/list_controllers' in srv_name: srv_type = rosservice.get_service_type(srv_name) if srv_type == 'controller_manager_msgs/ListControllers': ctrlman_ns = srv_name.split( '/controller_manager/list_controllers')[0] if ctrlman_ns == '': ctrlman_ns = '/' # ctrlman_ns is a Controller Manager namespace if ctrlman_ns not in self.list_ctrlers: # we haven't connected to it yet, create the service proxies self.controller_manager_connect(ctrlman_ns) ctrlman_ns_list_cur.append(ctrlman_ns) # remove every controller manager which isn't up anymore for ctrlman_ns_old in self.list_ctrlers.keys(): if ctrlman_ns_old not in ctrlman_ns_list_cur: self.controller_manager_disconnect(ctrlman_ns_old) # refresh the controller list for the current controller manager self.refresh_loadable_ctrlers() self.refresh_ctrlers() except Exception as e: self.sig_sysmsg.emit(e.message)
def wait_service_ready(service_name, url): remote_service_type = "" while remote_service_type == "": remote_service_type = get_remote_service_info(service_name, url) if (remote_service_type == ""): rospy.loginfo( "Failed to get the remote type of service %s. Retrying...", service_name) time.sleep(1) local_service_type = None while local_service_type == None: local_service_type = get_service_type(service_name) if (local_service_type == None): rospy.loginfo( "Failed to get the local type of service %s. Retrying...", service_name) time.sleep(1) if remote_service_type != local_service_type: return None, None local_service_args = None while local_service_args == None: local_service_args = get_service_args(service_name) if (local_service_args == None): rospy.loginfo( "Failed to get the arguments list of service %s. Retrying...", service_name) time.sleep(1) service_args = local_service_args.split() return local_service_type, service_args
def get_service_types(self, services): service_types = [] for service in services: service_types.append( [service[0], rosservice.get_service_type(service[0])]) return service_types
def generate_type_info_msg(self): """ Basic connection details are provided by get system state from the master, which is a one shot call to give you information about every connection possible. it does not however provide type info information and the only way of retrieving that from the master is making one xmlrpc call to the master for every single connection. This gets expensive, so generating this information is usually delayed until we need it and done via this method. """ if self.type_info is None: if self.type == PUBLISHER or self.type == SUBSCRIBER: try: self.type_info = rostopic.get_topic_type( self.name)[0] # message type self.type_msg = self.type_info except rostopic.ROSTopicIOException as topic_exc: rospy.logwarn(topic_exc) elif self.type == SERVICE: try: self.type_info = rosservice.get_service_uri(self.name) self.type_msg = rosservice.get_service_type(self.name) except rosservice.ROSServiceIOException as service_exc: rospy.logwarn(service_exc) elif self.type == ACTION_SERVER or self.type == ACTION_CLIENT: try: goal_topic = self.name + '/goal' goal_topic_type = rostopic.get_topic_type(goal_topic) self.type_info = re.sub( 'ActionGoal$', '', goal_topic_type[0]) # Base type for action self.type_msg = self.type_info except rostopic.ROSTopicIOException as topic_exc: rospy.logwarn(topic_exc.msg) return self # chaining
def trigger_configuration(self): """ Callback when the configuration button is clicked """ image_topics = sorted(rostopic.find_by_type('sensor_msgs/Image')) try: topic_index = image_topics.index(self._sub.resolved_name) except (AttributeError, ValueError): topic_index = 0 topic_name, ok = QInputDialog.getItem(self._widget, "Select topic name", "Topic name", image_topics, topic_index) if ok: self._create_subscriber(topic_name) available_rosservices = [] for s in rosservice.get_service_list(): try: if rosservice.get_service_type(s) in _SUPPORTED_SERVICES: available_rosservices.append(s) except: pass try: srv_index = available_rosservices.index(self._srv.resolved_name) except (AttributeError, ValueError): srv_index = 0 srv_name, ok = QInputDialog.getItem(self._widget, "Select service name", "Service name", available_rosservices, srv_index) if ok: self._create_service_client(srv_name)
def _refresh_ctrlers_cb(self): try: # refresh the list of controller managers we can find srv_list = rosservice.get_service_list() ctrlman_ns_list_cur = [] for srv_name in srv_list: if 'controller_manager/list_controllers' in srv_name: srv_type = rosservice.get_service_type(srv_name) if srv_type == 'controller_manager_msgs/ListControllers': ctrlman_ns = srv_name.split('/controller_manager/list_controllers')[0] if ctrlman_ns == '': ctrlman_ns = '/' # ctrlman_ns is a Controller Manager namespace if ctrlman_ns not in self.list_ctrlers: # we haven't connected to it yet, create the service proxies self.controller_manager_connect(ctrlman_ns) ctrlman_ns_list_cur.append(ctrlman_ns) # remove every controller manager which isn't up anymore for ctrlman_ns_old in self.list_ctrlers.keys(): if ctrlman_ns_old not in ctrlman_ns_list_cur: self.controller_manager_disconnect(ctrlman_ns_old) # refresh the controller list for the current controller manager self.refresh_loadable_ctrlers() self.refresh_ctrlers() except Exception as e: self.sig_sysmsg.emit(e.message)
def __check_service(self, service_name): if rosservice.get_service_type(service_name): # None self._print_info("Checking service '%s': OK" % service_name) return 'succeeded' else: self.ALL_OK = False self._print_fatal("Checking service '%s': Failed" % service_name) return 'aborted'
def checkService(self, service_name): if rosservice.get_service_type(service_name): rospy.loginfo('Checking service %s: OK' % service_name) return 'succeeded' else: rospy.logerr('Checking service %s: Failed' % service_name) self.ALL_OK = False return 'aborted'
def test_offline(self): import rosservice orig_uri = os.environ['ROS_MASTER_URI'] os.environ['ROS_MASTER_URI'] = 'http://fake_host:12356' try: c = 'rosservice' try: rosservice.get_service_type('/add_two_ints') self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass try: rosservice._rosservice_cmd_list([c, 'list']) self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass try: rosservice._rosservice_cmd_info([c, 'info', '/add_two_ints']) self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass try: rosservice._rosservice_cmd_type([c, 'type', '/add_two_ints']) self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass try: rosservice._rosservice_cmd_uri([c, 'uri', '/add_two_ints']) self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass try: rosservice._rosservice_cmd_find([c, 'find', 'test_ros/AddTwoInts']) self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass try: rosservice._rosservice_cmd_call([c, 'call', '/add_two_ints', '1', '2']) self.fail("should have raised ROSServiceIOException") except rosservice.ROSServiceIOException: pass finally: os.environ['ROS_MASTER_URI'] = orig_uri
def create_ros_graph_snapshot(): master = rosgraph.Master('snapshot') node_names = list() nodes = list() params = list() services_dict = dict() topics_dict = dict() if not (master.is_online()): print("Error: ROSMaster not found") # Get parameters for param_name in master.getParamNames(): if param_name not in BLACK_LIST_PARAM and not ( param_name.startswith('/roslaunch')): params.append(param_name) state = master.getSystemState() #get the system state pubs, subs, services = state #get all topics type topic_list = master.getTopicTypes() for topic, topic_type in topic_list: topics_dict[topic] = topic_type #get all service types for service_name, _ in services: services_dict[service_name] = rosservice.get_service_type(service_name) # Get all nodes for s in state: for _, l in s: for n in l: if n not in BLACK_LIST_NODE: node_names.append(n) node_names = list(set(node_names)) for n in node_names: node = rg.Node(n) for pub, nodes_name in pubs: if not check_black_list(pub, BLACK_LIST_TOPIC): continue if n in nodes_name: node.publishers.add(rg.Interface(pub, topics_dict[pub])) for sub, nodes_name in subs: if not check_black_list(sub, BLACK_LIST_TOPIC): continue if n in nodes_name: node.subscribers.add(rg.Interface(sub, topics_dict[sub])) for serv, nodes_name in services: if not check_black_list(serv, BLACK_LIST_SERV): continue if n in nodes_name: node.services.add(rg.Interface(serv, services_dict[serv])) node.check_actions() nodes.append(node) return nodes
def get_service_type(self, svc_name, clb=None): """ Args: svc (str): The ROS Service name. clb (function, optional): Callback function that is called upon response is received. """ service_type = rosservice.get_service_type(svc_name) return service_type
def get_controller_namespaces(): service_list = rosservice.get_service_list() for service in service_list: try: service_type = rosservice.get_service_type(service) except rosservice.ROSServiceIOException: pass else: if service_type == 'controller_manager_msgs/ListControllers': yield service.split('/')[1]
def get_services(): try: services = get_service_list() content = [] for i in services: content.append([i, get_service_type(i), get_service_node(i)]) return jsonify(status=0, result=content) except: return jsonify(status=-1, result=[])
def _configure_internal_services(self, service_names): """ Create rospy handles to all of the services that we are configured to be able to call. """ i = 0 for name in service_names: rospy.loginfo("configuring service %s", name) resolved_name = rospy.resolve_name(name) rospy.wait_for_service(name, timeout=60.) type_ = rosservice.get_service_type(resolved_name) if type_ is None: raise rospy.ROSInitException( "cannot proxy service [%s]: unknown type" % resolved_name) i += 1 # for efficiency, we generate a passthrough service # definition that does not do any serializatoin on the # request or response. This requires more work because the # instantiated class has to have the correct properties. real_service_class = roslib.message.get_service_class(type_) real_req = real_service_class._request_class real_resp = real_service_class._response_class request_d = { '_type': real_req._type, '_md5sum': real_req._md5sum, '_full_text': real_req._full_text, } response_d = { '_type': real_resp._type, '_md5sum': real_resp._md5sum, '_full_text': real_resp._full_text, } service_class = classobj( 's_passthrough_%s' % i, (object, ), { '_type': real_service_class._type, '_md5sum': real_service_class._md5sum, '_request_class': classobj('passthrough_request_%s' % i, (PassthroughServiceMessage, ), request_d), '_response_class': classobj('passthrough_response_%s' % i, (PassthroughServiceMessage, ), response_d), }) self.services[resolved_name] = rospy.ServiceProxy(name, service_class, persistent=True) rospy.loginfo("proxying %s", resolved_name)
def generate_advertisement_connection_details(self, connection_type, name, node): ''' Creates all the extra details to create a connection object from an advertisement rule. This is a bit different to the previous one - we just need the type and single node uri that everything originates from (don't need to generate all the pub/sub connections themselves. Probably flips could be merged into this sometime, but it'd be a bit gnarly. @param connection_type : the connection type (one of gateway_msgs.msg.ConnectionType) @type string @param name : the name of the connection @type string @param node : the master node name it comes from @param string @return the utils.Connection object complete with type_info and xmlrpc_uri @type utils.Connection ''' # Very important here to check for the results of xmlrpc_uri and especially topic_type # https://github.com/robotics-in-concert/rocon_multimaster/issues/173 # In the watcher thread, we get the local connection index (whereby the arguments of this function # come from) via master.get_connection_state. That means there is a small amount of time from # getting the topic name, to checking for hte xmlrpc_uri and especially topic_type here in which # the topic could have disappeared. When this happens, it returns None. connection = None xmlrpc_uri = self.lookupNode(node) if xmlrpc_uri is None: return connection if connection_type == rocon_python_comms.PUBLISHER or connection_type == rocon_python_comms.SUBSCRIBER: type_info = rostopic.get_topic_type(name)[0] # message type if type_info is not None: connection = utils.Connection( gateway_msgs.Rule(connection_type, name, node), type_info, type_info, xmlrpc_uri) elif connection_type == rocon_python_comms.SERVICE: type_info = rosservice.get_service_uri(name) type_msg = rosservice.get_service_type(name) if type_info is not None: connection = utils.Connection( gateway_msgs.Rule(connection_type, name, node), type_msg, type_info, xmlrpc_uri) elif connection_type == rocon_python_comms.ACTION_SERVER or connection_type == rocon_python_comms.ACTION_CLIENT: goal_topic = name + '/goal' goal_topic_type = rostopic.get_topic_type(goal_topic) type_info = re.sub('ActionGoal$', '', goal_topic_type[0]) # Base type for action if type_info is not None: connection = utils.Connection( gateway_msgs.Rule(connection_type, name, node), type_info, type_info, xmlrpc_uri) return connection
def get_service_class_by_service_name(service_name): #TODO: this is technically a bug because it doesn't use the ctx's #master handle type_name = rosservice.get_service_type(service_name) if type_name: val = roslib.message.get_service_class(type_name, reload_on_error=True) if not val: pkg, base_type = roslib.names.package_resource_name(type_name) print >> sys.stderr, """Cannot retrieve type [%s]. Please type 'rosmake %s' """%(type_name, pkg) else: return val
def _srv_exists(srv_name, srv_type): """ Check if a ROS service of specific name and type exists. This method has the overhead of one ROS master query. @param srv_name: Fully qualified service name @type srv_name: str @param srv_type: Service type @type srv_type: str """ if not srv_name or not srv_type: return False return srv_type == rosservice.get_service_type(srv_name)
def service_type_resolver( self, service_name): # function resolving the type of a service if service_name in self.services_available_type.keys(): service_type = self.services_available_type[service_name] else: try: resolved_service_name = rospy.resolve_name( service_name) # required or not ? service_type = rosservice.get_service_type( resolved_service_name ) # maybe better to store and retrieve from update instead? except rosservice.ROSServiceIOException: # exception can occur -> just reraise raise return service_type
def get_service_info(service_name): """ GET /api/<version>/service/<service_name> GET information about a ROS service. """ service_name = "/" + service_name service_type = rosservice.get_service_type(service_name) if not service_type: return error("No such service exists") return jsonify({ "request_type": service_type, "node": rosservice.get_service_node(service_name), "args": rosservice.get_service_args(service_name).split(" ") })
def add_service(self, service_name, ws_name=None, service_type=None): resolved_service_name = rospy.resolve_name(service_name) if service_type is None: service_type = rosservice.get_service_type(resolved_service_name) if not service_type: print 'Unknown service %s' % service_name return False if ws_name is None: ws_name = service_name if ws_name.startswith('/'): ws_name = ws_name[1:] self.services[ws_name] = Service(service_name, service_type) return True
def get_service_types(self, services): service_types = [] for service in services: if service: try: service_name_str = str(service[0]) service_type_str = rosservice.get_service_type(service_name_str) if service_type_str is not None: service_types.append([service_name_str, service_type_str]) except rospy.ServiceException as e: rospy.logerr("Information is invalid for the service : %s . %s" % (service_name_str, e)) continue except rosservice.ROSServiceIOException as e: rospy.logerr("Unable to communicate with service : %s . %s" % (service_name_str, e)) continue return service_types
def get_service_types(self, services): service_types = [] for service in services: if service: try: service_name_str = str(service[0]) service_type_str = rosservice.get_service_type(service_name_str) if service_type_str is not None: service_types.append([service_name_str, service_type_str]) except rospy.ServiceException as e: rospy.logerr("Information is invalid for the service : %s . %s" % (service_name_str, e)) continue except rospy.ServiceIOException as e: rospy.logerr("Unable to communicate with service : %s . %s" % (service_name_str, e)) continue return service_types
def _generate_tool_tip(self, url): if url is not None and ':' in url: item_type, item_path = url.split(':', 1) if item_type == 'node': tool_tip = 'Node:\n %s' % (item_path) service_names = rosservice.get_service_list(node=item_path) if service_names: tool_tip += '\nServices:' for service_name in service_names: try: service_type = rosservice.get_service_type(service_name) tool_tip += '\n %s [%s]' % (service_name, service_type) except rosservice.ROSServiceIOException, e: tool_tip += '\n %s' % (e) return tool_tip elif item_type == 'topic': topic_type, topic_name, _ = rostopic.get_topic_type(item_path) return 'Topic:\n %s\nType:\n %s' % (topic_name, topic_type)
def transient_type_resolver( self, service_name): # function resolving the type of a service svc = self.available.get(service_name) if svc: if svc.type is None: # if the type is unknown, lets discover it (needed to interface) try: resolved_service_name = rospy.resolve_name( service_name) # required or not ? svc.type = rosservice.get_service_type( resolved_service_name) except rosservice.ROSServiceIOException: # exception can occur -> just reraise raise return svc.type # return the type else: rospy.logerr( "ERROR while resolving {service_name}. Service not known as available. Ignoring" .format(**locals())) return None
def _configure_internal_services(self, service_names): """ Create rospy handles to all of the services that we are configured to be able to call. """ i = 0 for name in service_names: rospy.loginfo("configuring service %s", name) resolved_name = rospy.resolve_name(name) rospy.wait_for_service(name, timeout=60.) type_ = rosservice.get_service_type(resolved_name) if type_ is None: raise rospy.ROSInitException("cannot proxy service [%s]: unknown type"%resolved_name) i += 1 # for efficiency, we generate a passthrough service # definition that does not do any serializatoin on the # request or response. This requires more work because the # instantiated class has to have the correct properties. real_service_class = roslib.message.get_service_class(type_) real_req = real_service_class._request_class real_resp = real_service_class._response_class request_d = { '_type': real_req._type, '_md5sum': real_req._md5sum, '_full_text': real_req._full_text, } response_d = { '_type': real_resp._type, '_md5sum': real_resp._md5sum, '_full_text': real_resp._full_text, } service_class = classobj('s_passthrough_%s'%i, (object,), { '_type' : real_service_class._type, '_md5sum' : real_service_class._md5sum, '_request_class' : classobj('passthrough_request_%s'%i, (PassthroughServiceMessage, ), request_d), '_response_class' : classobj('passthrough_response_%s'%i, (PassthroughServiceMessage,), response_d), }) self.services[resolved_name] = rospy.ServiceProxy(name, service_class, persistent=True) rospy.loginfo("proxying %s", resolved_name)
def call_service(service, args=None): # Given the service name, fetch the type and class of the service, # and a request instance service_type = get_service_type(str(service)) if service_type is None: raise InvalidServiceException(service) service_class = get_service_class(service_type) inst = get_service_request_instance(service_type) # Populate the instance with the provided args args_to_service_request_instance(service, inst, args) # Call the service proxy = ServiceProxy(service, service_class) response = proxy.call(inst) # Turn the response into JSON and pass to the callback json_response = extract_values(response) return json_response
def trigger_configuration(self): """ Callback when the configuration button is clicked """ topic_name, ok = QInputDialog.getItem(self._widget, "Select topic name", "Topic name", rostopic.find_by_type('sensor_msgs/Image')) if ok: self._create_subscriber(topic_name) available_rosservices = [] for s in rosservice.get_service_list(): try: if rosservice.get_service_type(s) in _SUPPORTED_SERVICES: available_rosservices.append(s) except: pass srv_name, ok = QInputDialog.getItem(self._widget, "Select service name", "Service name", available_rosservices) if ok: self._create_service_client(srv_name)
def trigger_configuration(self): topic_name, ok = QInputDialog.getItem( self._widget, "Select topic name", "Topic name", rostopic.find_by_type('sensor_msgs/Image')) if ok: self._create_subscriber(topic_name) available_rosservices = [] for s in rosservice.get_service_list(): try: if rosservice.get_service_type( s) == "object_recognition_srvs/Recognize": available_rosservices.append(s) except: pass srv_name, ok = QInputDialog.getItem(self._widget, "Select service name", "Service name", available_rosservices) if ok: self._create_service_client(srv_name)
def find_service_namespace(service_name, service_type=None, unique=False): ''' Find a namespace corresponding with service name and service type. :param str service_name: unresolved name of the service looked for (e.g. 'get_interactions', not '/concert/interactions/get_interactions') :param str service_type: type name of service looked for (e.g. std_msgs/String) if service_type is None, it does not check type :param bool unique: flag to select the lookup behaviour (single/multiple results) :returns: the namespace corresponding with service name and type(unique) or list of namespaces (non-unique) :rtype: str :raises: :exc:`.MultipleFoundException` If it find multiple service if unique flag is on :raises: :exc:`.NotFoundException` If it does not find service name in registerd :raises: :exc:`.ROSServiceIOException` If it disconnect with ros master ''' try: master = rosgraph.Master(rospy.get_name()) _, _, srvs = master.getSystemState() found_namespaces = [] for s, nodelist in srvs: if not service_type: if s.split('/')[-1] == service_name and get_service_type( s) == service_type: found_namespaces.append(nodelist[0]) else: if s.split('/')[-1] == service_name: found_namespaces.append(nodelist[0]) if len(found_namespaces) == 0: raise NotFoundException(str(service_name)) if unique: if len(found_namespaces) > 1: raise MultipleFoundException(str(found_namespaces)) else: return found_namespaces[0] else: return found_namespaces except socket.error: raise ROSServiceIOException("unable to communicate with master!")
def find_service_namespace(service_name, service_type=None, unique=False): ''' Find a namespace corresponding with service name and service type. :param str service_name: unresolved name of the service looked for (e.g. 'get_interactions', not '/concert/interactions/get_interactions') :param str service_type: type name of service looked for (e.g. std_msgs/String) if service_type is None, it does not check type :param bool unique: flag to select the lookup behaviour (single/multiple results) :returns: the namespace corresponding with service name and type(unique) or list of namespaces (non-unique) :rtype: str :raises: :exc:`.MultipleFoundException` If it find multiple service if unique flag is on :raises: :exc:`.NotFoundException` If it does not find service name in registerd :raises: :exc:`.ROSServiceIOException` If it disconnect with ros master ''' try: master = rosgraph.Master(rospy.get_name()) _, _, srvs = master.getSystemState() found_namespaces = [] for s, nodelist in srvs: if not service_type: if s.split('/')[-1] == service_name and get_service_type(s) == service_type: found_namespaces.append(nodelist[0]) else: if s.split('/')[-1] == service_name: found_namespaces.append(nodelist[0]) if len(found_namespaces) == 0: raise NotFoundException(str(service_name)) if unique: if len(found_namespaces) > 1: raise MultipleFoundException(str(found_namespaces)) else: return found_namespaces[0] else: return found_namespaces except socket.error: raise ROSServiceIOException("unable to communicate with master!")
def typeStringFromService(self, service): try: return rosservice.get_service_type(service) except: print "Can't find service %s" % (service,) return None
def test_get_service_type(self): import rosservice self.assertEquals('test_rosmaster/AddTwoInts', rosservice.get_service_type('/add_two_ints')) self.assertEquals(None, rosservice.get_service_type('/fake_add_two_ints'))
message_file_paths.append(new_f) final_f_paths_qtty = len(message_file_paths) print "We are sure that " + str( final_f_paths_qtty) + " message files are depended." # Get services print "Getting current services..." # Returns a list of services and their node providing it services = master.getSystemState()[2] service_names = [s[0] for s in services] srvs_qtty = len(service_names) print "Found " + str(srvs_qtty) + " services." services_and_types = [] for name in service_names: type_ = get_service_type(name) services_and_types.append([name, type_]) # print "Service: '" + name + "' has type: '" + type_ + "'" srv_types_list = [] for service, type_ in services_and_types: if type_ not in srv_types_list: srv_types_list.append(type_) unique_srvs_qtty = len(srv_types_list) print "Found " + str(unique_srvs_qtty) + " service messages used." pkgs_and_srvs_dict = {} srvs_msg_paths = [] for t in srv_types_list: pkg_name, msg_name = t.split('/')
def typeStringFromService(self, service): try: return rosservice.get_service_type(service) except: print "Can't find service %s" % (service, ) return None
def typeStringFromService(self, service): try: return rosservice.get_service_type(service) except: return None
import rosservice import rostopic import rosnode from rospy import client if __name__ == '__main__': service_list = rosservice.get_service_list() list = client.get_published_topics('/') type = rostopic.get_topic_type('/rosout_agg') type = rosservice.get_service_type('/rosout/get_loggers') printvalue = True # question = "select the topics" # title = "bridge" # listofoptions = ["option1" , "option2"] # choise = easygui.multchoicebox(question,title,listofoptions) pass
def generate_connection_details(self, connection_type, name, node): """ Creates all the extra details to create a connection object from a rule. @param connection_type : the connection type (one of gateway_msgs.msg.ConnectionType) @type string @param name : the name of the connection @type string @param node : the master node name it comes from @param string @return the utils.Connection object complete with type_info and xmlrpc_uri @type utils.Connection """ # Very important here to check for the results of xmlrpc_uri and especially topic_type # https://github.com/robotics-in-concert/rocon_multimaster/issues/173 # In the watcher thread, we get the local connection index (whereby the arguments of this function # come from) via master.get_connection_state. That means there is a small amount of time from # getting the topic name, to checking for hte xmlrpc_uri and especially topic_type here in which # the topic could have disappeared. When this happens, it returns None. connections = [] xmlrpc_uri = node.split(",")[1] node = node.split(",")[0] if xmlrpc_uri is None: return connections if connection_type == rocon_python_comms.PUBLISHER or connection_type == rocon_python_comms.SUBSCRIBER: type_info = rostopic.get_topic_type(name)[0] # message type if type_info is not None: connections.append( utils.Connection( gateway_msgs.Rule(connection_type, name, node), type_info, type_info, xmlrpc_uri)) else: rospy.logwarn( 'Gateway : [%s] does not have type_info. Cannot flip' % name) elif connection_type == rocon_python_comms.SERVICE: type_info = rosservice.get_service_uri(name) type_msg = rosservice.get_service_type(name) if type_info is not None: connections.append( utils.Connection( gateway_msgs.Rule(connection_type, name, node), type_msg, type_info, xmlrpc_uri)) elif connection_type == rocon_python_comms.ACTION_SERVER: goal_type_info = rostopic.get_topic_type(name + '/goal')[ 0] # message type cancel_type_info = rostopic.get_topic_type(name + '/cancel')[ 0] # message type status_type_info = rostopic.get_topic_type(name + '/status')[ 0] # message type feedback_type_info = rostopic.get_topic_type(name + '/feedback')[ 0] # message type result_type_info = rostopic.get_topic_type(name + '/result')[ 0] # message type if (goal_type_info is not None and cancel_type_info is not None and status_type_info is not None and feedback_type_info is not None and result_type_info is not None): connections.append( utils.Connection( gateway_msgs.Rule(rocon_python_comms.SUBSCRIBER, name + '/goal', node), goal_type_info, goal_type_info, xmlrpc_uri)) connections.append( utils.Connection( gateway_msgs.Rule(rocon_python_comms.SUBSCRIBER, name + '/cancel', node), cancel_type_info, cancel_type_info, xmlrpc_uri)) connections.append( utils.Connection( gateway_msgs.Rule(rocon_python_comms.PUBLISHER, name + '/status', node), status_type_info, status_type_info, xmlrpc_uri)) connections.append( utils.Connection( gateway_msgs.Rule(rocon_python_comms.PUBLISHER, name + '/feedback', node), feedback_type_info, feedback_type_info, xmlrpc_uri)) connections.append( utils.Connection( gateway_msgs.Rule(rocon_python_comms.PUBLISHER, name + '/result', node), result_type_info, result_type_info, xmlrpc_uri)) elif connection_type == rocon_python_comms.ACTION_CLIENT: goal_type_info = rostopic.get_topic_type(name + '/goal')[ 0] # message type cancel_type_info = rostopic.get_topic_type(name + '/cancel')[ 0] # message type status_type_info = rostopic.get_topic_type(name + '/status')[ 0] # message type feedback_type_info = rostopic.get_topic_type(name + '/feedback')[ 0] # message type result_type_info = rostopic.get_topic_type(name + '/result')[ 0] # message type if (goal_type_info is not None and cancel_type_info is not None and status_type_info is not None and feedback_type_info is not None and result_type_info is not None): connections.append( utils.Connection( gateway_msgs.Rule(rocon_python_comms.PUBLISHER, name + '/goal', node), goal_type_info, goal_type_info, xmlrpc_uri)) connections.append( utils.Connection( gateway_msgs.Rule(rocon_python_comms.PUBLISHER, name + '/cancel', node), cancel_type_info, cancel_type_info, xmlrpc_uri)) connections.append( utils.Connection( gateway_msgs.Rule(rocon_python_comms.SUBSCRIBER, name + '/status', node), status_type_info, status_type_info, xmlrpc_uri)) connections.append( utils.Connection( gateway_msgs.Rule(rocon_python_comms.SUBSCRIBER, name + '/feedback', node), feedback_type_info, feedback_type_info, xmlrpc_uri)) connections.append( utils.Connection( gateway_msgs.Rule(rocon_python_comms.SUBSCRIBER, name + '/result', node), result_type_info, result_type_info, xmlrpc_uri)) return connections
def getServiceType(service): """ Returns the type of the specified ROS service, """ try: return rosservice.get_service_type(service) except: return ""
def arch(): try: rospy.init_node('handler', anonymous=True) currentServices = [] loggerCount = 0 last_topics = [] last_nodes = [] last_publish = {} last_publish1 = {} currentTopics = [] loggerCount = 0 global currentReported global serviceExpeptions global noServiceIntermediator global oldnoServiceIntermediator service_dict = {} old_service_dict = {} length = 0 updated = False oldReported = list() while not rospy.is_shutdown(): new_topics = rospy.get_published_topics() new_nodes = rosnode.get_node_names() new_publish = {} new_publish1 = {} inc_topics = [ item for item in new_topics if item not in last_topics ] inc_nodes = [item for item in new_nodes if item not in last_nodes] inc_service_dict = {} inc_publish = {} inc_publish1 = {} inc_service_dict = {} inc_reported = {} for topic, typ in new_topics: info = rostopic.get_info_text(topic) subscribers = parse_info_sub(info) publishers = parse_info_pub(info) new_publish[topic] = set(subscribers) new_publish1[topic] = set(publishers) if (topic not in last_publish.keys() ) or set(subscribers) != last_publish[topic]: inc_publish[topic] = set(subscribers) if (topic not in last_publish1.keys() ) or set(publishers) != last_publish1[topic]: inc_publish1[topic] = set(publishers) try: for newService, Provider in get_current_services(): if not newService in currentServices: currentServices.append(newService) newServiceHandler(newService) service_dict[newService] = [ rosservice.get_service_type(newService), rosservice.get_service_args(newService) ] if (newService not in old_service_dict.keys() ) or service_dict[newService] != old_service_dict[ newService]: inc_service_dict[newService] = [ rosservice.get_service_type(newService), rosservice.get_service_args(newService) ] except Exception as e: print e pass if old_service_dict != service_dict: old_service_dict = dict(service_dict) updated = True inc_reported = [ item for item in currentReported if item not in oldReported ] oldReported = list(currentReported) if len(inc_reported) != 0: updated = True if noServiceIntermediator != oldnoServiceIntermediator: oldnoServiceIntermediator = list(noServiceIntermediator) print print print 'Services calls not being reported for these services: ' + str( noServiceIntermediator) if inc_topics or inc_nodes or inc_publish or inc_publish1 != inc_service_dict or inc_reported: y = {} y["topics"] = send_topics(inc_topics) y["nodes"] = send_nodes(inc_nodes) y["pub"] = sendPub(inc_publish) y["sub"] = sendSub(inc_publish1) y["service"] = inc_service_dict y["calls"] = inc_reported last_nodes = list(new_nodes) last_topics = list(new_topics) last_publish = dict(new_publish) last_publish1 = dict(new_publish1) updated = False requests.get(URL, data=json.dumps(y)) except Exception as e: print e pass
def get_service_type(self, srv): return rosservice.get_service_type(srv)
def arch(): try: rospy.init_node('handler', anonymous=True) currentServices = [] loggerCount = 0 last_topics = [] last_nodes = [] last_publish = {} last_publish1 = {} currentTopics = [] loggerCount = 0 global currentReported global serviceExpeptions global noServiceIntermediator global oldnoServiceIntermediator service_dict = {} old_service_dict = {} length = 0 updated = False oldReported = list() while not rospy.is_shutdown(): new_topics = rospy.get_published_topics() new_nodes = rosnode.get_node_names() new_publish = {} new_publish1 = {} inc_topics = [item for item in new_topics if item not in last_topics] inc_nodes = [item for item in new_nodes if item not in last_nodes] inc_service_dict = {} inc_publish = {} inc_publish1 = {} inc_service_dict = {} inc_reported = {} for topic, typ in new_topics: info = rostopic.get_info_text(topic) subscribers = parse_info_sub(info) publishers = parse_info_pub(info) new_publish[topic] = set(subscribers) new_publish1[topic] = set(publishers) if (topic not in last_publish.keys()) or set(subscribers) != last_publish[topic]: inc_publish[topic] = set(subscribers) if (topic not in last_publish1.keys()) or set(publishers) != last_publish1[topic]: inc_publish1[topic] = set(publishers) try: for newService, Provider in get_current_services(): if not newService in currentServices: currentServices.append(newService) newServiceHandler(newService) service_dict[newService] = [rosservice.get_service_type(newService), rosservice.get_service_args(newService)] if (newService not in old_service_dict.keys()) or service_dict[newService] != old_service_dict[newService]: inc_service_dict[newService] = [rosservice.get_service_type(newService), rosservice.get_service_args(newService)] except Exception as e: print e pass if old_service_dict != service_dict: old_service_dict = dict(service_dict) updated = True inc_reported = [item for item in currentReported if item not in oldReported] oldReported = list(currentReported) if len(inc_reported) != 0: updated = True if noServiceIntermediator != oldnoServiceIntermediator: oldnoServiceIntermediator = list(noServiceIntermediator) print print print 'Services calls not being reported for these services: ' + str(noServiceIntermediator) if inc_topics or inc_nodes or inc_publish or inc_publish1 != inc_service_dict or inc_reported: y = {} y["topics"] = send_topics(inc_topics) y["nodes"] = send_nodes(inc_nodes) y["pub"] = sendPub(inc_publish) y["sub"] = sendSub(inc_publish1) y["service"] = inc_service_dict y["calls"] = inc_reported last_nodes = list(new_nodes) last_topics = list(new_topics) last_publish = dict(new_publish) last_publish1 = dict(new_publish1) updated = False requests.get(URL, data=json.dumps(y)) except Exception as e: print e pass
def get_service_type(self,srv): return rosservice.get_service_type(srv)