rcl  master
C API providing common ROS client library functionality.
time.h
Go to the documentation of this file.
1 // Copyright 2015 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #ifndef RCL__TIME_H_
18 #define RCL__TIME_H_
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include "rcl/allocator.h"
26 #include "rcl/macros.h"
27 #include "rcl/types.h"
28 #include "rcl/visibility_control.h"
29 #include "rcutils/time.h"
30 
32 #define RCL_S_TO_NS RCUTILS_S_TO_NS
33 #define RCL_MS_TO_NS RCUTILS_MS_TO_NS
35 #define RCL_US_TO_NS RCUTILS_US_TO_NS
37 
39 #define RCL_NS_TO_S RCUTILS_NS_TO_S
40 #define RCL_NS_TO_MS RCUTILS_NS_TO_MS
42 #define RCL_NS_TO_US RCUTILS_NS_TO_US
44 
49 
51 
61 typedef enum rcl_clock_type_t
62 {
72 
74 typedef struct rcl_duration_t
75 {
79 
81 typedef enum rcl_clock_change_t
82 {
92 
94 typedef struct rcl_time_jump_t
95 {
101 
107 typedef void (* rcl_jump_callback_t)(
108  const struct rcl_time_jump_t * time_jump,
109  bool before_jump,
110  void * user_data);
111 
113 typedef struct rcl_jump_threshold_t
114 {
124 
127 {
133  void * user_data;
135 
137 typedef struct rcl_clock_t
138 {
147  // void (*set_now) (rcl_time_point_value_t);
149  void * data;
152 } rcl_clock_t;
153 
155 typedef struct rcl_time_point_t
156 {
162 
163 // typedef struct rcl_rate_t
164 // {
165 // rcl_time_point_value_t trigger_time;
166 // int64_t period;
167 // rcl_clock_type_t clock;;
168 // } rcl_rate_t;
169 // TODO(tfoote) integrate rate and timer implementations
170 
172 
189 RCL_PUBLIC
190 RCL_WARN_UNUSED
191 bool
193 
195 
217 RCL_PUBLIC
218 RCL_WARN_UNUSED
219 rcl_ret_t
221  enum rcl_clock_type_t clock_type, rcl_clock_t * clock,
222  rcl_allocator_t * allocator);
223 
225 
252 RCL_PUBLIC
253 RCL_WARN_UNUSED
254 rcl_ret_t
256  rcl_clock_t * clock);
257 
259 
281 RCL_PUBLIC
282 RCL_WARN_UNUSED
283 rcl_ret_t
285  rcl_clock_t * clock,
286  rcl_allocator_t * allocator);
287 
289 
314 RCL_PUBLIC
315 RCL_WARN_UNUSED
316 rcl_ret_t
318  rcl_clock_t * clock);
319 
321 
342 RCL_PUBLIC
343 RCL_WARN_UNUSED
344 rcl_ret_t
346  rcl_clock_t * clock,
347  rcl_allocator_t * allocator);
348 
350 
377 RCL_PUBLIC
378 RCL_WARN_UNUSED
379 rcl_ret_t
381  rcl_clock_t * clock);
382 
384 
408 RCL_PUBLIC
409 RCL_WARN_UNUSED
410 rcl_ret_t
412  rcl_clock_t * clock,
413  rcl_allocator_t * allocator);
414 
416 
442 RCL_PUBLIC
443 RCL_WARN_UNUSED
444 rcl_ret_t
446  rcl_clock_t * clock);
447 
449 
472 RCL_PUBLIC
473 RCL_WARN_UNUSED
474 rcl_ret_t
476  rcl_time_point_t * start, rcl_time_point_t * finish, rcl_duration_t * delta);
477 
479 
499 RCL_PUBLIC
500 RCL_WARN_UNUSED
501 rcl_ret_t
502 rcl_clock_get_now(rcl_clock_t * clock, rcl_time_point_value_t * time_point_value);
503 
504 
506 
531 RCL_PUBLIC
532 RCL_WARN_UNUSED
533 rcl_ret_t
535 
537 
562 RCL_PUBLIC
563 RCL_WARN_UNUSED
564 rcl_ret_t
566 
567 
569 
593 RCL_PUBLIC
594 RCL_WARN_UNUSED
595 rcl_ret_t
597  rcl_clock_t * clock, bool * is_enabled);
598 
600 
627 RCL_PUBLIC
628 RCL_WARN_UNUSED
629 rcl_ret_t
631  rcl_clock_t * clock, rcl_time_point_value_t time_value);
632 
634 
665 RCL_PUBLIC
666 RCL_WARN_UNUSED
667 rcl_ret_t
669  rcl_clock_t * clock, rcl_jump_threshold_t threshold, rcl_jump_callback_t callback,
670  void * user_data);
671 
673 
698 RCL_PUBLIC
699 RCL_WARN_UNUSED
700 rcl_ret_t
702  rcl_clock_t * clock, rcl_jump_callback_t callback, void * user_data);
703 
704 #ifdef __cplusplus
705 }
706 #endif
707 
708 #endif // RCL__TIME_H_
rcutils_duration_value_t
int64_t rcutils_duration_value_t
rcl_clock_t::jump_callbacks
rcl_jump_callback_info_t * jump_callbacks
An array of added jump callbacks.
Definition: time.h:142
RCL_CLOCK_UNINITIALIZED
@ RCL_CLOCK_UNINITIALIZED
Clock uninitialized.
Definition: time.h:64
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.
rcl_clock_type_t
rcl_clock_type_t
Time source type, used to indicate the source of a time measurement.
Definition: time.h:61
rcl_clock_t::type
enum rcl_clock_type_t type
Clock type.
Definition: time.h:140
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.
rcl_time_point_t::nanoseconds
rcl_time_point_value_t nanoseconds
Nanoseconds of the point in time.
Definition: time.h:158
rcl_time_jump_t
struct rcl_time_jump_t rcl_time_jump_t
Struct to describe a jump in time.
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.
types.h
rcl_ret_t
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:23
RCL_ROS_TIME_DEACTIVATED
@ RCL_ROS_TIME_DEACTIVATED
The source switched to SYSTEM_TIME from ROS_TIME.
Definition: time.h:88
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.
rcl_time_jump_t::clock_change
rcl_clock_change_t clock_change
Indicate whether or not the source of time changed.
Definition: time.h:97
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.
time.h
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.
rcl_jump_threshold_t
struct rcl_jump_threshold_t rcl_jump_threshold_t
Describe the prerequisites for calling a time jump callback.
rcl_duration_t::nanoseconds
rcl_duration_value_t nanoseconds
Duration in nanoseconds and its source.
Definition: time.h:77
rcl_time_point_value_t
rcutils_time_point_value_t rcl_time_point_value_t
A single point in time, measured in nanoseconds since the Unix epoch.
Definition: time.h:46
rcl_clock_t::data
void * data
Clock storage.
Definition: time.h:149
RCL_STEADY_TIME
@ RCL_STEADY_TIME
Use a steady clock time.
Definition: time.h:70
RCL_ROS_TIME_ACTIVATED
@ RCL_ROS_TIME_ACTIVATED
The source switched to ROS_TIME from SYSTEM_TIME.
Definition: time.h:86
rcl_jump_callback_info_t::callback
rcl_jump_callback_t callback
Callback to fucntion.
Definition: time.h:129
rcl_time_point_t
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.
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.
RCL_ROS_TIME
@ RCL_ROS_TIME
Use ROS time.
Definition: time.h:66
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.
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.
rcl_time_jump_t
Struct to describe a jump in time.
Definition: time.h:94
rcl_jump_threshold_t::min_backward
rcl_duration_t min_backward
Definition: time.h:122
rcl_jump_callback_info_t::threshold
rcl_jump_threshold_t threshold
Threshold to decide when to call the callback.
Definition: time.h:131
rcl_clock_t::get_now
rcl_ret_t(* get_now)(void *data, rcl_time_point_value_t *now)
Pointer to get_now function.
Definition: time.h:146
rcl_time_point_t
A single point in time, measured in nanoseconds, the reference point is based on the source.
Definition: time.h:155
rcl_jump_threshold_t
Describe the prerequisites for calling a time jump callback.
Definition: time.h:113
rcl_jump_callback_info_t
struct rcl_jump_callback_info_t rcl_jump_callback_info_t
Struct to describe an added callback.
rcl_time_point_t::clock_type
rcl_clock_type_t clock_type
Clock type of the point in time.
Definition: time.h:160
rcl_clock_fini
rcl_ret_t rcl_clock_fini(rcl_clock_t *clock)
Finalize a clock.
RCL_ROS_TIME_NO_CHANGE
@ RCL_ROS_TIME_NO_CHANGE
The source before and after the jump is ROS_TIME.
Definition: time.h:84
RCL_SYSTEM_TIME
@ RCL_SYSTEM_TIME
Use system time.
Definition: time.h:68
rcutils_time_point_value_t
int64_t rcutils_time_point_value_t
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.
rcl_jump_threshold_t::on_clock_change
bool on_clock_change
True to call callback when the clock type changes.
Definition: time.h:116
rcl_clock_t
Encapsulation of a time source.
Definition: time.h:137
rcl_jump_callback_t
void(* rcl_jump_callback_t)(const struct rcl_time_jump_t *time_jump, bool before_jump, void *user_data)
Definition: time.h:107
rcl_enable_ros_time_override
rcl_ret_t rcl_enable_ros_time_override(rcl_clock_t *clock)
Enable the ROS time abstraction override.
rcl_clock_t::allocator
rcl_allocator_t allocator
Custom allocator used for internal allocations.
Definition: time.h:151
rcl_jump_callback_info_t::user_data
void * user_data
Pointer passed to the callback.
Definition: time.h:133
rcl_duration_t
struct rcl_duration_t rcl_duration_t
A duration of time, measured in nanoseconds and its source.
rcutils_allocator_t
allocator.h
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.
rcl_clock_valid
bool rcl_clock_valid(rcl_clock_t *clock)
Check if the clock has valid values.
rcl_disable_ros_time_override
rcl_ret_t rcl_disable_ros_time_override(rcl_clock_t *clock)
Disable the ROS time abstraction override.
rcl_clock_t
struct rcl_clock_t rcl_clock_t
Encapsulation of a time source.
rcl_duration_value_t
rcutils_duration_value_t rcl_duration_value_t
A duration of time, measured in nanoseconds.
Definition: time.h:48
rcl_clock_change_t
rcl_clock_change_t
Enumeration to describe the type of time jump.
Definition: time.h:81
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.
rcl_time_jump_t::delta
rcl_duration_t delta
The new time minus the last time before the jump.
Definition: time.h:99
rcl_jump_threshold_t::min_forward
rcl_duration_t min_forward
Definition: time.h:119
rcl_clock_t::num_jump_callbacks
size_t num_jump_callbacks
Number of callbacks in jump_callbacks.
Definition: time.h:144
RCL_SYSTEM_TIME_NO_CHANGE
@ RCL_SYSTEM_TIME_NO_CHANGE
The source before and after the jump is SYSTEM_TIME.
Definition: time.h:90
rcl_jump_callback_info_t
Struct to describe an added callback.
Definition: time.h:126
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.
rcl_duration_t
A duration of time, measured in nanoseconds and its source.
Definition: time.h:74