ROS 2 Topics & rqt_graph
Be brave enough to start a conversation that matters. – Margaret Wheatley
Introduction
In the previous post, I discussed Robot Operating System 2 Nodes. This post expands upon that one and discusses ROS 2 topics.
ROS Topics
A tutorial at ros.org on this topic (no pun intended) is here. ROS 2 communicates via a system of publisher and subscriber Nodes as in this figure:
That said, topics don’t have to only be point-to-point communications; they can be one-to-many or many-to-many as well. The tutorial walks you through starting up turtlesim and rqt_graph. My graph looks like this:
When you are in rqt_graph you can hover the mouse over any area in the window to get more info on the area under the mouse. As documented:
The graph is depicting how the
/turtlesim
node and the/teleop_turtle
node are communicating with each other over a topic. The/teleop_turtle
node is publishing data (the keystrokes you enter to move the turtle around) to the/turtle1/cmd_vel
topic, and the/turtlesim
node is subscribed to that topic to receive the data
You can get a more detailed view by unchecking all of the hide boxes:
Operations on Topics
The tutorial covers various command line operations on topics such as list, echo, info, and rates. You can also show the types of messages flowing over your topics with ros2 interface show. For example:
You can also publish out messages via the “ros2 topic pub” command line call or query the rate messages are being sent with “ros2 topic hz.” Examples are available in the tutorial. Optionally, you may also parameterize ROS 2.
Other Message Passing Mechanisms
Another way ROS 2 can pass messages is with service calls, covered here. The main gotcha with service calls is they are not guaranteed to respond to a request, especially over wireless networks and particularly not when nodes are over the horizon. Be especially careful when defining callbacks. As an alternative to services, another communication method available in ROS 2 are actions, documented here.