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.
public final class TimeInterpolatableBuffer<T> extends Object
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 Type Method Description void
addSample(double timeSeconds, T sample)
Add a sample to the buffer.void
clear()
Clear all old samples.static <T extends Interpolatable<T>>
TimeInterpolatableBuffer<T>createBuffer(double historySizeSeconds)
Create a new TimeInterpolatableBuffer that stores a given subclass ofInterpolatable
.static <T> TimeInterpolatableBuffer<T>
createBuffer(Interpolator<T> interpolateFunction, double historySizeSeconds)
Create a new TimeInterpolatableBuffer.static TimeInterpolatableBuffer<Double>
createDoubleBuffer(double historySizeSeconds)
Create a new TimeInterpolatableBuffer to store Double values.NavigableMap<Double,T>
getInternalBuffer()
Grant access to the internal sample buffer.Optional<T>
getSample(double timeSeconds)
Sample the buffer at the given time.
-
Method Details
-
createBuffer
public static <T> TimeInterpolatableBuffer<T> createBuffer(Interpolator<T> interpolateFunction, double historySizeSeconds)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.historySizeSeconds
- The history size of the buffer.- Returns:
- The new TimeInterpolatableBuffer.
-
createBuffer
public static <T extends Interpolatable<T>> TimeInterpolatableBuffer<T> createBuffer(double historySizeSeconds)Create a new TimeInterpolatableBuffer that stores a given subclass ofInterpolatable
.- Type Parameters:
T
- The type ofInterpolatable
to store in the buffer.- Parameters:
historySizeSeconds
- The history size of the buffer.- Returns:
- The new TimeInterpolatableBuffer.
-
createDoubleBuffer
Create a new TimeInterpolatableBuffer to store Double values.- Parameters:
historySizeSeconds
- The history size of the buffer.- Returns:
- The new TimeInterpolatableBuffer.
-
addSample
Add a sample to the buffer.- Parameters:
timeSeconds
- The timestamp of the sample.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:
timeSeconds
- The time at which to sample.- 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.
-