0
$\begingroup$

Rosanswers logo

How to get the names of all topics that publish a given message? E.g. when I add an image viewer in RVIZ, it already lists for you all topics that publish a sensor_msgs/Image message, so you choose which one you want to subscribe to! How can I achieve something like this in C++? Say I have a message called A, I want to get the names of all topics that publish A. Appreciate any help or suggestions:-)


Originally posted by Martian on ROS Answers with karma: 7 on 2020-12-11

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Apologies if this is the wrong part of the rviz code that does what you're asking, but I think what you're looking for is ros::master::getTopics() which is used here https://github.com/ros-visualization/rviz/blob/3cdc03a5186a53f644c5abd55b9971457bdffa1c/src/rviz/add_display_dialog.cpp#L124 in rviz to get the list of topics and add them to the display for drop downs (~85% sure this is the right thing, but it was a quick glance, either way this will do what you're asking).

Here's the API docs for that file http://docs.ros.org/en/melodic/api/roscpp/html/master_8h.html and it clearly shows the basic "get info" style calls to get all the topics and nodes on the network graph.


Originally posted by stevemacenski with karma: 8272 on 2020-12-12

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Martian on 2020-12-12:
These links are more than enough for my question to be answered! Thanks a lot for the references:-)

$\endgroup$