public class PIDController
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private double |
m_deltaError |
private double |
m_derivativeConstant |
private double |
m_error |
private double |
m_integralConstant |
private double |
m_maxChangeOutput |
private double |
m_output |
private double |
m_previousError |
private double |
m_previousOutput |
private double |
m_proportionalConstant |
private double |
m_sumOfError |
private double |
m_tolerance |
Constructor and Description |
---|
PIDController(double[] pidConstants)
Creator
|
PIDController(double[] pidConstants,
double maxChangeOutput)
Creator
|
PIDController(double p,
double i,
double d)
Creator
|
PIDController(double p,
double i,
double d,
double maxChangeOutput,
double tolerance)
Creator
|
Modifier and Type | Method and Description |
---|---|
private double |
calculateD()
You can't call this
Calculates the derivative output of the controller
|
private double |
calculateI()
You can't call this
Calculates the integral output of the controller
Sum of error is set to zero if the error is within the tolerance range
if the sum of the error is acting against your proportional term, reset the sum to just be the current error
|
double |
calculateOutput(double processVariable,
double setpoint)
Use this to get the new output of the controller every loop
|
private double |
calculateP()
You can't call this
Calculates the proportional output of the controller
|
double |
getError()
Get the current error as calculated the last time you called calculate output
|
private double |
makeInRange(double output)
this will ensure that the output of the controller is between -1 and 1
|
void |
setD(double d)
Sets the derivative constant after the controller has been created
|
void |
setI(double i)
Sets the integral constant after the controller has been created
|
void |
setP(double p)
Sets the proportional constant after the controller has been created
|
void |
setPIDConstants(double p,
double i,
double d)
This will set the PID constants after a controller has already been created
|
private double m_proportionalConstant
private double m_integralConstant
private double m_derivativeConstant
private double m_maxChangeOutput
private double m_tolerance
private double m_previousOutput
private double m_output
private double m_error
private double m_previousError
private double m_deltaError
private double m_sumOfError
public PIDController(double[] pidConstants)
pidConstants
- array of constants in the order proportional, integral, derivativepublic PIDController(double p, double i, double d)
p
- proportionali
- integrald
- derivativepublic PIDController(double[] pidConstants, double maxChangeOutput)
pidConstants
- array of pid constants in the order proportional, integral, derivativemaxChangeOutput
- this is currently unsupported -- will be used to set a limit on the amount that the output of this controller can change bypublic PIDController(double p, double i, double d, double maxChangeOutput, double tolerance)
p
- proportionali
- integrald
- derivativemaxChangeOutput
- this is currently unsupported -- will be used to set a limit on the amount that the output of this controller can change bytolerance
- this is the acceptable amount of error for the controllerpublic void setPIDConstants(double p, double i, double d)
p
- proportionali
- integrald
- derivativepublic void setP(double p)
p
- proportionalpublic void setI(double i)
i
- integralpublic void setD(double d)
d
- derivativepublic double calculateOutput(double processVariable, double setpoint)
processVariable
- this is the sensor valuesetpoint
- this is the value you want the sensor to readprivate double calculateP()
private double calculateI()
private double calculateD()
private double makeInRange(double output)
output
- the unmodified outputpublic double getError()