Class ComposedFeedbackController

java.lang.Object
org.chsrobotics.lib.controllers.ComposedFeedbackController
All Implemented Interfaces:
FeedbackController

public class ComposedFeedbackController extends Object implements FeedbackController
A controller made of a sum of filters, each multiplied by a constant gain. Instead of the input value, the error between the setpoint and input is what is given to the filters.

For example, this can easily be turned into a simple PID controller by constructing as follows:

new ComposedController(Map.of(new NullFilter(), kP, new IntegratingFilter(window), kI, new DifferentiatingFilter(), kD))

  • Constructor Details

    • ComposedFeedbackController

      public ComposedFeedbackController(List<Filter> filters)
      Constructs a ComposedController.
      Parameters:
      filters - A list of filters to combine into the controller.
    • ComposedFeedbackController

      public ComposedFeedbackController(Map<Filter,Double> values)
      Constructs a ComposedController.
      Parameters:
      values - A map of filters to their gains.
  • Method Details

    • reset

      public void reset()
      Description copied from interface: FeedbackController
      Resets the controller.
      Specified by:
      reset in interface FeedbackController
    • setSetpoint

      public void setSetpoint(double value)
      Description copied from interface: FeedbackController
      Sets the setpoint (target) of the controller.
      Specified by:
      setSetpoint in interface FeedbackController
      Parameters:
      value - The new target of the controller.
    • getSetpoint

      public double getSetpoint()
      Description copied from interface: FeedbackController
      Returns the current setpoint (target) of the controller.
      Specified by:
      getSetpoint in interface FeedbackController
      Returns:
      The current setpoint.
    • calculate

      public double calculate(double measurement)
      Description copied from interface: FeedbackController
      Returns an output from the controller with the default robot loop time.

      This must be called at a rate of once every robot loop to be consistent.

      Specified by:
      calculate in interface FeedbackController
      Parameters:
      measurement - The value of the measured feedback.
      Returns:
      The output of the controller.
    • calculate

      public double calculate(double measurement, double dtSeconds)
      Description copied from interface: FeedbackController
      Returns an output from the controller with a given dt.
      Specified by:
      calculate in interface FeedbackController
      Parameters:
      measurement - The value of the measured feedback.
      dtSeconds - The time, in seconds, since the last update of this controller.
      Returns:
      The output of the controller.
    • getCurrentValue

      public double getCurrentValue()
      Description copied from interface: FeedbackController
      Returns the last output of the controller without updating with a new value.
      Specified by:
      getCurrentValue in interface FeedbackController
      Returns:
      The last ouptut of the controller.
    • setSetpointTolerance

      public void setSetpointTolerance(double positionErrorProportion, double velocityErrorProportion)
      Description copied from interface: FeedbackController
      Sets the maximum error of both position and velocity allowed for atSetpoint() to return true.
      Specified by:
      setSetpointTolerance in interface FeedbackController
      Parameters:
      positionErrorProportion - The maximum allowed position error, as a proportion of the setpoint.
      velocityErrorProportion - The maximum allowed absolute velocity per second, as a proportion of the setpoint / second.
    • atSetpoint

      public boolean atSetpoint()
      Description copied from interface: FeedbackController
      Returns whether the controller has reached the setpoint with minimal velocity.
      Specified by:
      atSetpoint in interface FeedbackController
      Returns:
      Whether the controller is within the minimum position and velocity errors.