Class PIDController
java.lang.Object
com.stuypulse.stuylib.control.Controller
com.stuypulse.stuylib.control.feedback.PIDController
The PID algorithm is a feedback control algorithm meant for calculating an output based on an
error between a measurement and a setpoint.
PID takes into account the error itself, the rate of change of error, and built-up error over time to create a stable controller.
Because it's a feedback algorithm, it will only react when the system is already behind (there must be error for there to be any output). *However, a feedback contrller can be easily combined with a feedforward model to reduce the delay.*
This PID controller is built by extending the Controller class. It has a dynamic rate, so it can detect how much time has passed between each update. It is made to be easy to use and simple to understand while still being accurate.
-
Constructor Summary
ConstructorDescriptionCreates a blank PIDController that doesn't movePIDController
(Number p, Number i, Number d) -
Method Summary
Modifier and TypeMethodDescriptionprotected double
calculate
(double setpoint, double measurement) Calculates the output of the controller given a setpoint and measurement.double
getD()
double
getI()
double
getP()
void
reset()
Resets the integrator in the PIDController.setDerivativeFilter
(IFilter... derivativeFilter) Add a filter to the error velocity / derivative of the PID controller.setIntegratorFilter
(Number range, Number limit) Add constraints to the integral of the PID ControllersetPID
(PIDController pidValues) Methods inherited from class com.stuypulse.stuylib.control.Controller
add, getError, getMeasurement, getOutput, getSetpoint, isDone, setMeasurementFilter, setOutputFilter, setSetpointFilter, update
-
Constructor Details
-
PIDController
- Parameters:
p
- The Proportional Multiplieri
- The Integral Multiplierd
- The Derivative Multiplier
-
PIDController
public PIDController()Creates a blank PIDController that doesn't move
-
-
Method Details
-
reset
public void reset()Resets the integrator in the PIDController. This automatically gets called if the gap between update() commands is too large -
calculate
protected double calculate(double setpoint, double measurement) Description copied from class:Controller
Calculates the output of the controller given a setpoint and measurement.- Specified by:
calculate
in classController
- Parameters:
setpoint
- setpointmeasurement
- measurement- Returns:
- calculated output
-
getP
public double getP()- Returns:
- the P value being used by the PID controller.
-
getI
public double getI()- Returns:
- the P value being used by the PID controller.
-
getD
public double getD()- Returns:
- the P value being used by the PID controller.
-
setP
- Parameters:
p
- new p value used by the PID controller.- Returns:
- reference to PIDController (so you can chain the commands together)
-
setI
- Parameters:
i
- new i value used by the PID controller.- Returns:
- reference to PIDController (so you can chain the commands together)
-
setD
- Parameters:
d
- new d value used by the PID controller.- Returns:
- reference to PIDController (so you can chain the commands together)
-
setPID
- Parameters:
p
- new p value used by the PID controller.i
- new i value used by the PID controller.d
- new d value used by the PID controller.- Returns:
- reference to PIDController (so you can chain the commands together)
-
setPID
- Parameters:
pidValues
- PIDController that stores the PID values- Returns:
- reference to PIDController (so you can chain the commands together)
-
setIntegratorFilter
Add constraints to the integral of the PID Controller- Parameters:
range
- the range of error in which the integral is allowed to accumulate (0 will disable)limit
- the max / min the integral is allowed to accumulate to (0 will disables)- Returns:
- reference to PIDController (so you can chain the commands together)
-
setDerivativeFilter
Add a filter to the error velocity / derivative of the PID controller.- Parameters:
derivativeFilter
- the filter to apply to derivative- Returns:
- reference to PIDController (so you can chain the commands together)
-