Throttler.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Fabian Reister ( fabian dot reister at kit dot edu )
17  * @date 2021
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #pragma once
23 
26 
27 namespace armarx
28 {
29 
30  /**
31  * @brief The Throttler class. Use this class to e.g. process data only at a certain frequency.
32  *
33  */
34  class Throttler
35  {
36  public:
37  /**
38  * @brief Construct a new Throttler object
39  *
40  * @param frequency in [Hz] to check
41  */
42  explicit Throttler(float frequency);
43 
44  /**
45  * @brief Check if enough time has passed since this function last returned true.
46  *
47  * @param timestamp in [µs]
48  * @return true if enough time has passed since last time when function
49  * returned true.
50  * @return false otherwise
51  */
52  bool check(const armarx::DateTime& timestamp) noexcept;
53 
54  private:
55  const armarx::Duration delay;
56 
57  armarx::DateTime lastTimeTrue{0};
58  };
59 
60 } // namespace armarx
DateTime.h
armarx::Throttler::check
bool check(const armarx::DateTime &timestamp) noexcept
Check if enough time has passed since this function last returned true.
Definition: Throttler.cpp:9
Duration.h
armarx::Throttler
The Throttler class.
Definition: Throttler.h:34
armarx::Throttler::Throttler
Throttler(float frequency)
Construct a new Throttler object.
Definition: Throttler.cpp:6
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28