mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
artf4165: D term of PID controller now uses change in input instead of change in error
This avoids large additions introduced by the D term when a step change occurs in the setpoint. Otherwise, the changes return the same values. Let error = setpoint - input and prevError = prevSetpoint - prevInput. If the D term is calculated via error - prevError, then:
error - prevError = (setpoint - input) - (prevSetpoint - prevInput)
If we ignore the setpoint changing, then we get:
error - prevError = (setpoint - input) - (setpoint - prevInput)
= prevInput - input
Change-Id: Ifa4af9b265e3c4bd263e8541355f2b80269693e9
This commit is contained in:
committed by
Brad Miller (WPI)
parent
918cde0c0f
commit
f0e3bb5164
@@ -33,7 +33,7 @@ public class PIDController implements PIDInterface, LiveWindowSendable, Controll
|
||||
private boolean m_continuous = false; // do the endpoints wrap around? eg.
|
||||
// Absolute encoder
|
||||
private boolean m_enabled = false; // is the pid controller enabled
|
||||
private double m_prevError = 0.0; // the prior sensor input (used to compute
|
||||
private double m_prevInput = 0.0; // the prior sensor input (used to compute
|
||||
// velocity)
|
||||
private double m_totalError = 0.0; // the sum of the errors for use in the
|
||||
// integral calc
|
||||
@@ -270,8 +270,8 @@ public class PIDController implements PIDInterface, LiveWindowSendable, Controll
|
||||
}
|
||||
|
||||
m_result =
|
||||
m_P * m_error + m_I * m_totalError + m_D * (m_error - m_prevError) + m_setpoint * m_F;
|
||||
m_prevError = m_error;
|
||||
m_P * m_error + m_I * m_totalError + m_D * (m_prevInput - input) + m_setpoint * m_F;
|
||||
m_prevInput = input;
|
||||
|
||||
if (m_result > m_maximumOutput) {
|
||||
m_result = m_maximumOutput;
|
||||
@@ -572,7 +572,7 @@ public class PIDController implements PIDInterface, LiveWindowSendable, Controll
|
||||
*/
|
||||
public synchronized void reset() {
|
||||
disable();
|
||||
m_prevError = 0;
|
||||
m_prevInput = 0;
|
||||
m_totalError = 0;
|
||||
m_result = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user