CycleUtil.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarX
19  * @author Mirko Waechter( mirko.waechter at kit dot edu)
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include <cstdint>
27 
28 #include <IceUtil/Time.h>
29 
30 namespace armarx
31 {
32  /**
33  * @brief This util class helps with keeping a cycle time during a control cycle.
34  * The main function is waitForCycleDuration(), which should be called in every cycle.
35  * The function will wait (virtual or system time) until the cycle time is reached.
36  * If the last cycle took already too long, it will return immediately.
37  * The last cycle time is updated, when waitForCycleDuration() is called.
38  * @note If system time is used (i.e. not the timeserver) the monotonic clock is used.
39  */
40  class CycleUtil
41  {
42  public:
44  CycleUtil(const std::int64_t& cycleDurationMs, bool forceSystemTime = false);
45  /**
46  * @brief resets startTime, lastCycleTime and cycleCount.
47  */
48  void reset();
49  /**
50  * @brief
51  * This function will wait (virtual or system time) until the cycle time is reached.
52  * If the last cycle took already too long, it will return immediately.
53  * The last cycle time is updated, when this function is called.
54  * @return returns the time the function waited
55  */
58 
59  /**
60  * @brief Time when object was constructed or reset was last called.
61  */
63 
64  /**
65  * @brief Time when the last cycle finished or start time.
66  */
68 
69  /**
70  * @brief Count of how many cycles were executed, i.e. how often waitForCycleDuration() was called.
71  */
72  std::int64_t getCycleCount() const;
76  float getBusyWaitShare() const;
77  void setBusyWaitShare(float value);
78 
79  protected:
80  static IceUtil::Time now();
86  std::int64_t cycleCount;
89  };
90 } // namespace armarx
armarx::CycleUtil::getCycleCount
std::int64_t getCycleCount() const
Count of how many cycles were executed, i.e.
Definition: CycleUtil.cpp:97
armarx::CycleUtil::getMinimumDuration
IceUtil::Time getMinimumDuration() const
Definition: CycleUtil.cpp:114
armarx::CycleUtil::getLastCycleTime
IceUtil::Time getLastCycleTime() const
Time when the last cycle finished or start time.
Definition: CycleUtil.cpp:146
armarx::CycleUtil::cycleCount
std::int64_t cycleCount
Definition: CycleUtil.h:86
armarx::CycleUtil
This util class helps with keeping a cycle time during a control cycle.
Definition: CycleUtil.h:40
armarx::CycleUtil::cycleMaxDuration
IceUtil::Time cycleMaxDuration
Definition: CycleUtil.h:85
armarx::CycleUtil::setBusyWaitShare
void setBusyWaitShare(float value)
Definition: CycleUtil.cpp:132
armarx::CycleUtil::getMaximumDuration
IceUtil::Time getMaximumDuration() const
Definition: CycleUtil.cpp:120
armarx::CycleUtil::cycleDuration
IceUtil::Time cycleDuration
Definition: CycleUtil.h:83
armarx::CycleUtil::getBusyWaitShare
float getBusyWaitShare() const
Definition: CycleUtil.cpp:126
armarx::CycleUtil::getAverageDuration
IceUtil::Time getAverageDuration() const
Definition: CycleUtil.cpp:103
armarx::CycleUtil::lastCycleTime
IceUtil::Time lastCycleTime
Definition: CycleUtil.h:82
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::CycleUtil::reset
void reset()
resets startTime, lastCycleTime and cycleCount.
Definition: CycleUtil.cpp:44
armarx::CycleUtil::waitForCycleDuration
IceUtil::Time waitForCycleDuration()
This function will wait (virtual or system time) until the cycle time is reached.
Definition: CycleUtil.cpp:53
armarx::CycleUtil::cycleMinDuration
IceUtil::Time cycleMinDuration
Definition: CycleUtil.h:84
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::CycleUtil::forceSystemTime
bool forceSystemTime
Definition: CycleUtil.h:87
armarx::CycleUtil::update
IceUtil::Time update()
Definition: CycleUtil.cpp:73
armarx::CycleUtil::getStartTime
IceUtil::Time getStartTime() const
Time when object was constructed or reset was last called.
Definition: CycleUtil.cpp:91
armarx::CycleUtil::CycleUtil
CycleUtil(const IceUtil::Time &cycleDuration, bool forceSystemTime=false)
Definition: CycleUtil.cpp:30
armarx::CycleUtil::now
static IceUtil::Time now()
Definition: CycleUtil.cpp:138
armarx::CycleUtil::startTime
IceUtil::Time startTime
Definition: CycleUtil.h:81
armarx::CycleUtil::busyWaitShare
float busyWaitShare
Definition: CycleUtil.h:88
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28