Repository navigation
Major refactor of cl_ros2_timer to use std::chrono literals
This commit refactors the cl_ros2_timer client library to replace its raw integer tick-count API with a duration-based API using C++ std::chrono literals, resolving Issue #61. The change improves timing accuracy, eliminates period-dependent behavior, and removes a significant amount of now-unnecessary infrastructure.
The Problem
Previously, CbTimerCountdownOnce and CbTimerCountdownLoop accepted integer tick counts, making their behavior dependent on the ClRos2Timer constructor's tick period. A call like configure_orthogonal<OrTimer, CbTimerCountdownOnce>(10) would wait 10 ticks — meaning 5 seconds with a 500ms timer, or 10 seconds with a 1-second timer. This made state machine timing fragile and non-obvious to read. Additionally, the implementation counted ticks internally, producing up to one full tick period of undershoot.
The Solution
CbTimerCountdownOnce and CbTimerCountdownLoop now accept rclcpp::Duration directly via C++ chrono literals (5s, 500ms, 4min). Each behavior creates its own dedicated rclcpp::WallTimer on entry and cancels it on exit, giving exact, period-independent timing. The residual timing error is now ~50ms, which is the irreducible floor imposed by the SMACC2 SignalDetector's 20Hz polling loop — not the timer period. The new API reads as intended: configure_orthogonal<OrTimer, CbTimerCountdownOnce>(10s) waits exactly 10 seconds regardless of how the orthogonal is configured.
Infrastructure Removed
Because the behaviors now own their own wall timers, the entire tick-passing stack became unnecessary. ClRos2Timer is now a pure marker client with no constructor arguments and no component creation. CpTimerListener1, which previously bridged CpRos2Timer tick signals to behavior callbacks, has been deleted. CbRos2Timer, a generic tick-based behavior that was present in documentation but unused in any state machine, has also been removed. CpRos2Timer is retained in the smacc2 core library as a generic reusable component.
Scope of Changes
All 22 or_timer.hpp files across the reference library have been updated to createClient() with no arguments. All configure_orthogonal call sites — spanning over 300 state files — have been updated from integer tick counts to chrono literals. CbTimerWithWorkSimulation in sm_multithread_test_1 has been rewritten to own its own wall timer with an explicit tickPeriod parameter. The cl_ros2_timer README and the smacc2_docs how-to guide and tutorials have been updated to reflect the new API. All 38 packages have been bumped to version 3.1.0.