Now that you understand why ROS 2 uses middleware to connect separate processes, letβs look at the three building blocks that make up the ROS 2 Computation Graph in practice: nodes, topics, and messages.
A Node is a modular process designed to perform a single computational task. Keeping nodes focused makes system design modular and reusable. For instance, a self-driving car might have:
Both the ui_display node on the robotβs screen and the fleet_management node on a cloud server subscribe to /battery_status. The battery monitor node doesnβt care who is listening; it just publishes the data!
The battery_monitor node publishes onto the /battery_status topic, and both the ui_display node and the fleet_mgmt node subscribe independently to that same topicβneither subscriber needs to know the other exists.
int32 sensor_id
float64 temperature
float64 humidity
string status
ROS 2 provides built-in primitive types (int32, float64, string, bool) as well as complex multi-field messages (such as geometry_msgs/msg/Twist, used to command linear and angular velocity for mobile robots).
Because Runestone CodeLens runs standard Python without third-party ROS libraries installed, letβs practice how ROS message deserialization works under the hood!
Write a Python script that parses incoming raw text payload strings (simulating a stream of message packets over a ROS topic) and extracts key sensor fields.
Arrange the blocks to form a minimal rclpy subscriber node: initialize the client library, create the node, create the subscription, spin, then shut down.