def get_topics(): """ Returns a list of all the active topics in the ROS system """ try: publishers, subscribers, services = Master('/rosbridge').getSystemState() return list(set([x for x, _ in publishers] + [x for x, _, in subscribers])) except: return []
def get_topics(topics_glob): """ Returns a list of all the active topics in the ROS system """ try: publishers, subscribers, services = Master('/rosbridge').getSystemState() # Filter the list of topics by whether they are public before returning. return filter_globs(topics_glob, list(set([x for x, _ in publishers] + [x for x, _, in subscribers]))) except: return []
def get_service_providers(queried_type, services_glob): """ Returns a list of node names that are advertising a service with the specified type """ _, _, services = Master('/rosbridge').getSystemState() service_type_providers = [] for service, providers in services: service_type = get_service_type(service, services_glob) if service_type == queried_type: service_type_providers += providers return service_type_providers
def get_service_providers(servicetype): """ Returns a list of node names that are advertising a service with the specified type """ try: publishers, subscribers, services = Master('/rosbridge').getSystemState() servdict = dict(services) if servicetype in servdict: return servdict[servicetype] else: return [] except socket.error: return []
def get_subscribers(topic): """ Returns a list of node names that are subscribing to the specified topic """ try: publishers, subscribers, services = Master('/rosbridge').getSystemState() subdict = dict(subscribers) if topic in subdict: return subdict[topic] else: return [] except socket.error: return []
def get_node_publications(node): """ Returns a list of topic names that are been published by the specified node """ try: publishers, subscribers, services = Master('/rosbridge').getSystemState() toReturn = [] for i, v in publishers: if node in v: toReturn.append(i) toReturn.sort() return toReturn except socket.error: return []
def get_topic_types(tlist): """Query the master about topics and their types.""" master = Master('/' + PROJ_NAME) ttdict = dict(master.getTopicTypes()) want = set(tlist) have = set(ttdict.keys()) missing = want - have if missing: raise GeneratorException("Unknown topic(s) referenced: %s" % ', '.join(missing)) return {to: ttdict[to] for to in (set(ttdict.keys()) & set(tlist))}
def get_publishers(topic, topics_glob): """ Returns a list of node names that are publishing the specified topic """ try: if any_match(str(topic), topics_glob): publishers, subscribers, services = Master('/rosbridge').getSystemState() pubdict = dict(publishers) if topic in pubdict: return pubdict[topic] else: return [] else: return [] except socket.error: return []
def get_topics_types(topics, topics_glob): try: # Get all types from master once topic_types = { topic: type for topic, type in Master('/rosbridge').getTopicTypes() } types = [] for i in topics: # Make sure topic is public & published if any_match(str(i), topics_glob) and i in topic_types: types.append(topic_types[i]) else: types.append("") return types except: return []
def __init__(self, include_regex_into_topic_names=True, prefix=DEFAULT_NAME): """ :param include_regex_into_topic_names: Whether names of update topic should contain the pattern. Just for better debugging. Has no influence on functionality :param prefix: address of the topic listener. The address is used for the subscribe service and all update topics. """ self.__handler = Master(rospy.get_name( )) # get access to the ROS master to use the topic directoy self.__lock = Lock() self.__update_topics = {} self.__include_regex_into_topic_names = include_regex_into_topic_names self.__topic_counter = 0 self.__subscribed_regular_expressions = [] self.__prefix = prefix self.__subscribe_service = rospy.Service( self.__prefix + TopicListener.SUBSCRIBE_SERVICE_NAME_POSTFIX, TopicUpdateSubscribe, self.__subscribe_callback_thread_safe) self.__existing_topics = []
def get_topics_and_types(topics_glob): """ Returns a list of all the active topics in the ROS system """ try: # Function getTopicTypes also returns inactive topics and does not # return topics with unknown message types, so it must be compared # to results from getSystemState. master = Master('/rosbridge') topic_types = master.getTopicTypes() publishers, subscribers, services = master.getSystemState() topics = set([x for x, _ in publishers] + [x for x, _ in subscribers]) # Filter the list of topics by whether they are public. topics = set(filter_globs(topics_glob, topics)) topic_types = [x for x in topic_types if x[0] in topics] # Add topics with unknown type messages. unknown_type = topics.difference([x for x, _ in topic_types]) return zip(*topic_types + [[x, ''] for x in unknown_type]) except: return []