LocalGuidance
A library that generates velocity references to follow a path.
any_worker::Rate Class Reference

#include <Rate.hpp>

Public Member Functions

 Rate (const std::string &name, const double timeStep)
 
 Rate (const RateOptions &options)
 
 Rate (Rate &&other)
 
RateOptionsgetOptions ()
 
const RateOptionsgetOptions () const
 
void reset ()
 
void sleep ()
 
const timespec & getSleepStartTime () const
 
const timespec & getSleepEndTime () const
 
const timespec & getStepTime () const
 
unsigned int getNumTimeSteps () const
 
unsigned int getNumWarnings () const
 
unsigned int getNumErrors () const
 
double getAwakeTime () const
 
double getAwakeTimeMean () const
 
double getAwakeTimeVar () const
 
double getAwakeTimeStdDev () const
 

Static Public Member Functions

static double GetDuration (const timespec &start, const timespec &end)
 
static void AddDuration (timespec &time, const double duration)
 

Protected Attributes

RateOptions options_
 Rate options. More...
 
timespec sleepStartTime_
 Point in time when the most recent sleep() started. More...
 
timespec sleepEndTime_
 Point in time when the most recent sleep() ended. More...
 
timespec stepTime_
 
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...
 
unsigned int numErrors_ = 0
 Counter storing how many times a time step took longer than the error threshold, not considering warnings. More...
 
timespec lastWarningPrintTime_
 Point in time when the last warning message was printed. More...
 
timespec lastErrorPrintTime_
 Point in time when the last error message was printed. More...
 
double awakeTime_ = 0.0
 Most recent time which elapsed between subsequent calls of sleep(). More...
 
double awakeTimeMean_ = 0.0
 Mean of the 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...
 

Static Protected Attributes

static constexpr long int NSecPerSec_ = 1e9
 Factor storing nanoseconds per seconds. More...
 
static constexpr double SecPerNSec_ = 1.0/NSecPerSec_
 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.

Constructor & Destructor Documentation

any_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.
any_worker::Rate::Rate ( const RateOptions options)

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

Parameters
optionsRate options.
any_worker::Rate::Rate ( Rate &&  other)

Move constructor.

Parameters
otherRate to move.

Member Function Documentation

static void any_worker::Rate::AddDuration ( timespec &  time,
const double  duration 
)
static

Add a duration to a time point.

Parameters
timeTime point.
durationDuration to add in seconds.
double any_worker::Rate::getAwakeTime ( ) const

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

Returns
Elapsed time in seconds.
double any_worker::Rate::getAwakeTimeMean ( ) const

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

Returns
Mean in seconds.
double any_worker::Rate::getAwakeTimeStdDev ( ) const

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

Returns
Standard deviation in seconds.
double any_worker::Rate::getAwakeTimeVar ( ) const

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

Returns
Variance in seconds^2.
static double any_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.
unsigned int any_worker::Rate::getNumErrors ( ) const
inline

Get the number of errors, not considering warnings.

Returns
Number of errors, not considering warnings.
unsigned int any_worker::Rate::getNumTimeSteps ( ) const
inline

Get the number of time steps.

Returns
Number of time steps.
unsigned int any_worker::Rate::getNumWarnings ( ) const
inline

Get the number of warnings.

Returns
Number of warnings.
RateOptions& any_worker::Rate::getOptions ( )
inline

Get the rate options by reference.

Returns
Rate options by reference.
const RateOptions& any_worker::Rate::getOptions ( ) const
inline

Get the rate options by constant reference.

Returns
Rate options by constant reference.
const timespec& any_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.
const timespec& any_worker::Rate::getSleepStartTime ( ) const
inline

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

Returns
Time when the most recent sleep() started.
const timespec& any_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.
void any_worker::Rate::reset ( )

Reset the internal memory and restart the step time.

void any_worker::Rate::sleep ( )

Sleep for the rest of the time step.

Member Data Documentation

double any_worker::Rate::awakeTime_ = 0.0
protected

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

double any_worker::Rate::awakeTimeM2_ = 0.0
protected

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

double any_worker::Rate::awakeTimeMean_ = 0.0
protected

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

timespec any_worker::Rate::lastErrorPrintTime_
protected

Point in time when the last error message was printed.

timespec any_worker::Rate::lastWarningPrintTime_
protected

Point in time when the last warning message was printed.

constexpr long int any_worker::Rate::NSecPerSec_ = 1e9
staticprotected

Factor storing nanoseconds per seconds.

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

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

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

Counter storing how many times sleep has been called.

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

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

RateOptions any_worker::Rate::options_
protected

Rate options.

constexpr double any_worker::Rate::SecPerNSec_ = 1.0/NSecPerSec_
staticprotected

Factor storing seconds per nanoseconds.

timespec any_worker::Rate::sleepEndTime_
protected

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

timespec any_worker::Rate::sleepStartTime_
protected

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

timespec any_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.


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