MRPT  2.0.5
List of all members | Public Types | Static Public Member Functions | Static Public Attributes
mrpt::Clock Class Reference

Detailed Description

Clock that is compatible with MRPT TTimeStamp representation.

Definition at line 18 of file Clock.h.

#include <mrpt/core/Clock.h>

Public Types

enum  Source { Realtime = 0, Monotonic }
 Options for setting the source of all timestamps across MRPT: setActiveClock(), now() More...
 
using rep = int64_t
 
using period = std::ratio< 1, 10000000 >
 
using duration = std::chrono::duration< rep, period >
 
using time_point = std::chrono::time_point< Clock >
 

Static Public Member Functions

static time_point now () noexcept
 Returns the current time using the currently selected Clock source. More...
 
static time_point fromDouble (const double t) noexcept
 Create a timestamp from its double representation. More...
 
static double toDouble (const time_point t) noexcept
 Converts a timestamp to a UNIX time_t-like number, with fractional part. More...
 
static void setActiveClock (const Source s)
 Changes the selected clock to get time from when calling now(). More...
 
static Source getActiveClock ()
 Returns the currently selected clock. More...
 
static int64_t resetMonotonicToRealTimeEpoch () noexcept
 Monotonic clock might drift over time with respect to Realtime. More...
 
static uint64_t getMonotonicToRealtimeOffset ()
 Returns the number of nanoseconds that are added to the output of the POSIX CLOCK_MONOTONIC to make timestamps match the epoch of POSIX CLOCK_REALTIME. More...
 

Static Public Attributes

static constexpr bool is_steady = std::chrono::system_clock::is_steady
 

Member Typedef Documentation

◆ duration

using mrpt::Clock::duration = std::chrono::duration<rep, period>

Definition at line 24 of file Clock.h.

◆ period

using mrpt::Clock::period = std::ratio<1, 10000000>

Definition at line 23 of file Clock.h.

◆ rep

using mrpt::Clock::rep = int64_t

Definition at line 21 of file Clock.h.

◆ time_point

using mrpt::Clock::time_point = std::chrono::time_point<Clock>

Definition at line 25 of file Clock.h.

Member Enumeration Documentation

◆ Source

Options for setting the source of all timestamps across MRPT: setActiveClock(), now()

Enumerator
Realtime 

Realtime: POSIX CLOCK_REALTIME.

The highest resolution available Typically this is better than 1 microsecond. Selected by default.

Monotonic 

Monotonic: POSIX CLOCK_MONOTONIC.

Only available in Linux systems.

Definition at line 41 of file Clock.h.

Member Function Documentation

◆ fromDouble()

mrpt::Clock::time_point mrpt::Clock::fromDouble ( const double  t)
staticnoexcept

Create a timestamp from its double representation.

See also
toDouble

Definition at line 99 of file Clock.cpp.

Referenced by mrpt::apps::MonteCarloLocalization_Base::prepareGT(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::readGTFile(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::readGTFileRGBD_TUM(), TEST(), and mrpt::system::time_tToTimestamp().

Here is the caller graph for this function:

◆ getActiveClock()

mrpt::Clock::Source mrpt::Clock::getActiveClock ( )
static

Returns the currently selected clock.

Definition at line 122 of file Clock.cpp.

References selectedClock.

◆ getMonotonicToRealtimeOffset()

uint64_t mrpt::Clock::getMonotonicToRealtimeOffset ( )
static

Returns the number of nanoseconds that are added to the output of the POSIX CLOCK_MONOTONIC to make timestamps match the epoch of POSIX CLOCK_REALTIME.

Definition at line 158 of file Clock.cpp.

References m2r_epoch, monotonic_epoch_init, resetMonotonicToRealTimeEpoch(), and MonotonicToRealtimeEpoch::rt2mono_diff.

Here is the call graph for this function:

◆ now()

mrpt::Clock::time_point mrpt::Clock::now ( )
staticnoexcept

Returns the current time using the currently selected Clock source.

See also
setActiveClock(), mrpt::Clock::Source

Definition at line 94 of file Clock.cpp.

References getCurrentTime().

Referenced by mrpt::system::CTimeLoggerEntry::CTimeLoggerEntry(), mrpt::opengl::COpenGLBuffer::RAII_Impl::destroy(), mrpt::apps::RawlogGrabberApp::dump_verbose_info(), mrpt::system::getCurrentTime(), mrpt::hwdrivers::CMyntEyeCamera::getObservation(), mrpt::apps::ICP_SLAM_App_Live::impl_get_next_observations(), mrpt::slam::CMetricMapBuilderICP::initialize(), mrpt::system::now(), mrpt::system::CTimeLoggerEntry::stop(), TEST(), and test_delay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetMonotonicToRealTimeEpoch()

int64_t mrpt::Clock::resetMonotonicToRealTimeEpoch ( )
staticnoexcept

Monotonic clock might drift over time with respect to Realtime.

The first time a time is requested to now() with Monotonic clock enabled, MRPT internally saves the current values of both, Realtime and Monotonic clocks, then use the difference in all subsequent calls to set Monotonic timepoints in the same epoch than Realtime.

By explicitly calling this static method, a user is able to force a resynchrnization between the two clocks. Potentially useful for systems that run for very long periods of time without interruption.

Returns
The mismatch between the former and the new estimations of the epochs differences between the two clocks, in units of nanoseconds.
Note
This method is ignored in non-Linux systems.

Definition at line 124 of file Clock.cpp.

References m2r_epoch, monotonic_epoch_init, MonotonicToRealtimeEpoch::monotonic_ns, MonotonicToRealtimeEpoch::realtime_ns, and MonotonicToRealtimeEpoch::rt2mono_diff.

Referenced by getCurrentTime(), getMonotonicToRealtimeOffset(), and TEST().

Here is the caller graph for this function:

◆ setActiveClock()

void mrpt::Clock::setActiveClock ( const Source  s)
static

Changes the selected clock to get time from when calling now().

Default: Realtime. Ignored in non-Linux systems.

Definition at line 114 of file Clock.cpp.

References ASSERT_, and selectedClock.

Referenced by TEST().

Here is the caller graph for this function:

◆ toDouble()

double mrpt::Clock::toDouble ( const time_point  t)
staticnoexcept

Converts a timestamp to a UNIX time_t-like number, with fractional part.

See also
fromDouble

Definition at line 106 of file Clock.cpp.

Referenced by mrpt::opengl::COpenGLBuffer::RAII_Impl::destroy(), mrpt::obs::CObservation::getDescriptionAsText(), mrpt::apps::RBPF_SLAM_App_Base::run(), TEST(), test_delay(), and mrpt::system::timestampTotime_t().

Here is the caller graph for this function:

Member Data Documentation

◆ is_steady

constexpr bool mrpt::Clock::is_steady = std::chrono::system_clock::is_steady
static

Definition at line 27 of file Clock.h.




Page generated by Doxygen 1.8.14 for MRPT 2.0.5 Git: 40e60e732 Thu Jul 9 08:38:35 2020 +0200 at jue jul 9 08:45:11 CEST 2020