Topics
Nodes communicate with each other using ROS 2 communication features. There are three types of communication: topics, services, and actions. We will discover all three of them, starting with topics.
Here, we will make some basic discoveries to get an idea of what a ROS 2 topic is, and you’ll learn much more about them, including how to write code for topics, in Chapter 5.
Running a topic publisher and subscriber
Stop all running nodes (Ctrl + C), and let’s come back to our first example.
In Terminal 1, input the following:
$ ros2 run demo_nodes_cpp talker
In Terminal 2, input the following:
$ ros2 run demo_nodes_cpp listener
In Terminal 3, input the following:
$ rqt_graph
If needed, refresh the view a few times, select Nodes/Topics (all), and you should get the same visual as in Figure 3.1.
In the middle, you will see a /chatter
box. This box represents a ROS 2 topic. What you can also see is that the talker node is sending something...