3. Nodes, topics, messages
These three words are all you need to read a ROS 2 system.
Term |
What it is |
Everyday equivalent |
|---|---|---|
node |
One small program doing one job |
One employee |
topic |
A named channel carrying data |
A labelled conveyor belt |
message |
The shape of the data sent |
An agreed form |
A node that sends into a topic is a publisher; one that receives is a subscriber.
Important
A publisher does not know who is listening, and does not care whether anyone is. It publishes and is done. Zero subscribers or ten, it behaves identically.
That is what makes the system flexible — and it is also why failures can be silent. Publish with nobody listening and nothing complains.
Try it with turtlesim
turtlesim ships with ROS 2 and is the fastest way to see this working.
Open three terminals (source /opt/ros/humble/setup.bash in each).
Terminal 1 — the turtle window
ros2 run turtlesim turtlesim_node
Terminal 2 — drive it with the arrow keys
ros2 run turtlesim turtle_teleop_key
Press the arrows and the turtle moves (this terminal must have focus).
Terminal 3 — watch the data in flight
ros2 topic echo /turtle1/cmd_vel
Press an arrow again and you will see:
linear:
x: 2.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0
Tip
This is the single most valuable thing ROS 2 gives you. You just watched the data flowing between two programs without modifying either one and without stopping them.
When a real robot will not move, this is the first command to run — it tells you immediately whether the command is even being sent.
The shape of a message
That data is a geometry_msgs/msg/Twist. See its full definition:
ros2 interface show geometry_msgs/msg/Twist
Vector3 linear
Vector3 angular
linear.x is forward speed in m/s; angular.z is turning rate in rad/s.
Note
Twist is exactly what a real AGV is commanded with, over a topic called
/cmd_vel. This turtle and a 200 kg robot take the identical message.
That is genuinely useful — code that drives the turtle drives the real robot with almost no changes.
See who talks to whom
ros2 node list
/turtlesim
/teleop_turtle
ros2 topic list
/parameter_events
/rosout
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose
Inspect one topic — who publishes, who subscribes, how many:
ros2 topic info /turtle1/cmd_vel
Type: geometry_msgs/msg/Twist
Publisher count: 1
Subscription count: 1
Important
Publisher count: 0 is a strong clue — nothing is sending into this topic at
all, even though the name appears in ros2 topic list.
Common when the node that should publish was never started, or crashed on startup.
The classic trap — mismatched names
The most common beginner failure is a topic name that does not match.
One node publishes to /cmd_vel, another listens on /cmd_vel_nav. Both run
perfectly. No error, no warning, and the data never meets.
Check with ros2 topic list and look for names that should not be there. Seeing
both /cmd_vel and /cmd_vel_nav when there should be one means a typo.
Previous: 2. Installing · Next: 4. Command-line tools