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

Enums§

ClockType
Type of clock to use for time queries