public class PIDController
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private boolean |
m_continuous |
private double |
m_D |
private boolean |
m_enabled |
private double |
m_error |
private double |
m_I |
private double |
m_input |
private double |
m_maximumInput |
private double |
m_maximumOutput |
private double |
m_minimumInput |
private double |
m_minimumOutput |
private double |
m_P |
private double |
m_prevError |
private double |
m_result |
private double |
m_setpoint |
private double |
m_tolerance |
private double |
m_totalError |
Constructor and Description |
---|
PIDController(double Kp,
double Ki,
double Kd)
Allocate a PID object with the given constants for P, I, D
|
Modifier and Type | Method and Description |
---|---|
private void |
calculate()
Read the input, calculate the output accordingly, and write to the output.
|
void |
disable()
Stop running the PIDController.
|
void |
enable()
Begin running the PIDController
|
double |
getD()
Get the Differential coefficient
|
double |
getError()
Retruns the current difference of the input from the setpoint
|
double |
getI()
Get the Integral coefficient
|
double |
getP()
Get the Proportional coefficient
|
double |
getSetpoint()
Returns the current setpoint of the PIDController
|
boolean |
onTarget()
Return true if the error is within the percentage of the total input range,
determined by setTolerance.
|
double |
performPID()
Return the current PID result for the last input set with setInput().
|
double |
performPID(double input)
Return the current PID result for the specified input.
|
void |
reset()
Reset the previous error,, the integral term, and disable the controller.
|
void |
setContinuous()
Set the PID controller to consider the input to be continuous,
Rather then using the max and min in as constraints, it considers them to
be the same point and automatically calculates the shortest route to
the setpoint.
|
void |
setContinuous(boolean continuous)
Set the PID controller to consider the input to be continuous,
Rather then using the max and min in as constraints, it considers them to
be the same point and automatically calculates the shortest route to
the setpoint.
|
void |
setInput(double input)
Set the input value to be used by the next call to performPID().
|
void |
setInputRange(double minimumInput,
double maximumInput)
Sets the maximum and minimum values expected from the input.
|
void |
setOutputRange(double minimumOutput,
double maximumOutput)
Sets the minimum and maximum values to write.
|
void |
setPID(double p,
double i,
double d)
Set the PID Controller gain parameters.
|
void |
setSetpoint(double setpoint)
Set the setpoint for the PIDController
|
void |
setTolerance(double percent)
Set the percentage error which is considered tolerable for use with
OnTarget.
|
private double m_P
private double m_I
private double m_D
private double m_input
private double m_maximumOutput
private double m_minimumOutput
private double m_maximumInput
private double m_minimumInput
private boolean m_continuous
private boolean m_enabled
private double m_prevError
private double m_totalError
private double m_tolerance
private double m_setpoint
private double m_error
private double m_result
public PIDController(double Kp, double Ki, double Kd)
Kp
- the proportional coefficientKi
- the integral coefficientKd
- the derivative coefficientprivate void calculate()
public void setPID(double p, double i, double d)
p
- Proportional coefficienti
- Integral coefficientd
- Differential coefficientpublic double getP()
public double getI()
public double getD()
public double performPID()
public double performPID(double input)
input
- The input value to be used to calculate the PID result.
This is always centered on zero and constrained the the max and min outspublic void setContinuous(boolean continuous)
continuous
- Set to true turns on continuous, false turns off continuouspublic void setContinuous()
public void setInputRange(double minimumInput, double maximumInput)
minimumInput
- the minimum value expected from the input, always positivemaximumInput
- the maximum value expected from the output, always positivepublic void setOutputRange(double minimumOutput, double maximumOutput)
minimumOutput
- the minimum value to write to the output, always positivemaximumOutput
- the maximum value to write to the output, always positivepublic void setSetpoint(double setpoint)
setpoint
- the desired setpointpublic double getSetpoint()
public double getError()
public void setTolerance(double percent)
percent
- error which is tolerablepublic boolean onTarget()
public void enable()
public void disable()
public void reset()
public void setInput(double input)
input
- Input value to the PID calculation.