Robotics StackExchange | Archived questions

[ROS2] How to know which topics are related to a node without running it?

Hey,

I'm just starting to learn ROS2 and I'm wondering whether it is possible to know the default topics of a node (or should I say an executable?) before you run it. Something like `ros2 node info turtlesim_node' but not having to start it first? Is there a command line tool for it?

Asked by Lucivius on 2022-11-29 14:31:34 UTC

Comments

Answers

Hi,

You can just go into the node file and look for publishers or subscribers. It would be located somewhere like this:

~/ros2_ws/src/package/package/src/file.cpp (it can also be a Python file)

For step by step instructions, check out this video: https://youtu.be/Ny7AL2XlXmY

Asked by rodrigo55 on 2022-12-07 09:15:26 UTC

Comments

For ROS 2, below command should print out the lines that contains the create_publisher inside the code to the terminal and you can extract the info such as topic name topic type etc from there. this should work with python and cpp

cat <path_to_source_file> | grep "create_publisher"

For ROS1, use

cat <path_to_source_file> | grep "advertise" for cpp and cat <path_to_source_file> | grep "Publisher" for python.

Asked by aarsh_t on 2022-12-07 10:33:59 UTC

Comments