Arrange the blocks from the lowest layer of the ROS 2 software stack to the highest.
Section 9.1 Middleware & The ROS 2 Computation Graph
In previous chapters, we looked at how individual components like sensors, actuators, and controllers work. Now, we face a bigger challenge: How do we get dozens of independent software modulesβlike camera drivers, path planners, and motor controllersβto talk to each other seamlessly and in real time?
Enter ROS 2 (Robot Operating System 2). Despite its name, ROS 2 is not a traditional operating system like Windows or Linux. Instead, it is a robotics middlewareβa set of software tools, communication protocols, and conventions that glue complex robotic applications together.

Subsection 9.1.1 Understanding Robotics Middleware
Imagine building an autonomous delivery robot, such as an Amazon Scout or a Starship delivery bot. The robot needs to:
-
Read distance data from a LiDAR sensor 50 times per second.
-
Read camera streams for obstacle detection.
-
Compute an optimal path to avoid a moving pedestrian.
-
Send motor commands to wheel drivers to execute that path.
If all of these features were written inside a single, giant Python script (a "monolithic application"), a crash in the camera code would freeze the motor controls, potentially causing the robot to run into a wall! A single monolithic script means one bug in the camera code crashes the whole robot.
To prevent this, modern robotics uses a distributed architecture. Each task runs as a separate, isolated process. Middleware provides the underlying communication plumbing so these separate programs can exchange data across memoryβor even across a local Wi-Fi networkβwithout needing to know the low-level details of networking protocols like TCP/IP or UDP.
The ROS 2 software stack is layered: at the top sit the ROS 2 Client Libraries (
rclpy / rclcpp) that your own Python or C++ code talks to; beneath that is the DDS Middleware Layer (e.g., Fast DDS) that actually moves data between processes; and at the bottom is the Operating System (Linux / Ubuntu) that everything runs on.
ROS 2 uses DDS (Data Distribution Service) as its underlying middleware backbone. DDS handles auto-discovery: when you turn on a new sensor on your robot, other components on the network discover it automatically!
Subsection 9.1.2 The ROS 2 Graph
When ROS 2 programs run, they form a web of connected components called the ROS 2 Computation Graph.
The primary elements of this graph are:
-
Nodes: Process entities that perform computation (e.g., a node reading camera frames).
-
Topics: Named data buses over which nodes pass messages (e.g.,
/camera/image_raw). -
Messages: Standardized data structures passed through topics.
For example, a Camera Driver node (Node A) publishes onto the
/camera/image topic, and a Pedestrian Detector node (Node B) subscribes to that same topic to receive each frame as it arrives.
Subsection 9.1.3 Section 9.1 Interactive Exercises
Subsubsection 9.1.3.1 Exercise 9.1.2: Parsons Problem β Assembling ROS 2 Architecture Layers
Reorder the blocks below to correctly represent the software stack from the lowest layer (hardware/OS) up to the userβs high-level Python code.
Checkpoint 9.1.2.
Reading Questions 9.1.4 Reading Questions
Check your understanding
1. Exercise 9.1.1: Middleware Architecture Conceptual Check.
Which of the following best describes the main benefit of using a middleware architecture like ROS 2 over a single monolithic program?
-
Middleware automatically speeds up mathematical calculations.
-
Incorrect. Middleware does not accelerate computation; it only handles communication between separate processes.
-
Middleware isolates software modules so a failure in one process (e.g., vision) does not crash critical operations (e.g., motor control).
-
Correct! Running each task as a separate, isolated process means a crash in one module, like the camera driver, does not freeze unrelated modules like the motor controller.
-
Middleware eliminates the need for hardware drivers.
-
Incorrect. Middleware handles communication between processes; it does not remove the need for drivers that talk to sensors and actuators.
-
Middleware allows a robot to operate without an operating system like Linux.
-
Incorrect. ROS 2 still runs on top of an operating system; the OS forms the base layer beneath the DDS middleware and client libraries.
You have attempted of activities on this page.
