Class Controller

java.lang.Object
com.stuypulse.stuylib.control.Controller
Direct Known Subclasses:
ArmFeedforward, ControllerGroup, ElevatorFeedforward, PIDController, PositionFeedforwardController, VelocityFeedforwardController

public abstract class Controller extends Object
A controller calculates an output variable given a setpoint and measurement of a single variable.

This base class can be used to represent single-input single-output control (SISO) algorithms (commonly PID and feedforward).

For any controller, digital filters can be applied to the incoming setpoints and measurements, or the outgoing outputs. This allows for the easy application of filters often involved with control theory, like motion profile filters for setpoints and low-pass filters for noisy measurements. *These filters are already provided in the StuyLib filters library.*

Different control schemes that share the same setpoint and measurement can also be concisely composed together if they all implement this class.

  • Constructor Details

    • Controller

      public Controller()
      Default initialization of a controller
  • Method Details

    • setSetpointFilter

      public final Controller setSetpointFilter(IFilter... setpointFilter)
      Set the setpoint filter of the controller
      Parameters:
      setpointFilter - setpoint filters
      Returns:
      reference to the controller
    • setMeasurementFilter

      public final Controller setMeasurementFilter(IFilter... measurementFilter)
      Set the measurement filter of the controller
      Parameters:
      measurementFilter - measurement filters
      Returns:
      reference to the controller
    • setOutputFilter

      public final Controller setOutputFilter(IFilter... outputFilter)
      Set the output filter of the controller
      Parameters:
      outputFilter - output filters
      Returns:
      reference to the controller
    • getSetpoint

      public final double getSetpoint()
      Returns:
      the most recent setpoint of the controller
    • getMeasurement

      public final double getMeasurement()
      Returns:
      the most recent measurement of the controller
    • getOutput

      public final double getOutput()
      Returns:
      the most recent output of the controller
    • getError

      public final double getError()
      Returns:
      the most recent error of the controller
    • isDone

      public final boolean isDone(double acceptableError)
      Determines if the controller is finished based on an acceptable error.
      Parameters:
      acceptableError - acceptable error for the controller
      Returns:
      whether or not the controller is done
    • add

      public final ControllerGroup add(Controller... other)
      Combines this controller into a group with other controllers that share the same setpoint and measurement.
      Parameters:
      other - the other controllers
      Returns:
      the group of controllers that
    • update

      public final double update(double setpoint, double measurement)
      Updates the state of the controller.

      Applies filters to setpoint and measurement, calculates output with filtered values, filters and returns output

      Parameters:
      setpoint - setpoint of the variable being controlled
      measurement - measurement of the variable being controlled
      Returns:
      the final output
    • calculate

      protected abstract double calculate(double setpoint, double measurement)
      Calculates the output of the controller given a setpoint and measurement.
      Parameters:
      setpoint - setpoint
      measurement - measurement
      Returns:
      calculated output