0
$\begingroup$

Rosanswers logo

Hi, let's say I want to subscribe multiple topics in one node. All the topics are named with same prefix, such as "/prefix_topic_a","/prefix_topic_b","/prefix_topic_c"...

Since the amount is not fixed, a hard-coding of subscription topic cannot be used. Is there anyway to find all topics with a certain prefix and automatically create subscribers for each topic? maybe using fuzzy string matching? Thanks!


Originally posted by runtao on ROS Answers with karma: 27 on 2020-11-27

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

It was interesting to me to check it out: https://answers.ros.org/question/206893/getting-list-of-published-topics-from-within-c-code/ You can get a list of topics from the C++ code, as shown in If you can get the topics, you'll be able to make partial matches or create a subscriber from them.


Originally posted by miura with karma: 1908 on 2020-11-28

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by runtao on 2020-11-28:
@miura, thanks, but it uses the master node in ROS1, which ROS2 dosen't have. How could the functionality be used in ROS2?

Comment by miura on 2020-11-28:
For ROS2, it seems that get_topic_names_and_types can be used.

You can also use get_topic_names_and_types in ROS2. http://docs.ros2.org/bouncy/api/rclcpp/classrclcpp_1_1node__interfaces_1_1_node_graph.html#a8389b748a52ef6280f5ac124ef153260

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.