mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +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
@@ -140,8 +140,8 @@ void PIDController::Calculate() {
|
||||
}
|
||||
|
||||
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_D * (m_prevInput - input) + m_setpoint * m_F;
|
||||
m_prevInput = input;
|
||||
|
||||
if (m_result > m_maximumOutput)
|
||||
m_result = m_maximumOutput;
|
||||
@@ -447,7 +447,7 @@ void PIDController::Reset() {
|
||||
Disable();
|
||||
|
||||
std::unique_lock<priority_mutex> sync(m_mutex);
|
||||
m_prevError = 0;
|
||||
m_prevInput = 0;
|
||||
m_totalError = 0;
|
||||
m_result = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user