MRPT  1.9.9
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-2019, 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  /** Sleeps for some time, such as the return of this method is 1/rate
32  * (seconds)
33  * after the return of the previous call.
34  * \return false if the rate could not be achieved ("we are already late"),
35  * true if all went right. */
36  bool sleep();
37 
38  private:
39  double m_rate_hz{1.0};
41 }; // End of class def.
42 
43 } // 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:25
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:19
virtual ~CRateTimer()=default
Dtor.
mrpt::system::CTicTac m_tictac
void setRate(const double rate_hz)
Changes the object loop rate (Hz)
Definition: CRateTimer.cpp:20



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019