Topic, publisher/subscriber, QoS
Topic is a data channel with a name and a fixed message type (for example, /sensor_data with std_msgs/Float64). Publisher pushes messages on that topic at its own pace; Any subscriber who has registered to listen to that topic will automatically receive it.
Publisher does not need to know whether anyone is listening or not, and there is no limit to the number of publishers/subscribers per topic. This is the most popular communication model in ROS 2 because it truly reflects the nature of robots: sensor data, status, and control commands are all continuous streams, not discrete requests.
How is the connection established?
Publisher and subscriber match by topic name and message type. If either differs, no connection is established; ROS 2 only logs warnings. A topic can have many publishers and many subscribers.
QoS: "quality" of transmission
Each side comes with a QoS set. The two most important fields:
| Field | Value | Meaning |
|---|---|---|
| Reliability | RELIABLE | Retransmit lost packets. No data loss, may delay. |
| Reliability | BEST_EFFORT | Lost packets are not retransmitted. Fast, suitable for continuous data like sensors. |
| Durability | VOLATILE | Only receive broadcast messages after connection (default). |
| Durability | TRANSIENT_LOCAL | Receive the last message, even broadcast before connecting. Used for statuses like map. |
Try: change QoS and connection
Select RELIABLE then increase the packet loss rate. Then change to BEST_EFFORT with the same packet loss rate and compare the data.
Important rule: if publisher and subscriber have incompatible QoS (e.g. publisher BEST_EFFORT, subscriber RELIABLE), the connection will not be established. There is usually only one "incompatible QoS" warning line in the log, which is easy to ignore, and the subscriber receives nothing.
Try it
Need 2 terminals (already source install/setup.bash, see Module 0):
# Terminal 1 — keep running; do not close
ros2 launch ros2_basics demo.launch.py
# Terminal 2
ros2 topic list
# Terminal 2 — this command runs continuously, Ctrl+C to stop
ros2 topic echo /sensor_data
# Terminal 2 — after Ctrl+C echo command above
ros2 topic info /sensor_data --verbose
Command --verbose displays the QoS of each publisher and subscriber, helping to find the reason why the two sides cannot talk.