![]() |
ros2_control - rolling
|
#include <statistics_types.hpp>
Public Types | |
| using | StatisticData = ros2_control::StatisticData |
Public Member Functions | |
| TimeWindowStatistics ()=default | |
| Construct a disabled collector. | |
| TimeWindowStatistics (double window_duration) | |
| void | set_window_duration (double window_duration) |
| double | get_window_duration () const |
| bool | is_enabled () const |
| void | reset () |
| Clear the window, keeping its duration. | |
| void | add_measurement (const double item, const double time_seconds) |
| StatisticData | get_statistics () const |
Static Public Attributes | |
| static constexpr std::size_t | NUM_BUCKETS = 10 |
| Number of time buckets the window is split into. | |
Statistics (average, minimum, maximum, standard deviation (population) and sample count) over the samples observed within the most recent window_duration seconds. Unlike MovingAverageStatistics, an old outlier leaves the statistics once the window has moved past it, so they describe the recent behaviour rather than the whole history.
The window is split into NUM_BUCKETS time buckets, each holding the running statistics of its samples, so the memory is constant and independent of the sample rate, and add_measurement() is O(1) and never allocates. The price is the resolution of the window's trailing edge: it advances one bucket at a time, so the statistics cover between (NUM_BUCKETS - 1) / NUM_BUCKETS of the duration and the full duration.
The time of a sample is given by the caller, so the window follows whichever clock drives the measurements (e.g. simulation time). If the time goes back past the current bucket (e.g. a reset simulation), the window is restarted.
The window ends at the latest sample, not at the current time: if the samples stop arriving (e.g. a stalled asynchronous component), get_statistics() keeps returning the last window until a new sample comes in, like the since-startup statistics do.
A non-positive (or non-finite) duration disables the collector: add_measurement() is a no-op. When statistics are not available, e.g. no observations have been made, NaNs are returned.
|
inlineexplicit |
| window_duration | Duration of the window in seconds. Non-positive disables the collector. |
|
inline |
Observe a sample. Samples older than the window are dropped. Note: samples whose value or time is NaN or infinity are discarded, as well as samples whose time divided by the bucket width (window_duration / NUM_BUCKETS) exceeds 1e18 in magnitude.
| item | The item that was observed |
| time_seconds | The time at which the item was observed, in seconds |
|
inline |
Return a StatisticData object, containing average, minimum, maximum, standard deviation (population) and sample count over the current window. For an empty window, the average, min, max and standard deviation are NaN.
|
inline |
|
inline |
|
inline |
Set the duration of the window and clear it.
| window_duration | Duration of the window in seconds. Non-positive disables the collector. |