Package xbot.common.math
Class PID
java.lang.Object
xbot.common.math.PID
This PID was extracted from WPILib. It has all the same functionality, but
does not run on its own separate thread.
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondouble
calculate
(double goal, double current, double p, double i, double d) Calculates the output value given P,I,D, a process variable and a goaldouble
calculate
(double goal, double current, double p, double i, double d, double f) Calculates the output value given P,I,D, a process variable and a goaldouble
calculate
(double goal, double current, double p, double i, double d, double f, double iZone) Calculates the output value given P,I,D, a process variable and a goalReturns an enum explaining the reason the PID is not on target.boolean
void
reset()
Resets the PID controller.void
setShouldCheckTolerances
(boolean checkError, boolean checkDerivative, boolean checkTime) Controls whether or not the tolerances are checked as part of isOnTarget().void
setTolerances
(double errorTolerance, double derivativeTolerance, double timeToleranceInSeconds) Set tolerances for the PID system.
-
Constructor Details
-
PID
public PID()
-
-
Method Details
-
reset
public void reset()Resets the PID controller. -
setTolerances
public void setTolerances(double errorTolerance, double derivativeTolerance, double timeToleranceInSeconds) Set tolerances for the PID system.- Parameters:
errorTolerance
- How close the error can be before it is considered "on-target." Negative values will cause that constraint to skipped when checking isOnTarget(). This is in the same units as your current and goal values.derivativeTolerance
- Set how small the derivative of the error can be before it is considered "on-target." This is roughly in the same units as your current and goal values, but per 1/20th of a second. e.g. if you wanted a minimum rotation speed of 5 degrees per second, this tolerance would need to be 0.25.
-
setShouldCheckTolerances
public void setShouldCheckTolerances(boolean checkError, boolean checkDerivative, boolean checkTime) Controls whether or not the tolerances are checked as part of isOnTarget(). -
calculate
public double calculate(double goal, double current, double p, double i, double d, double f, double iZone) Calculates the output value given P,I,D, a process variable and a goal- Parameters:
goal
- What value you are trying to achievecurrent
- What the value under observation currently isp
- Proportionate responsei
- Integral response.d
- Derivative response.f
- Feed-forward response- Returns:
- The output value to achieve goal
-
calculate
public double calculate(double goal, double current, double p, double i, double d, double f) Calculates the output value given P,I,D, a process variable and a goal- Parameters:
goal
- What value you are trying to achievecurrent
- What the value under observation currently isp
- Proportionate responsei
- Integral response.d
- Derivative response.f
- Feed-forward response.- Returns:
- The output value to achieve goal
-
calculate
public double calculate(double goal, double current, double p, double i, double d) Calculates the output value given P,I,D, a process variable and a goal- Parameters:
goal
- What value you are trying to achievecurrent
- What the value under observation currently isp
- Proportionate responsei
- Integral response.d
- Derivative response.- Returns:
- The output value to achieve goal
-
isOnTarget
public boolean isOnTarget() -
getOffTargetReason
Returns an enum explaining the reason the PID is not on target. It has the following priority list if there are multiple reasons (higher ones overrule lower ones): - Too much error - Too much derivative - Waiting for time stability - On Target- Returns:
- The reason the PID is not on target.
-