Class DifferentiatingFilter

java.lang.Object
org.chsrobotics.lib.math.filters.Filter
org.chsrobotics.lib.math.filters.DifferentiatingFilter

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

Approximated with finite timesteps.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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 dtSeconds)
    Adds the value to the window and calculates the current output of the filter, with a change in time since the last call of this.
    double
    Returns the current output of the filter without updating with a new value.
    void
    Resets the history of the filter.

    Methods inherited from class org.chsrobotics.lib.math.filters.Filter

    add, scalarMultiply

    Methods inherited from class java.lang.Object

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

    • DifferentiatingFilter

      public DifferentiatingFilter()
  • Method Details

    • calculate

      public double calculate(double value, double dtSeconds)
      Description copied from class: Filter
      Adds the value to the window and calculates the current output of the filter, with a change in time since the last call of this.

      Some filters do not use time in their calculations, and this method is identical to calculate() for them.

      Specified by:
      calculate in class Filter
      Parameters:
      value - the value to input to the filter.
      dtSeconds - The change in time since the last call of the filter.
      Returns:
      The current output of the filter.
    • 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 class 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 class Filter
    • getCurrentOutput

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