Fawkes API  Fawkes Development Version
fawkes::Clock Class Reference

This is supposed to be the central clock in Fawkes. More...

#include <utils/time/clock.h>

Public Types

enum  TimesourceSelector { DEFAULT, REALTIME, EXTERNAL }
 Select the time source. More...
 

Public Member Functions

virtual ~Clock ()
 Destructor. More...
 
void register_ext_timesource (TimeSource *ts, bool make_default=false)
 Register an external time source. More...
 
void set_ext_default_timesource (bool ext_is_default)
 Set/unset the external time source as the default time source. More...
 
bool is_ext_default_timesource () const
 Checks whether the external time source is the default time soucre. More...
 
bool has_ext_timesource () const
 Check whether an external time source is registered. More...
 
Time ext_to_realtime (const Time &t)
 Convert a time given w.r.t. More...
 
Time native_to_time (const Time &t)
 Convert some native time to a Fawkes time. More...
 
void remove_ext_timesource (TimeSource *ts=0)
 Remove external time source. More...
 
void get_time (struct timeval *tv) const
 Returns the time of the selected time source. More...
 
void get_time (struct timeval *tv, TimesourceSelector sel) const
 Returns the time of the selected time source. More...
 
void get_time (Time &time) const
 Returns the time of the selected time source. More...
 
void get_time (Time &time, TimesourceSelector sel) const
 Returns the time of the selected time source. More...
 
void get_time (Time *time) const
 Returns the time of the selected time source. More...
 
void get_time (Time *time, TimesourceSelector sel) const
 Returns the time of the selected time source. More...
 
void get_systime (struct timeval *tv) const
 Returns the system time. More...
 
void get_systime (Time &time) const
 Returns the time of the selected time source. More...
 
void get_systime (Time *time) const
 Returns the time of the selected time source. More...
 
Time now () const
 Get the current time. More...
 
float elapsed (Time *t) const
 How much time has elapsed since t? Calculated as "now - t" in seconds. More...
 
float sys_elapsed (Time *t) const
 How much system time has elapsed since t? Use only for system time criteria like timeouts. More...
 

Static Public Member Functions

static Clockinstance ()
 Clock initializer. More...
 
static void finalize ()
 Finalize. More...
 

Detailed Description

This is supposed to be the central clock in Fawkes.

It is implemented as a singleton to ensure that there is only one object. So-called TimeSources can be registered at the Clock their current time can be retrieved through the Clock.

Author
Daniel Beck, Tim Niemueller

Definition at line 34 of file clock.h.

Member Enumeration Documentation

◆ TimesourceSelector

Select the time source.

Enumerator
DEFAULT 

select the default time source

REALTIME 

select the system time source

EXTERNAL 

select the external time source

Definition at line 39 of file clock.h.

Constructor & Destructor Documentation

◆ ~Clock()

fawkes::Clock::~Clock ( )
virtual

Destructor.

Definition at line 53 of file clock.cpp.

Member Function Documentation

◆ elapsed()

float fawkes::Clock::elapsed ( Time t) const

How much time has elapsed since t? Calculated as "now - t" in seconds.

Parameters
ttime
Returns
elapsed seconds

Definition at line 282 of file clock.cpp.

Referenced by FvAqtVisionThreads::empty_time().

◆ ext_to_realtime()

Time fawkes::Clock::ext_to_realtime ( const Time t)

Convert a time given w.r.t.

the external time source into the system time.

Parameters
tthe time that is converted to the system time
Returns
the time in system time

Definition at line 308 of file clock.cpp.

References fawkes::TimeSource::conv_to_realtime(), fawkes::Time::get_timeval(), and fawkes::Time::set_time().

◆ finalize()

void fawkes::Clock::finalize ( )
static

Finalize.

Definition at line 77 of file clock.cpp.

◆ get_systime() [1/3]

◆ get_systime() [2/3]

void fawkes::Clock::get_systime ( Time time) const

Returns the time of the selected time source.

Parameters
timereference to Time instance where the time is stored

Definition at line 249 of file clock.cpp.

◆ get_systime() [3/3]

void fawkes::Clock::get_systime ( Time time) const

Returns the time of the selected time source.

Parameters
timepointer to Time instance where the time is stored

Definition at line 259 of file clock.cpp.

◆ get_time() [1/6]

void fawkes::Clock::get_time ( struct timeval *  tv) const

◆ get_time() [2/6]

void fawkes::Clock::get_time ( struct timeval *  tv,
TimesourceSelector  sel 
) const

Returns the time of the selected time source.

