Skip to main content

Module clock

Module clock 

Source
Expand description

Clock API for nros

This module provides clock abstraction for different time sources:

  • SystemTime: Wall clock time (affected by system time changes)
  • SteadyTime: Monotonic time (not affected by system time changes)
  • RosTime: Simulation time (can be paused/scaled)

§Example

use nros::clock::{Clock, ClockType};

// Create a system clock
let clock = Clock::system();
let now = clock.now();
println!("Current time: {} sec", now.sec);

// Create a steady clock for measuring durations
let clock = Clock::steady();
let start = clock.now();
// ... do work ...
let elapsed = clock.now() - start;

§Where the time comes from

With a platform port linked (the platform-clock feature), every clock reads the PORT: nros_platform_time_now_ns for the wall, and nros_platform_clock_ns for the monotonic. Without one there is no clock to read, and all three types fall back to an internal counter the caller advances with update_steady_time() — suitable for a bare-metal RTIC or polling loop, which is the only build where that counter has an owner.

Structs§

Clock
A clock for querying time
WallClockState
What the wall-clock stamps mean right now: the answer to nros_platform_wall_clock_state(), field for field.

Enums§

ClockType
Type of clock to use for time queries
WallClockSource
Which source answers the wall clock (WallClockState::source); the values of NROS_WALL_CLOCK_SOURCE_* in nros/platform.h.

Functions§

wall_clock_state
The wall clock’s state from the linked port, or None when this build has no port to ask (no platform-clock), the same condition under which Clock::system falls back to its counter.