Skip to content

ROS 2 Time, Duration, and Sim Time

Source: ros2-copilot-skills time skill

Why This Matters

Time bugs are some of the most frustrating ROS 2 failures because they often appear as TF errors, stale messages, impossible durations, or simulation-only breakage. The fix is usually not a special case but a consistent time model.

Distilled Takeaways

  • ROS time, system time, and steady time serve different purposes and should not be mixed casually.
  • If you use simulation or bag playback, all relevant nodes should agree on use_sim_time.
  • Message stamps should come from the ROS node clock so the rest of the graph can reason about them correctly.
  • Time(0) in TF lookups means “latest available,” which is often safer than demanding an exact current transform.
  • Timers and rate-based loops are not interchangeable in callback-driven architectures.

Practical Guidance

  • Enable sim time consistently across the session or not at all.
  • Guard against zero time before the first /clock message arrives.
  • Use timers for periodic callbacks and reserve rate sleep for dedicated loops.
  • Audit time handling whenever TF extrapolation or stale-data warnings appear.

Corroborating References

When to Read the Original Source

Go to the original skill when you want concrete Python and C++ time arithmetic, timeout patterns, timer behavior notes, and the practical warnings around sim time, Time(0), and callback blocking.