2 #include <argos3/core/utility/logging/argos_log.h>
19 ::gettimeofday(&tNow,
nullptr);
22 timersub(&tNow, &m_tPast, &tDiff);
23 return tDiff.tv_sec * 1000000 + tDiff.tv_usec;
31 Real fValue =
static_cast<Real>(unValue) / 1e6;
41 if(unMicroSecDiff < m_unNominalPeriod) {
42 ::timespec tSleepPeriod;
43 tSleepPeriod.tv_sec =
static_cast<UInt32>((m_unNominalPeriod - unMicroSecDiff) / 1e6);
44 tSleepPeriod.tv_nsec = (m_unNominalPeriod - unMicroSecDiff) * 1000;
45 ::nanosleep(&tSleepPeriod,
nullptr);
48 LOGERR <<
"[WARNING] Nominal rate "
50 <<
" loops per sec delayed by "
51 << (unMicroSecDiff - m_unNominalPeriod)
56 ::gettimeofday(&m_tPast,
nullptr);
63 m_fNominalRate =
Abs(f_rate);
64 m_unNominalPeriod = 1e6 / m_fNominalRate;
65 ::gettimeofday(&m_tPast,
nullptr);
unsigned int UInt32
32-bit unsigned integer.
unsigned long long UInt64
64-bit unsigned integer.
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
CARGoSLog LOGERR(std::cerr, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_RED))
T Abs(const T &t_v)
Returns the absolute value of the passed argument.
CRate(Real f_rate)
Class constructor.
UInt64 ElapsedUS() const
Returns the time elapsed since the last sleep in microseconds.
void Sleep()
Sleeps for the appropriate time to complete the period.
void SetRate(Real f_rate)
Sets the rate and resets the internal clock.
Real ElapsedS() const
Returns the time elapsed since the last sleep in seconds.