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:
Tyler Veness
2015-07-14 17:01:42 -07:00
committed by Brad Miller (WPI)
parent 918cde0c0f
commit f0e3bb5164
4 changed files with 12 additions and 12 deletions

View File

@@ -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;
}