Lesson 12 of 2250 minutes

Robot Observability and Replay

Start with the lesson question, connect the representations, and test the model with evidence.

ros2observabilityrosbag2replayloggingtopic statisticsdebugging

Learning objectives

  • Explain nodes, messages, topics, services, and actions.
  • Select the appropriate ROS 2 communication pattern for a task.
  • Inspect and diagnose a small robot computation graph.
Lesson flowHook, model, explanationShow guidance

Inspect the opening phenomenon

Predict what changes, then name the evidence.

Apply in the lab

Name the evidence before reading the answer.

Read only what helps

Then use the lab and recall check.

More when needed

Transcript and resources stay available below.

Course progress

AI & Robotics Foundations · Programming Robot Systems with ROS 2 Concepts · Lesson 12

Robot Observability and Replay

In progress

Decision challenge

Observe the phenomenon. Then connect the representations.

Use the opening example to make a prediction, identify evidence, and explain which model supports it.

Why Did the Robot Bug Disappear? ROS 2 Record and Replay

Name one signal that should survive an intermittent late-braking failure.

Before

Name one signal that should survive an intermittent late-braking failure.

During

Track the five evidence-loop stages.

After

Explain what replay cannot prove about physical motion.

Reference drawerTranscript, source notes, scripts, and package status stay tucked away until you need them.7 files

Lesson reading

live

50 min

Video script

draft

Transcript fallback

available

courses/ai-robotics/modules/04-programming-robot-systems-with-ros2/lessons/03-robot-observability-and-replay/video-transcript.md

Build a Robot Evidence Packet

draft

30 min

Mastery check

live

7 questions / 10 min

Book section:courses/ai-robotics/modules/04-programming-robot-systems-with-ros2/lessons/03-robot-observability-and-replay/book-section.md
Transcript for accessibility and fallback

# Video transcript A robot brakes late once, then the bug disappears. What evidence survives? Observe live topics, logs, action states, parameters, and physical outcomes. Record the smallest sufficient set as timestamped messages, and tie every signal to a hypothesis. Inspect the bag before trusting it: check topics, message counts, duration, timestamps, and the failure window. Replay under controlled conditions, then compare expected and observed software outputs. If replay matches the original command stream, what is still not proven? The physical robot's motion. Replay is evidence—not physical reality.

Reading lab

Core explanation

Connect the lesson's words, diagrams, graphs, evidence, and equations.

The failure that disappeared

A delivery robot brakes late once, but behaves normally when the engineer watches it. Restarting the robot removes the immediate symptom—and also destroys much of the evidence.

Retrieval pause: What would you need to record before trying the same route again?

Observability means arranging signals so a human can reconstruct what the system believed, received, decided, and commanded. Replay turns selected timestamped messages into a repeatable software experiment. Neither is a substitute for physical evidence.

Robot evidence loop

The evidence loop

StageQuestionUseful evidence
ObserveWhat changed before the symptom?topic values and rates, logs, action states, parameters
RecordWhich signals must survive the run?selected timestamped topics and metadata
InspectIs the recording complete enough?ros2 bag info, topic list, counts, duration, timing plots
ReplayCan software consumers see the same message sequence?controlled playback, selected topics, rate, logs
CompareWhich hypothesis fits both runs?expected versus observed timing, values, states, outputs

The order matters. Recording everything without a question can create a huge bag while missing the operator decision, parameter change, or hardware state that explains the failure.

Worked example: late braking

Suppose /scan remains healthy, but /cmd_vel stays positive 300 milliseconds after a near obstacle appears.

  1. Hypothesis: perception publishes late, planning reacts late, or the actuator applies the command late.
  2. Observe: log the safety state and monitor message age/period where topic statistics are enabled.
  3. Record: capture /scan, /cmd_vel, /tf, /tf_static, relevant state topics, and /clock when simulation time is used.
  4. Inspect: confirm those topics exist in the bag and that the failure window is present.
  5. Replay: feed the recorded topics to the software under test in an isolated environment.
  6. Compare: if software again emits late /cmd_vel, the evidence points into the recorded-input/software path. If it does not, investigate unrecorded state, nondeterminism, timing, middleware, or hardware.

That result narrows the investigation; it does not prove a motor physically stopped on time.

Recording and inspecting with rosbag2

ROS 2's rosbag2 records timestamped communications and can play them back. Prefer an explicit topic set tied to the hypothesis:

ros2 bag record -o late_braking /scan /cmd_vel /tf /tf_static
ros2 bag info late_braking
ros2 bag play late_braking

