rcl  master
C API providing common ROS client library functionality.
Classes | Macros | Typedefs | Enumerations | Functions
time.h File Reference
#include "rcl/allocator.h"
#include "rcl/macros.h"
#include "rcl/types.h"
#include "rcl/visibility_control.h"
#include "rcutils/time.h"
Include dependency graph for time.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rcl_duration_t
 A duration of time, measured in nanoseconds and its source. More...
 
struct  rcl_time_jump_t
 Struct to describe a jump in time. More...
 
struct  rcl_jump_threshold_t
 Describe the prerequisites for calling a time jump callback. More...
 
struct  rcl_jump_callback_info_t
 Struct to describe an added callback. More...
 
struct  rcl_clock_t
 Encapsulation of a time source. More...
 
struct  rcl_time_point_t
 A single point in time, measured in nanoseconds, the reference point is based on the source. More...
 

Macros

#define RCL_S_TO_NS   RCUTILS_S_TO_NS
 Convenience macro to convert seconds to nanoseconds. More...
 
#define RCL_MS_TO_NS   RCUTILS_MS_TO_NS
 Convenience macro to convert milliseconds to nanoseconds. More...
 
#define RCL_US_TO_NS   RCUTILS_US_TO_NS
 Convenience macro to convert microseconds to nanoseconds. More...
 
#define RCL_NS_TO_S   RCUTILS_NS_TO_S
 Convenience macro to convert nanoseconds to seconds. More...
 
#define RCL_NS_TO_MS   RCUTILS_NS_TO_MS
 Convenience macro to convert nanoseconds to milliseconds. More...
 
#define RCL_NS_TO_US   RCUTILS_NS_TO_US
 Convenience macro to convert nanoseconds to microseconds. More...
 

Typedefs

typedef rcutils_time_point_value_t rcl_time_point_value_t
 A single point in time, measured in nanoseconds since the Unix epoch. More...
 
typedef rcutils_duration_value_t rcl_duration_value_t
 A duration of time, measured in nanoseconds. More...
 
typedef enum rcl_clock_type_t rcl_clock_type_t
 Time source type, used to indicate the source of a time measurement. More...
 
typedef struct rcl_duration_t rcl_duration_t
 A duration of time, measured in nanoseconds and its source. More...
 
typedef enum rcl_clock_change_t rcl_clock_change_t
 Enumeration to describe the type of time jump. More...
 
typedef struct rcl_time_jump_t rcl_time_jump_t
 Struct to describe a jump in time. More...
 
typedef void(* rcl_jump_callback_t) (const struct rcl_time_jump_t *time_jump, bool before_jump, void *user_data)
 
typedef struct rcl_jump_threshold_t rcl_jump_threshold_t
 Describe the prerequisites for calling a time jump callback. More...
 
typedef struct rcl_jump_callback_info_t rcl_jump_callback_info_t
 Struct to describe an added callback. More...
 
typedef struct rcl_clock_t rcl_clock_t
 Encapsulation of a time source. More...
 
typedef struct rcl_time_point_t rcl_time_point_t
 A single point in time, measured in nanoseconds, the reference point is based on the source. More...
 

Enumerations

enum  rcl_clock_type_t { RCL_CLOCK_UNINITIALIZED = 0, RCL_ROS_TIME, RCL_SYSTEM_TIME, RCL_STEADY_TIME }
 Time source type, used to indicate the source of a time measurement. More...
 
enum  rcl_clock_change_t { RCL_ROS_TIME_NO_CHANGE = 1, RCL_ROS_TIME_ACTIVATED = 2, RCL_ROS_TIME_DEACTIVATED = 3, RCL_SYSTEM_TIME_NO_CHANGE = 4 }
 Enumeration to describe the type of time jump. More...
 

Functions

bool rcl_clock_valid (rcl_clock_t *clock)
 Check if the clock has valid values. More...
 
rcl_ret_t rcl_clock_init (enum rcl_clock_type_t clock_type, rcl_clock_t *clock, rcl_allocator_t *allocator)
 Initialize a clock based on the passed type. More...
 
rcl_ret_t rcl_clock_fini (rcl_clock_t *clock)
 Finalize a clock. More...
 
rcl_ret_t rcl_ros_clock_init (rcl_clock_t *clock, rcl_allocator_t *allocator)
 Initialize a clock as a RCL_ROS_TIME time source. More...
 
rcl_ret_t rcl_ros_clock_fini (rcl_clock_t *clock)
 Finalize a clock as a RCL_ROS_TIME time source. More...
 
rcl_ret_t rcl_steady_clock_init (rcl_clock_t *clock, rcl_allocator_t *allocator)
 Initialize a clock as a RCL_STEADY_TIME time source. More...
 
