15 #ifndef RCLCPP__TIMER_HPP_
16 #define RCLCPP__TIMER_HPP_
24 #include <type_traits>
27 #include "rclcpp/clock.hpp"
28 #include "rclcpp/context.hpp"
29 #include "rclcpp/function_traits.hpp"
30 #include "rclcpp/macros.hpp"
31 #include "rclcpp/rate.hpp"
32 #include "rclcpp/utilities.hpp"
33 #include "rclcpp/visibility_control.hpp"
34 #include "tracetools/tracetools.h"
35 #include "tracetools/utils.hpp"
37 #include "rcl/error_handling.h"
40 #include "rmw/error_handling.h"
49 RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(
TimerBase)
59 Clock::SharedPtr clock,
60 std::chrono::nanoseconds period,
61 rclcpp::Context::SharedPtr context);
111 std::shared_ptr<const rcl_timer_t>
121 std::chrono::nanoseconds
153 Clock::SharedPtr clock_;
154 std::shared_ptr<rcl_timer_t> timer_handle_;
156 std::atomic<bool> in_use_by_wait_set_{
false};
160 using VoidCallbackType = std::function<void ()>;
161 using TimerCallbackType = std::function<void (TimerBase &)>;
166 typename std::enable_if<
184 Clock::SharedPtr clock, std::chrono::nanoseconds period, FunctorT && callback,
187 :
TimerBase(clock, period, context), callback_(std::forward<FunctorT>(callback))
190 rclcpp_timer_callback_added,
191 static_cast<const void *
>(get_timer_handle().get()),
192 static_cast<const void *
>(&callback_));
194 rclcpp_callback_register,
195 static_cast<const void *
>(&callback_),
196 tracetools::get_symbol(callback_));
218 throw std::runtime_error(
"Failed to notify timer that callback occurred");
229 TRACEPOINT(callback_start,
static_cast<const void *
>(&callback_),
false);
230 execute_callback_delegate<>();
231 TRACEPOINT(callback_end,
static_cast<const void *
>(&callback_));
236 typename CallbackT = FunctorT,
237 typename std::enable_if<
242 execute_callback_delegate()
248 typename CallbackT = FunctorT,
249 typename std::enable_if<
254 execute_callback_delegate()
275 typename std::enable_if<
292 std::chrono::nanoseconds period,
293 FunctorT && callback,
Context which encapsulates shared state between nodes and other similar entities.
Generic timer. Periodically executes a user-specified callback.
bool is_steady() override
Is the clock steady (i.e. is the time between ticks constant?)
virtual ~GenericTimer()
Default destructor.
void execute_callback() override
virtual RCLCPP_PUBLIC ~TimerBase()
TimerBase destructor.
RCLCPP_PUBLIC bool is_canceled()
Return the timer cancellation state.
RCLCPP_PUBLIC void reset()
Reset the timer.
virtual RCLCPP_PUBLIC bool call()=0
Indicate that we're about to execute the callback.
RCLCPP_PUBLIC TimerBase(Clock::SharedPtr clock, std::chrono::nanoseconds period, rclcpp::Context::SharedPtr context)
TimerBase constructor.
RCLCPP_PUBLIC bool exchange_in_use_by_wait_set_state(bool in_use_state)
Exchange the "in use by wait set" state for this timer.
virtual bool is_steady()=0
Is the clock steady (i.e. is the time between ticks constant?)
RCLCPP_PUBLIC bool is_ready()
Check if the timer is ready to trigger the callback.
virtual RCLCPP_PUBLIC void execute_callback()=0
Call the callback function when the timer signal is emitted.
RCLCPP_PUBLIC std::chrono::nanoseconds time_until_trigger()
Check how long the timer has until its next scheduled callback.
RCLCPP_PUBLIC void cancel()
Cancel the timer.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
@ RCL_STEADY_TIME
Use a steady clock time.
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.
#define RCL_RET_OK
Success return code.
#define RCL_RET_TIMER_CANCELED
Given timer was canceled return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.