ROS 2 rclcpp + rcl - kilted  kilted
ROS 2 C++ Client Library with ROS Client Library
Public Member Functions | Protected Attributes | List of all members
rclcpp::GenericTimer< FunctorT, > Class Template Reference

Generic timer. Periodically executes a user-specified callback. More...

#include <rclcpp/timer.hpp>

Inheritance diagram for rclcpp::GenericTimer< FunctorT, >:
Inheritance graph
[legend]
Collaboration diagram for rclcpp::GenericTimer< FunctorT, >:
Collaboration graph
[legend]

Public Member Functions

 GenericTimer (Clock::SharedPtr clock, std::chrono::nanoseconds period, FunctorT &&callback, rclcpp::Context::SharedPtr context, bool autostart=true)
 Default constructor. More...
 
virtual ~GenericTimer ()
 Default destructor.
 
std::shared_ptr< void > call () override
 
void execute_callback (const std::shared_ptr< void > &data) override
 
template<typename CallbackT = FunctorT, typename std::enable_if< rclcpp::function_traits::same_arguments< CallbackT, VoidCallbackType >::value >::type * = nullptr>
void execute_callback_delegate (const rcl_timer_call_info_t &)
 
template<typename CallbackT = FunctorT, typename std::enable_if< rclcpp::function_traits::same_arguments< CallbackT, TimerCallbackType >::value >::type * = nullptr>
void execute_callback_delegate (const rcl_timer_call_info_t &)
 
template<typename CallbackT = FunctorT, typename std::enable_if< rclcpp::function_traits::same_arguments< CallbackT, TimerInfoCallbackType >::value >::type * = nullptr>
void execute_callback_delegate (const rcl_timer_call_info_t &timer_call_info)
 
bool is_steady () override
 Is the clock steady (i.e. is the time between ticks constant?) More...
 
- Public Member Functions inherited from rclcpp::TimerBase
RCLCPP_PUBLIC TimerBase (Clock::SharedPtr clock, std::chrono::nanoseconds period, rclcpp::Context::SharedPtr context, bool autostart=true)
 TimerBase constructor. More...
 
virtual RCLCPP_PUBLIC ~TimerBase ()
 TimerBase destructor.
 
RCLCPP_PUBLIC void cancel ()
 Cancel the timer. More...
 
RCLCPP_PUBLIC bool is_canceled ()
 Return the timer cancellation state. More...
 
RCLCPP_PUBLIC void reset ()
 Reset the timer. More...
 
RCLCPP_PUBLIC std::shared_ptr< const rcl_timer_tget_timer_handle ()
 
RCLCPP_PUBLIC std::chrono::nanoseconds time_until_trigger ()
 Check how long the timer has until its next scheduled callback. More...
 
RCLCPP_PUBLIC bool is_ready ()
 Check if the timer is ready to trigger the callback. More...
 
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. More...
 
RCLCPP_PUBLIC void set_on_reset_callback (std::function< void(size_t)> callback)
 Set a callback to be called when the timer is reset. More...
 
RCLCPP_PUBLIC void clear_on_reset_callback ()
 Unset the callback registered for reset timer.
 

Protected Attributes

FunctorT callback_
 
- Protected Attributes inherited from rclcpp::TimerBase
std::recursive_mutex callback_mutex_
 
std::function< void(size_t)> on_reset_callback_ {nullptr}
 
Clock::SharedPtr clock_
 
std::shared_ptr< rcl_timer_ttimer_handle_
 
std::atomic< bool > in_use_by_wait_set_ {false}
 

Additional Inherited Members

- Protected Member Functions inherited from rclcpp::TimerBase
RCLCPP_PUBLIC void set_on_reset_callback (rcl_event_callback_t callback, const void *user_data)
 

Detailed Description

template<typename FunctorT, typename std::enable_if< rclcpp::function_traits::same_arguments< FunctorT, VoidCallbackType >::value||rclcpp::function_traits::same_arguments< FunctorT, TimerCallbackType >::value||rclcpp::function_traits::same_arguments< FunctorT, TimerInfoCallbackType >::value >::type * = nullptr>
class rclcpp::GenericTimer< FunctorT, >

Generic timer. Periodically executes a user-specified callback.

Definition at line 225 of file timer.hpp.

Constructor & Destructor Documentation

◆ GenericTimer()

template<typename FunctorT , typename std::enable_if< rclcpp::function_traits::same_arguments< FunctorT, VoidCallbackType >::value||rclcpp::function_traits::same_arguments< FunctorT, TimerCallbackType >::value||rclcpp::function_traits::same_arguments< FunctorT, TimerInfoCallbackType >::value >::type * = nullptr>
rclcpp::GenericTimer< FunctorT, >::GenericTimer ( Clock::SharedPtr  clock,
std::chrono::nanoseconds  period,
FunctorT &&  callback,
rclcpp::Context::SharedPtr  context,
bool  autostart = true 
)
inlineexplicit

Default constructor.

Parameters
[in]clockThe clock providing the current time.
[in]periodThe interval at which the timer fires.
[in]callbackUser-specified callback function.
[in]contextcustom context to be used.
autostarttimer state on initialization

Definition at line 238 of file timer.hpp.

Member Function Documentation

◆ call()

template<typename FunctorT , typename std::enable_if< rclcpp::function_traits::same_arguments< FunctorT, VoidCallbackType >::value||rclcpp::function_traits::same_arguments< FunctorT, TimerCallbackType >::value||rclcpp::function_traits::same_arguments< FunctorT, TimerInfoCallbackType >::value >::type * = nullptr>
std::shared_ptr<void> rclcpp::GenericTimer< FunctorT, >::call ( )
inlineoverridevirtual
See also
rclcpp::TimerBase::call
Exceptions
std::runtime_errorif it failed to notify timer that callback will occurr

Implements rclcpp::TimerBase.

Definition at line 272 of file timer.hpp.

References RCL_RET_OK, RCL_RET_TIMER_CANCELED, and rcl_timer_call_with_info().

Here is the call graph for this function:

◆ execute_callback()

template<typename FunctorT , typename std::enable_if< rclcpp::function_traits::same_arguments< FunctorT, VoidCallbackType >::value||rclcpp::function_traits::same_arguments< FunctorT, TimerCallbackType >::value||rclcpp::function_traits::same_arguments< FunctorT, TimerInfoCallbackType >::value >::type * = nullptr>
void rclcpp::GenericTimer< FunctorT, >::execute_callback ( const std::shared_ptr< void > &  data)
inlineoverridevirtual
See also
rclcpp::TimerBase::execute_callback

Implements rclcpp::TimerBase.

Definition at line 289 of file timer.hpp.

◆ is_steady()

template<typename FunctorT , typename std::enable_if< rclcpp::function_traits::same_arguments< FunctorT, VoidCallbackType >::value||rclcpp::function_traits::same_arguments< FunctorT, TimerCallbackType >::value||rclcpp::function_traits::same_arguments< FunctorT, TimerInfoCallbackType >::value >::type * = nullptr>
bool rclcpp::GenericTimer< FunctorT, >::is_steady ( )
inlineoverridevirtual

Is the clock steady (i.e. is the time between ticks constant?)

Returns
True if the clock used by this timer is steady.

Implements rclcpp::TimerBase.

Definition at line 339 of file timer.hpp.

References RCL_STEADY_TIME.


The documentation for this class was generated from the following file: