|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlejos.util.PIDController
public class PIDController
Proportional <P>, Integral <I>, Derivative <D> controller implementation.
P
depends on the present error, I
on the accumulation of past errors, and D
is a
prediction of future errors, based on
current rate of change.
Proportional gain, Kp:
Larger values typically mean faster response since the larger the error, the larger the proportional term compensation.
An excessively large proportional gain will lead to process instability and oscillation.
Integral gain, Ki: Larger values imply steady state errors are eliminated more quickly. The trade-off is larger overshoot: any negative error integrated during transient response must be integrated away by positive error before reaching steady state.
Derivative gain, Kd: Larger values decrease overshoot, but slow down transient response and may lead to instability due to signal noise amplification in the differentiation of the error.
Definitions:
doPID(int)
.
P
(sometimes called gain) makes a change to the output that is proportional to the
current error value. The proportional response is adjusted by multiplying the error by Kp. A high proportional gain
results in a large change in the output for a given change in the error.
The integral term I
(sometimes called reset) accelerates the movement of the process towards the setpoint and eliminates the residual
steady-state error that
occurs with a proportional only controller. However, since the integral term is responding to accumulated errors from the past,
it can cause the present value to overshoot the setpoint value. The magnitude of the contribution of the integral term to the
overall control action is determined by the integral gain, Ki. This implementation uses I += Ki * error * dt
.
If error is potentially large, using a small Ki gain
value may be necessary as the amplitude of I
may cause instability.
Integral windup is basically what happens when the controller is pushed into a state where it has reached the maximum output power but the set point has not been reached. In this situation the integral term will continue to grow even though it can no longer have any impact on the controller output. The problem is that when the controller finally manages to get to the set point the integral term may have grown very large and this will cause an overshoot that can take a relatively long time to correct (as the integral value now needs to unwind). Two classic examples are:
D
(sometimes called rate) slows the rate of change of the controller output and this effect is most noticeable
close to the controller setpoint. Hence, derivative control is used to reduce the magnitude of the overshoot produced by the
integral component (I
) and improve the combined controller-process stability. The rate of change of the process error is
calculated by determining the slope of the error over time and multiplying this rate of change by the derivative gain Kd.
The D term in the controller is highly sensitive to noise in the error term, and can cause a process to become unstable if
the noise and the derivative gain Kd are sufficiently large.
It is important to tune the PID controller with an implementation of a consistent delay between calls to doPID()
because the MV calc in a PID controller is time-dependent by definition. This implementation provides an optional delay (set
in the constructor) and calculates the time delta (dt
) between
calls to
in milliseconds.
doPID(int)
Reference: Wikipedia- http://en.wikipedia.org/wiki/PID_controller
Field Summary | |
---|---|
static int |
PID_DEADBAND
The deadband value ID. |
static int |
PID_I
The integral accumulator I value. |
static int |
PID_I_LIMITHIGH
The Integral high limit cutoff value ID. |
static int |
PID_I_LIMITLOW
The Integral low limit cutoff value ID. |
static int |
PID_KD
Derivitive term ID |
static int |
PID_KI
Integral term ID. |
static int |
PID_KP
Proportional term ID |
static int |
PID_LIMITHIGH
The MV high limit cutoff value ID. |
static int |
PID_LIMITLOW
The MV low limit cutoff value ID. |
static int |
PID_PV
The process variable ( PV ) value. |
static int |
PID_RAMP_POWER
The Ramping Exponential value ID. |
static int |
PID_RAMP_THRESHOLD
The Ramping Threshold value ID. |
static int |
PID_SETPOINT
The Setpoint value ID. |
Constructor Summary | |
---|---|
PIDController(int setpoint,
int msdelay)
Construct a PID controller instance using passed setpoint (SP) and millisecond delay (used before returning from a call to doPID() ). |
Method Summary | |
---|---|
Logger |
deregisterDataLogger()
De-register the registered NXTDataLogger . |
int |
doPID(int processVariable)
Do the PID calc for a single iteration. |
void |
freezeIntegral(boolean status)
Freeze or resume integral accumulation. |
int |
getDelay()
Returns the doPID() timing delay. |
float |
getPIDParam(int paramID)
Get PID controller parameters. |
boolean |
isIntegralFrozen()
|
boolean |
registerDataLogger(Logger dataLogger)
Register a NXTDataLogger instance to log the PID variables. |
void |
setDelay(int msdelay)
Set the desired delay before doPID() returns. |
void |
setPIDParam(int paramID,
float value)
Set PID controller parameters. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int PID_KP
setPIDParam(int, float)
,
getPIDParam(int)
,
Constant Field Valuespublic static final int PID_KI
I
accumulator is an int so any decimal places are rounded in the calc:
I += Ki * error * dt;
setPIDParam(int, float)
,
getPIDParam(int)
,
Constant Field Valuespublic static final int PID_KD
setPIDParam(int, float)
,
getPIDParam(int)
,
Constant Field Valuespublic static final int PID_RAMP_POWER
setPIDParam(int, float)
,
getPIDParam(int)
,
Constant Field Valuespublic static final int PID_RAMP_THRESHOLD
doPID(int)
. The value passed to setPIDParam()
is cast to an int.
setPIDParam(int, float)
,
getPIDParam(int)
,
Constant Field Valuespublic static final int PID_DEADBAND
SP
.
setPIDParam(int, float)
,
getPIDParam(int)
,
Constant Field Valuespublic static final int PID_LIMITHIGH
MV
). Set to a large value to
effectively disable. This is applied to MV
before any ramping. Default is 900 at instantiation. The value
passed to setPIDParam()
is cast to an int.
setPIDParam(int, float)
,
getPIDParam(int)
,
Constant Field Valuespublic static final int PID_LIMITLOW
MV
). Set to a large negative value to
effectively disable. This is applied to MV
before any ramping. Default is -900. The value passed to setPIDParam()
is cast to an int.
setPIDParam(int, float)
,
getPIDParam(int)
,
Constant Field Valuespublic static final int PID_SETPOINT
setPIDParam(int, float)
,
getPIDParam(int)
,
doPID(int)
,
Constant Field Valuespublic static final int PID_I_LIMITLOW
I (Ki * error * dt)
less than a defined value. Set to zero
to disable. Default is 0. Setting this clears the I
term accumulator. The value passed to setPIDParam()
is cast to an int.
This is one methodology to manage integral windup.
setPIDParam(int, float)
,
getPIDParam(int)
,
freezeIntegral(boolean)
,
PID_I_LIMITHIGH
,
Constant Field Valuespublic static final int PID_I_LIMITHIGH
I (Ki * error * dt)
greater than a defined value. Set to zero
to disable. Default is 0. Setting this clears the I
term accumulator. The value passed to setPIDParam()
is cast to an int.
This is one methodology to manage integral windup.
setPIDParam(int, float)
,
getPIDParam(int)
,
freezeIntegral(boolean)
,
PID_I_LIMITLOW
,
Constant Field Valuespublic static final int PID_I
I
value. Read-only.Calling setPIDParam() with this is ignored. The I value is the
accumulator for Ki * error * dt
.
public static final int PID_PV
PV
) value. Read-only.Calling setPIDParam() with this is ignored. The PV value is the
last value passed to doPID()
.
doPID(int)
,
Constant Field ValuesConstructor Detail |
---|
public PIDController(int setpoint, int msdelay)
doPID()
).
setpoint
- The goal of the MVmsdelay
- The delay in milliseconds. Set to 0 to disable any delay.doPID(int)
,
setDelay(int)
Method Detail |
---|
public void setPIDParam(int paramID, float value)
paramID
- What parameter to set. See the constant definitions for this class.value
- The value to set it to. Note that some values are cast to int depending on the particular paramID value used.getPIDParam(int)
public float getPIDParam(int paramID)
paramID
- What parameter to get. See the constant definitions for this class.
setPIDParam(int, float)
public void freezeIntegral(boolean status)
This is one methodology to manage integral windup. This is false by default at instantiation.
status
- true to freeze, false to thawisIntegralFrozen()
public boolean isIntegralFrozen()
true
if the integral accumulation is frozenfreezeIntegral(boolean)
public int doPID(int processVariable)
setDelay()
or in the constructor.
processVariable
- The PV value from the process (sensor reading, etc.).
MV
to input into the process (motor speed, etc.)setDelay(int)
public boolean registerDataLogger(Logger dataLogger)
NXTDataLogger
instance to log the PID variables. If the logger instance is in
cached mode, the headers must not have been set before calling this method or false
is returned.
PIDController
will
set the column headers and log values on every call to doPID()
.
This is useful when using the NXJChartingLogger tool to visualize the PID response by monitoring the internal variables.
dataLogger
- A NXTDataLogger
instance in realtime or cached logging mode.
true
if successful, false
otherwise.NXTDataLogger
,
deregisterDataLogger()
public Logger deregisterDataLogger()
NXTDataLogger
.
NXTDataLogger
that was registered, null
if no logger has been registered.registerDataLogger(lejos.util.Logger)
public void setDelay(int msdelay)
doPID()
returns. Set to zero to effectively disable.
msdelay
- Delay in millisecondsgetDelay()
public int getDelay()
doPID()
timing delay.
setDelay()
setDelay(int)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |