ROS 2 rclcpp + rcl - humble  humble
ROS 2 C++ Client Library with ROS Client Library
timer.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__TIMER_H_
18 #define RCL__TIMER_H_
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include <stdbool.h>
26 
27 #include "rcl/allocator.h"
28 #include "rcl/context.h"
29 #include "rcl/guard_condition.h"
30 #include "rcl/macros.h"
31 #include "rcl/time.h"
32 #include "rcl/types.h"
33 #include "rmw/rmw.h"
34 
35 typedef struct rcl_timer_impl_s rcl_timer_impl_t;
36 
38 typedef struct rcl_timer_s
39 {
43 
45 
57 typedef void (* rcl_timer_callback_t)(rcl_timer_t *, int64_t);
58 
60 RCL_PUBLIC
61 RCL_WARN_UNUSED
64 
66 
151 RCL_PUBLIC
152 RCL_WARN_UNUSED
153 rcl_ret_t
155  rcl_timer_t * timer,
156  rcl_clock_t * clock,
157  rcl_context_t * context,
158  int64_t period,
159  const rcl_timer_callback_t callback,
160  rcl_allocator_t allocator);
161 
163 
188 RCL_PUBLIC
189 RCL_WARN_UNUSED
190 rcl_ret_t
191 rcl_timer_fini(rcl_timer_t * timer);
192 
194 
232 RCL_PUBLIC
233 RCL_WARN_UNUSED
234 rcl_ret_t
235 rcl_timer_call(rcl_timer_t * timer);
236 
238 
257 RCL_PUBLIC
258 RCL_WARN_UNUSED
259 rcl_ret_t
260 rcl_timer_clock(rcl_timer_t * timer, rcl_clock_t ** clock);
261 
263 
287 RCL_PUBLIC
288 RCL_WARN_UNUSED
289 rcl_ret_t
290 rcl_timer_is_ready(const rcl_timer_t * timer, bool * is_ready);
291 
293 
323 RCL_PUBLIC
324 RCL_WARN_UNUSED
325 rcl_ret_t
326 rcl_timer_get_time_until_next_call(const rcl_timer_t * timer, int64_t * time_until_next_call);
327 
329 
355 RCL_PUBLIC
356 RCL_WARN_UNUSED
357 rcl_ret_t
358 rcl_timer_get_time_since_last_call(const rcl_timer_t * timer, int64_t * time_since_last_call);
359 
361 
382 RCL_PUBLIC
383 RCL_WARN_UNUSED
384 rcl_ret_t
385 rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period);
386 
388 
413 RCL_PUBLIC
414 RCL_WARN_UNUSED
415 rcl_ret_t
416 rcl_timer_exchange_period(const rcl_timer_t * timer, int64_t new_period, int64_t * old_period);
417 
419 
436 RCL_PUBLIC
437 RCL_WARN_UNUSED
439 rcl_timer_get_callback(const rcl_timer_t * timer);
440 
442 
463 RCL_PUBLIC
464 RCL_WARN_UNUSED
467 
469 
490 RCL_PUBLIC
491 RCL_WARN_UNUSED
492 rcl_ret_t
494 
496 
519 RCL_PUBLIC
520 RCL_WARN_UNUSED
521 rcl_ret_t
522 rcl_timer_is_canceled(const rcl_timer_t * timer, bool * is_canceled);
523 
525 
545 RCL_PUBLIC
546 RCL_WARN_UNUSED
547 rcl_ret_t
549 
551 
569 RCL_PUBLIC
570 RCL_WARN_UNUSED
571 const rcl_allocator_t *
572 rcl_timer_get_allocator(const rcl_timer_t * timer);
573 
575 
588 RCL_PUBLIC
589 RCL_WARN_UNUSED
592 
593 #ifdef __cplusplus
594 }
595 #endif
596 
597 #endif // RCL__TIMER_H_
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:31
Encapsulation of a time source.
Definition: time.h:138
Encapsulates the non-global state of an init/shutdown cycle.
Definition: context.h:114
Handle for a rcl guard condition.
Structure which encapsulates a ROS Timer.
Definition: timer.h:39
rcl_timer_impl_t * impl
Private implementation pointer.
Definition: timer.h:41
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_get_time_since_last_call(const rcl_timer_t *timer, int64_t *time_since_last_call)
Retrieve the time since the previous call to rcl_timer_call() occurred.
void(* rcl_timer_callback_t)(rcl_timer_t *, int64_t)
User callback signature for timers.
Definition: timer.h:57
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_get_time_until_next_call(const rcl_timer_t *timer, int64_t *time_until_next_call)
Calculate and retrieve the time until the next call in nanoseconds.
Definition: timer.c:313
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_call(rcl_timer_t *timer)
Call the timer's callback and set the last call time.
Definition: timer.c:243
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_init(rcl_timer_t *timer, rcl_clock_t *clock, rcl_context_t *context, int64_t period, const rcl_timer_callback_t callback, rcl_allocator_t allocator)
Initialize a timer.
Definition: timer.c:127
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_reset(rcl_timer_t *timer)
Reset a timer.
Definition: timer.c:416
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_get_period(const rcl_timer_t *timer, int64_t *period)
Retrieve the period of the timer.
Definition: timer.c:350
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_exchange_period(const rcl_timer_t *timer, int64_t new_period, int64_t *old_period)
Exchange the period of the timer and return the previous period.
Definition: timer.c:360
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_clock(rcl_timer_t *timer, rcl_clock_t **clock)
Retrieve the clock of the timer.
Definition: timer.c:233
RCL_PUBLIC RCL_WARN_UNUSED rcl_timer_callback_t rcl_timer_get_callback(const rcl_timer_t *timer)
Return the current timer callback.
Definition: timer.c:375
RCL_PUBLIC RCL_WARN_UNUSED rcl_timer_callback_t rcl_timer_exchange_callback(rcl_timer_t *timer, const rcl_timer_callback_t new_callback)
Exchange the current timer callback and return the current callback.
Definition: timer.c:383
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_cancel(rcl_timer_t *timer)
Cancel a timer.
Definition: timer.c:393
struct rcl_timer_s rcl_timer_t
Structure which encapsulates a ROS Timer.
RCL_PUBLIC RCL_WARN_UNUSED rcl_guard_condition_t * rcl_timer_get_guard_condition(const rcl_timer_t *timer)
Retrieve a guard condition used by the timer to wake the waitset when using ROSTime.
Definition: timer.c:447
RCL_PUBLIC RCL_WARN_UNUSED rcl_timer_t rcl_get_zero_initialized_timer(void)
Return a zero initialized timer.
Definition: timer.c:56
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_fini(rcl_timer_t *timer)
Finalize a timer.
Definition: timer.c:204
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_is_canceled(const rcl_timer_t *timer, bool *is_canceled)
Retrieve the canceled state of a timer.
Definition: timer.c:406
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_timer_is_ready(const rcl_timer_t *timer, bool *is_ready)
Calculates whether or not the timer should be called.
Definition: timer.c:295
RCL_PUBLIC RCL_WARN_UNUSED const rcl_allocator_t * rcl_timer_get_allocator(const rcl_timer_t *timer)
Return the allocator for the timer.
Definition: timer.c:439
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:23