MyRoboPathOpen Robotics Lab
Software Architecture & Frameworks18 min readUpdated 2026-03-30All Levels

Robot Operating Systems: ROS 2 Architecture Explained from Hardware to Applications

The Complete End-to-End Architectural Blueprint: DDS Middleware, Computation Graphs, TF2 Transforms & ros2_control

MyRoboPath Robotics Software Lab
ROS 2 & Autonomous Systems Core Team
Robot Operating Systems: ROS 2 Architecture Explained from Hardware to Applications
Discovery Mechanism
Zero-Master DDS
Automated UDP multicast discovery without centralized broker
TF2 Interpolation Buffer
10.0 Seconds
Time-travel coordinate transform caching
ros2_control Loop Rate
100 Hz - 1 kHz
Real-time deterministic actuator update cycle
Microcontroller Bridge
micro-ROS
Direct ROS 2 DDS integration onto FreeRTOS/Zephyr MCUs

Core Engineering Takeaways

  • •ROS 2 is not an operating system, but a modular robotics software middleware providing hardware abstraction, inter-process communication, and standardized navigation/manipulation libraries.
  • •ROS 2 eliminates the single-point-of-failure (roscore) of ROS 1 by adopting industry-standard DDS (Data Distribution Service) with automated peer-to-peer discovery over UDP.
  • •Topics provide asynchronous many-to-many publish-subscribe data streaming (sensor readings, motor velocity commands).
  • •Services provide synchronous one-to-one request-response transactions (resetting an odometry count, triggering camera calibration).
  • •Actions provide long-running, preemptible goal execution with continuous progress feedback (navigating to a charging dock, executing an arm trajectory).
  • •The TF2 coordinate frame library maintains the spatial relationships between robot links (map → odom → base_link → laser_frame) across time buffers.
  • •ros2_control isolates physics and high-level controllers from vendor-specific motor drivers through standardized Hardware Interfaces (Command and State interfaces).
Prerequisites
  • Familiarity with modern C++ (C++14/17) or Python 3 object-oriented programming
  • Basic knowledge of Linux terminal, processes, and network communication (IP/UDP)

1. Why ROS 2? Overcoming the Limits of ROS 1 with DDS

The Limitations of ROS 1

Created in 2007 at Willow Garage, ROS 1 revolutionized academic robotics research. However, it had architectural limitations that prevented deployment in commercial, mission-critical robots:

  1. 1
    Centralized Master (roscore): A single master process held the address book of all nodes. If roscore crashed or experienced network dropouts, the entire robot halted.
  2. 2
    No Real-Time Determinism: The Linux TCP/IP transport had unpredictable scheduling jitter, making it unsuitable for direct brushless motor control loops.
  3. 3
    Weak Wireless Networking: Wi-Fi dropouts caused master disconnects and broken socket states.
  4. 4
    No Native Multi-Robot Support: Deploying a fleet of 50 warehouse robots required complex network tunneling hacks.

The ROS 2 DDS Revolution

ROS 2 replaces the proprietary network layer with DDS (Data Distribution Service)—an international military- and aerospace-grade standard (OMG DDS) used in air traffic control, nuclear reactors, and warships.

DDS introduces:

  • Brokerless Peer-to-Peer Discovery: Nodes broadcast UDP multicasts to discover each other dynamically. There is zero master node.
  • Configurable Quality of Service (QoS): Developers can configure packet delivery behavior per-topic (e.g., allow dropping old sensor frames vs guarantee delivery of emergency stop commands).
  • Security (SROS 2): Native TLS authentication, access control policies, and hardware-accelerated encryption.
Table 1: Architectural Comparison: ROS 1 vs ROS 2
FeatureROS 1 (Melodic / Noetic)ROS 2 (Humble / Iron / Jazzy)
Central MasterMandatory (roscore single point of failure)None (Decentralized peer-to-peer DDS discovery)
Transport MiddlewareCustom TCPROS / UDPROSStandardized OMG DDS (FastDDS, CycloneDDS)
Real-Time CapabilityNone (Best-effort non-realtime)Full POSIX Real-Time Linux (PREEMPT_RT) support
Node LifecycleUncontrolled start/stopManaged Lifecycle Nodes (Unconfigured, Inactive, Active)
Microcontroller Supportrosserial (fragile UART bridge)micro-ROS (Native DDS clients on FreeRTOS/Zephyr)
Multi-Robot FleetsRequires complex multi-master bridgesNative Domain IDs (0-232) isolate multiple robot fleets
Build Toolcatkin_make / catkin toolscolcon with ament_cmake and ament_python

