Module: interpolator
-
template<typename T, size_t nArgs = 1>
class Interpolator : public SysModel - #include <interpolator.h>
A class that interpolates from a given table of points and outputs the result as a message payload.
The table is given in
setDataPoints
as a matrix, where the first column represents the simulation time (the independent variable), and the rest of columns are the data to be interpolated.The result of the interpolation will be a vector of floats. This vector is then taken by the virtual method
setPayloadValues
to fill in the payload as needed.Interpolation through splines of configurable degrees. Zero degrees is piece-wise constant between data points, one degree is linear interpolation, two degrees is quadratic interpolation, three degrees is cubic interpolation… Note that cubic interpolation guarantees continous first and second derivatives, which might be useful for certain applications.
Public Functions
-
inline void setDataPoints(const Eigen::MatrixXd &points, uint16_t degrees = 1)
Set the points to use for interpolation. The first column corresponds to the independent value, the simulation time in nanoseconds, while the rest of columns are the data to use for interpolation.
- Parameters:
points – A matrix containing data points where the first column represents the independent values and subsequent columns represent the values to interpolate.
degrees – The degree of the spline to fit (default is 1).
-
inline void Reset(uint64_t CurrentSimNanos)
Calls
UpdateState
with the given time- Parameters:
CurrentSimNanos – The current simulation time in nanoseconds used to update the state of the interpolator and generate the output message.
-
inline void UpdateState(uint64_t CurrentSimNanos)
Updates the state of the interpolator based on the current simulation time.
It then prepares a message payload and sets its values using the current simulation time and the interpolated result from the spline function.
- Parameters:
CurrentSimNanos – The current simulation time in nanoseconds used to update the state of the interpolator and generate the output message.
- Throws:
std::invalid_argument – if the interpolator has not been initialized properly (i.e., if
xMin
andxMax
are both zero).
Public Members
-
BSKLogger bskLogger
Logger used to log errors
Protected Functions
-
virtual void setPayloadValues(T &payload, uint64_t CurrentSimNanos, const Eigen::Array<double, nArgs, 1> &interp) = 0
Called by
UpdateState
with the simulation time and the interpolated values.This method should modify the given paylod object and fill it with the desired values given the function inputs.
-
inline double scale(double val)
Scales a single value to the range [0, 1] based on the object’s xMin and xMax.
This method normalizes the input value
val
by subtractingxMin
and dividing by the range (xMax - xMin
). The result is clamped to ensure it remains within the range [0, 1].- Parameters:
val – The value to scale.
- Returns:
The scaled value in the range [0, 1].
-
inline Eigen::VectorXd scale(Eigen::VectorXd val)
Scales a vector of values to the range [0, 1] based on the object’s xMin and xMax.
This method normalizes each element in the input vector
val
by subtractingxMin
and dividing by the range (xMax - xMin
), returning a new vector with the scaled values.- Parameters:
val – The vector of values to scale.
- Returns:
An Eigen::VectorXd containing the scaled values.
-
inline void setDataPointsImpl(const Eigen::MatrixXd &points, uint16_t degrees = 1)
Sets the data points for spline fitting based on the given matrix of points.
- Parameters:
points – A matrix containing data points where the first column represents the independent values and subsequent columns represent the values to interpolate.
degrees – The degree of the spline to fit (default is 1).
- Throws:
std::invalid_argument – if the first column of points contains only one unique value.
-
inline void setDataPoints(const Eigen::MatrixXd &points, uint16_t degrees = 1)