Class MovingAverageFilter

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

public class MovingAverageFilter extends Filter
Filter which computes the arithmetic mean of a stream of data.
  • Constructor Details

    • MovingAverageFilter

      public MovingAverageFilter(int window, MovingAverageFilter.MEAN_IMPLEMENTATION impl)
      Constructs a MovingAverageFilter.
      Parameters:
      window - Number of values to look back when calculating the average. If zero or negative, will be an indefinite window.
      impl - Implementation of the mean to use.
  • 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.
    • reset

      public void reset()
      Description copied from class: Filter
      Resets the history of the filter.
      Specified by:
      reset in class Filter
    • getCurrentOutput

      public double getCurrentOutput()
      Description copied from class: Filter
      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()).