chrono::ChRealtimeStepTimer Class Reference

Description

Class for a timer which attempts to enforce soft real-time.
Two different mechanisms are provided:
   1) Spin(), spins in place waiting for real time to catch up with the simulation time.
   2) SuggestSimulationStep(): returns a suggested value for the integration step size based on the wall clock time
   required for completing the previous iteration of the simulation loop.
The first mechanism is the standard way of enforcing soft real time. The mechanism implemented through
SuggestSimulationStep has the drawback of changing the integration step size in an uncontrollable manner thus
resulting in slightly different results on different platforms or at different runs. It is kept for backward
compatibility.

#include <ChRealtimeStep.h>

Inheritance diagram for chrono::ChRealtimeStepTimer:
Collaboration diagram for chrono::ChRealtimeStepTimer:

Public Member Functions

 ChRealtimeStepTimer ()
 Create the timer (outside the simulation loop, preferably just before beginning the loop)
 
void Spin (double step)
 Call this function INSIDE the simulation loop, just ONCE per loop (preferably as the last call in the loop), passing it the integration step size used at this step. More...
 
double SuggestSimulationStep (double max_step=0.02, double min_step=std::numeric_limits< double >::epsilon())
 Call this function INSIDE the simulation loop, just ONCE per loop, to get the suggested time for the next integration time step. More...
 
- Public Member Functions inherited from chrono::ChTimer< double >
void start ()
 Start the timer.
 
void stop ()
 Stops the timer.
 
void reset ()
 Reset the total accumulated time (when repeating multiple start() stop() start() stop() )
 
unsigned long long GetTimeMilliseconds () const
 Returns the time in [ms]. More...
 
unsigned long long GetTimeMillisecondsIntermediate () const
 Returns the time in [ms] since start(). It does not require stop().
 
unsigned long long GetTimeMicroseconds () const
 Returns the time in [us]. More...
 
unsigned long long GetTimeMicrosecondsIntermediate () const
 Returns the time in [us] since start(). It does not require stop().
 
double GetTimeSeconds () const
 Returns the time in [s], with real_type precision Use start()..stop() before calling this.
 
double GetTimeSecondsIntermediate () const
 Returns the time in [s] since start(). It does not require stop().
 
double operator() () const
 Get the last timer value, in seconds, with the () operator.
 

Member Function Documentation

◆ Spin()

void chrono::ChRealtimeStepTimer::Spin ( double  step)
inline

Call this function INSIDE the simulation loop, just ONCE per loop (preferably as the last call in the loop), passing it the integration step size used at this step.

If the time elapsed over the last step (i.e., from the last call to Spin) is small than the integration step size, this function will spin in place until real time catches up with the simulation time, thus providing soft real-time capabilities.

◆ SuggestSimulationStep()

double chrono::ChRealtimeStepTimer::SuggestSimulationStep ( double  max_step = 0.02,
double  min_step = std::numeric_limits<double>::epsilon() 
)
inline

Call this function INSIDE the simulation loop, just ONCE per loop, to get the suggested time for the next integration time step.

If the previous simulation step was completed fast enough, this function will suggest a corresponding small value for advancing the simulated time; vice-versa, it will return higher values (up to a maximum 'max_step' limit) if the simulation goes slow because of high CPU overhead. If the clamping value of 'max_step' is not reached, the real-time and simulated time should always match. There is also an optional 'min_step' value, to avoid too small of an integration step.

Parameters
max_stepupper limit for step
min_steplower limit for step

The documentation for this class was generated from the following file:
  • /builds/uwsbel/chrono/src/chrono/core/ChRealtimeStep.h