ROS 2 rclcpp + rcl - rolling  rolling-e7363f10
ROS 2 C++ Client Library with ROS Client Library
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 <stdbool.h>
26 #include <stddef.h>
27 
28 #include "rcl/allocator.h"
29 #include "rcl/macros.h"
30 #include "rcl/types.h"
31 #include "rcl/visibility_control.h"
32 #include "rcutils/time.h"
33 
35 #define RCL_S_TO_NS RCUTILS_S_TO_NS
37 #define RCL_MS_TO_NS RCUTILS_MS_TO_NS
39 #define RCL_US_TO_NS RCUTILS_US_TO_NS
40 
42 #define RCL_NS_TO_S RCUTILS_NS_TO_S
44 #define RCL_NS_TO_MS RCUTILS_NS_TO_MS
46 #define RCL_NS_TO_US RCUTILS_NS_TO_US
47 
49 typedef rcutils_time_point_value_t rcl_time_point_value_t;
51 typedef rcutils_duration_value_t rcl_duration_value_t;
52 
54 
64 typedef enum rcl_clock_type_e
65 {
75 
77 typedef struct rcl_duration_s
78 {
82 
84 typedef enum rcl_clock_change_e
85 {
95 
97 typedef struct rcl_time_jump_s
98 {
104 
110 typedef void (* rcl_jump_callback_t)(
111  const rcl_time_jump_t * time_jump,
112  bool before_jump,
113  void * user_data);
114 
116 typedef struct rcl_jump_threshold_s
117 {
127 
130 {
136  void * user_data;
138 
140 typedef struct rcl_clock_s
141 {
150  // void (*set_now) (rcl_time_point_value_t);
152  void * data;
156 
158 typedef struct rcl_time_point_s
159 {
165 
166 // typedef struct rcl_rate_t
167 // {
168 // rcl_time_point_value_t trigger_time;
169 // int64_t period;
170 // rcl_clock_type_t clock;;
171 // } rcl_rate_t;
172 // TODO(tfoote) integrate rate and timer implementations
173 
175 
195 RCL_PUBLIC
196 RCL_WARN_UNUSED
197 bool
199 
201 
218 RCL_PUBLIC
219 RCL_WARN_UNUSED
220 bool
222 
224 
246 RCL_PUBLIC
247 RCL_WARN_UNUSED
248 rcl_ret_t
250  rcl_clock_type_t clock_type, rcl_clock_t * clock,
251  rcl_allocator_t * allocator);
252 
254 
281 RCL_PUBLIC
282 RCL_WARN_UNUSED
283 rcl_ret_t
285  rcl_clock_t * clock);
286 
288 
310 RCL_PUBLIC
311 RCL_WARN_UNUSED
312 rcl_ret_t
314  rcl_clock_t * clock,
315  rcl_allocator_t * allocator);
316 
318 
343 RCL_PUBLIC
344 RCL_WARN_UNUSED
345 rcl_ret_t
347  rcl_clock_t * clock);
348 
350 
371 RCL_PUBLIC
372 RCL_WARN_UNUSED
373 rcl_ret_t
375  rcl_clock_t * clock,
376  rcl_allocator_t * allocator);
377 
379 
406 RCL_PUBLIC
407 RCL_WARN_UNUSED
408 rcl_ret_t
410  rcl_clock_t * clock);
411 
413 
437 RCL_PUBLIC
438 RCL_WARN_UNUSED
439 rcl_ret_t
441  rcl_clock_t * clock,
442  rcl_allocator_t * allocator);
443 
445 
471 RCL_PUBLIC
472 RCL_WARN_UNUSED
473 rcl_ret_t
475  rcl_clock_t * clock);
476 
478 
501 RCL_PUBLIC
502 RCL_WARN_UNUSED
503 rcl_ret_t
505  const rcl_time_point_t * start, const rcl_time_point_t * finish, rcl_duration_t * delta);
506 
508 
528 RCL_PUBLIC
529 RCL_WARN_UNUSED
530 rcl_ret_t
531 rcl_clock_get_now(rcl_clock_t * clock, rcl_time_point_value_t * time_point_value);
532 
533 
535 
560 RCL_PUBLIC
561 RCL_WARN_UNUSED
562 rcl_ret_t
564 
566 
591 RCL_PUBLIC
592 RCL_WARN_UNUSED
593 rcl_ret_t
595 
596 
598 
622 RCL_PUBLIC
623 RCL_WARN_UNUSED
624 rcl_ret_t
626  rcl_clock_t * clock, bool * is_enabled);
627 
629 
656 RCL_PUBLIC
657 RCL_WARN_UNUSED
658 rcl_ret_t
660  rcl_clock_t * clock, rcl_time_point_value_t time_value);
661 
663 
694 RCL_PUBLIC
695 RCL_WARN_UNUSED
696 rcl_ret_t
698  rcl_clock_t * clock, rcl_jump_threshold_t threshold, rcl_jump_callback_t callback,
699  void * user_data);
700 
702 
727 RCL_PUBLIC
728 RCL_WARN_UNUSED
729 rcl_ret_t
731  rcl_clock_t * clock, rcl_jump_callback_t callback, void * user_data);
732 
733 #ifdef __cplusplus
734 }
735 #endif
736 
737 #endif // RCL__TIME_H_
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:31
Encapsulation of a time source.
Definition: time.h:141
rcl_jump_callback_info_t * jump_callbacks
An array of added jump callbacks.
Definition: time.h:145
void * data
Clock storage.
Definition: time.h:152
rcl_allocator_t allocator
Custom allocator used for internal allocations.
Definition: time.h:154
rcl_ret_t(* get_now)(void *data, rcl_time_point_value_t *now)
Pointer to get_now function.
Definition: time.h:149
rcl_clock_type_t type
Clock type.
Definition: time.h:143
size_t num_jump_callbacks
Number of callbacks in jump_callbacks.
Definition: time.h:147
A duration of time, measured in nanoseconds and its source.
Definition: time.h:78
rcl_duration_value_t nanoseconds
Duration in nanoseconds and its source.
Definition: time.h:80
Struct to describe an added callback.
Definition: time.h:130
void * user_data
Pointer passed to the callback.
Definition: time.h:136
rcl_jump_threshold_t threshold
Threshold to decide when to call the callback.
Definition: time.h:134
rcl_jump_callback_t callback
Callback to fucntion.
Definition: time.h:132
Describe the prerequisites for calling a time jump callback.
Definition: time.h:117
rcl_duration_t min_forward
Definition: time.h:122
bool on_clock_change
True to call callback when the clock type changes.
Definition: time.h:119
rcl_duration_t min_backward
Definition: time.h:125
Struct to describe a jump in time.
Definition: time.h:98
rcl_clock_change_t clock_change
Indicate whether or not the source of time changed.
Definition: time.h:100
rcl_duration_t delta
The new time minus the last time before the jump.
Definition: time.h:102
A single point in time, measured in nanoseconds, the reference point is based on the source.
Definition: time.h:159
rcl_clock_type_t clock_type
Clock type of the point in time.
Definition: time.h:163
rcl_time_point_value_t nanoseconds
Nanoseconds of the point in time.
Definition: time.h:161
RCL_PUBLIC RCL_WARN_UNUSED 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.
Definition: time.c:153
enum rcl_clock_type_e rcl_clock_type_t
Time source type, used to indicate the source of a time measurement.
RCL_PUBLIC RCL_WARN_UNUSED 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.
Definition: time.c:191
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_enable_ros_time_override(rcl_clock_t *clock)
Enable the ROS time abstraction override.
Definition: time.c:299
struct rcl_clock_s rcl_clock_t
Encapsulation of a time source.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_difference_times(const rcl_time_point_t *start, const rcl_time_point_t *finish, rcl_duration_t *delta)
Compute the difference between two time points.
Definition: time.c:243
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_steady_clock_fini(rcl_clock_t *clock)
Finalize a clock as a RCL_STEADY_TIME time source.
Definition: time.c:204
RCL_PUBLIC RCL_WARN_UNUSED 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.
Definition: time.c:263
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_clock_fini(rcl_clock_t *clock)
Finalize a clock.
Definition: time.c:133
struct rcl_duration_s rcl_duration_t
A duration of time, measured in nanoseconds and its source.
rcl_clock_change_e
Enumeration to describe the type of time jump.
Definition: time.h:85
@ RCL_ROS_TIME_DEACTIVATED
The source switched to SYSTEM_TIME from ROS_TIME.
Definition: time.h:91
@ RCL_SYSTEM_TIME_NO_CHANGE
The source before and after the jump is SYSTEM_TIME.
Definition: time.h:93
@ RCL_ROS_TIME_NO_CHANGE
The source before and after the jump is ROS_TIME.
Definition: time.h:87
@ RCL_ROS_TIME_ACTIVATED
The source switched to ROS_TIME from SYSTEM_TIME.
Definition: time.h:89
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:49
RCL_PUBLIC RCL_WARN_UNUSED 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.
Definition: time.c:217
RCL_PUBLIC RCL_WARN_UNUSED bool rcl_clock_time_started(rcl_clock_t *clock)
Check if the clock has started.
Definition: time.c:78
struct rcl_time_jump_s rcl_time_jump_t
Struct to describe a jump in time.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_ros_clock_fini(rcl_clock_t *clock)
Finalize a clock as a RCL_ROS_TIME time source.
Definition: time.c:176
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_disable_ros_time_override(rcl_clock_t *clock)
Disable the ROS time abstraction override.
Definition: time.c:321
RCL_PUBLIC RCL_WARN_UNUSED 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.
Definition: time.c:392
void(* rcl_jump_callback_t)(const rcl_time_jump_t *time_jump, bool before_jump, void *user_data)
Definition: time.h:110
RCL_PUBLIC RCL_WARN_UNUSED 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.
Definition: time.c:343
RCL_PUBLIC RCL_WARN_UNUSED 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.
Definition: time.c:436
struct rcl_jump_callback_info_s rcl_jump_callback_info_t
Struct to describe an added callback.
struct rcl_time_point_s rcl_time_point_t
A single point in time, measured in nanoseconds, the reference point is based on the source.
rcl_clock_type_e
Time source type, used to indicate the source of a time measurement.
Definition: time.h:65
@ RCL_ROS_TIME
Use ROS time.
Definition: time.h:69
@ RCL_SYSTEM_TIME
Use system time.
Definition: time.h:71
@ RCL_CLOCK_UNINITIALIZED
Clock uninitialized.
Definition: time.h:67
@ RCL_STEADY_TIME
Use a steady clock time.
Definition: time.h:73
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_system_clock_fini(rcl_clock_t *clock)
Finalize a clock as a RCL_SYSTEM_TIME time source.
Definition: time.c:230
rcutils_duration_value_t rcl_duration_value_t
A duration of time, measured in nanoseconds.
Definition: time.h:51
RCL_PUBLIC RCL_WARN_UNUSED 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.
Definition: time.c:361
enum rcl_clock_change_e rcl_clock_change_t
Enumeration to describe the type of time jump.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_clock_init(rcl_clock_type_t clock_type, rcl_clock_t *clock, rcl_allocator_t *allocator)
Initialize a clock based on the passed type.
Definition: time.c:100
struct rcl_jump_threshold_s rcl_jump_threshold_t
Describe the prerequisites for calling a time jump callback.
RCL_PUBLIC RCL_WARN_UNUSED bool rcl_clock_valid(rcl_clock_t *clock)
Check if the clock has valid values.
Definition: time.c:88
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:25