diff --git a/firmware/controllers/math/pid.cpp b/firmware/controllers/math/pid.cpp index 92a6eb5608..6a5170ae98 100644 --- a/firmware/controllers/math/pid.cpp +++ b/firmware/controllers/math/pid.cpp @@ -45,12 +45,20 @@ float Pid::getValue(float target, float input, float dTime) { prevError = error; + /** + * If we have exceeded the ability of the controlled device to hit target, the I factor will keep accumulating and approach infinity. + * Here we limit the I-term #353 + */ + if (iTerm > maxResult - (pTerm + dTerm + pid->offset)) + iTerm = maxResult - (pTerm + dTerm + pid->offset); + + if (iTerm < minResult - (pTerm + dTerm + pid->offset)) + iTerm = minResult - (pTerm + dTerm + pid->offset); + float result = pTerm + iTerm + dTerm + pid->offset; if (result > maxResult) { -// iTerm -= result - maxResult; result = maxResult; } else if (result < minResult) { -// iTerm += minResult - result; result = minResult; } return result; diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 4d4748e377..932a50727b 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -249,5 +249,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20170212; + return 20170213; }