ROS 2: Zero to Robot  ยท  Illustrated Learning Book

Chapter 19: QoS, DDS, Diagnostics, and Safety Architecture

From "it works" to "reliable in production"
Prerequisite: Chapter 2 (Topic/Service/Action), Chapter 18
Running project: ARCHO in a production environment
Concepts: DDS, QoS, Diagnostics, Safety Layers
Reading time: 150 to 170 minutes
What we'll cover in this chapter 19.1DDS: the hidden heart of ROS 2 communication 19.2Why QoS exists 19.3QoS policies, one by one 19.4QoS mismatch: when the Topic exists but no data arrives 19.5ROS_DOMAIN_ID and RMW 19.6Full review: when to use Topic, Service, Action, or Parameter 19.7Diagnostics: ARCHO must be able to say whether it is healthy 19.8Multi-layer safety architecture 19.9Summary, glossary, and exercises

19.1DDS: the hidden heart of ROS 2 communication

From Chapter 2 up to now, we've worked with Topics, Services, and Actions many times without ever asking how messages actually get from one Node to another. The answer to that question is one of the most important differences between ROS 2 and its predecessor (ROS 1): ROS 2 is built on top of an industry-standard Middleware called DDS.

๐Ÿ“– What DDS handles
  • Discovery โ€” automatically finding other Nodes on the network
  • Actual transport of messages
  • Quality of Service (QoS)
  • Communication between different Processes on a single computer
  • Communication between multiple different computers
  • Serialization (converting data into a transportable format)
  • Communication security
flowchart TB A["ROS 2 Node"] --> B["rclcpp / rclpy"] --> C["rcl"] --> D["RMW"] --> E["DDS Implementation"] --> F["Network"] style D fill:#eef0ff,stroke:#3d4bf5 style E fill:#f4effe,stroke:#8b5cf6

19.2Why QoS exists

๐Ÿง  Not all data has the same value

If one out of a thousand LiDAR scans is lost, that's usually not a disaster. But if ARCHO's emergency stop command is lost, that can be dangerous. A map might be published late, but every new Subscriber should still be able to get its latest version โ€” even if it comes online after the initial publication. That's why a single, fixed communication behavior for every message simply doesn't make sense.

QoS (Quality of Service) is exactly what tunes this: every Topic can have its own communication behavior.

19.3QoS policies, one by one

Reliability

ModeBehaviorSuitable for
ReliableThe message must be delivered; if a packet is lost, it is retriedParameter Events, configuration, sensitive non-real-time commands
Best EffortIf the message arrives, great; if not, the next one comes alongCamera Stream, LiDAR, fast sensor data, weak WiFi networks

Durability

ModeBehavior
VolatileThe Subscriber only receives messages published after it connects; it does not see earlier messages
Transient LocalThe Publisher keeps the last piece of data so new Subscribers can also receive it โ€” for example, for a Map

History

ModeBehavior
Keep Last (depth=N)Only the last N messages are kept
Keep AllAll messages are kept up to the system's resource limits โ€” this can consume a lot of memory

Deadline, Lifespan, and Liveliness

PolicyMeaningExample
DeadlineHow often, at minimum, a message must arriveThe LiDAR must publish every 100 milliseconds; otherwise a Deadline Missed is reported โ€” very useful for Health Monitoring
LifespanHow long a message stays validA velocity command from 5 seconds ago should no longer be executed
LivelinessWhether the Publisher is still aliveIf the motor command Publisher dies, the system can automatically zero the command

19.4QoS mismatch: when the Topic exists but no data arrives

โš ๏ธ One of the most confusing ROS 2 bugs

Suppose ARCHO's LiDAR publishes with Best Effort, but a new Subscriber only accepts Reliable. Result: the connection either never forms, or the expected behavior doesn't happen โ€” and the telltale sign is that /scan shows up in ros2 topic list, but no data is ever received.

dev@archo:~$ ros2 topic info /scan --verbose Publisher count: 1 QoS profile: Reliability: BEST_EFFORT Subscription count: 1 QoS profile: Reliability: RELIABLE

This command is exactly where you'll spot a mismatch between a Publisher and a Subscriber.

19.5ROS_DOMAIN_ID and RMW

๐Ÿ“– ROS_DOMAIN_ID is like a separate communication channel
export ROS_DOMAIN_ID=20

Systems with different Domain IDs usually don't see a shared ROS Graph. For example, one lab could use Domain 10 and another lab Domain 20 so their Discovery traffic doesn't mix.

โš ๏ธ Domain ID is not a security mechanism

