Skip to content

fix: track frame timestamp per-stream in HW clock mode (silences false reset warnings on DDS) - #3531

Merged
remibettan merged 1 commit into
realsenseai:ros2-developmentfrom
remibettan:fix/hw-clock-reset-per-stream
Jun 30, 2026
Merged

remibettan merged 1 commit into
realsenseai:ros2-developmentfrom
remibettan:fix/hw-clock-reset-per-stream

Conversation

@remibettan

Copy link
Copy Markdown
Collaborator

Summary

Fixes a wrapper-side false positive in BaseRealSenseNode::frameSystemTimeSec() that floods the logs with Hardware clock reset detected. Resetting ROS time base. warnings — and forces a spurious time-base rebase on most frames — when running with multi-stream sources that report timestamps in RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK (currently: DDS devices, e.g. D555).

USB devices report RS2_TIMESTAMP_DOMAIN_GLOBAL_TIME and never enter this branch, so they're unaffected.

Root cause

_previous_frame_time was a single shared double compared against the timestamp of every incoming frame regardless of which stream it came from. With multiple streams running at different rates (depth/color/IMU), frames legitimately interleave out of order against that one global value, so the _previous_frame_time > timestamp_ms check trips on most frames and is interpreted as a hardware clock reset.

Fix

Make _previous_frame_time a per-stream std::map<int, double> keyed by rs2::stream_profile::unique_id(). Each stream's monotonicity is now checked only against itself. On a genuine backward jump, clear the whole map so other streams re-seed silently on their next frame (the new time base would make their stored "previous" values stale anyway).

Validation

Tested on Ubuntu 22.04 / Humble against a D555 over DDS (librealsense 2.59.9 from source).

Before: Hardware clock reset detected repeating continuously throughout the run.

After: exactly one frame's time domain is HARDWARE_CLOCK. Timestamps may reset periodically. informational notice at startup (the expected first-frame seed), and zero Hardware clock reset detected messages during steady-state streaming.

The remaining log lines from dds-metadata-syncer / dds-topic-reader / color-formats-converter originate in librealsense's DDS layer, not the wrapper, and are out of scope for this PR.

Risk

  • USB / GLOBAL_TIME path: untouched (early-out before this branch).
  • Real HW clock wraps: still produce one warning + rebase, then quiet — same observable behavior as before, just no longer spammed by interleave artifacts.
  • No public API change.

🤖 Generated with Claude Code

…k reset warnings

The hardware-clock branch of frameSystemTimeSec compared every incoming
frame's timestamp against a single shared _previous_frame_time. With
multi-stream sources (e.g. DDS devices, where frames are tagged with
RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK), frames from different streams
running at different rates interleave out of order against that one
global value, triggering false "Hardware clock reset detected" warnings
and spurious time-base resets on nearly every frame.

Make _previous_frame_time a per-stream map keyed by the rs2 stream
unique_id, so each stream's monotonicity is checked only against itself.
On a real backward jump, clear the map so other streams re-seed silently
against the new time base on their next frame.

USB devices (GLOBAL_TIME domain) are unaffected — they don't enter this
branch.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@remibettan
remibettan requested a review from Nir-Az June 29, 2026 11:55

@Nir-Az Nir-Az left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@remibettan
remibettan merged commit 20739e5 into realsenseai:ros2-development Jun 30, 2026
9 of 10 checks passed
@remibettan
remibettan deleted the fix/hw-clock-reset-per-stream branch June 30, 2026 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants