Class Filter

java.lang.Object
org.chsrobotics.lib.math.filters.Filter
Direct Known Subclasses:
ComposedFilter, DifferentiatingFilter, ExponentialMovingAverage, IntegratingFilter, MovingAverageFilter, RateLimiter, ThresholdFilter

public abstract class Filter extends Object
Common superclass for this library's filters.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static final Filter
    add(Filter filterA, Filter filterB)
    Returns a filter of a sum of the outputs of two other filters.
    double
    calculate(double value)
    Adds the value to the window and calculates the current output of the filter.
    abstract 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.
    abstract double
    Returns the current output of the filter without updating with a new value.
    abstract void
    Resets the history of the filter.
    static Filter
    scalarMultiply(Filter filter, double scalar)
    Returns a new filter of the outputs of a filter multiplied by a scalar.

    Methods inherited from class java.lang.Object

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

    • Filter

      public Filter()
  • Method Details

    • calculate

      public double calculate(double value)
      Adds the value to the window and calculates the current output of the filter.

      Uses the time elapsed since last calling this method as a parameter. If this method is being called for the first time, uses the time since construction.

      Parameters:
      value - The value to input to the filter.
      Returns:
      The current output of the filter.
    • calculate

      public abstract 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.

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

      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.
    • reset

      public abstract void reset()
      Resets the history of the filter.
    • getCurrentOutput

      public abstract double getCurrentOutput()
      Returns the current output of the filter without updating with a new value.
      Returns:
      The current output of the filter (0 if no values have been given to calculate()).
    • add

      public static final Filter add(Filter filterA, Filter filterB)
      Returns a filter of a sum of the outputs of two other filters.
      Parameters:
      filterA - The first filter to sum.
      filterB - The other filter to sum.
      Returns:
      A new, composed filter.
    • scalarMultiply

      public static Filter scalarMultiply(Filter filter, double scalar)
      Returns a new filter of the outputs of a filter multiplied by a scalar.
      Parameters:
      filter - The filter to multiply.
      scalar - The scalar value to multiply by.
      Returns:
      A new filter.