class mrpt::system::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).

#include <mrpt/system/CRateTimer.h>

class CRateTimer
{
public:
    // construction

    CRateTimer(const double rate_hz = 1.0);

    //
methods

    void setRate(const double rate_hz);
    double rate() const;
    bool sleep();
};

Construction

CRateTimer(const double rate_hz = 1.0)

Ctor: specifies the desired rate (Hz)

Methods

void setRate(const double rate_hz)

Changes the object loop rate (Hz)

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.