Class DifferentiatingFilter

  • All Implemented Interfaces:
    Filter

    public class DifferentiatingFilter
    extends java.lang.Object
    implements Filter
    A filter that returns the rate of change (derivative) of a stream of data.

    Approximated with finite timesteps.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double calculate​(double value)
      Calculates the rate of change (derivative) of a value relative to the filter's previous input, using the default loop time of the robot.
      double calculate​(double value, double dt)
      Calculates the rate of change (derivative) of a value relative to the filter's previous input, using a given change in time.
      double getCurrentOutput()
      Returns the current output of the filter without updating with a new value.
      void reset()
      Resets the history of the filter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DifferentiatingFilter

        public DifferentiatingFilter()
    • Method Detail

      • calculate

        public double calculate​(double value,
                                double dt)
        Calculates the rate of change (derivative) of a value relative to the filter's previous input, using a given change in time.

        The initial previous value is 0.

        Returns 0 if dt is equal to 0 (although negative values of dt won't be meaningful either).

        Parameters:
        value - The double value to input to the filter.
        dt - The elapsed time (in seconds) since the last call of either calculate method.
        Returns:
        The rate of change, in units/second, between the current value and the previous value.
      • calculate

        public double calculate​(double value)
        Calculates the rate of change (derivative) of a value relative to the filter's previous input, using the default loop time of the robot.

        The initial previous value is 0.

        Specified by:
        calculate in interface Filter
        Parameters:
        value - The double value to input to the filter.
        Returns:
        The rate of change, in units/second, between the current value and the previous value.
      • reset

        public void reset()
        Resets the history of the filter.
        Specified by:
        reset in interface Filter
      • getCurrentOutput

        public double getCurrentOutput()
        Returns the current output of the filter without updating with a new value.
        Specified by:
        getCurrentOutput in interface Filter
        Returns:
        The current output of the filter (0 if no values have been given to calculate()).