upkie 6.1.0
Open-source wheeled biped robots
|
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. | |
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.
|
explicit |
Initialize clock.
frequency | Desired tick frequency in [Hz]. It should be an integer that divides one million. |
void upkie::cpp::utils::SynchronousClock::wait_for_next_tick | ( | ) |
Wait until the next tick of the internal clock.