rcl_ret_t rcl_steady_clock_fini (rcl_clock_t *clock)
 Finalize a clock as a RCL_STEADY_TIME time source. More...
 
rcl_ret_t rcl_system_clock_init (rcl_clock_t *clock, rcl_allocator_t *allocator)
 Initialize a clock as a RCL_SYSTEM_TIME time source. More...
 
rcl_ret_t rcl_system_clock_fini (rcl_clock_t *clock)
 Finalize a clock as a RCL_SYSTEM_TIME time source. More...
 
rcl_ret_t rcl_difference_times (rcl_time_point_t *start, rcl_time_point_t *finish, rcl_duration_t *delta)
 Compute the difference between two time points. More...
 
rcl_ret_t rcl_clock_get_now (rcl_clock_t *clock, rcl_time_point_value_t *time_point_value)
 Fill the time point value with the current value of the associated clock. More...
 
rcl_ret_t rcl_enable_ros_time_override (rcl_clock_t *clock)
 Enable the ROS time abstraction override. More...
 
rcl_ret_t rcl_disable_ros_time_override (rcl_clock_t *clock)
 Disable the ROS time abstraction override. More...
 
rcl_ret_t rcl_is_enabled_ros_time_override (rcl_clock_t *clock, bool *is_enabled)
 Check if the RCL_ROS_TIME time source has the override enabled. More...
 
rcl_ret_t rcl_set_ros_time_override (rcl_clock_t *clock, rcl_time_point_value_t time_value)
 Set the current time for this RCL_ROS_TIME time source. More...
 
rcl_ret_t rcl_clock_add_jump_callback (rcl_clock_t *clock, rcl_jump_threshold_t threshold, rcl_jump_callback_t callback, void *user_data)
 Add a callback to be called when a time jump exceeds a threshold. More...
 
rcl_ret_t rcl_clock_remove_jump_callback (rcl_clock_t *clock, rcl_jump_callback_t callback, void *user_data)
 Remove a previously added time jump callback. More...
 

Macro Definition Documentation

◆ RCL_S_TO_NS

#define RCL_S_TO_NS   RCUTILS_S_TO_NS

Convenience macro to convert seconds to nanoseconds.

◆ RCL_MS_TO_NS

#define RCL_MS_TO_NS   RCUTILS_MS_TO_NS

Convenience macro to convert milliseconds to nanoseconds.

◆ RCL_US_TO_NS

#define RCL_US_TO_NS   RCUTILS_US_TO_NS

Convenience macro to convert microseconds to nanoseconds.

◆ RCL_NS_TO_S

#define RCL_NS_TO_S   RCUTILS_NS_TO_S

Convenience macro to convert nanoseconds to seconds.

◆ RCL_NS_TO_MS

#define RCL_NS_TO_MS   RCUTILS_NS_TO_MS

Convenience macro to convert nanoseconds to milliseconds.

◆ RCL_NS_TO_US

#define RCL_NS_TO_US   RCUTILS_NS_TO_US

Convenience macro to convert nanoseconds to microseconds.

Typedef Documentation

◆ rcl_time_point_value_t

A single point in time, measured in nanoseconds since the Unix epoch.

◆ rcl_duration_value_t

A duration of time, measured in nanoseconds.

◆ rcl_clock_type_t

Time source type, used to indicate the source of a time measurement.

◆ rcl_duration_t

A duration of time, measured in nanoseconds and its source.

◆ rcl_clock_change_t

Enumeration to describe the type of time jump.

◆ rcl_time_jump_t

Struct to describe a jump in time.

◆ rcl_jump_callback_t

typedef void(* rcl_jump_callback_t) (const struct rcl_time_jump_t *time_jump, bool before_jump, void *user_data)

Signature of a time jump callback.

Parameters
[in]time_jumpA description of the jump in time.
[in]before_jumpEvery jump callback is called twice: once before the clock changes and once after. This is true the first call and false the second.
[in]user_dataA pointer given at callback registration which is passed to the callback.

◆ rcl_jump_threshold_t

Describe the prerequisites for calling a time jump callback.

◆ rcl_jump_callback_info_t

Struct to describe an added callback.

◆ rcl_clock_t

typedef struct rcl_clock_t rcl_clock_t

Encapsulation of a time source.

◆ rcl_time_point_t

A single point in time, measured in nanoseconds, the reference point is based on the source.

Enumeration Type Documentation

◆ rcl_clock_type_t

Time source type, used to indicate the source of a time measurement.

