ros2 topic — inspect, publish and measure topic data rates
Atlasbot · 17/8/2026 · 11 min read
When two nodes are supposed to communicate through a topic but do not work as expected, ros2 topic answers most questions: whether data arrives, at what frequency, and how to simulate data to test the other node without running the entire system.
Key concepts
| Command | Purpose |
|---|---|
ros2 topic list | List all available topics |
ros2 topic echo /cmd_vel | Print topic data to the terminal in real time |
ros2 topic info /cmd_vel | Show the message type and publisher/subscriber counts |
ros2 topic hz /scan | Measure the actual publishing frequency (Hz) |
ros2 topic bw /scan | Measure the topic's bandwidth consumption (bytes/second) |
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{...}" | Publish a message manually |
How it works
Debugging a robot that does not move with ros2 topic usually follows this order:
ros2 topic list | grep cmd_vel # does the /cmd_vel topic exist?
ros2 topic info /cmd_vel # are there any publishers?
ros2 topic echo /cmd_vel # does the incoming data match expectations?
ros2 topic hz /cmd_vel # is the publishing frequency too low?
If ros2 topic echo prints nothing while control commands are being sent, the problem is on the sending side. If it prints the correct data but the robot remains still, investigate the receiving side — ros2 topic narrows the fault to one side before you open the code.
In short:
ros2 topic echo+ros2 topic hzare the most frequently used commands in everyday debugging — echo answers "is the data correct?" and hz answers "is the rate correct?".
Publish manually to test a receiving node:
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist \
"{linear: {x: 0.2}, angular: {z: 0.0}}" --rate 10
This simulates a publisher sending "move straight at 0.2 m/s" commands at 10Hz — useful for testing the node receiving /cmd_vel without running the entire navigation system above it.
Technical details
Parameters
Some lesser-known but useful flags/subcommands for deeper debugging:
| Flag/command | Effect |
|---|---|
ros2 topic echo /scan --once | Print exactly 1 message and exit, rather than running continuously |
ros2 topic echo /scan --qos-reliability best_effort | Override echo's QoS to read a topic when the default is incompatible — for debugging only |
ros2 topic find sensor_msgs/msg/LaserScan | Find all topics publishing the specified message type |
ros2 topic pub ... --once | Send exactly 1 message and stop (the default without --rate) |
Practical applications
Combining ros2 topic pub with recordings from ros2 bag (covered in a following article) creates a useful regression testing workflow: record a known-good sequence of control commands before changing code, then replay the exact sequence afterward and compare the node's behavior. This catches regression bugs without always running the robot's full set of physical sensors.
Practical example
$ ros2 topic echo /battery_status --once
Output:
voltage: 12.4
percentage: 0.85
temperature: 32.1
---
$ ros2 topic find sensor_msgs/msg/Image
Output:
/camera/color/image_raw
/camera/depth/image_raw
--once is useful for quickly checking a current value (for example, battery level) without continuous terminal output; find helps identify how many image topics are running without remembering every name.
Common mistakes
- Forgetting to stop
ros2 topic pub --rateafter testing — this manual publisher keeps sending commands and can conflict with the real navigation publisher also writing to/cmd_vel, causing the robot to alternate unpredictably between two command sources. ros2 topic echoprints nothing despite a working publisher — before blaming the publisher, check for QoS incompatibility (see the QoS article). Use--qos-reliability best_effortto rule this out while debugging.- YAML syntax errors in the message passed to
ros2 topic pub— missing braces or colons cause confusing parse errors. For complex messages with nested fields, write a separate YAML file and useros2 topic pub /cmd_vel geometry_msgs/msg/Twist -f file.yamlrather than typing directly on the command line. - Using
ros2 topic pubfor a real-time control loop — this tool is for testing/debugging and does not guarantee the latency or reliability needed for production control. Actual control logic belongs in a properly written node, rather than depending on CLI commands.
Conclusion
ros2 topic is the central toolkit for debugging inter-node communication — echo/hz answer "correct data, correct rate?", while pub isolates and tests individual nodes. Always narrow down the fault (list → info → echo → hz) before opening the code. The next article covers ros2 service — the equivalent toolkit for request-response communication.
Get new articles and lessons by email
When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.
Unsubscribe any time with the link in each email. See our Privacy policy.