|
mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
|
Timer wrapper supporting ROS and thread-based implementations. More...
#include <timer.hpp>
Public Types | |
| using | EventCallback = std::function<void()> |
| Type of the accepted callback. | |
| using | EventCoroCallback = CoroCallback<void()> |
| Type of the accepted coroutine callback. | |
Public Member Functions | |
| Timer (const RosTimerOptions &options, std::chrono::nanoseconds period, EventCallback callback) | |
| Construct a ROS-based timer with a regular callback. | |
| Timer (const RosTimerOptions &options, std::chrono::nanoseconds period, EventCoroCallback callback) | |
| Construct a ROS-based timer with a coroutine callback. | |
| Timer (const ThreadTimerOptions &options, std::chrono::nanoseconds period, EventCallback callback) | |
| Construct a thread-based timer with a regular callback. | |
| Timer (const ThreadTimerOptions &options, std::chrono::nanoseconds period, EventCoroCallback callback) | |
| Construct a thread-based timer with a coroutine callback. | |
| void | stop () |
| Stop the timer. | |
| void | start_or_reset () |
| Start or reset the timer. | |
| void | set_period (std::chrono::nanoseconds period) |
| Set the timer period. | |
| bool | is_running () const |
| Check whether the timer is currently running. | |
Timer wrapper supporting ROS and thread-based implementations.
You can chose the timer implementation by calling the constructor with the respective config type (RosTimerOptions, ThreadTimerOptions).
|
explicit |
|
explicit |
|
explicit |
|
explicit |
|
nodiscard |
Check whether the timer is currently running.
| void mrs_lib::Timer::set_period | ( | std::chrono::nanoseconds | period | ) |
Set the timer period.
| period | New timer period. |
Changing the period also resets the timer countdown and starts the timer if it was previously stopped.
| void mrs_lib::Timer::start_or_reset | ( | ) |
Start or reset the timer.
If the timer is stopped, this starts it. If it is already running, its countdown is reset using the currently configured period.
| void mrs_lib::Timer::stop | ( | ) |
Stop the timer.
After calling this method, the timer will not invoke its callback until start_or_reset is called.