Skip to content

Commit 6d01e84

Browse files
committed
Get content of topic from launch_testing_ros::WaitForTopics
Signed-off-by: Giorgio Pintaudi [email protected] #346
1 parent 954a211 commit 6d01e84

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

launch_testing_ros/launch_testing_ros/wait_for_topics.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def method_2():
4646
print('Given topics are receiving messages !')
4747
print(wait_for_topics.topics_not_received()) # Should be an empty set
4848
print(wait_for_topics.topics_received()) # Should be {'topic_1', 'topic_2'}
49+
print(wait_for_topics.messages_received('topic_1')) # Should be [message_1, ...]
4950
wait_for_topics.shutdown()
5051
"""
5152

@@ -86,6 +87,12 @@ def topics_not_received(self):
8687
"""Topics that did not receive any messages."""
8788
return self.__ros_node.expected_topics - self.__ros_node.received_topics
8889

90+
def messages_received(self, topic_name):
91+
"""List of received messages of a specific topic."""
92+
if topic_name not in self.__ros_node.received_messages:
93+
raise KeyError("No message received with topic " + topic_name)
94+
return self.__ros_node.received_messages[topic_name]
95+
8996
def __enter__(self):
9097
if not self.wait():
9198
raise RuntimeError('Did not receive messages on these topics: ',
@@ -109,6 +116,7 @@ def start_subscribers(self, topic_tuples):
109116
self.subscriber_list = []
110117
self.expected_topics = {name for name, _ in topic_tuples}
111118
self.received_topics = set()
119+
self.received_messages = {}
112120

113121
for topic_name, topic_type in topic_tuples:
114122
# Create a subscriber
@@ -127,6 +135,7 @@ def topic_callback(data):
127135
if topic_name not in self.received_topics:
128136
self.get_logger().debug('Message received for ' + topic_name)
129137
self.received_topics.add(topic_name)
138+
self.received_messages.setdefault(topic_name, []).append(data)
130139
if self.received_topics == self.expected_topics:
131140
self.msg_event_object.set()
132141

0 commit comments

Comments
 (0)