pub struct Clock { /* private fields */ }Expand description
A clock for querying time
Clocks provide access to different time sources. Each node typically has an associated clock, but you can also create standalone clocks.
Implementations§
Source§impl Clock
impl Clock
Sourcepub const fn system() -> Clock
pub const fn system() -> Clock
Create a system time clock
System time reflects the real-world wall clock time.
Sourcepub const fn steady() -> Clock
pub const fn steady() -> Clock
Create a steady (monotonic) time clock
Steady time is guaranteed to only increase and is not affected by system time changes.
Sourcepub const fn ros_time() -> Clock
pub const fn ros_time() -> Clock
Create a ROS time clock
ROS time can be overridden for simulation. When no override is active, it returns system time.
Sourcepub const fn clock_type(&self) -> ClockType
pub const fn clock_type(&self) -> ClockType
Get the clock type
Sourcepub fn now(&self) -> Time
pub fn now(&self) -> Time
Get the current time from this clock
§Platform behavior
- With
std: Usesstd::time::SystemTimeorstd::time::Instant - Without
std: Uses internal counters that must be updated manually
Sourcepub fn set_ros_time_override(nanos: i64)
pub fn set_ros_time_override(nanos: i64)
Set a ROS time override
When set, all RosTime clocks will return this time instead of
system time. This is useful for simulation.
§Arguments
nanos- Nanoseconds since epoch
Sourcepub fn set_ros_time_override_time(time: Time)
pub fn set_ros_time_override_time(time: Time)
Set a ROS time override from a Time value
Sourcepub fn clear_ros_time_override()
pub fn clear_ros_time_override()
Clear the ROS time override
After clearing, RosTime clocks will return system time again.
Sourcepub fn is_ros_time_override_active() -> bool
pub fn is_ros_time_override_active() -> bool
Check if a ROS time override is active
Sourcepub fn get_ros_time_override() -> Option<Time>
pub fn get_ros_time_override() -> Option<Time>
Get the current ROS time override value (if active)
Sourcepub fn update_steady_time(delta_nanos: i64)
pub fn update_steady_time(delta_nanos: i64)
Update the steady time counter
For no_std environments, call this periodically from your
main loop or RTIC task to advance the steady clock.
§Arguments
delta_nanos- Nanoseconds elapsed since last call
Sourcepub fn update_steady_time_ms(delta_ms: u64)
pub fn update_steady_time_ms(delta_ms: u64)
Update the steady time counter (milliseconds version)
Convenience method for RTIC tasks using millisecond intervals.
§Arguments
delta_ms- Milliseconds elapsed since last call
Sourcepub fn set_steady_time(nanos: i64)
pub fn set_steady_time(nanos: i64)
Set the steady time counter to a specific value
Use this to initialize the clock or synchronize with an external time source.
Sourcepub fn get_steady_time_nanos() -> i64
pub fn get_steady_time_nanos() -> i64
Get the current steady time counter value