chrono::ChRealtimeStepTimer Class Reference

Description

Class for a timer which measure the time spent in VR or game-like simulation loops, and suggests a dt integration step for the physical simulation for the next step.

Uses high-resolution timer. Note that the suggested integrations step tries to keep a true real-time pace in advancing the simulation, that is the simulated time should match the real time. The suggested step may be non-constant because the overhead of the simulation loop may vary because of varying overhead in visualization, collision or simulation.

#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 while{} loop)
 
double SuggestSimulationStep (double max_step=0.02, double min_step=CH_NANOTOL)
 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. More...
 
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

double chrono::ChRealtimeStepTimer::SuggestSimulationStep ( double  max_step = 0.02,
double  min_step = CH_NANOTOL 
)

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

If the ChRealtimeStepTimer measured that previous simulation step required few real-time, it will suggest a corresponding small value for advancing the simulated time, and viceversa will give higher values (up to a maximum 'max_step' limit, however) 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, which avoids too small integration steps.

Parameters
max_stepupper limit for step
min_steplower limit for step