Parameters
tvpointer to a timeval struct where the time is written to
selallows to select the time source

Definition at line 153 of file clock.cpp.

References DEFAULT, EXTERNAL, fawkes::TimeSource::get_time(), and REALTIME.

◆ get_time() [3/6]

void fawkes::Clock::get_time ( Time time) const

Returns the time of the selected time source.

Parameters
timereference to a time where the result is stored

Definition at line 193 of file clock.cpp.

References get_time().

◆ get_time() [4/6]

void fawkes::Clock::get_time ( Time time,
TimesourceSelector  sel 
) const

Returns the time of the selected time source.

Parameters
timereference to a time where the result is stored
selallows to select the time source

Definition at line 206 of file clock.cpp.

References get_time().

◆ get_time() [5/6]

void fawkes::Clock::get_time ( Time time) const

Returns the time of the selected time source.

Parameters
timepointer to a Time instance

Definition at line 216 of file clock.cpp.

References get_time().

◆ get_time() [6/6]

void fawkes::Clock::get_time ( Time time,
TimesourceSelector  sel 
) const

Returns the time of the selected time source.

Parameters
timepointer to a Time instance where the time is stored
selallows to select the time source

Definition at line 229 of file clock.cpp.

References get_time().

◆ has_ext_timesource()

bool fawkes::Clock::has_ext_timesource ( ) const

Check whether an external time source is registered.

Returns
true if an external time source is registered

Definition at line 350 of file clock.cpp.

◆ instance()

Clock * fawkes::Clock::instance ( )
static

Clock initializer.

This one is static and has to be called to instantiate a Clock object. In further calls it just returns a pointer to the Clock object.

Returns
a pointer to the Clock object

Definition at line 65 of file clock.cpp.

Referenced by fawkes::FawkesMainThread::FawkesMainThread(), fawkes::LaserOccupancyGrid::get_cell_costs(), fawkes::Interface::Interface(), fawkes::LaserOccupancyGrid::reset_old(), fawkes::SimulatorTimeSource::SimulatorTimeSource(), fawkes::Time::Time(), and fawkes::TimeWait::wait().

◆ is_ext_default_timesource()

bool fawkes::Clock::is_ext_default_timesource ( ) const

Checks whether the external time source is the default time soucre.

Returns
true if external time source is default time source

Definition at line 142 of file clock.cpp.

◆ native_to_time()

Time fawkes::Clock::native_to_time ( const Time t)

Convert some native time to a Fawkes time.

If communicating with some entity using some native time format (e.g. a simulation giving offset timestamps from the simulation start) it is necessary to convert them to a time that the time is comparable to other times generated using the clock (and hence external timesource).

Parameters
tthe time that is to be converted to the a Fawkes time
Returns
the time in Fawkes time comparable to other times queried from this lock. Identity of the given time if no external time source has been registered.

Definition at line 333 of file clock.cpp.

References fawkes::TimeSource::conv_native_to_exttime(), fawkes::Time::get_timeval(), and fawkes::Time::set_time().

◆ now()

◆ register_ext_timesource()

void fawkes::Clock::register_ext_timesource ( TimeSource ts,
bool  make_default = false 
)

Register an external time source.

Parameters
tsa pointer to the external time source
make_defaultif true, this time source is made the default timesource which means that for every call of get_time() the time of the external time source is returned

Definition at line 92 of file clock.cpp.

Referenced by fawkes::TimeSourceAspectIniFin::init(), and GazsimTimesourceThread::init().

◆ remove_ext_timesource()

void fawkes::Clock::remove_ext_timesource ( TimeSource ts = 0)

Remove external time source.

If an external timesource is currently set it is removed. The time source will not be deleted but only the reference to it is removed.

Parameters
tsonly remove time source if it equals ts, if NULL remove no matter what.

Definition at line 108 of file clock.cpp.

Referenced by fawkes::TimeSourceAspectIniFin::finalize(), and GazsimTimesourceThread::finalize().

◆ set_ext_default_timesource()

void fawkes::Clock::set_ext_default_timesource ( bool  ext_is_default)

Set/unset the external time source as the default time source.

Parameters
ext_is_defaulttrue to make external time source the default, false to disable it as the default.

Definition at line 124 of file clock.cpp.

◆ sys_elapsed()

float fawkes::Clock::sys_elapsed ( Time t) const

How much system time has elapsed since t? Use only for system time criteria like timeouts.

Parameters
ttime
Returns
elapsed system seconds

Definition at line 295 of file clock.cpp.

References fawkes::time_diff_sec().


The documentation for this class was generated from the following files: