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
A class for calling sleep() in a loop, such that the amount of sleep time will be computed to make th...
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
A high-performance stopwatch, with typical resolution of nanoseconds.
CRateTimer(const double rate_hz=1.0)
Ctor: specifies the desired rate (Hz)
Definition: CRateTimer.cpp:24
virtual ~CRateTimer()=default
Dtor.
mrpt::system::CTicTac m_tictac
void setRate(const double rate_hz)
Changes the object loop rate (Hz)
Definition: CRateTimer.cpp:25
double rate() const
Gets current rate (Hz)



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