Public Member Functions | Private Attributes | List of all members
corbo::Rate Class Reference

Rate objects can be used to run loops at a desired rate. More...

#include <time.h>

Public Member Functions

Duration lastCycleTime () const
 Return actual execution time of the last cycle. More...
 
 Rate (const Duration &dt)
 Cosntruct rate object from duration object (interval length) More...
 
 Rate (double frequency)
 Construct rate object from frequency [1/s]. More...
 
void reset ()
 
bool sleep ()
 Sleep for the remaining duration to met the desired frequency (w.r.t previous sleep call) More...
 
void updateCycleTime (const Duration &dt)
 Update cycle time without resetting start time. More...
 

Private Attributes

Duration _cycle_time
 
Duration _last_cycle_time = Duration(0)
 
Time _start = Time::now()
 

Detailed Description

Rate objects can be used to run loops at a desired rate.

Rate rate(10) // The loop should run at 10 Hz
while (1)
{
// perform some work which is ideally finished before 1/10 s
// in order to remain synchronized
rate.sleep(); // pause to synchronize with 10 Hz
}

This class is inspired and based on the ROS class ros::Time http://wiki.ros.org/roscpp/Overview/Time

See also
Time Duration
Author
Christoph Rösmann (chris.nosp@m.toph.nosp@m..roes.nosp@m.mann.nosp@m.@tu-d.nosp@m.ortm.nosp@m.und.d.nosp@m.e)

Definition at line 375 of file time.h.

Constructor & Destructor Documentation

◆ Rate() [1/2]

corbo::Rate::Rate ( double  frequency)
inlineexplicit

Construct rate object from frequency [1/s].

Definition at line 379 of file time.h.

◆ Rate() [2/2]

corbo::Rate::Rate ( const Duration dt)
inlineexplicit

Cosntruct rate object from duration object (interval length)

Definition at line 381 of file time.h.

Member Function Documentation

◆ lastCycleTime()

Duration corbo::Rate::lastCycleTime ( ) const
inline

Return actual execution time of the last cycle.

Definition at line 390 of file time.h.

◆ reset()

void corbo::Rate::reset ( )
inline

Definition at line 384 of file time.h.

◆ sleep()

bool corbo::Rate::sleep ( )

Sleep for the remaining duration to met the desired frequency (w.r.t previous sleep call)

Definition at line 53 of file time.cpp.

◆ updateCycleTime()

void corbo::Rate::updateCycleTime ( const Duration dt)
inline

Update cycle time without resetting start time.

Definition at line 387 of file time.h.

Member Data Documentation

◆ _cycle_time

Duration corbo::Rate::_cycle_time
private

Definition at line 394 of file time.h.

◆ _last_cycle_time

Duration corbo::Rate::_last_cycle_time = Duration(0)
private

Definition at line 395 of file time.h.

◆ _start

Time corbo::Rate::_start = Time::now()
private

Definition at line 393 of file time.h.


The documentation for this class was generated from the following files:
corbo::Rate::Rate
Rate(double frequency)
Construct rate object from frequency [1/s].
Definition: time.h:379


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:07:21