Template Class ThrottledCallback

Class Documentation

template<class Callback>
class ThrottledCallback

A throttled callback that encapsulates the logic to throttle a callback so it is only called after a given period in seconds (or more). The dropped calls can optionally be received in a dropped callback, that could be used to count the number of calls dropped.

Template Parameters:

Callback – The std::function callback

Public Functions

inline ThrottledCallback(Callback &&keep_callback = nullptr, Callback &&drop_callback = nullptr, const rclcpp::Duration &throttle_period = rclcpp::Duration(0, 0), rclcpp::Clock::SharedPtr clock = std::make_shared<rclcpp::Clock>())

Constructor.

Parameters:
  • keep_callback[in] The callback to call when kept, i.e. not dropped. Defaults to nullptr

  • drop_callback[in] The callback to call when dropped because of the throttling. Defaults to nullptr

  • throttle_period[in] The throttling period duration in seconds. Defaults to 0.0, i.e. no throttling

  • clock[in] The clock to throttle against. Defaults to using RCL_SYSTEM_TIME

inline const rclcpp::Duration &getThrottlePeriod() const

Throttle period getter.

Returns:

The current throttle period duration in seconds being used

inline void setClock(rclcpp::Clock::SharedPtr clock)

Set the clock to throttle against.

Parameters:

clock[in] The clock to set

inline void setThrottlePeriod(const rclcpp::Duration &throttle_period)

Throttle period setter.

Parameters:

throttle_period[in] The new throttle period duration in seconds to use

inline void setKeepCallback(const Callback &keep_callback)

Keep callback setter.

Parameters:

keep_callback[in] The new keep callback to use

inline void setDropCallback(const Callback &drop_callback)

Drop callback setter.

Parameters:

drop_callback[in] The new drop callback to use

inline const rclcpp::Time &getLastCalledTime() const

Last called time.

Returns:

The last time the keep callback was called

template<class ...Args>
inline void callback(Args&&... args)

Callback that throttles the calls to the keep callback provided. When dropped because of throttling, the drop callback is called instead.

Parameters:

args[in] The input arguments

template<class ...Args>
inline void operator()(Args&&... args)

Operator() that simply calls the callback() method forwarding the input arguments.

Parameters:

args[in] The input arguments