Skip to content
PPHYSICAL AI GUIDESTART HERE →

Field guide

ROS 2 Sensor Timing: Clock Domains, Pairing and Freshness

Separate clock agreement, sensor timestamp pairing, and observation freshness with a source-based ROS 2 timing worksheet and a reproducible offline calculation.

By Physical AI Guide Editorial TeamPublished Updated

The short answer

Before accepting a synchronized sensor pair, prove that the timestamps are comparable, that they describe the intended measurement events, and that the observations are still fresh when the application uses them. Nearby timestamps are not a complete timing contract.

For a camera and a robot-state stream, keep three decisions separate:

  1. Clock agreement: Can these timestamps be compared in the same time domain and session?
  2. Pairing: Are the measurement events close enough together for this task?
  3. Freshness: Are those measurements recent enough at the actual decision point?

This guide provides a source-mapped review worksheet and an offline calculation that makes those distinctions visible. We reviewed the ROS 2 time design and pinned Jazzy Python implementations on November 3, 2026. We executed the standalone arithmetic example below, not ROS nodes or a physical robot. The acceptance rules are editorial engineering guidance, not measured deployment performance or safety certification.

Write down what each timestamp means

A numeric timestamp is incomplete without its origin and event meaning. Before subtracting two values, ask the driver owner to document:

  • which clock produced the stamp, including any hardware-to-host conversion;
  • whether the event is exposure, acquisition completion, driver publication, or another named point;
  • which host and process session produced it;
  • whether simulation time is enabled on the relevant node;
  • what evidence bounds clock offset and uncertainty;
  • what happens to queued observations after a restart or time jump.

These are proposed interface questions. ROS message transport does not answer them for an arbitrary sensor driver.

The ROS 2 time design distinguishes SystemTime, SteadyTime, and ROSTime. It describes ROS time following system time when its override is inactive and following a time source when active. The node’s use_sim_time parameter activates the ROS time source. The document also expects synchronized system clocks for meaningful event timestamps across a ROS network.

Setting use_sim_time is not evidence that two hardware sensors share a clock. A driver may report device time, host time, or a converted value. Require the conversion contract rather than inferring it from the parameter name.

Our coordinate-frame guide covers which geometric transform belongs to an observation. This guide addresses whether the observation and decision times can be compared before that lookup is meaningful.

Choose clocks for their purpose

The design’s time abstractions serve different jobs. The following review implications are our synthesis, not a complete implementation guarantee.

Clock Documented role Review implication
System time Tied to the system clock Record host synchronization evidence before comparing events from different machines
ROS time Can follow a published time source for simulation or replay Record override state, initialization, pauses, and jumps
Steady time Intended for uses such as hardware timeouts Use elapsed-time evidence locally; do not subtract it from a ROS observation stamp

The pinned Jazzy rclpy.clock source adds an important implementation detail: a directly constructed Clock() defaults to SYSTEM_TIME. Do not assume every clock object automatically follows a node’s simulated time. Review how the actual component obtains its clock and attaches its time source.

That source also documents sleep_until and sleep_for: a ROS-clock sleep can wait indefinitely if the time source is misconfigured and the context never shuts down. Switching ROS time on or off can end the sleep with a false result. A return from a timing call is therefore not automatically evidence that the intended interval elapsed.

Keep observation time and local elapsed-time monitoring separate. For communication loss and command validity, see the QoS and stale-data guide. The clock review supplies a prerequisite for interpreting its age checks, not a replacement for those checks.

What approximate synchronization actually checks

In the reviewed Jazzy Python ApproximateTimeSynchronizer, messages are queued by their header timestamps. Candidate groups are passed to the callback when their maximum-minus-minimum timestamp is strictly less than slop, with messages present in the corresponding queues.

That condition does not compare the timestamps with the current decision time. It is a pairing condition, not a freshness deadline. The implementation also limits each queue by queue_size, removing its oldest timestamp when over the limit. More queue capacity is not proof of lower latency.

Two implications follow from that code inspection:

  • Increasing slop can admit a wider timestamp spread. It does not correct clock offset, redefine exposure time, or make an old observation new.
  • The strict inequality matters at the exact boundary. Do not write an acceptance test that assumes equality passes without checking the installed implementation.

The same source warns against assigning current ROS time to headerless messages through allow_headerless, because delays are unpredictable. A substituted timestamp cannot retrospectively establish when a sensor acquired its measurement. Keep that distinction visible if a pipeline must handle headerless data.

These statements describe the pinned Python implementation, not every language, ROS distribution, or later release. Verify your installed package before turning them into a version-specific test expectation.

Reproduce the pairing-versus-age calculation

Consider invented camera and joint-state stamps in milliseconds, already expressed in the same initialized clock domain and session. Assume their declared event meanings are suitable for comparison. Set an illustrative pairing limit of 25 ms and a freshness limit of 100 ms.

Those numbers are examples, not recommended robot limits. The calculation models only timestamp spread and age. It does not reproduce queue selection, callback scheduling, sensor uncertainty, or all message_filters behavior.

cases = [
    ("recent pair", 1000, 1010, 1040),
    ("old pair", 1000, 1010, 1500),
    ("exact pairing boundary", 1000, 1025, 1040),
    ("future observation", 1000, 1010, 1005),
]
slop_ms = 25
max_age_ms = 100
for name, camera_ms, joints_ms, decision_ms in cases:
    spread = abs(camera_ms - joints_ms)
    ages = [decision_ms - stamp for stamp in (camera_ms, joints_ms)]
    paired = spread < slop_ms
    fresh = all(0 <= age <= max_age_ms for age in ages)
    print(name, "spread_ms=", spread, "ages_ms=", ages,
          "paired=", paired, "fresh=", fresh)

