Main MRPT website > C++ reference for MRPT 1.9.9
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-2017, 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/utils/CTicTac.h>
12 
13 namespace mrpt
14 {
15 namespace utils
16 {
17 /** A class for calling sleep() in a loop, such that the amount of sleep time
18  * will be computed
19  * to make the loop run at the desired rate (in Hz).
20  * \note [New in MRPT 1.5.0]
21  * \ingroup mrpt_base_grp
22  */
24 {
25  public:
26  /** Ctor: specifies the desired rate (Hz) */
27  CRateTimer(const double rate_hz = 1.0);
28  /** Dtor */
29  virtual ~CRateTimer();
30 
31  /** Changes the object loop rate (Hz) */
32  void setRate(const double rate_hz);
33  /** Sleeps for some time, such as the return of this method is 1/rate
34  * (seconds)
35  * after the return of the previous call.
36  * \return false if the rate could not be achieved ("we are already late"),
37  * true if all went right. */
38  bool sleep();
39 
40  private:
41  double m_rate_hz;
43 }; // End of class def.
44 
45 } // End of namespace
46 } // End of namespace
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
void setRate(const double rate_hz)
Changes the object loop rate (Hz)
Definition: CRateTimer.cpp:21
virtual ~CRateTimer()
Dtor.
Definition: CRateTimer.cpp:20
This class implements a high-performance stopwatch.
Definition: CTicTac.h:23
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::utils::CTicTac m_tictac
Definition: CRateTimer.h:42
CRateTimer(const double rate_hz=1.0)
Ctor: specifies the desired rate (Hz)
Definition: CRateTimer.cpp:19
A class for calling sleep() in a loop, such that the amount of sleep time will be computed to make th...
Definition: CRateTimer.h:23



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019