rcl  beta1
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 
15 #ifndef RCL__TIME_H_
16 #define RCL__TIME_H_
17 
18 #if __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 #include "rcl/macros.h"
24 #include "rcl/types.h"
25 #include "rcl/visibility_control.h"
26 
28 #define RCL_S_TO_NS(seconds) (seconds * (1000 * 1000 * 1000))
29 #define RCL_MS_TO_NS(milliseconds) (milliseconds * (1000 * 1000))
31 #define RCL_US_TO_NS(microseconds) (microseconds * 1000)
33 
35 #define RCL_NS_TO_S(nanoseconds) (nanoseconds / (1000 * 1000 * 1000))
36 #define RCL_NS_TO_MS(nanoseconds) (nanoseconds / (1000 * 1000))
38 #define RCL_NS_TO_US(nanoseconds) (nanoseconds / 1000)
40 
42 typedef uint64_t rcl_time_point_value_t;
44 typedef int64_t rcl_duration_value_t;
45 
48 {
53 };
54 
56 typedef struct rcl_time_source_t
57 {
59  void (* pre_update)(void);
60  void (* post_update)(void);
61  rcl_ret_t (* get_now)(void * data, rcl_time_point_value_t * now);
62  // void (*set_now) (rcl_time_point_value_t);
63  void * data;
65 
66 struct rcl_ros_time_source_storage_t;
67 
69 typedef struct rcl_time_point_t
70 {
71  rcl_time_point_value_t nanoseconds;
74 
76 typedef struct rcl_duration_t
77 {
78  rcl_duration_value_t nanoseconds;
81 
82 // typedef struct rcl_rate_t
83 // {
84 // rcl_time_point_value_t trigger_time;
85 // int64_t period;
86 // rcl_time_source_t * time_source;
87 // } rcl_rate_t;
88 // TODO(tfoote) integrate rate and timer implementations
89 
91 
102 bool
104 
106 
117 rcl_ret_t
119 
121 
133 rcl_ret_t
135 
137 
148 rcl_ret_t
150 
152 
166 rcl_ret_t
168 
170 
183 rcl_ret_t
185 
187 
201 rcl_ret_t
203 
205 
222 rcl_ret_t
223 rcl_init_time_point(rcl_time_point_t * time_point, rcl_time_source_t * time_source);
224 
226 
238 rcl_ret_t
240 
242 
257 rcl_ret_t
258 rcl_init_duration(rcl_duration_t * duration, rcl_time_source_t * time_source);
259 
261 
273 rcl_ret_t
275 
277 
292 
294 
309 
311 
326 
328 
344 rcl_ret_t
346 
348 
365 rcl_ret_t
367  rcl_duration_t * delta);
368 
370 
381 rcl_ret_t
383 
384 
386 
398 rcl_ret_t
400 
402 
414 rcl_ret_t
416 
417 
419 
432 rcl_ret_t
434  bool * is_enabled);
435 
437 
451 rcl_ret_t
453  rcl_time_point_value_t time_value);
454 
456 
483 rcl_ret_t
484 rcl_system_time_now(rcl_time_point_value_t * now);
485 
487 
514 rcl_ret_t
515 rcl_steady_time_now(rcl_time_point_value_t * now);
516 
517 #if __cplusplus
518 }
519 #endif
520 
521 #endif // RCL__TIME_H_
rcl_ret_t rcl_get_time_point_now(rcl_time_point_t *time_point)
Fill the time point with the current value of the associated clock.
A single point in time, measured in nanoseconds, the reference point is based on the source...
Definition: time.h:69
rcl_ret_t rcl_disable_ros_time_override(rcl_time_source_t *time_source)
Disable the ROS time abstraction override.
rcl_ret_t rcl_system_time_now(rcl_time_point_value_t *now)
Retrieve the current time as a rcl_time_point_value_t.
rcl_duration_value_t nanoseconds
Definition: time.h:78
rcl_ret_t rcl_init_ros_time_source(rcl_time_source_t *time_source)
Initialize a time_source as a RCL_ROS_TIME time source.
rcl_time_source_t * time_source
Definition: time.h:79
void * data
Definition: time.h:63
rmw_ret_t rcl_ret_t
Definition: types.h:20
enum rcl_time_source_type_t type
Definition: time.h:58
void(* post_update)(void)
Definition: time.h:60
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_ret_t(* get_now)(void *data, rcl_time_point_value_t *now)
Definition: time.h:61
rcl_time_source_t * rcl_get_default_ros_time_source(void)
Get the default RCL_ROS_TIME time source.
rcl_ret_t rcl_fini_time_point(rcl_time_point_t *time_point)
Finalize a time_point.
rcl_ret_t rcl_is_enabled_ros_time_override(rcl_time_source_t *time_source, bool *is_enabled)
Check if the RCL_ROS_TIME time source has the override enabled.
rcl_time_point_value_t nanoseconds
Definition: time.h:71
rcl_ret_t rcl_init_steady_time_source(rcl_time_source_t *time_source)
Initialize a time_source as a RCL_STEADY_TIME time source.
rcl_ret_t rcl_set_default_ros_time_source(rcl_time_source_t *process_time_source)
Set the current time on the RCL_ROS_TIME time source.
rcl_ret_t rcl_fini_ros_time_source(rcl_time_source_t *time_source)
Finalize a time_source as a RCL_ROS_TIME time source.
Definition: time.h:52
struct rcl_time_source_t rcl_time_source_t
Encapsulation of a time source.
rcl_ret_t rcl_enable_ros_time_override(rcl_time_source_t *time_source)
Enable the ROS time abstraction override.
Definition: time.h:49
void(* pre_update)(void)
Definition: time.h:59
int64_t rcl_duration_value_t
A duration of time, measured in nanoseconds.
Definition: time.h:44
rcl_time_source_type_t
Time source type, used to indicate the source of a time measurement.
Definition: time.h:47
rcl_ret_t rcl_init_time_point(rcl_time_point_t *time_point, rcl_time_source_t *time_source)
Initialize a time point using the time_source.
Encapsulation of a time source.
Definition: time.h:56
rcl_time_source_t * rcl_get_default_system_time_source(void)
Get the default RCL_SYSTEM_TIME time source.
rcl_ret_t rcl_set_ros_time_override(rcl_time_source_t *time_source, rcl_time_point_value_t time_value)
Set the current time for this RCL_ROS_TIME time source.
Definition: time.h:50
rcl_ret_t rcl_fini_steady_time_source(rcl_time_source_t *time_source)
Finalize a time_source as a RCL_STEADY_TIME time source.
#define RCL_WARN_UNUSED
Ignored return values of functions with this macro will emit a warning.
Definition: macros.h:25
rcl_time_source_t * rcl_get_default_steady_time_source(void)
Get the default RCL_STEADY_TIME time source.
#define RCL_PUBLIC
Definition: visibility_control.h:48
struct rcl_duration_t rcl_duration_t
A duration of time, measured in nanoseconds and its source.
A duration of time, measured in nanoseconds and its source.
Definition: time.h:76
uint64_t rcl_time_point_value_t
A single point in time, measured in nanoseconds since the Unix epoch.
Definition: time.h:42
rcl_ret_t rcl_init_system_time_source(rcl_time_source_t *time_source)
Initialize a time_source as a RCL_SYSTEM_TIME time source.
rcl_time_source_t * time_source
Definition: time.h:72
rcl_ret_t rcl_fini_duration(rcl_duration_t *duration)
Finalize a duration.
bool rcl_time_source_valid(rcl_time_source_t *time_source)
Check if the time_source has valid values.
rcl_ret_t rcl_init_duration(rcl_duration_t *duration, rcl_time_source_t *time_source)
Initialize a duration using the time_source.
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_ret_t rcl_steady_time_now(rcl_time_point_value_t *now)
Retrieve the current time as a rcl_time_point_value_t object.
rcl_ret_t rcl_fini_system_time_source(rcl_time_source_t *time_source)
Finalize a time_source as a RCL_SYSTEM_TIME time source.
Definition: time.h:51