Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
bota_worker::Rate Class Reference

#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
 
RateOptionsgetOptions ()
 
const RateOptionsgetOptions () 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...
 

Detailed Description

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.

Definition at line 79 of file Rate.hpp.

Constructor & Destructor Documentation

bota_worker::Rate::Rate ( const std::string &  name,
const double  timeStep 
)

Simple constructor. Starts the clock. Call reset() to restart it if you do not intend to call sleep() immediately.

Parameters
nameName for printing.
timeStepTime step in seconds.

Definition at line 48 of file Rate.cpp.

bota_worker::Rate::Rate ( RateOptions  options)
explicit

Advanced constructor. Starts the clock. Call reset() to restart it if you do not intend to call sleep() immediately.

Parameters
optionsRate options.

Definition at line 52 of file Rate.cpp.

bota_worker::Rate::Rate ( Rate &&  other)
noexcept

Move constructor.

Parameters
otherRate to move.

Definition at line 57 of file Rate.cpp.

Member Function Documentation

void bota_worker::Rate::addDuration ( timespec &  time,
const double  duration 
)
static

Add a duration to a time point.

Parameters
timeTime point.
durationDuration to add in seconds.

Definition at line 219 of file Rate.cpp.

double bota_worker::Rate::getAwakeTime ( ) const

Get the most recent time which elapsed between subsequent calls of sleep().

Returns
Elapsed time in seconds.

Definition at line 173 of file Rate.cpp.

double bota_worker::Rate::getAwakeTimeMean ( ) const

Get the mean of the time which elapsed between subsequent calls of sleep().

Returns
Mean in seconds.

Definition at line 185 of file Rate.cpp.

double bota_worker::Rate::getAwakeTimeStdDev ( ) const

Get the standard deviation of the time which elapsed between subsequent calls of sleep().

Returns
Standard deviation in seconds.

Definition at line 209 of file Rate.cpp.

double bota_worker::Rate::getAwakeTimeVar ( ) const

Get the variance of the time which elapsed between subsequent calls of sleep().

Returns
Variance in seconds^2.

Definition at line 197 of file Rate.cpp.

double bota_worker::Rate::getDuration ( const timespec &  start,
const timespec &  end 
)
static

Get the duration between start and end time points.

Parameters
startStart time point.
endEnd time point.
Returns
Duration in seconds.

Definition at line 214 of file Rate.cpp.

unsigned int bota_worker::Rate::getNumErrors ( ) const
inline

Get the number of errors, not considering warnings.

Returns
Number of errors, not considering warnings.

Definition at line 213 of file Rate.hpp.

unsigned int bota_worker::Rate::getNumTimeSteps ( ) const
inline

Get the number of time steps.

Returns
Number of time steps.

Definition at line 195 of file Rate.hpp.

unsigned int bota_worker::Rate::getNumWarnings ( ) const
inline

Get the number of warnings.

Returns
Number of warnings.

Definition at line 204 of file Rate.hpp.

RateOptions& bota_worker::Rate::getOptions ( )
inline

Get the rate options by reference.

Returns
Rate options by reference.

Definition at line 140 of file Rate.hpp.

const RateOptions& bota_worker::Rate::getOptions ( ) const
inline

Get the rate options by constant reference.

Returns
Rate options by constant reference.

Definition at line 149 of file Rate.hpp.

const timespec& bota_worker::Rate::getSleepEndTime ( ) const
inline

Get the time when the most recent sleep() was supposed to end.

Returns
Time when the most recent sleep() was supposed to end.

Definition at line 177 of file Rate.hpp.

const timespec& bota_worker::Rate::getSleepStartTime ( ) const
inline

Get the time when the most recent sleep() started.

Returns
Time when the most recent sleep() started.

Definition at line 168 of file Rate.hpp.

const timespec& bota_worker::Rate::getStepTime ( ) const
inline

Get the time when the most recent step should have started.

Returns
Time when the most recent step should have started.

Definition at line 186 of file Rate.hpp.

void bota_worker::Rate::reset ( )

Reset the internal memory and restart the step time.

Definition at line 74 of file Rate.cpp.

void bota_worker::Rate::sleep ( )

Sleep for the rest of the time step.

Definition at line 96 of file Rate.cpp.

Member Data Documentation

double bota_worker::Rate::awakeTime_ = 0.0
protected

Most recent time which elapsed between subsequent calls of sleep().

Definition at line 108 of file Rate.hpp.

double bota_worker::Rate::awakeTimeM2_ = 0.0
protected

Helper variable to compute the variance of the time step which elapsed between subsequent calls of sleep().

Definition at line 112 of file Rate.hpp.

double bota_worker::Rate::awakeTimeMean_ = 0.0
protected

Mean of the time which elapsed between subsequent calls of sleep().

Definition at line 110 of file Rate.hpp.

timespec bota_worker::Rate::lastErrorPrintTime_ {}
protected

Point in time when the last error message was printed.

Definition at line 106 of file Rate.hpp.

timespec bota_worker::Rate::lastWarningPrintTime_ {}
protected

Point in time when the last warning message was printed.

Definition at line 104 of file Rate.hpp.

constexpr long int bota_worker::Rate::N_SEC_PER_SEC = static_cast<long int>(1e9)
staticprotected

Factor storing nanoseconds per seconds.

Definition at line 83 of file Rate.hpp.

unsigned int bota_worker::Rate::numErrors_ = 0
protected

Counter storing how many times a time step took longer than the error threshold, not considering warnings.

Definition at line 102 of file Rate.hpp.

unsigned int bota_worker::Rate::numTimeSteps_ = 0
protected

Counter storing how many times sleep has been called.

Definition at line 98 of file Rate.hpp.

unsigned int bota_worker::Rate::numWarnings_ = 0
protected

Counter storing how many times a time step took longer than the warning threshold.

Definition at line 100 of file Rate.hpp.

RateOptions bota_worker::Rate::options_ {}
protected

Rate options.

Definition at line 88 of file Rate.hpp.

constexpr double bota_worker::Rate::SEC_PER_N_SEC = 1.0 / N_SEC_PER_SEC
staticprotected

Factor storing seconds per nanoseconds.

Definition at line 85 of file Rate.hpp.

timespec bota_worker::Rate::sleepEndTime_ {}
protected

Point in time when the most recent sleep() ended.

Definition at line 93 of file Rate.hpp.

timespec bota_worker::Rate::sleepStartTime_ {}
protected

Point in time when the most recent sleep() started.

Definition at line 91 of file Rate.hpp.

timespec bota_worker::Rate::stepTime_ {}
protected

Point in time when the most recent step should have started. If the timing is fine, the step time is equal to the sleep end time.

Definition at line 96 of file Rate.hpp.


The documentation for this class was generated from the following files:


bota_worker
Author(s):
autogenerated on Wed Mar 3 2021 03:09:10