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 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 of Interpolatable.
      Type Parameters:
      T - The type of Interpolatable to store in the buffer.
      Parameters:
      historySizeSeconds - The history size of the buffer.
      Returns:
      The new TimeInterpolatableBuffer.
    • createDoubleBuffer

      public static TimeInterpolatableBuffer<Double> createDoubleBuffer​(double historySizeSeconds)
      Create a new TimeInterpolatableBuffer to store Double values.
      Parameters:
      historySizeSeconds - The history size of the buffer.
      Returns:
      The new TimeInterpolatableBuffer.
    • addSample

      public void addSample​(double timeSeconds, T sample)
      Add a sample to the buffer.
      Parameters:
      timeSeconds - The timestamp of the sample.
      sample - The sample object.
    • clear

      public void clear()
      Clear all old samples.
    • getSample

      public Optional<T> getSample​(double timeSeconds)
      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.