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_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 []