Class CRateTimer

Class Documentation

class CRateTimer

A class for calling sleep() in a loop, such that the amount of sleep time will be computed to make the loop run at the desired rate (in Hz).

Public Functions

CRateTimer(const double rate_hz = 1.0)

Ctor: specifies the desired rate (Hz)

virtual ~CRateTimer() = default

Dtor

void setRate(const double rate_hz)

Changes the object loop rate (Hz)

inline double rate() const

Gets current rate (Hz)

bool sleep()

Sleeps for some time, such as the return of this method is 1/rate (seconds) after the return of the previous call.

Returns:

false if the rate could not be achieved (“we are already late”), true if all went right.