Package edu.wpi.first.math.interpolation
Class TimeInterpolatableBuffer<T>
java.lang.Object
edu.wpi.first.math.interpolation.TimeInterpolatableBuffer<T>
- Type Parameters:
T
- The type stored in this buffer.
The TimeInterpolatableBuffer provides an easy way to estimate past measurements. One application
might be in conjunction with the DifferentialDrivePoseEstimator, where knowledge of the robot
pose at the time when vision or other global measurement were recorded is necessary, or for
recording the past angles of mechanisms as measured by encoders.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a sample to the buffer.void
clear()
Clear all old samples.static <T extends Interpolatable<T>>
TimeInterpolatableBuffer<T>createBuffer
(double historySize) Create a new TimeInterpolatableBuffer that stores a given subclass ofInterpolatable
.static <T> TimeInterpolatableBuffer<T>
createBuffer
(Interpolator<T> interpolateFunction, double historySize) Create a new TimeInterpolatableBuffer.static TimeInterpolatableBuffer<Double>
createDoubleBuffer
(double historySize) Create a new TimeInterpolatableBuffer to store Double values.Grant access to the internal sample buffer.getSample
(double time) Sample the buffer at the given time.
-
Method Details
-
createBuffer
public static <T> TimeInterpolatableBuffer<T> createBuffer(Interpolator<T> interpolateFunction, double historySize) Create a new TimeInterpolatableBuffer.- Type Parameters:
T
- The type of data to store in the buffer.- Parameters:
interpolateFunction
- The function used to interpolate between values.historySize
- The history size of the buffer in seconds.- Returns:
- The new TimeInterpolatableBuffer.
-
createBuffer
public static <T extends Interpolatable<T>> TimeInterpolatableBuffer<T> createBuffer(double historySize) Create a new TimeInterpolatableBuffer that stores a given subclass ofInterpolatable
.- Type Parameters:
T
- The type ofInterpolatable
to store in the buffer.- Parameters:
historySize
- The history size of the buffer in seconds.- Returns:
- The new TimeInterpolatableBuffer.
-
createDoubleBuffer
Create a new TimeInterpolatableBuffer to store Double values.- Parameters:
historySize
- The history size of the buffer in seconds.- Returns:
- The new TimeInterpolatableBuffer.
-
addSample
Add a sample to the buffer.- Parameters:
time
- The timestamp of the sample in seconds.sample
- The sample object.
-
clear
Clear all old samples. -
getSample
Sample the buffer at the given time. If the buffer is empty, an empty Optional is returned.- Parameters:
time
- The time at which to sample in seconds.- Returns:
- The interpolated value at that timestamp or an empty Optional.
-
getInternalBuffer
Grant access to the internal sample buffer. Used in Pose Estimation to replay odometry inputs stored within this buffer.- Returns:
- The internal sample buffer.
-