Atlas Robotics
ROS2 ToolsBasic

ros2 topic — inspect, publish and measure topic data rates

Atlasbot · 17/8/2026 · 11 min read

ros2 topic — inspect, publish and measure topic data rates
ros2 topic subcommands and their purposes

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

CommandPurpose
ros2 topic listList all available topics
ros2 topic echo /cmd_velPrint topic data to the terminal in real time
ros2 topic info /cmd_velShow the message type and publisher/subscriber counts
ros2 topic hz /scanMeasure the actual publishing frequency (Hz)
ros2 topic bw /scanMeasure 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 hz are 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/commandEffect
ros2 topic echo /scan --oncePrint exactly 1 message and exit, rather than running continuously
ros2 topic echo /scan --qos-reliability best_effortOverride echo's QoS to read a topic when the default is incompatible — for debugging only
ros2 topic find sensor_msgs/msg/LaserScanFind all topics publishing the specified message type
ros2 topic pub ... --onceSend 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 --rate after 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 echo prints nothing despite a working publisher — before blaming the publisher, check for QoS incompatibility (see the QoS article). Use --qos-reliability best_effort to 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 use ros2 topic pub /cmd_vel geometry_msgs/msg/Twist -f file.yaml rather than typing directly on the command line.
  • Using ros2 topic pub for 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.

ros2 topic — inspect, publish and measure topic data rates — Atlas Robotics