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

Decides which messages of a stream to pass so that the output rate does not exceed a cap. More...

#include <rate_throttle.hpp>

Public Member Functions

 RateThrottle (const double rate)
 RateThrottle (const std::chrono::nanoseconds period)
bool accept (const rclcpp::Time &now)
 decide whether a message arriving at now should be passed (and register it if so)

Detailed Description

Decides which messages of a stream to pass so that the output rate does not exceed a cap.

Deadline (GCRA-like) scheduling: the next allowed time advances by one period per passed message, so a faster, jittery input is decimated to the cap on average instead of undershooting it. A message up to period/4 early is passed, a late message keeps at most period/2 of catch-up credit, so there are no bursts after a pause (passed messages are at least period/4 apart). An input slower than the cap is passed as is. Not thread-safe.

Constructor & Destructor Documentation

◆ RateThrottle() [1/2]

mrs_lib::internal::RateThrottle::RateThrottle ( const double rate)
inlineexplicit
Parameters
ratemaximum output rate [Hz], <= 0 disables throttling

◆ RateThrottle() [2/2]

mrs_lib::internal::RateThrottle::RateThrottle ( const std::chrono::nanoseconds period)
inlineexplicit
Parameters
periodminimum output period, <= 0 disables throttling

Member Function Documentation

◆ accept()

bool mrs_lib::internal::RateThrottle::accept ( const rclcpp::Time & now)
inline

decide whether a message arriving at now should be passed (and register it if so)

Parameters
nowcurrent time, all calls have to use the same clock type
Returns
true if the message should be passed
Exceptions
std::runtime_errorif now has a different clock type than the previous calls

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