Class Controller
- Direct Known Subclasses:
ArmFeedforward,ControllerGroup,ElevatorFeedforward,PIDController,PositionFeedforwardController,VelocityFeedforwardController
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal ControllerGroupadd(Controller... other) Combines this controller into a group with other controllers that share the same setpoint and measurement.protected abstract doublecalculate(double setpoint, double measurement) Calculates the output of the controller given a setpoint and measurement.final doublegetError()final doublefinal doublefinal doublefinal booleanisDone(double acceptableError) Determines if the controller is finished based on an acceptable error.final ControllersetMeasurementFilter(IFilter... measurementFilter) Set the measurement filter of the controllerfinal ControllersetOutputFilter(IFilter... outputFilter) Set the output filter of the controllerfinal ControllersetSetpointFilter(IFilter... setpointFilter) Set the setpoint filter of the controllerfinal doubleupdate(double setpoint, double measurement) Updates the state of the controller.
-
Constructor Details
-
Controller
public Controller()Default initialization of a controller
-
-
Method Details
-
setSetpointFilter
Set the setpoint filter of the controller- Parameters:
setpointFilter- setpoint filters- Returns:
- reference to the controller
-
setMeasurementFilter
Set the measurement filter of the controller- Parameters:
measurementFilter- measurement filters- Returns:
- reference to the controller
-
setOutputFilter
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
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 controlledmeasurement- 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- setpointmeasurement- measurement- Returns:
- calculated output
-