Domain ID only separates Discovery โ€” it does not encrypt or protect the communication. Relying on Domain ID or a WiFi password for real security isn't enough โ€” this is something later chapters on security will explore further (if we continue down that path).

๐Ÿ“– What RMW is

ROS Middleware โ€” the layer that connects ROS 2 to an actual DDS implementation (such as Cyclone DDS or Fast DDS). As we saw in the diagram above, this layer sits between rcl and the DDS itself and lets ROS 2 switch between different DDS implementations without changing code.

๐Ÿ“– The golden sentence of QoS

QoS doesn't determine what data a message carries; it determines how reliably, persistently, freshly, and promptly that data is delivered.

19.6Full review: when to use Topic, Service, Action, or Parameter

Now that you understand DDS and QoS, it's a good time to review the four main ROS 2 communication types (which we worked with in Chapters 2 and 3) all together:

TypeSuitable forExample in ARCHO
TopicContinuous data stream; the Publisher doesn't need to know who is listeningLiDAR Scan, IMU, Encoder, Battery Status, Camera Image
ServiceFast, short request/response; not suitable for long-running workReset Odometry, Clear Fault, Enable Motor, Get Firmware Version
ActionWork that takes time and needs Goal/Feedback/Result and CancelNavigate to Pose, Dock Robot, Follow Waypoints, Calibrate Wheels
ParameterConfiguring a Node's behavior; unsuitable for fast sensor datamax_velocity, wheel_radius, safety_distance, controller_frequency
flowchart TB Q1["Continuous data?"] -->|Yes| T["Topic"] Q2["Quick, short request?"] -->|Yes| S["Service"] Q3["Long task with Progress and Cancel?"] -->|Yes| A["Action"] Q4["A Node's configuration?"] -->|Yes| P["Parameter"] style T fill:#eef0ff,stroke:#3d4bf5 style S fill:#eafaf3,stroke:#0e9e6e style A fill:#f4effe,stroke:#8b5cf6 style P fill:#fdf3e4,stroke:#c8862c

19.7Diagnostics: ARCHO must be able to say whether it is healthy

An industrial robot shouldn't just work; it must be able to answer the question: "Am I healthy or not?"

Health states

StateMeaning
OKEverything is normal
WARNThere's an issue, but it's not yet dangerous
ERRORA serious error has occurred
STALEThe data we're receiving from this component is no longer up to date

Example of a snapshot of ARCHO's status:

LiDAR:        OK
IMU:          OK
Battery:      WARN
Motor Driver: ERROR
Camera:       STALE

Health Manager

flowchart LR L["LiDAR Driver"] --> HM["Health Manager"] I["IMU Driver"] --> HM M["Motor Driver"] --> HM B["Battery Driver"] --> HM LO["Localization"] --> HM N["Nav2"] --> HM style HM fill:#3d4bf5,color:#fff

Based on all these inputs, the Health Manager decides: should the mission continue? Should speed be reduced? Should ARCHO stop completely? Should the operator be notified?

Heartbeat and sensor timeouts

๐Ÿ“– What a Heartbeat is

A simple message that just says "I'm still alive." For example, the MCU sends a Heartbeat every 50 milliseconds. If the main computer doesn't see a Heartbeat for 300 milliseconds, it concludes the MCU has disconnected โ€” exactly the same Watchdog principle we saw in Chapters 16 and 18.

now - last_scan_time > 0.5 second
      โ†“
LiDAR Timeout
      โ†“
Controller stop โ†’ Mission pause โ†’ Operator notification

Fault Severity

LevelExample
InfoMap loaded
WarningBattery below 30%
Recoverable ErrorLiDAR temporarily unavailable
Critical ErrorMotor overcurrent, Emergency stop active

Overall system health State Machine

stateDiagram-v2 [*] --> BOOTING BOOTING --> INITIALIZING INITIALIZING --> READY READY --> RUNNING RUNNING --> DEGRADED DEGRADED --> RUNNING RUNNING --> FAULT DEGRADED --> FAULT FAULT --> RECOVERY RECOVERY --> READY

For example, if ARCHO's camera fails but Navigation can continue using only the LiDAR, the system moves to the DEGRADED state โ€” not stopped, but with reduced capability. If the Encoder fails, this is a more serious error, and the system moves to FAULT.

19.8Multi-layer safety architecture

โš ๏ธ A common wrong assumption

We shouldn't assume that "because the ROS 2 Nodes are healthy, the robot is safe." Software can crash, the network can drop, a wrong Topic can get published, the CPU can hang, or an old command can mistakenly persist. That's exactly why real safety can't live in just one software layer.