2. The 7-Layer Robotics Architecture: Silicon to High-Level Planning

A production-ready ROS 2 robot organizes software into a modular 7-tier pipeline:

  1. 1
    Hardware Tier: Physical brushless actuators, encoders, IMUs, 2D/3D LiDARs, depth cameras, and battery systems.
  2. 2
    Micro-ROS & Embedded Tier: Microcontrollers (ESP32, STM32) running FreeRTOS with micro-ROS clients, executing hard real-time PID loops and publishing raw tick counts.
  3. 3
    Hardware Driver Nodes: Linux processes communicating over USB/Ethernet/CAN (e.g., sllidar_ros2, realsense2_camera) converting hardware bytes into standardized ROS 2 messages.
  4. 4
    Coordinate Transformation (TF2): Real-time spatial tracking of all robot links and sensor mounting positions.
  5. 5
    Localization & Mapping (SLAM): Sensor fusion nodes (robot_localization, slam_toolbox) creating global maps and computing robot pose.
  6. 6
    Motion Planning & Navigation (Nav2 / MoveIt 2): High-level path generation, dynamic obstacle avoidance, and trajectory tracking.
  7. 7
    Application Logic & Behavior Trees: Mission controllers (e.g., "drive to Table 4, pick up pallet, return to charging station").

3. Core Execution Graph: Nodes, Executers, and Lifecycles

Nodes

A Node is a single, focused process responsible for one discrete task (e.g., one node reads the camera, another detects faces, another drives the motors). Dividing software into hundreds of small nodes ensures that if a camera driver crashes, the safety stop and motor nodes remain fully alive.

Managed Lifecycle Nodes

In safety-critical robots, you cannot allow a motor controller to start spinning wheels while the LiDAR node is still booting up. ROS 2 provides Lifecycle Nodes with explicit finite state machines:

  • Unconfigured: The node is instantiated but has not allocated memory or claimed hardware.
  • Inactive: Configuration parameters are loaded, memory buffers are pre-allocated, but callbacks are paused.
  • Active: Full execution mode, publishing and processing data.
  • Finalized: Cleanly shut down with all hardware safely depowered.

4. Communication Trio: Topics, Services, and Actions

ROS 2 provides three distinct communication patterns for nodes:

1. Topics (Publish-Subscribe)

  • Pattern: Asynchronous, many-to-many, non-blocking data streaming.
  • Analogy: Radio broadcasting. The publisher broadcasts data regardless of whether anyone is listening.
  • Use Case: High-rate sensor telemetry (e.g., /scan for 30Hz LiDAR scans, /odom for 100Hz odometry, /cmd_vel for wheel speed commands).

2. Services (Request-Response)

  • Pattern: Synchronous, one-to-one, blocking or callback-based transaction.
  • Analogy: Making a telephone call. The client sends a question and waits for the server to reply.
  • Use Case: Quick, momentary operations (e.g., /reset_trip_distance, /calibrate_gyro, /set_camera_exposure).

3. Actions (Goal - Feedback - Result)

  • Pattern: Asynchronous, client-server, long-running, preemptible goal execution.
  • Analogy: Ordering a taxi. You submit a goal destination; the taxi driver continuously reports progress (distance remaining, ETA); you can cancel the ride midway; upon arrival, you receive a final completion receipt.
  • Use Case: Multi-second or multi-minute operations (e.g., /navigate_to_pose, /execute_trajectory, /dock_to_charger).

5. Quality of Service (QoS): Real-Time Sensor Transport Tuning

In ROS 1, all communication defaulted to reliable TCP. In wireless robotics, if a single 30 FPS camera packet is lost, TCP pauses the entire stream to retransmit the lost packet, resulting in buffering lag. By the time the video recovers, the frames are 2 seconds old—causing the robot to drive off a cliff.

ROS 2 solves this by introducing QoS Profiles:

  • Reliability:
  • *Best Effort:* Drops packets if network is congested. (Essential for high-rate sensor streams like LiDAR and video).
  • *Reliable:* Guarantees packet arrival with retransmissions. (Mandatory for motor commands and safety stops).
  • Durability:
  • *Volatile:* Only nodes currently online receive messages.
  • *Transient Local:* The publisher retains the latest message in memory and automatically delivers it to any new subscriber that comes online 10 minutes later (ideal for static maps on /map).
  • History & Depth:
  • *Keep Last (Depth N):* Retains only the NN most recent samples in memory.
velocity_publisher.py
python
import rclpy
from rclpy.node import Node
from rclpy.qos import QoSProfile, ReliabilityPolicy, DurabilityPolicy
from geometry_msgs.msg import Twist