We ran this standard-library Python calculation. Its results were:

Illustrative case Timestamp spread Ages at decision Pairing condition Proposed freshness rule
Recent pair 10 ms 40 ms, 30 ms Pass Pass
Old pair 10 ms 500 ms, 490 ms Pass Fail
Exact pairing boundary 25 ms 40 ms, 15 ms Fail Pass
Future observation 10 ms 5 ms, -5 ms Pass Fail

The old pair is the key counterexample: it satisfies the timestamp-spread condition while failing the age requirement. A successful synchronizer callback would not settle the freshness question.

The final row needs investigation, not automatic clamping to zero. A future timestamp could reflect clock offset, inconsistent event definitions, conversion error, or an unsuitable decision clock. This example cannot identify which explanation applies. Its proposed freshness rule deliberately rejects negative age until the contract explains it.

For a real deployment, derive limits from task motion, measurement uncertainty, processing time, and the validated control design. If you cannot bound the relation between clocks, record age as not comparable, not as a passing number.

The sensor-timing acceptance worksheet

Use this proposed matrix in an isolated, non-actuating environment before any separately authorized hardware procedure. We have not executed these ROS fault cases.

Case Proposed receiving-team check Evidence to retain
Streams use different clocks or epochs Do not calculate cross-stream age until a valid mapping is established Clock identities, timestamp meaning, mapping and uncertainty
Simulated time enabled, no clock received Do not authorize time-dependent processing on an uninitialized clock Override state, clock value, first valid update
Header stamps are close but both old Apply a separate age check at consumption Both stamps, decision time, clock identity, verdict
Clock pauses during replay Distinguish a paused data timeline from elapsed host time ROS-time trace and separate local elapsed-time trace
Clock jumps backward Review retained pairs, caches, and pending decisions before resuming Jump event, old/new timeline session, invalidation decision
Clock jumps forward Re-evaluate ages and deadlines under the documented policy Jump magnitude, affected work, expired or retained state
Sensor or process restarts Re-establish timestamp origin and conversion before reuse Session identity, clock mapping, first accepted observation
Pairing callback never arrives Check delivery and queue/timestamp conditions separately Effective QoS, received stamps, queue settings, callback trace

The time design explicitly supports paused and backward-moving time, and treats zero as uninitialized when an active ROS time source has not supplied a value. That is different from the special “latest transform” meaning of zero in a tf2 lookup. Do not transfer a sentinel’s meaning between APIs.

The pinned rclpy source exposes jump callbacks and thresholds for forward jumps, backward jumps, and clock-source changes. Registering a callback does not itself clear application caches or validate pending work. Document what the application does in response and collect the actual outcome.

Keep a timing contract with each regression

Copy this record beside a captured incident or component regression:

Component and package revision:
Streams and timestamp event meanings:
Clock identities, hosts, and timeline/session:
Hardware-to-host conversion and uncertainty:
use_sim_time and time-source owner:
Pairing spread limit and rationale:
Age limit, decision point, and rationale:
Measured stamps and decision time:
Local elapsed-time evidence:
Pause, jump, and restart behavior:
Queued observations retained or invalidated:
Observed result: NOT TESTED
Decision and unresolved evidence:

Our incident-recording guide explains what to preserve and how to separate original outputs from replayed results. Add this timing contract so the replay does not silently compare one timeline with another. Our lifecycle-readiness guide addresses the separate decision about when restarted components may resume work.

A useful acceptance statement is narrow: “These streams used the documented clock mapping, met the selected spread and age limits, and handled the named pause and restart cases in this configuration.” It is not “the sensors are synchronized, therefore the robot is safe.” Physical stopping behavior and protective functions require their own system-level evidence.

Sources and evidence limits

First-party material reviewed November 3, 2026:

  1. ROS 2 Clock and Time design. Used for clock abstractions, use_sim_time, /clock, initialization, pauses, and discontinuities. This is architectural guidance, not a test of every current client library. Its displayed written and modified dates are inconsistent, so we do not infer a reliable update chronology from them.
  2. Jazzy rclpy.clock, pinned revision. Used for the direct constructor’s default, jump callback API, and documented sleep behavior. Source inspection only.
  3. Jazzy Python message_filters, pinned revision. Used for header-based queues, strict spread comparison, queue trimming, and headerless-message warnings. Source inspection only.

The three-part timing contract, review matrix, and illustrative acceptance limits are our synthesis. Only the offline arithmetic example was executed. No sensor latency, clock accuracy, ROS integration outcome, physical reliability, or safety performance was measured.

Frequently asked questions

Does approximate timestamp synchronization prove that robot inputs are fresh?

No. Messages can have nearby header timestamps while both are old when consumed. Check clock comparability, timestamp meaning, pairing spread, and age at the decision separately.

Does use_sim_time synchronize physical sensor clocks?

No. The ROS time abstraction changes the time source used by participating node clocks. It does not establish the relationship between a sensor's hardware timestamp and that time source.

Is message_filters slop a maximum sensor latency?

Not in the reviewed Jazzy Python implementation. Its pairing condition compares the spread of message header timestamps against slop. It does not compare those stamps with the current decision time.