Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
tap::algorithms::LinearInterpolationPredictor Class Reference

#include <linear_interpolation_predictor.hpp>

Public Member Functions

 LinearInterpolationPredictor ()
 
void update (float newValue, uint32_t currTime)
 
float getInterpolatedValue (uint32_t currTime)
 
void reset (float initialValue, uint32_t initialTime)
 

Detailed Description

A class that allows you to linearly interpolate discrete measurements. Useful for increasing the resolution of data measurements. For example, if you receive input data at 10 ms intervals and are running a controller ever 1 ms, you can use this class so that the data you receive won't be in 10 ms steps, but rather will interpolate using past data to predict the data until new data is received.

Usecase example, pseudocode:

while (true) {
if (new value received) {
li.update(value);
}
runcontroller(li.getInterpolated(tap::arch::clock::getTimeMilliseconds()));
}
Definition linear_interpolation_predictor.hpp:52
void update(float newValue, uint32_t currTime)
Definition linear_interpolation_predictor.cpp:35
uint32_t getTimeMilliseconds()
Definition clock.hpp:61

Constructor & Destructor Documentation

◆ LinearInterpolationPredictor()

tap::algorithms::LinearInterpolationPredictor::LinearInterpolationPredictor ( )

Member Function Documentation

◆ getInterpolatedValue()

float tap::algorithms::LinearInterpolationPredictor::getInterpolatedValue ( uint32_t  currTime)
inline

Returns the current value, that is: $y$ in the equation $y=slope\cdot (currTime - lastUpdateCallTime) + previousValue$ in the units of whatever value you are inputting in the update function.

Note
Slope is defined by the previous two values passed into the update function, a period preceeding lastUpdateCallTime.
use a millisecond-resolution timer, e.g. tap::arch::clock::getTimeMilliseconds()
Parameters
[in]currTimethe current clock time, in ms.
Returns
the interpolated value.

◆ reset()

void tap::algorithms::LinearInterpolationPredictor::reset ( float  initialValue,
uint32_t  initialTime 
)

Resets the predictor. The slope will be reset to 0 and the initial values and time will be used to initialize the predictor.

Note
It is highly recommended that you call this function before calling update to "initialize" the system.
Parameters
[in]initialValueThe value to set the previous value to when resetting.
[in]initialTimeThe value to set the previous time to when resetting.

◆ update()

void tap::algorithms::LinearInterpolationPredictor::update ( float  newValue,
uint32_t  currTime 
)

Updates the interpolation using the newValue.

Note
only call this when you receive a new value (use remote rx counter to tell when there is new data from the remote, for example).
This function should be called with increasing values of currTime.
Parameters
[in]newValuethe new data used in the interpolation.
[in]currTimeThe time that this function was called.

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