ROS 2 rclcpp + rcl - kilted  kilted
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 "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
34 #define RCL_MS_TO_NS RCUTILS_MS_TO_NS
36 #define RCL_US_TO_NS RCUTILS_US_TO_NS
37 
39 #define RCL_NS_TO_S RCUTILS_NS_TO_S
41 #define RCL_NS_TO_MS RCUTILS_NS_TO_MS
43 #define RCL_NS_TO_US RCUTILS_NS_TO_US
44 
46 typedef rcutils_time_point_value_t rcl_time_point_value_t;
48 typedef rcutils_duration_value_t rcl_duration_value_t;
49 
51 
61 typedef enum rcl_clock_type_e
62 {
72 
74 typedef struct rcl_duration_s
75 {
79 
81 typedef enum rcl_clock_change_e
82 {
92 
94 typedef struct rcl_time_jump_s
95 {
101 
107 typedef void (* rcl_jump_callback_t)(
108  const rcl_time_jump_t * time_jump,
109  bool before_jump,
110  void * user_data);
111 
113 typedef struct rcl_jump_threshold_s
114 {
124 
127 {
133  void * user_data;
135 
137 typedef struct rcl_clock_s
138 {
147  // void (*set_now) (rcl_time_point_value_t);
149  void * data;
153 
155 typedef struct rcl_time_point_s
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 
192 RCL_PUBLIC
193 RCL_WARN_UNUSED
194 bool
196 
198 
215 RCL_PUBLIC
216 RCL_WARN_UNUSED
217 bool
219 
221 
243 RCL_PUBLIC
244 RCL_WARN_UNUSED
245 rcl_ret_t
247  rcl_clock_type_t clock_type, rcl_clock_t * clock,
248  rcl_allocator_t * allocator);
249 
251 
278 RCL_PUBLIC
279 RCL_WARN_UNUSED
280 rcl_ret_t
282  rcl_clock_t * clock);
283 
285 
307 RCL_PUBLIC
308 RCL_WARN_UNUSED
309 rcl_ret_t
311  rcl_clock_t * clock,
312  rcl_allocator_t * allocator);
313 
315 
340 RCL_PUBLIC
341 RCL_WARN_UNUSED
342 rcl_ret_t
344  rcl_clock_t * clock);
345 
347 
368 RCL_PUBLIC
369 RCL_WARN_UNUSED
370 rcl_ret_t
372  rcl_clock_t * clock,
373  rcl_allocator_t * allocator);
374 
376 
403 RCL_PUBLIC
404 RCL_WARN_UNUSED
405 rcl_ret_t
407  rcl_clock_t * clock);
408 
410 
434 RCL_PUBLIC
435 RCL_WARN_UNUSED
436 rcl_ret_t
438  rcl_clock_t * clock,
439  rcl_allocator_t * allocator);
440 
442 
468 RCL_PUBLIC
469 RCL_WARN_UNUSED
470 rcl_ret_t
472  rcl_clock_t * clock);
473 
475 
498 RCL_PUBLIC
499 RCL_WARN_UNUSED
500 rcl_ret_t
502  const rcl_time_point_t * start, const rcl_time_point_t * finish, rcl_duration_t * delta);
503 
505 
525 RCL_PUBLIC
526 RCL_WARN_UNUSED
527 rcl_ret_t
528 rcl_clock_get_now(rcl_clock_t * clock, rcl_time_point_value_t * time_point_value);
529 
530 
532 
557 RCL_PUBLIC
558 RCL_WARN_UNUSED
559 rcl_ret_t
561 
563 
588 RCL_PUBLIC
589 RCL_WARN_UNUSED
590 rcl_ret_t
592 
593 
595 
619 RCL_PUBLIC
620 RCL_WARN_UNUSED
621 rcl_ret_t
623  rcl_clock_t * clock, bool * is_enabled);
624 
626 
653 RCL_PUBLIC
654 RCL_WARN_UNUSED
655 rcl_ret_t
657  rcl_clock_t * clock, rcl_time_point_value_t time_value);
658 
660 
691 RCL_PUBLIC
692 RCL_WARN_UNUSED
693 rcl_ret_t
695  rcl_clock_t * clock, rcl_jump_threshold_t threshold, rcl_jump_callback_t callback,
696  void * user_data);
697 
699 
724 RCL_PUBLIC
725 RCL_WARN_UNUSED
726 rcl_ret_t
728  rcl_clock_t * clock, rcl_jump_callback_t callback, void * user_data);
729 
730 #ifdef __cplusplus
731 }
732 #endif
733 
734 #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:138
rcl_jump_callback_info_t * jump_callbacks
An array of added jump callbacks.
Definition: time.h:142
void * data
Clock storage.
Definition: time.h:149
rcl_allocator_t allocator
Custom allocator used for internal allocations.
Definition: time.h:151
rcl_ret_t(* get_now)(void *data, rcl_time_point_value_t *now)
Pointer to get_now function.
Definition: time.h:146
rcl_clock_type_t type
Clock type.
Definition: time.h:140
size_t num_jump_callbacks
Number of callbacks in jump_callbacks.
Definition: time.h:144
A duration of time, measured in nanoseconds and its source.
Definition: time.h:75
rcl_duration_value_t nanoseconds
Duration in nanoseconds and its source.
Definition: time.h:77
Struct to describe an added callback.
Definition: time.h:127
void * user_data
Pointer passed to the callback.
Definition: time.h:133
rcl_jump_threshold_t threshold
Threshold to decide when to call the callback.
Definition: time.h:131
rcl_jump_callback_t callback
Callback to fucntion.
Definition: time.h:129
Describe the prerequisites for calling a time jump callback.
Definition: time.h:114
rcl_duration_t min_forward
Definition: time.h:119
bool on_clock_change
True to call callback when the clock type changes.
Definition: time.h:116
rcl_duration_t min_backward
Definition: time.h:122
Struct to describe a jump in time.
Definition: time.h:95
rcl_clock_change_t clock_change
Indicate whether or not the source of time changed.
Definition: time.h:97
rcl_duration_t delta
The new time minus the last time before the jump.
Definition: time.h:99
A single point in time, measured in nanoseconds, the reference point is based on the source.
Definition: time.h:156
rcl_clock_type_t clock_type
Clock type of the point in time.
Definition: time.h:160
rcl_time_point_value_t nanoseconds
Nanoseconds of the point in time.
Definition: time.h:158
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:132
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:82
@ RCL_ROS_TIME_DEACTIVATED
The source switched to SYSTEM_TIME from ROS_TIME.
Definition: time.h:88
@ RCL_SYSTEM_TIME_NO_CHANGE
The source before and after the jump is SYSTEM_TIME.
Definition: time.h:90
@ RCL_ROS_TIME_NO_CHANGE
The source before and after the jump is ROS_TIME.
Definition: time.h:84
@ RCL_ROS_TIME_ACTIVATED
The source switched to ROS_TIME from SYSTEM_TIME.
Definition: time.h:86
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_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:76
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:107
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:62
@ RCL_ROS_TIME
Use ROS time.
Definition: time.h:66
@ RCL_SYSTEM_TIME
Use system time.
Definition: time.h:68
@ RCL_CLOCK_UNINITIALIZED
Clock uninitialized.
Definition: time.h:64
@ RCL_STEADY_TIME
Use a steady clock time.
Definition: time.h:70
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:48
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:98
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:86
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:24