AUTh-ARL Core Stack  0.7
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
arl::utils::Timer Class Reference

Provides timing capabilities, like measure the time elapsed since the last call (e.g. useful in a control loop). More...

#include <timer.h>

Public Member Functions

 Timer ()
 
 ~Timer ()
 
void init ()
 Initialize timer to run for the first time. More...
 
double timeElapsedSinceLastCall ()
 Returns the time elapsed in seconds since the last call of this function. Useful in control loops, to know how much time elapsed since the previous control cycle. More...
 
std::string getCurrentDateTime ()
 Returns the current date and time in a string format. More...
 
void sleep (double input)
 Sleeps for the given amount of seconds. More...
 
void startPoint ()
 Saves locally the current time in order to be used as a starting point from arl::utils::Timer::timeFromStartPoint. Call it in the beginning of the code that you want to measure. More...
 
std::chrono::steady_clock::time_point getCurrPoint ()
 Returns the current time. Useful if used in combination with arl::utils::Timer::timeFromGivenPoint. More...
 
double timeFromStartPoint ()
 Provides the time elapsed in seconds from the last call of arl::utils::Timer::startPoint. More...
 
double timeFromGivenPoint (const std::chrono::steady_clock::time_point &given_point)
 Provides the time elapsed in seconds from a given point. The given point can be obtained if you first call arl::utils::Timer::getCurrPoint. More...
 

Detailed Description

Provides timing capabilities, like measure the time elapsed since the last call (e.g. useful in a control loop).

Example of use:

#include <autharl_core/utils/timer.h>
// ...
Timer timer;
// Control loop
double t = 0;
while(true)
{
// Calculate the total time in sec since the control loop started
t += timer.timeElapsedSinceLastCall();
std::cout << t << std::endl;
// Run the loop every 1ms;
timer.sleep(0.001);
}

Constructor & Destructor Documentation

arl::utils::Timer::Timer ( )
arl::utils::Timer::~Timer ( )

Member Function Documentation

std::string arl::utils::Timer::getCurrentDateTime ( )

Returns the current date and time in a string format.

Returns
The current date and time;
std::chrono::steady_clock::time_point arl::utils::Timer::getCurrPoint ( )

Returns the current time. Useful if used in combination with arl::utils::Timer::timeFromGivenPoint.

void arl::utils::Timer::init ( )

Initialize timer to run for the first time.

Use it in case you want to initialize the arl::utils::Timer::timeElapsedSinceLastCall().

void arl::utils::Timer::sleep ( double  input)

Sleeps for the given amount of seconds.

Parameters
inputThe time to sleep in seconds.
void arl::utils::Timer::startPoint ( )

Saves locally the current time in order to be used as a starting point from arl::utils::Timer::timeFromStartPoint. Call it in the beginning of the code that you want to measure.

double arl::utils::Timer::timeElapsedSinceLastCall ( )

Returns the time elapsed in seconds since the last call of this function. Useful in control loops, to know how much time elapsed since the previous control cycle.

Returns
The time elapsed in seconds
See Also
arl::utils::Timer::init()
double arl::utils::Timer::timeFromGivenPoint ( const std::chrono::steady_clock::time_point &  given_point)

Provides the time elapsed in seconds from a given point. The given point can be obtained if you first call arl::utils::Timer::getCurrPoint.

Parameters
given_pointThe given time point.
Returns
The time elapsed in seconds.
double arl::utils::Timer::timeFromStartPoint ( )

Provides the time elapsed in seconds from the last call of arl::utils::Timer::startPoint.

Returns
The time elapsed in seconds.