rclcpp  master
C++ ROS Client Library API
Public Member Functions | Protected Attributes | List of all members
rclcpp::TimerBase Class Referenceabstract

#include <timer.hpp>

Inheritance diagram for rclcpp::TimerBase:
Inheritance graph
[legend]
Collaboration diagram for rclcpp::TimerBase:
Collaboration graph
[legend]

Public Member Functions

 TimerBase (Clock::SharedPtr clock, std::chrono::nanoseconds period, rclcpp::Context::SharedPtr context)
 TimerBase constructor. More...
 
virtual ~TimerBase ()
 TimerBase destructor. More...
 
void cancel ()
 Cancel the timer. More...
 
bool is_canceled ()
 Return the timer cancellation state. More...
 
void reset ()
 Reset the timer. More...
 
virtual void execute_callback ()=0
 Call the callback function when the timer signal is emitted. More...
 
std::shared_ptr< const rcl_timer_tget_timer_handle ()
 
std::chrono::nanoseconds time_until_trigger ()
 Check how long the timer has until its next scheduled callback. More...
 
virtual bool is_steady ()=0
 Is the clock steady (i.e. is the time between ticks constant?) More...
 
bool is_ready ()
 Check if the timer is ready to trigger the callback. More...
 
bool exchange_in_use_by_wait_set_state (bool in_use_state)
 Exchange the "in use by wait set" state for this timer. More...
 

Protected Attributes

Clock::SharedPtr clock_
 
std::shared_ptr< rcl_timer_ttimer_handle_
 
std::atomic< bool > in_use_by_wait_set_ {false}
 

Constructor & Destructor Documentation

◆ TimerBase()

rclcpp::TimerBase::TimerBase ( Clock::SharedPtr  clock,
std::chrono::nanoseconds  period,
rclcpp::Context::SharedPtr  context 
)
explicit

TimerBase constructor.

Parameters
clockA clock to use for time and sleeping
periodThe interval at which the timer fires
contextnode context

◆ ~TimerBase()

virtual rclcpp::TimerBase::~TimerBase ( )
virtual

TimerBase destructor.

Member Function Documentation

◆ cancel()

void rclcpp::TimerBase::cancel ( )

Cancel the timer.

Exceptions
std::runtime_errorif the rcl_timer_cancel returns a failure

◆ is_canceled()

bool rclcpp::TimerBase::is_canceled ( )

Return the timer cancellation state.

Returns
true if the timer has been cancelled, false otherwise
Exceptions
std::runtime_errorif the rcl_get_error_state returns 0
rclcpp::exceptions::RCLErrorsome child class exception based on ret

◆ reset()

void rclcpp::TimerBase::reset ( )

Reset the timer.

Exceptions
std::runtime_errorif the rcl_timer_reset returns a failure

◆ execute_callback()

virtual void rclcpp::TimerBase::execute_callback ( )
pure virtual

Call the callback function when the timer signal is emitted.

Implemented in rclcpp::GenericTimer< FunctorT, >, and rclcpp::GenericTimer< FunctorT >.

◆ get_timer_handle()

std::shared_ptr<const rcl_timer_t> rclcpp::TimerBase::get_timer_handle ( )

◆ time_until_trigger()

std::chrono::nanoseconds rclcpp::TimerBase::time_until_trigger ( )

Check how long the timer has until its next scheduled callback.

Returns
A std::chrono::duration representing the relative time until the next callback.
Exceptions
std::runtime_errorif the rcl_timer_get_time_until_next_call returns a failure

◆ is_steady()

virtual bool rclcpp::TimerBase::is_steady ( )
pure virtual

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

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

Implemented in rclcpp::GenericTimer< FunctorT, >, and rclcpp::GenericTimer< FunctorT >.

◆ is_ready()

bool rclcpp::TimerBase::is_ready ( )

Check if the timer is ready to trigger the callback.

This function expects its caller to immediately trigger the callback after this function, since it maintains the last time the callback was triggered.

Returns
True if the timer needs to trigger.
Exceptions
std::runtime_errorif it failed to check timer

◆ exchange_in_use_by_wait_set_state()

bool rclcpp::TimerBase::exchange_in_use_by_wait_set_state ( bool  in_use_state)

Exchange the "in use by wait set" state for this timer.

This is used to ensure this timer is not used by multiple wait sets at the same time.

Parameters
[in]in_use_statethe new state to exchange into the state, true indicates it is now in use by a wait set, and false is that it is no longer in use by a wait set.
Returns
the previous state.

Member Data Documentation

◆ clock_

Clock::SharedPtr rclcpp::TimerBase::clock_
protected

◆ timer_handle_

std::shared_ptr<rcl_timer_t> rclcpp::TimerBase::timer_handle_
protected

◆ in_use_by_wait_set_

std::atomic<bool> rclcpp::TimerBase::in_use_by_wait_set_ {false}
protected

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