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

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

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

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

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