Class TimeInterpolatableBuffer<T>

  • Type Parameters:
    T - The type stored in this buffer.

    public 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 Detail

      • createBuffer

        public static <T> TimeInterpolatableBuffer<T> createBuffer​(TimeInterpolatableBuffer.InterpolateFunction<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<DoublecreateDoubleBuffer​(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 T getSample​(double timeSeconds)
        Sample the buffer at the given time. If the buffer is empty, this will return null.
        Parameters:
        timeSeconds - The time at which to sample.
        Returns:
        The interpolated value at that timestamp. Might be null.