Class ProfiledPIDController
- All Implemented Interfaces:
TelemetryLoggable, ComplexTunable
-
Constructor Summary
ConstructorsConstructorDescriptionProfiledPIDController(double Kp, double Ki, double Kd, TrapezoidProfile.Constraints constraints) Allocates a ProfiledPIDController with the given constants for Kp, Ki, and Kd.ProfiledPIDController(double Kp, double Ki, double Kd, TrapezoidProfile.Constraints constraints, double period) Allocates a ProfiledPIDController with the given constants for Kp, Ki, and Kd. -
Method Summary
Modifier and TypeMethodDescriptionbooleanatGoal()Returns true if the error is within the tolerance of the error.booleanReturns true if the error is within the tolerance of the error.doublecalculate(double measurement) Returns the next output of the PID controller.doublecalculate(double measurement, double goal) Returns the next output of the PIDController.doublecalculate(double measurement, TrapezoidProfile.State goal) Returns the next output of the PID controller.doublecalculate(double measurement, TrapezoidProfile.State goal, TrapezoidProfile.Constraints constraints) Returns the next output of the PID controller.voidDisables continuous input.voidenableContinuousInput(double minimumInput, double maximumInput) Enables continuous input.doubleReturns the accumulated error used in the integral calculation of this controller.Get the velocity and acceleration constraints for this controller.doublegetD()Gets the differential coefficient.getGoal()Gets the goal for the ProfiledPIDController.doublegetI()Gets the integral coefficient.doublegetIZone()Get the IZone range.doublegetP()Gets the proportional coefficient.doubleGets the period of this controller.doubleReturns the difference between the setpoint and the measurement.doubleReturns the position tolerance of this controller.Returns the current setpoint of the ProfiledPIDController.Gets the telemetry table type.Gets the tunable table type.doubleReturns the change in error per second.doubleReturns the velocity tolerance of this controller.voidlogTo(TelemetryTable table) Logs the object to aTelemetryTable.voidpublishTunable(TunableTable table) Publishes the tunable to the given table.voidreset(double measuredPosition) Reset the previous error and the integral term.voidreset(double measuredPosition, double measuredVelocity) Reset the previous error and the integral term.voidreset(TrapezoidProfile.State measurement) Reset the previous error and the integral term.voidsetConstraints(TrapezoidProfile.Constraints constraints) Set velocity and acceleration constraints for goal.voidsetD(double Kd) Sets the differential coefficient of the PID controller gain.voidsetGoal(double goal) Sets the goal for the ProfiledPIDController.voidSets the goal for the ProfiledPIDController.voidsetI(double Ki) Sets the integral coefficient of the PID controller gain.voidsetIntegratorRange(double minimumIntegral, double maximumIntegral) Sets the minimum and maximum contributions of the integral term.voidsetIZone(double iZone) Sets the IZone range.voidsetP(double Kp) Sets the proportional coefficient of the PID controller gain.voidsetPID(double Kp, double Ki, double Kd) Sets the PID Controller gain parameters.voidsetTolerance(double positionTolerance) Sets the error which is considered tolerable for use with atSetpoint().voidsetTolerance(double positionTolerance, double velocityTolerance) Sets the error which is considered tolerable for use with atSetpoint().Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ComplexTunable
publishChildTunable, publishChildTunable, removeChildTunable, setChildTunableChanged, updateTunable
-
Constructor Details
-
ProfiledPIDController
public ProfiledPIDController(double Kp, double Ki, double Kd, TrapezoidProfile.Constraints constraints) Allocates a ProfiledPIDController with the given constants for Kp, Ki, and Kd.- Parameters:
Kp- The proportional coefficient.Ki- The integral coefficient.Kd- The derivative coefficient.constraints- Velocity and acceleration constraints for goal.- Throws:
IllegalArgumentException- if kp < 0IllegalArgumentException- if ki < 0IllegalArgumentException- if kd < 0
-
ProfiledPIDController
public ProfiledPIDController(double Kp, double Ki, double Kd, TrapezoidProfile.Constraints constraints, double period) Allocates a ProfiledPIDController with the given constants for Kp, Ki, and Kd.- Parameters:
Kp- The proportional coefficient.Ki- The integral coefficient.Kd- The derivative coefficient.constraints- Velocity and acceleration constraints for goal.period- The period between controller updates in seconds. The default is 0.02 seconds.- Throws:
IllegalArgumentException- if kp < 0IllegalArgumentException- if ki < 0IllegalArgumentException- if kd < 0IllegalArgumentException- if period <= 0
-
-
Method Details
-
setPID
public void setPID(double Kp, double Ki, double Kd) Sets the PID Controller gain parameters.Sets the proportional, integral, and differential coefficients.
This setter is intended for online tuning.
- Parameters:
Kp- The proportional coefficient. Must be >= 0.Ki- The integral coefficient. Must be >= 0.Kd- The differential coefficient. Must be >= 0.
-
setP
public void setP(double Kp) Sets the proportional coefficient of the PID controller gain.This setter is intended for online tuning.
- Parameters:
Kp- The proportional coefficient. Must be >= 0.
-
setI
public void setI(double Ki) Sets the integral coefficient of the PID controller gain.This setter is intended for online tuning.
- Parameters:
Ki- The integral coefficient. Must be >= 0.
-
setD
public void setD(double Kd) Sets the differential coefficient of the PID controller gain.This setter is intended for online tuning.
- Parameters:
Kd- The differential coefficient. Must be >= 0.
-
setIZone
public void setIZone(double iZone) Sets the IZone range. When the absolute value of the position error is greater than IZone, the total accumulated error will reset to zero, disabling integral gain until the absolute value of the position error is less than IZone. This is used to prevent integral windup. Must be non-negative. Passing a value of zero will effectively disable integral gain. Passing a value ofDouble.POSITIVE_INFINITYdisables IZone functionality.- Parameters:
iZone- Maximum magnitude of error to allow integral control.- Throws:
IllegalArgumentException- if iZone <= 0
-
getP
public double getP()Gets the proportional coefficient.- Returns:
- proportional coefficient
-
getI
public double getI()Gets the integral coefficient.- Returns:
- integral coefficient
-
getD
public double getD()Gets the differential coefficient.- Returns:
- differential coefficient
-
getIZone
public double getIZone()Get the IZone range.- Returns:
- Maximum magnitude of error to allow integral control.
-
getPeriod
public double getPeriod()Gets the period of this controller.- Returns:
- The period of the controller.
-
getPositionTolerance
public double getPositionTolerance()Returns the position tolerance of this controller.- Returns:
- the position tolerance of the controller.
-
getVelocityTolerance
public double getVelocityTolerance()Returns the velocity tolerance of this controller.- Returns:
- the velocity tolerance of the controller.
-
getAccumulatedError
public double getAccumulatedError()Returns the accumulated error used in the integral calculation of this controller.- Returns:
- The accumulated error of this controller.
-
setGoal
Sets the goal for the ProfiledPIDController.- Parameters:
goal- The desired goal state.
-
setGoal
public void setGoal(double goal) Sets the goal for the ProfiledPIDController.- Parameters:
goal- The desired goal position.
-
getGoal
Gets the goal for the ProfiledPIDController.- Returns:
- The goal.
-
atGoal
public boolean atGoal()Returns true if the error is within the tolerance of the error.This will return false until at least one input value has been computed.
- Returns:
- True if the error is within the tolerance of the error.
-
setConstraints
Set velocity and acceleration constraints for goal.- Parameters:
constraints- Velocity and acceleration constraints for goal.
-
getConstraints
Get the velocity and acceleration constraints for this controller.- Returns:
- Velocity and acceleration constraints.
-
getSetpoint
Returns the current setpoint of the ProfiledPIDController.- Returns:
- The current setpoint.
-
atSetpoint
public boolean atSetpoint()Returns true if the error is within the tolerance of the error.This will return false until at least one input value has been computed.
- Returns:
- True if the error is within the tolerance of the error.
-
enableContinuousInput
public void enableContinuousInput(double minimumInput, double maximumInput) Enables continuous input.Rather then using the max and min input range as constraints, it considers them to be the same point and automatically calculates the shortest route to the setpoint.
- Parameters:
minimumInput- The minimum value expected from the input.maximumInput- The maximum value expected from the input.
-
disableContinuousInput
public void disableContinuousInput()Disables continuous input. -
setIntegratorRange
public void setIntegratorRange(double minimumIntegral, double maximumIntegral) Sets the minimum and maximum contributions of the integral term.The internal integrator is clamped so that the integral term's contribution to the output stays between minimumIntegral and maximumIntegral. This prevents integral windup.
- Parameters:
minimumIntegral- The minimum contribution of the integral term.maximumIntegral- The maximum contribution of the integral term.
-
setTolerance
public void setTolerance(double positionTolerance) Sets the error which is considered tolerable for use with atSetpoint().- Parameters:
positionTolerance- Position error which is tolerable.
-
setTolerance
public void setTolerance(double positionTolerance, double velocityTolerance) Sets the error which is considered tolerable for use with atSetpoint().- Parameters:
positionTolerance- Position error which is tolerable.velocityTolerance- Velocity error which is tolerable.
-
getPositionError
public double getPositionError()Returns the difference between the setpoint and the measurement.- Returns:
- The error.
-
getVelocityError
public double getVelocityError()Returns the change in error per second.- Returns:
- The change in error per second.
-
calculate
public double calculate(double measurement) Returns the next output of the PID controller.- Parameters:
measurement- The current measurement of the process variable.- Returns:
- The controller's next output.
-
calculate
Returns the next output of the PID controller.- Parameters:
measurement- The current measurement of the process variable.goal- The new goal of the controller.- Returns:
- The controller's next output.
-
calculate
public double calculate(double measurement, double goal) Returns the next output of the PIDController.- Parameters:
measurement- The current measurement of the process variable.goal- The new goal of the controller.- Returns:
- The controller's next output.
-
calculate
public double calculate(double measurement, TrapezoidProfile.State goal, TrapezoidProfile.Constraints constraints) Returns the next output of the PID controller.- Parameters:
measurement- The current measurement of the process variable.goal- The new goal of the controller.constraints- Velocity and acceleration constraints for goal.- Returns:
- The controller's next output.
-
reset
Reset the previous error and the integral term.- Parameters:
measurement- The current measured State of the system.
-
reset
public void reset(double measuredPosition, double measuredVelocity) Reset the previous error and the integral term.- Parameters:
measuredPosition- The current measured position of the system.measuredVelocity- The current measured velocity of the system.
-
reset
public void reset(double measuredPosition) Reset the previous error and the integral term.- Parameters:
measuredPosition- The current measured position of the system. The velocity is assumed to be zero.
-
logTo
Description copied from interface:TelemetryLoggableLogs the object to aTelemetryTable.- Specified by:
logToin interfaceTelemetryLoggable- Parameters:
table- telemetry table
-
getTelemetryType
Description copied from interface:TelemetryLoggableGets the telemetry table type. Default is no specified table type (null). A mismatch in type during logging results in a reported warning, so this should always return the same value.- Specified by:
getTelemetryTypein interfaceTelemetryLoggable- Returns:
- Table type
-
publishTunable
Description copied from interface:ComplexTunablePublishes the tunable to the given table.This function may be called when the tunable is initially published or republished during backend migration, and it must not throw. If an exception escapes, registry and backend state is not guaranteed to be restored.
- Specified by:
publishTunablein interfaceComplexTunable- Parameters:
table- table
-
getTunableType
Description copied from interface:ComplexTunableGets the tunable table type. Default is no specified table type (null).- Specified by:
getTunableTypein interfaceComplexTunable- Returns:
- Table type
-