Enumerator
RCL_CLOCK_UNINITIALIZED 
RCL_ROS_TIME 
RCL_SYSTEM_TIME 
RCL_STEADY_TIME 

◆ rcl_clock_change_t

Enumeration to describe the type of time jump.

Enumerator
RCL_ROS_TIME_NO_CHANGE 

The source before and after the jump is ROS_TIME.

RCL_ROS_TIME_ACTIVATED 

The source switched to ROS_TIME from SYSTEM_TIME.

RCL_ROS_TIME_DEACTIVATED 

The source switched to SYSTEM_TIME from ROS_TIME.

RCL_SYSTEM_TIME_NO_CHANGE 

The source before and after the jump is SYSTEM_TIME.

Function Documentation

◆ rcl_clock_valid()

bool rcl_clock_valid ( rcl_clock_t clock)

Check if the clock has valid values.

This function returns true if the time source appears to be valid. It will check that the type is not uninitialized, and that pointers are not invalid. Note that if data is uninitialized it may give a false positive.

Parameters
[in]clockthe handle to the clock which is being queried
Returns
true if the source is believed to be valid, otherwise return false.

◆ rcl_clock_init()

rcl_ret_t rcl_clock_init ( enum rcl_clock_type_t  clock_type,
rcl_clock_t clock,
rcl_allocator_t allocator 
)

Initialize a clock based on the passed type.

This will allocate all necessary internal structures, and initialize variables.

Parameters
[in]clock_typethe type identifying the time source to provide
[in]clockthe handle to the clock which is being initialized
[in]allocatorThe allocator to use for allocations
Returns
RCL_RET_OK if the time source was successfully initialized, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_clock_fini()

rcl_ret_t rcl_clock_fini ( rcl_clock_t clock)

Finalize a clock.

This will deallocate all necessary internal structures, and clean up any variables. It can be combined with any of the init functions.

Passing a clock with type RCL_CLOCK_UNINITIALIZED will result in RCL_RET_INVALID_ARGUMENT being returned.

Parameters
[in]clockthe handle to the clock which is being finalized
Returns
RCL_RET_OK if the time source was successfully finalized, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_ros_clock_init()

rcl_ret_t rcl_ros_clock_init ( rcl_clock_t clock,
rcl_allocator_t allocator 
)

Initialize a clock as a RCL_ROS_TIME time source.

This will allocate all necessary internal structures, and initialize variables. It is specifically setting up a RCL_ROS_TIME time source.

Parameters
[in]clockthe handle to the clock which is being initialized
[in]allocatorThe allocator to use for allocations
Returns
RCL_RET_OK if the time source was successfully initialized, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_ros_clock_fini()

rcl_ret_t rcl_ros_clock_fini ( rcl_clock_t clock)

Finalize a clock as a RCL_ROS_TIME time source.

This will deallocate all necessary internal structures, and clean up any variables. It is specifically setting up a RCL_ROS_TIME time source. It is expected to be paired with the init fuction.

Parameters
[in]clockthe handle to the clock which is being initialized
Returns
RCL_RET_OK if the time source was successfully finalized, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_steady_clock_init()

rcl_ret_t rcl_steady_clock_init ( rcl_clock_t clock,
rcl_allocator_t allocator 
)

Initialize a clock as a RCL_STEADY_TIME time source.

This will allocate all necessary internal structures, and initialize variables. It is specifically setting up a RCL_STEADY_TIME time source.

Parameters
[in]clockthe handle to the clock which is being initialized
[in]allocatorThe allocator to use for allocations
Returns
RCL_RET_OK if the time source was successfully initialized, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_steady_clock_fini()

rcl_ret_t rcl_steady_clock_fini ( rcl_clock_t clock)

Finalize a clock as a RCL_STEADY_TIME time source.

Finalize the clock as a RCL_STEADY_TIME time source.

This will deallocate all necessary internal structures, and clean up any variables. It is specifically setting up a steady time source. It is expected to be paired with the init fuction.

Parameters
[in]clockthe handle to the clock which is being initialized
Returns
RCL_RET_OK if the time source was successfully finalized, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_system_clock_init()

rcl_ret_t rcl_system_clock_init ( rcl_clock_t clock,
rcl_allocator_t allocator 
)

Initialize a clock as a RCL_SYSTEM_TIME time source.

Initialize the clock as a RCL_SYSTEM_TIME time source.

This will allocate all necessary internal structures, and initialize variables. It is specifically setting up a system time source.

Parameters
[in]clockthe handle to the clock which is being initialized
[in]allocatorThe allocator to use for allocations
Returns
RCL_RET_OK if the time source was successfully initialized, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_system_clock_fini()

rcl_ret_t rcl_system_clock_fini ( rcl_clock_t clock)

