nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
nros::Timer Class Reference

#include <timer.hpp>

Public Member Functions

Result cancel ()
 
bool is_cancelled () const
 Check if the timer is cancelled.
 
bool is_valid () const
 Check if the timer is initialized and valid.
 
Timeroperator= (Timer &&other)
 
Result reset ()
 
 Timer ()
 
 Timer (Timer &&other)
 
 ~Timer ()
 Destructor — cancels the timer.
 

Friends

class Node
 

Detailed Description

Repeating or one-shot timer registered with the executor.

Timers fire during spin_once() when their period has elapsed. The callback is a C function pointer with a user context.

Usage:

void on_timer(void* ctx) { /* periodic work *&zwj;/ }
nros::Timer timer;
NROS_TRY(node.create_timer(timer, 1000, on_timer)); // 1000ms period
// timer fires during nros::spin_once()
timer.cancel();
timer.reset(); // restart from zero
Definition future.hpp:40

Constructor & Destructor Documentation

◆ ~Timer()

nros::Timer::~Timer ( )
inline

Destructor — cancels the timer.

◆ Timer() [1/2]

nros::Timer::Timer ( Timer &&  other)
inline

◆ Timer() [2/2]

nros::Timer::Timer ( )
inline

Default constructor — creates an uninitialized timer. Use Node::create_timer() to initialize.

Member Function Documentation

◆ cancel()

Result nros::Timer::cancel ( )
inline

Cancel the timer. It stops firing but remains in the executor. Use reset() to restart it.

◆ is_cancelled()

bool nros::Timer::is_cancelled ( ) const
inline

Check if the timer is cancelled.

◆ is_valid()

bool nros::Timer::is_valid ( ) const
inline

Check if the timer is initialized and valid.

◆ operator=()

Timer & nros::Timer::operator= ( Timer &&  other)
inline

◆ reset()

Result nros::Timer::reset ( )
inline

Reset the timer (restart from zero elapsed time). If cancelled, this also un-cancels it.

Friends And Related Symbol Documentation

◆ Node

friend class Node
friend

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