Understanding ROS 2 Publish-Subscribe Architecture for Robot Sensors
Introduction
Robot sensors continuously produce information. Cameras generate images, IMUs produce motion measurements, and lidar sensors generate distance data.
ROS 2 uses a publish-subscribe communication model that allows sensor nodes to publish data while other nodes subscribe to it.
Publisher and Subscriber
The basic architecture is:
Sensor Node
|
| Publisher
v
/sensor/data
|
+----------+
| |
v v
Perception Logger
Subscriber Subscriber
The publisher does not need to know exactly which subscribers are consuming its data.
ROS 2 Topics
A topic represents a named stream of messages.
Examples:
/camera/image_raw
/imu/data
/scan
/joint_states
A camera node might publish:
/camera/image_raw
An object detection node can subscribe to that topic.
Message Types
Every ROS 2 topic has a message type.
For example, sensor messages may use standard interfaces such as:
sensor_msgs/msg/Image
sensor_msgs/msg/Imu
sensor_msgs/msg/LaserScan
The message type defines the structure of the data.
Inspecting Topics
List active topics:
ros2 topic list
Inspect a topic:
ros2 topic info /imu/data
Display messages:
ros2 topic echo /imu/data
Measure publishing frequency:
ros2 topic hz /imu/data
These commands are useful when debugging sensor pipelines.
Quality of Service
ROS 2 uses Quality of Service (QoS) policies to control how messages are delivered.
Important QoS concepts include:
- Reliability
- Durability
- History
- Queue depth
For sensor streams, the correct QoS configuration depends on the application.
For example, a camera pipeline may prefer recent frames instead of building up a large queue of old frames.
Sensor Pipeline Example
Consider an autonomous robot with a camera:
Camera Driver
|
v
/ camera/image_raw
|
v
Image Processing
|
v
Object Detection
|
v
/ detected_objects
|
v
Planner
Each component can be developed and tested independently.
Time Stamps
Sensor messages should include accurate timestamps.
Timestamps allow downstream systems to:
- Synchronize sensor streams
- Estimate latency
- Correlate sensor measurements
- Perform sensor fusion
For multi-sensor systems, consistent time handling is essential.
Handling High-Frequency Sensors
High-frequency sensors can produce large amounts of data.
For example:
IMU: hundreds of samples/sec
Camera: tens of frames/sec
Lidar: multiple scans/sec
Applications should consider:
- CPU usage
- Memory usage
- Network bandwidth
- Queue sizes
- Processing latency
Do not allow slow subscribers to create unbounded memory growth.
Connecting AI to Sensor Topics
A Physical AI perception node can subscribe directly to ROS 2 sensor topics:
Camera
|
v
ROS 2 Topic
|
v
AI Model
|
v
Detection
|
v
Robot Planner
The AI model may run on a GPU using CUDA or TensorRT, while ROS 2 handles communication between system components.
Debugging Checklist
When sensor data is not reaching a node, check:
ros2 node list
ros2 topic list
ros2 topic info /sensor/topic
ros2 topic echo /sensor/topic
Then verify:
- The publisher is running.
- The topic name is correct.
- The message type matches.
- QoS settings are compatible.
- The subscriber is running.
- Network or DDS configuration is correct.
Conclusion
ROS 2 publish-subscribe architecture makes sensor processing modular and scalable. Publishers can produce sensor data independently, while multiple subscribers can consume the same stream for perception, logging, visualization, or control.
For Physical AI, this architecture provides a practical way to connect sensor data with AI models and robot decision-making components.
Useful Links
Website: www.v-modal.com
SDK Flutter: https://github.com/v-modal/vmodal_sdk_flutter
SDK Android: https://github.com/v-modal/vmodal_sdk_android
Discord: https://discord.gg/K72z28KU
Top comments (0)