MRPT  2.0.4
List of all members | Public Member Functions | Private Attributes
mrpt::system::CRateTimer Class Reference

Detailed Description

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).

Note
[New in MRPT 1.5.0]

Definition at line 21 of file system/CRateTimer.h.

#include <mrpt/system/CRateTimer.h>

Public Member Functions

 CRateTimer (const double rate_hz=1.0)
 Ctor: specifies the desired rate (Hz) More...
 
virtual ~CRateTimer ()=default
 Dtor. More...
 
void setRate (const double rate_hz)
 Changes the object loop rate (Hz) More...
 
double rate () const
 Gets current rate (Hz) More...
 
bool sleep ()
 Sleeps for some time, such as the return of this method is 1/rate (seconds) after the return of the previous call. More...
 

Private Attributes

double m_rate_hz {1.0}
 
mrpt::system::CTicTac m_tictac
 

Constructor & Destructor Documentation

◆ CRateTimer()

CRateTimer::CRateTimer ( const double  rate_hz = 1.0)

Ctor: specifies the desired rate (Hz)

Definition at line 24 of file CRateTimer.cpp.

References setRate().

Here is the call graph for this function:

◆ ~CRateTimer()

virtual mrpt::system::CRateTimer::~CRateTimer ( )
virtualdefault

Dtor.

Member Function Documentation

◆ rate()

double mrpt::system::CRateTimer::rate ( ) const
inline

Gets current rate (Hz)

Definition at line 33 of file system/CRateTimer.h.

References m_rate_hz.

Referenced by mrpt::system::CControlledRateTimer::actualControlledRate(), and mrpt::system::CControlledRateTimer::sleep().

Here is the caller graph for this function:

◆ setRate()

void CRateTimer::setRate ( const double  rate_hz)

Changes the object loop rate (Hz)

Definition at line 25 of file CRateTimer.cpp.

References ASSERT_ABOVE_, and m_rate_hz.

Referenced by CRateTimer(), mrpt::apps::RawlogGrabberApp::SensorThread(), and mrpt::system::CControlledRateTimer::sleep().

Here is the caller graph for this function:

◆ sleep()

bool CRateTimer::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.

Definition at line 30 of file CRateTimer.cpp.

References ASSERT_ABOVE_, ASSERT_ABOVEEQ_, ASSERT_BELOWEQ_, mrpt::system::os::fprintf(), m_rate_hz, m_tictac, mrpt::system::CTicTac::Tac(), and mrpt::system::CTicTac::Tic().

Referenced by mrpt::apps::RawlogGrabberApp::SensorThread(), and mrpt::system::CControlledRateTimer::sleep().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_rate_hz

double mrpt::system::CRateTimer::m_rate_hz {1.0}
private

Definition at line 43 of file system/CRateTimer.h.

Referenced by rate(), setRate(), and sleep().

◆ m_tictac

mrpt::system::CTicTac mrpt::system::CRateTimer::m_tictac
private

Definition at line 44 of file system/CRateTimer.h.

Referenced by sleep().




Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020