class VelocityPublisher(Node):
    def __init__(self):
        super().__init__('velocity_publisher_node')
        
        # Configure Best-Effort QoS for high-rate low-latency motor control
        qos = QoSProfile(
            reliability=ReliabilityPolicy.BEST_EFFORT,
            durability=DurabilityPolicy.VOLATILE,
            depth=1
        )
        
        self.publisher_ = self.create_publisher(Twist, '/cmd_vel', qos)
        self.timer = self.create_timer(0.05, self.timer_callback) # 20 Hz
        self.get_logger().info('Velocity Publisher Initialized at 20 Hz')

    def timer_callback(self):
        msg = Twist()
        msg.linear.x = 0.5   # Drive forward at 0.5 m/s
        msg.angular.z = 0.1  # Gentle arc turning at 0.1 rad/s
        self.publisher_.publish(msg)

def main(args=None):
    rclpy.init(args=args)
    node = VelocityPublisher()
    try:
        rclpy.spin(node)
    except KeyboardInterrupt:
        pass
    finally:
        node.destroy_node()
        rclpy.shutdown()

6. The TF2 Transform Tree: The Spatial Glue of Robotics

A robot has many physical parts: wheels, chassis, a mast, and sensors. When a LiDAR mounted on top of a 50cm mast detects an obstacle 2 meters ahead, how does the chassis navigation planner know where that obstacle is relative to its wheels?

TF2 (Transform Library) solves this by maintaining a directed acyclic tree of coordinate frames:

map⟶odom⟶base_link⟶laser_frame\text{map} \longrightarrow \text{odom} \longrightarrow \text{base\_link} \longrightarrow \text{laser\_frame}
  • map: Global fixed world frame. Has long-term drift correction from SLAM. (Discontinuous jumps during loop closure).
  • odom: Continuous, smooth world-fixed frame derived from wheel encoders and IMU. Never jumps, but slowly drifts over distance.
  • base_link: Rigidly attached to the center of rotation of the robot chassis.
  • laser_frame / camera_link: Attached to sensor mounting points.

TF2 automatically interpolates between coordinate frames across time, allowing any node to ask: *"Where was the laser beam relative to the global map 80 milliseconds ago?"*

7. Hardware Abstraction (ros2_control) & Autonomous Navigation (Nav2)

ros2_control: The Hardware Bridge

Writing custom motor driver code for every robot creates massive technical debt. ros2_control standardizes actuation:

  • Hardware Interface: A C++ plugin that talks to your specific motor driver (via CAN, UART, or SPI). It exposes standardized Command Interfaces (e.g., target velocity, target torque) and State Interfaces (actual position, actual velocity).
  • Controllers: Ready-to-use real-time controller plugins (e.g., diff_drive_controller, joint_trajectory_controller) that read /cmd_vel and command hardware interfaces without knowing the underlying motor chip.

Nav2: The Autonomous Navigation System

Nav2 is the state-of-the-art navigation stack for mobile robots. It includes:

  • Global Planner: Finds the optimal collision-free path from current pose to goal on a static map (A* or Dijkstra).
  • Costmaps (Global & Local): 2D occupancy grids that inflate obstacles based on the robot's physical footprint.
  • Controller (Local Planner): Generates smooth /cmd_vel commands that track the global path while dynamically steering around moving obstacles (DWB, TEB Local Planner, MPPI).
  • Behavior Trees: Orchestrates complex navigation sequences with automated recovery actions (spinning in place to clear sensor costmaps, reversing out of dead-ends).
Frequently Asked Questions

Common Questions & Troubleshooting

Q:Can ROS 2 run on microcontrollers like ESP32 or STM32?

Yes! Using micro-ROS (the official embedded extension of ROS 2), microcontrollers run a lightweight XRCE-DDS client over UART, SPI, or Ethernet. Microcontrollers can directly create ROS 2 publishers and subscribers, integrating seamlessly into the computation graph alongside desktop computers.

Q:Which ROS 2 distribution should I choose?

Always choose the latest Long Term Support (LTS) release for production robotics. ROS 2 Humble Hawksbill (Ubuntu 22.04 LTS) and ROS 2 Jazzy Jalisco (Ubuntu 24.04 LTS) provide 5 years of security updates and active hardware vendor driver support.

Q:Why does my subscriber not receive messages from my publisher?

In ROS 2, the most common culprit is a Quality of Service (QoS) mismatch. If a publisher is configured with Best Effort reliability, a subscriber configured with Reliable reliability will silently reject all incoming messages because the QoS contracts are incompatible.