From 88bbd25042f16001dfd1dd5efae03bb77bc70509 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 11 Jul 2020 15:05:18 -0400 Subject: [PATCH] PidIndustrial does not limit iTerm #1599 --- firmware/util/math/pid.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/firmware/util/math/pid.cpp b/firmware/util/math/pid.cpp index 034c5db0b4..e1a73de2ad 100644 --- a/firmware/util/math/pid.cpp +++ b/firmware/util/math/pid.cpp @@ -251,9 +251,6 @@ float PidIndustrial::getOutput(float target, float input, float dTime) { float error = (target - input) * errorAmplificationCoef; float pTerm = parameters->pFactor * error; - // update the I-term - iTerm += parameters->iFactor * dTime * error; - // calculate dTerm coefficients if (fabsf(derivativeFilterLoss) > DBL_EPSILON) { // restore Td in the Standard form from the Parallel form: Td = Kd / Kc @@ -272,11 +269,14 @@ float PidIndustrial::getOutput(float target, float input, float dTime) { // (error - previousError) = (target-input) - (target-prevousInput) = -(input - prevousInput) dTerm = dTerm * ad + (error - previousError) * bd; + // update the I-term + iTerm += parameters->iFactor * dTime * error; + // calculate output and apply the limits float output = pTerm + iTerm + dTerm + getOffset(); float limitedOutput = limitOutput(output); - // apply the integrator anti-windup + // apply the integrator anti-windup on top of the "normal" iTerm change above // If p.antiwindupFreq = 0, then iTerm is equal to PidParallelController's iTerm += dTime * antiwindupFreq * (limitedOutput - output);