From 3ab2e22e39d540e652248dc357033d8c1b96b6cb Mon Sep 17 00:00:00 2001 From: Greg Balke Date: Sun, 16 Feb 2020 13:54:44 -0800 Subject: [PATCH] Retrieve topics from ROS Host --- blue_interface/rosbridge_client.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/blue_interface/rosbridge_client.py b/blue_interface/rosbridge_client.py index 27e8e24..344278c 100644 --- a/blue_interface/rosbridge_client.py +++ b/blue_interface/rosbridge_client.py @@ -51,6 +51,23 @@ def id_counter(self): self._id_counter += 1 return self._id_counter + def get_topics(self, callback=None, errback=None): + """Retrieve list of topics in ROS. + Note: + To make this a blocking call, pass ``None`` to the ``callback`` parameter . + Returns: + list: List of topics if blocking, otherwise ``None``. + """ + service = _Service(self, '/rosapi/topics', 'rosapi/Topics') + + result = service.request({}, callback) + + if callback: + return + + assert 'topics' in result + return result['topics'] + def publisher(self, topic_name, message_type, latch=False, queue_size=1): """Create a _Publisher object if the given topic hasn't been advertised, otherwise return the existing publisher that is currently advertising the topic.