#include <Rate.hpp>
Public Member Functions | |
double | getAwakeTime () const |
double | getAwakeTimeMean () const |
double | getAwakeTimeStdDev () const |
double | getAwakeTimeVar () const |
unsigned int | getNumErrors () const |
unsigned int | getNumTimeSteps () const |
unsigned int | getNumWarnings () const |
RateOptions & | getOptions () |
const RateOptions & | getOptions () const |
const timespec & | getSleepEndTime () const |
const timespec & | getSleepStartTime () const |
const timespec & | getStepTime () const |
Rate (const std::string &name, const double timeStep) | |
Rate (RateOptions options) | |
Rate (Rate &&other) noexcept | |
void | reset () |
void | sleep () |
Static Public Member Functions | |
static void | addDuration (timespec &time, const double duration) |
static double | getDuration (const timespec &start, const timespec &end) |
Protected Attributes | |
double | awakeTime_ = 0.0 |
Most recent time which elapsed between subsequent calls of sleep(). More... | |
double | awakeTimeM2_ = 0.0 |
Helper variable to compute the variance of the time step which elapsed between subsequent calls of sleep(). More... | |
double | awakeTimeMean_ = 0.0 |
Mean of the time which elapsed between subsequent calls of sleep(). More... | |
timespec | lastErrorPrintTime_ {} |
Point in time when the last error message was printed. More... | |
timespec | lastWarningPrintTime_ {} |
Point in time when the last warning message was printed. More... | |
unsigned int | numErrors_ = 0 |
Counter storing how many times a time step took longer than the error threshold, not considering warnings. More... | |
unsigned int | numTimeSteps_ = 0 |
Counter storing how many times sleep has been called. More... | |
unsigned int | numWarnings_ = 0 |
Counter storing how many times a time step took longer than the warning threshold. More... | |
RateOptions | options_ {} |
Rate options. More... | |
timespec | sleepEndTime_ {} |
Point in time when the most recent sleep() ended. More... | |
timespec | sleepStartTime_ {} |
Point in time when the most recent sleep() started. More... | |
timespec | stepTime_ {} |
Static Protected Attributes | |
static constexpr long int | N_SEC_PER_SEC = static_cast<long int>(1e9) |
Factor storing nanoseconds per seconds. More... | |
static constexpr double | SEC_PER_N_SEC = 1.0 / N_SEC_PER_SEC |
Factor storing seconds per nanoseconds. More... | |
Rate class for repeated processing at a certain rate. The processing time is defined as the "awake" time, the time between the "sleep" time. This class implements a sleep() method for sleeping for the remaining time of the time step. Also statistics about the awake time are taken.
If the awake time is bigger than the time step (timing is violated), there are two behaviors implemented:
Enforce the rate: Try to keep the rate constant by compensating with shorter time steps. | | | | | | | |===—>|===—>|============|===|===–>|===—>| | | | | | | |
Do not enforce the rate: Try to keep the single time step constant. | | | | | | | |===—>|===—>|============|===—>|===—>|===—>| | | | | | | |
Legend: | Step time === Awake time –> Sleep time
The time step, the time step thresholds for warnings and errors and the setting to enforce the rate can be changed during run-time of this class.
bota_worker::Rate::Rate | ( | const std::string & | name, |
const double | timeStep | ||
) |
|
explicit |
|
noexcept |
|
static |
double bota_worker::Rate::getAwakeTime | ( | ) | const |
double bota_worker::Rate::getAwakeTimeMean | ( | ) | const |
double bota_worker::Rate::getAwakeTimeStdDev | ( | ) | const |
double bota_worker::Rate::getAwakeTimeVar | ( | ) | const |
|
static |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void bota_worker::Rate::reset | ( | ) |
void bota_worker::Rate::sleep | ( | ) |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticprotected |
|
protected |
|
protected |
|
protected |