Finalize a clock as a RCL_SYSTEM_TIME time source.

Finalize the clock as a RCL_SYSTEM_TIME time source.

This will deallocate all necessary internal structures, and clean up any variables. It is specifically setting up a system time source. It is expected to be paired with the init fuction.

Parameters
[in]clockthe handle to the clock which is being initialized.
Returns
RCL_RET_OK if the time source was successfully finalized, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_difference_times()

rcl_ret_t rcl_difference_times ( rcl_time_point_t start,
rcl_time_point_t finish,
rcl_duration_t delta 
)

Compute the difference between two time points.

This function takes two time points and computes the duration between them. The two time points must be using the same time abstraction, and the resultant duration will also be of the same abstraction.

The value will be computed as duration = finish - start. If start is after finish the duration will be negative.

Parameters
[in]startThe time point for the start of the duration.
[in]finishThe time point for the end of the duration.
[out]deltaThe duration between the start and finish.
Returns
RCL_RET_OK if the difference was computed successfully, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_clock_get_now()

rcl_ret_t rcl_clock_get_now ( rcl_clock_t clock,
rcl_time_point_value_t time_point_value 
)

Fill the time point value with the current value of the associated clock.

This function will populate the data of the time_point_value object with the current value from it's associated time abstraction.

Parameters
[in]clockThe time source from which to set the value.
[out]time_point_valueThe time_point value to populate.
Returns
RCL_RET_OK if the last call time was retrieved successfully, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_enable_ros_time_override()

rcl_ret_t rcl_enable_ros_time_override ( rcl_clock_t clock)

Enable the ROS time abstraction override.

This method will enable the ROS time abstraction override values, such that the time source will report the set value instead of falling back to system time.

Parameters
[in]clockThe clock to enable.
Returns
RCL_RET_OK if the time source was enabled successfully, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_disable_ros_time_override()

rcl_ret_t rcl_disable_ros_time_override ( rcl_clock_t clock)

Disable the ROS time abstraction override.

This method will disable the RCL_ROS_TIME time abstraction override values, such that the time source will report the system time even if a custom value has been set.

Parameters
[in]clockThe clock to disable.
Returns
RCL_RET_OK if the time source was disabled successfully, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_is_enabled_ros_time_override()

rcl_ret_t rcl_is_enabled_ros_time_override ( rcl_clock_t clock,
bool *  is_enabled 
)

Check if the RCL_ROS_TIME time source has the override enabled.

This will populate the is_enabled object to indicate if the time overide is enabled. If it is enabled, the set value will be returned. Otherwise this time source will return the equivalent to system time abstraction.

Parameters
[in]clockThe clock to query.
[out]is_enabledWhether the override is enabled..
Returns
RCL_RET_OK if the time source was queried successfully, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_set_ros_time_override()

rcl_ret_t rcl_set_ros_time_override ( rcl_clock_t clock,
rcl_time_point_value_t  time_value 
)

Set the current time for this RCL_ROS_TIME time source.

This function will update the internal storage for the RCL_ROS_TIME time source. If queried and override enabled the time source will return this value, otherwise it will return the system time.

Parameters
[in]clockThe clock to update.
[in]time_valueThe new current time.
Returns
RCL_RET_OK if the time source was set successfully, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occur.

◆ rcl_clock_add_jump_callback()

rcl_ret_t rcl_clock_add_jump_callback ( rcl_clock_t clock,
rcl_jump_threshold_t  threshold,
rcl_jump_callback_t  callback,
void *  user_data 
)

Add a callback to be called when a time jump exceeds a threshold.

The callback is called twice when the threshold is exceeded: once before the clock is updated, and once after. The user_data pointer is passed to the callback as the last argument. A callback and user_data pair must be unique among the callbacks added to a clock.

Parameters
[in]clockA clock to add a jump callback to.
[in]thresholdCriteria indicating when to call the callback.
[in]callbackA callback to call.
[in]user_dataA pointer to be passed to the callback.
Returns
RCL_RET_OK if the callback was added successfully, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR an unspecified error occurs.

◆ rcl_clock_remove_jump_callback()

rcl_ret_t rcl_clock_remove_jump_callback ( rcl_clock_t clock,
rcl_jump_callback_t  callback,
void *  user_data 
)

Remove a previously added time jump callback.

Parameters
[in]clockThe clock to remove a jump callback from.
[in]thresholdCriteria indicating when to call callback.
[in]callbackThe callback to call.
[in]user_dataA pointer to be passed to the callback.
Returns
RCL_RET_OK if the callback was added successfully, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_ERROR the callback was not found or an unspecified error occurs.