MRPT  2.0.4
system/CRateTimer.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/system/CTicTac.h>
12 
13 namespace mrpt::system
14 {
15 /** A class for calling sleep() in a loop, such that the amount of sleep time
16  * will be computed
17  * to make the loop run at the desired rate (in Hz).
18  * \note [New in MRPT 1.5.0]
19  * \ingroup mrpt_system_grp
20  */
22 {
23  public:
24  /** Ctor: specifies the desired rate (Hz) */
25  CRateTimer(const double rate_hz = 1.0);
26  /** Dtor */
27  virtual ~CRateTimer() = default;
28 
29  /** Changes the object loop rate (Hz) */
30  void setRate(const double rate_hz);
31 
32  /** Gets current rate (Hz) */
33  double rate() const { return m_rate_hz; }
34 
35  /** Sleeps for some time, such as the return of this method is 1/rate
36  * (seconds)
37  * after the return of the previous call.
38  * \return false if the rate could not be achieved ("we are already late"),
39  * true if all went right. */
40  bool sleep();
41 
42  private:
43  double m_rate_hz{1.0};
45 }; // End of class def.
46 
47 } // namespace mrpt::system
mrpt::system::CRateTimer::rate
double rate() const
Gets current rate (Hz)
Definition: system/CRateTimer.h:33
mrpt::system::CTicTac
A high-performance stopwatch, with typical resolution of nanoseconds.
Definition: system/CTicTac.h:18
mrpt::system::CRateTimer::m_tictac
mrpt::system::CTicTac m_tictac
Definition: system/CRateTimer.h:44
mrpt::system::CRateTimer::sleep
bool sleep()
Sleeps for some time, such as the return of this method is 1/rate (seconds) after the return of the p...
Definition: CRateTimer.cpp:30
mrpt::system::CRateTimer
A class for calling sleep() in a loop, such that the amount of sleep time will be computed to make th...
Definition: system/CRateTimer.h:22
mrpt::system::CRateTimer::CRateTimer
CRateTimer(const double rate_hz=1.0)
Ctor: specifies the desired rate (Hz)
Definition: CRateTimer.cpp:24
mrpt::system::CRateTimer::setRate
void setRate(const double rate_hz)
Changes the object loop rate (Hz)
Definition: CRateTimer.cpp:25
CTicTac.h
mrpt::system::CRateTimer::~CRateTimer
virtual ~CRateTimer()=default
Dtor.
mrpt::system::CRateTimer::m_rate_hz
double m_rate_hz
Definition: system/CRateTimer.h:43
mrpt::system
Definition: backtrace.h:15



Page generated by Doxygen 1.8.18 for MRPT 2.0.4 at Thu Sep 24 07:14:18 UTC 2020