Timer

class rclpy.timer.Rate(timer: Timer, *, context)

A utility for sleeping at a fixed rate.

destroy()
sleep()

Block until timer triggers.

Care should be taken when calling this from a callback. This may block forever if called in a callback in a SingleThreadedExecutor.

class rclpy.timer.Timer(callback: Callable, callback_group: CallbackGroup, timer_period_ns: int, clock: rclpy.clock.Clock, *, context: Context | None = None, autostart: bool = True)

Create a Timer.

If autostart is True (the default), the timer will be started and every timer_period_sec number of seconds the provided callback function will be called. If autostart is False, the timer will be created but not started; it can then be started by calling reset() on the timer object.

Parameters:
  • callback – A user-defined callback function that is called when the timer expires.

  • callback_group – The callback group for the timer. If None, then the default callback group for the node is used.

  • timer_period_ns – The period (in nanoseconds) of the timer.

  • clock – The clock which the timer gets time from.

  • context – The context to be associated with.

  • autostart – Whether to automatically start the timer after creation; defaults to True.

cancel()
property clock
destroy()
property handle
is_canceled()
is_ready()
reset()
time_since_last_call()
time_until_next_call()
property timer_period_ns