Three types of Stop

TypeBehavior
Normal StopThe Controller smoothly brings speed down to zero
Protective StopA fast but controlled stop due to a detected human or hazardous obstacle
Emergency StopA fully hardware-level cutoff of actuator power โ€” this must never be just a software Topic

Six safety layers

flowchart TB L1["Layer 1: Nav2 Collision Avoidance"] --> L2["Layer 2: Software Safety Supervisor"] L2 --> L3["Layer 3: MCU Watchdog"] L3 --> L4["Layer 4: Motor Driver Protections"] L4 --> L5["Layer 5: Safety Relay / E-Stop Circuit"] L5 --> L6["Layer 6: Mechanical Brake"] style L1 fill:#eef0ff,stroke:#3d4bf5 style L6 fill:#fdeeec,stroke:#d64a3c
๐Ÿง  Why six layers, not one

If Layer 1 (Nav2's intelligent collision avoidance) fails for any reason, the layers below it must still be able to contain the risk. This is exactly the lesson we learned in Chapter 18 about "one safety layer is not enough" โ€” here we turn that principle into a complete six-layer architecture.

Safety Supervisor

flowchart TB A["Nav2 cmd_vel"] --> S["Safety Supervisor"] S --> Q1["E-stop active?"] S --> Q2["Human too close?"] S --> Q3["Localization lost?"] S --> Q4["Motor fault?"] S --> Q5["Command timeout?"] S --> O["safe_cmd_vel"] style S fill:#3d4bf5,color:#fff style O fill:#eafaf3,stroke:#0e9e6e

Safety Supervisor inputs: cmd_vel, LiDAR safety zones, Bumper, E-stop, motor faults, Localization quality, and battery status. Outputs: safe_cmd_vel, motor_enable, protective_stop.

Zone-based speed limits

ZoneAllowed speed
Open warehouse area0.8 meters/second
Near humans0.3 meters/second
Docking area0.1 meters/second

These limits can change dynamically based on the map, live LiDAR data, current position, mission type, and human presence.

Bumper: the last physical layer

flowchart LR A["Bumper Pressed"] --> B["Immediate Motor Stop"] --> C["Mission Cancel"] --> D["Reverse Only After Validation"] style A fill:#fdeeec,stroke:#d64a3c
โš ๏ธ Never reverse immediately

When the Bumper is pressed, ARCHO must never immediately reverse without an automatic check first โ€” an obstacle, or even a human, could be standing right behind it.

๐Ÿ“– The golden sentence of Safety

Real safety means that even when high-level software makes a mistake, the hardware and low-level control never allow a dangerous state to occur.

19.9Chapter 19 summary

ARCHO now not only works, but also knows how to cope with unfavorable network conditions (QoS), how to report which part of its body is unhealthy (Diagnostics), and how to protect itself and the humans around it even when something goes wrong in software (multi-layer safety architecture). These are exactly the differences that separate a student project from a real industrial product.

โœ… Learning checkpoint
  • I can explain the difference between Reliable and Best Effort with an example.
  • I know why Transient Local is more suitable than Volatile for a Map.
  • I can recognize the common symptom of a QoS mismatch and know which command to use to investigate it.
  • I know why ROS_DOMAIN_ID is not a security mechanism.
  • I can explain the four health states (OK/WARN/ERROR/STALE) with an example.
  • I know why safety must be designed across six independent layers, not one.
๐ŸŒ Connection to the main project

ARCHO Project now has a Health Manager with four status levels, a Safety Supervisor with six independent safety layers, and properly tuned QoS Profiles for each type of data (fast sensor data versus critical commands).

What the next chapter adds

In Chapter 20 โ€” the final chapter of this path โ€” we bring together everything we built across these 19 chapters and see ARCHO's complete final industrial architecture.

Chapter 19 glossary

DDS
Data Distribution Service; the Middleware standard underlying ROS 2's communication infrastructure.
QoS (Quality of Service)
A set of policies that determine the reliability, persistence, and timeliness behavior of a Topic's communication.
RMW
ROS Middleware; the layer that connects ROS 2 to a specific DDS implementation.
ROS_DOMAIN_ID
An identifier that separates the Discovery of multiple independent ROS 2 systems from each other.
Diagnostic Aggregator
A system that collects and summarizes the health status of all subsystems.
Heartbeat
A simple periodic message that confirms a subsystem is alive.
Safety Supervisor
A software layer that filters the final motion command based on safety conditions.
Protective Stop
A fast but controlled stop due to an obvious hazard, between Normal Stop and Emergency Stop.

Chapter 19 common mistakes โ€” summary