Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
|
Represents data measured using a sensor at a given time. More...
#include <data.h>
Public Member Functions | |
DataPoint () | |
Construct an invalid DataPoint, holding no data. | |
DataPoint (T data) | |
Construct a new DataPoint object, measured now. | |
DataPoint (datatime_t time, T data) | |
Construct a new DataPoint object, measured at the given time. | |
operator bool () const | |
Check if this measurement is valid. | |
bool | isFresh (std::chrono::milliseconds duration) const |
Check if this measurement was taken recently. | |
bool | isValid () const |
Check if this measurement is valid. | |
datatime_t | getTime () const |
Get the time at which the measurement was taken. | |
T | getData () const |
Get the value of this data point. | |
T | getDataOrElse (T defaultData) |
Get the value of this data point, defaulting to a given value if this data point is invalid. | |
template<typename F> | |
DataPoint< std::invoke_result_t< F, T > > | transform (const F &f) |
Transforms the data in this datapoint by the given function. | |
Represents data measured using a sensor at a given time.
T | The type of data measured from the sensor. |
|
inline |
Construct a new DataPoint object, measured now.
data | The piece of data |
|
inline |
Construct a new DataPoint object, measured at the given time.
time | The time at which the data was measured. |
data | The piece of data. |
|
inline |
Get the value of this data point.
bad_datapoint_access | If this data point is not valid. |
|
inline |
Get the value of this data point, defaulting to a given value if this data point is invalid.
defaultData | The value to return if this data point is not valid. |
defaultData
.
|
inline |
Get the time at which the measurement was taken.
UB if data point is not valid.
|
inline |
Check if this measurement was taken recently.
duration | The data is fresh if it was taken at most this many milliseconds ago. |
duration
milliseconds ago, false otherwise.
|
inline |
Check if this measurement is valid.
|
inline |
Check if this measurement is valid.
Equivalent to isValid().
|
inline |
Transforms the data in this datapoint by the given function.
F | A callable type that accepts T and outputs some other type. |
f | The function that transforms data. |
f(getData())
and has the same timestamp as this datapoint if it's valid, otherwise an empty datapoint.