Use ros2 bag <verb> --help for the installed distribution's current options. Recording all topics with -a is useful for exploration, but it can increase storage and expose unrelated data. A bag is only as complete as the signals, time basis, and failure window it contains.

Logs, statistics, and bags answer different questions

  • Logs explain discrete software events and decisions when messages include useful context.
  • Topic statistics can summarize message age and period for enabled subscriptions; they help expose delay and irregular arrival.
  • Bags preserve selected timestamped communications for later inspection and playback.
  • Physical measurements show what the mechanism and environment actually did.

No single layer proves the entire causal chain.

Replay is controlled evidence, not time travel

Playback republishes recorded communications. It may differ from the original run because wall-clock load, scheduler order, random seeds, external services, unrecorded parameters, device drivers, network conditions, and physical dynamics can differ.

Three safe claims:

  1. The bag contains a particular recorded sequence.
  2. A consumer produced a particular output under stated replay conditions.
  3. Repeated replay did or did not reproduce the software symptom.

One unsafe claim: “The replay proves the physical robot behaved identically.”

Misconception checks

“More logs always mean better observability”

Volume is not structure. Evidence needs timestamps, stable identifiers, severity, context, and a question it can answer.

“If replay succeeds once, the bug is fixed”

A successful replay may only show that one recorded case no longer fails. Test the causal hypothesis, edge cases, and live system separately.

“No message in the bag means no message was published”

It may also mean the topic was not selected, discovered, compatible, or recorded successfully. First verify the recorder's subscriptions and bag metadata.

Retrieval practice

For a robot that turns unexpectedly, name:

  • two topics to record;
  • one log event to add;
  • one bag-inspection check;
  • one conclusion replay cannot establish.

Summary

  • Start with a falsifiable failure hypothesis.
  • Observe and record the smallest sufficient evidence set.
  • Inspect the bag before trusting it.
  • Replay under documented conditions.
  • Compare expected and observed evidence across software and physical layers.

Sources and further study

External sources are linked for learning; their text, diagrams, screenshots, and code are not republished.

Practice labBuild a Robot Evidence PacketOpen this when you are ready to apply the model, collect evidence, and check your explanation.30 min

Lab: Build a Robot Evidence Packet

Objective

Design a minimal evidence plan for an intermittent robot failure, then inspect a simulated bag summary and defend what replay can prove.

Materials

  • Text editor, spreadsheet, or paper
  • Lesson evidence-loop visual
  • Optional ROS 2 installation with turtlesim and rosbag2

Steps

  1. Write a falsifiable hypothesis for a turtle or mobile robot that reacts late to a command.
  2. Select three topics, one log event, one parameter snapshot, and one physical observation.
  3. For each item, state the question it answers and the timestamp or identifier needed to correlate it.
  4. Inspect this simulated bag summary: duration 18 s; /scan 180 messages; /cmd_vel 72 messages; /tf 510 messages; no safety-state topic.
  5. Decide which hypotheses the bag can test and which remain underdetermined.
  6. Write a replay protocol: isolated consumers, playback rate, topics, expected output, and stop condition.
  7. Compare two outcomes: the late command reproduces on every replay; it never reproduces on replay.
  8. State one next experiment for each outcome.

Optional CLI extension:

ros2 bag record -o evidence_packet /turtle1/pose /turtle1/cmd_vel
ros2 bag info evidence_packet
ros2 bag play evidence_packet

Use the installed distribution's ros2 bag --help; do not drive physical hardware for this lab.

Expected Result

The submission includes a hypothesis-linked signal table, identifies the missing safety-state evidence, documents replay conditions, distinguishes recorded messages from physical motion, and proposes different next experiments for reproduced versus unreproduced symptoms.

Troubleshooting

  • Empty bag: verify topic names, publisher presence, recorder subscription, and stop/finalization.
  • Replay has no consumer output: confirm consumers are running, names/types/QoS are compatible, and simulated time is configured consistently.
  • Evidence cannot separate causes: add one discriminating signal rather than collecting unrelated data.
  • Storage grows too quickly: narrow topics, duration, or use an appropriate storage/splitting configuration.

Reflection Questions

  1. Why is a missing topic in a bag weaker evidence than a recorded topic value?
  2. Which original-run conditions should a replay report include?
  3. What physical measurement would complement /cmd_vel when investigating late braking?

Extension Challenge

Design a snapshot-mode trigger that preserves the seconds before and after an intermittent fault. Specify the trigger, buffer evidence, privacy boundary, retention rule, and how you would verify that the snapshot is usable.

Accessibility and Safety Fallback

Complete the entire activity with the simulated summary and a screen-reader-friendly table. No robot, paid software, video, or ROS installation is required.