mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
Loading...
Searching...
No Matches
mrs_lib::ROSTimer Class Reference

rclcpp::Timer wrapper. The interface is the same as with rclcpp::Timer, except for the initialization method. More...

#include <timer_handler.h>

+ Inheritance diagram for mrs_lib::ROSTimer:
+ Collaboration diagram for mrs_lib::ROSTimer:

Public Member Functions

 ROSTimer (const rclcpp::Node::SharedPtr &node, const rclcpp::Rate &rate, const std::function< void()> &callback)
 
 ROSTimer (const mrs_lib::TimerHandlerOptions &opts, const rclcpp::Rate &rate, const std::function< void()> &callback)
 
template<typename C >
 ROSTimer (const mrs_lib::TimerHandlerOptions &opts, const rclcpp::Rate &rate, Task<>(C::*method)(), C *instance)
 Create Ros timer with coroutine callback.
 
template<typename C >
 ROSTimer (const mrs_lib::TimerHandlerOptions &opts, const rclcpp::Rate &rate, Task<>(C::*method)(), std::shared_ptr< C > instance)
 Create Ros timer with coroutine callback.
 
virtual void stop () override
 stop the timer
 
virtual void start () override
 start the timer
 
virtual void setPeriod (const rclcpp::Duration &duration) override
 set the timer period/duration
 
virtual void setCallback (const std::function< void()> &callback) override
 change the callback method
 
virtual bool running () override
 returns true if callbacks should be called
 
 ROSTimer (const ROSTimer &)=delete
 
 ROSTimer (ROSTimer &&)=delete
 
ROSTimeroperator= (const ROSTimer &)=delete
 
ROSTimeroperator= (ROSTimer &&)=delete
 
- Public Member Functions inherited from mrs_lib::MRSTimer
 MRSTimer (const MRSTimer &)=default
 
 MRSTimer (MRSTimer &&)=default
 
MRSTimeroperator= (const MRSTimer &)=default
 
MRSTimeroperator= (MRSTimer &&)=default
 

Additional Inherited Members

- Public Types inherited from mrs_lib::MRSTimer
using callback_t = std::function< void()>
 
- Static Protected Member Functions inherited from mrs_lib::MRSTimer
template<typename C >
static std::function< void()> createNonReentrantCallback (Task<>(C::*method)(), C *instance)
 Create a callback for coroutine that should only run once at a time.
 
- Protected Attributes inherited from mrs_lib::MRSTimer
rclcpp::Node::SharedPtr node_
 

Detailed Description

rclcpp::Timer wrapper. The interface is the same as with rclcpp::Timer, except for the initialization method.

Constructor & Destructor Documentation

◆ ROSTimer() [1/2]

template<typename C >
mrs_lib::ROSTimer::ROSTimer ( const mrs_lib::TimerHandlerOptions opts,
const rclcpp::Rate &  rate,
Task<>(C::*)()  method,
C *  instance 
)
inline

Create Ros timer with coroutine callback.

Using coroutine callbacks is only allowed with reentrant callback group. If the specified callback group is not reentrant, this throws an exception.

To make the callback design simpler, the coroutine itself will not run again until the previous one completely finished.

◆ ROSTimer() [2/2]

template<typename C >
mrs_lib::ROSTimer::ROSTimer ( const mrs_lib::TimerHandlerOptions opts,
const rclcpp::Rate &  rate,
Task<>(C::*)()  method,
std::shared_ptr< C >  instance 
)
inline

Create Ros timer with coroutine callback.

Using coroutine callbacks is only allowed with reentrant callback group. If the specified callback group is not reentrant, this throws an exception.

To make the callback design simpler, the coroutine itself will not run again until the previous one completely finished.

Member Function Documentation

◆ running()

bool mrs_lib::ROSTimer::running ( )
overridevirtual

returns true if callbacks should be called

Returns
true if timer is running

Implements mrs_lib::MRSTimer.

◆ setCallback()

void mrs_lib::ROSTimer::setCallback ( const std::function< void()> &  callback)
overridevirtual

change the callback method

Usable e.g. for running thread with a specific parameter if you bind it using std::bind

Parameters
callbackcallback method to be called.

Implements mrs_lib::MRSTimer.

◆ setPeriod()

void mrs_lib::ROSTimer::setPeriod ( const rclcpp::Duration &  duration)
overridevirtual

set the timer period/duration

Parameters
duration
reset

Implements mrs_lib::MRSTimer.

◆ start()

void mrs_lib::ROSTimer::start ( )
overridevirtual

start the timer

Implements mrs_lib::MRSTimer.

◆ stop()

void mrs_lib::ROSTimer::stop ( )
overridevirtual

stop the timer

Implements mrs_lib::MRSTimer.


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