upkie 6.1.0
Open-source wheeled biped robots
Loading...
Searching...
No Matches
upkie::cpp::utils::SynchronousClock Class Reference

Synchronous (blocking) clock. More...

#include <SynchronousClock.h>

Public Member Functions

 SynchronousClock (double frequency)
 Initialize clock. More...
 
void wait_for_next_tick ()
 Wait until the next tick of the internal clock. More...
 
double measured_period () const noexcept
 Get measured period in seconds.
 
int skip_count () const noexcept
 Get last number of clock cycles skipped.
 
double slack () const noexcept
 Get the last sleep duration duration in seconds.
 

Detailed Description

Synchronous (blocking) clock.

This clock ticks at a fixed frequency. It provides a method to wait for the next tick (which is always blocking, see below), and reports missed ticks if applicable.

The difference between a blocking clock and a rate limiter lies in the behavior when skipping cycles. A rate limiter does nothing if there is no time left, as the caller's rate does not need to be limited. On the contrary, a synchronous clock waits for the next tick, which is by definition in the future, so it always waits for a non-zero duration.

Internally all durations in this class are stored in microseconds.

Constructor & Destructor Documentation

◆ SynchronousClock()

upkie::cpp::utils::SynchronousClock::SynchronousClock ( double  frequency)
explicit

Initialize clock.

Parameters
frequencyDesired tick frequency in [Hz]. It should be an integer that divides one million.

Member Function Documentation

◆ wait_for_next_tick()

void upkie::cpp::utils::SynchronousClock::wait_for_next_tick ( )

Wait until the next tick of the internal clock.

Note
This function will always block and wait for the next tick into the future. It will warn if it detects some missed ticks since the last call.

The documentation for this class was generated from the following files: