MRPT  1.9.9
system/CRateTimer.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://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();
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;
41 }; // End of class def.
42 
43 }
44 
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:26
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()
Dtor.
Definition: CRateTimer.cpp:20
mrpt::system::CTicTac m_tictac
void setRate(const double rate_hz)
Changes the object loop rate (Hz)
Definition: CRateTimer.cpp:21



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020