bug fix EGO PID controller + some improvements. (#879)

* Fix for EGO pid

* Further improvements on ego PID

* Stop EGO controllers from calculating while DFCO is active. To prevent integrator windup.

* Fix bug in DFCO enable/disable of the controller

Co-authored-by: Tjeerd <tjeerdie@users.noreply.github.com>
This commit is contained in:
Tjeerd 2022-07-09 14:22:18 +02:00 committed by GitHub
parent ce7ea412db
commit ca2bab0725
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View File

@ -605,7 +605,7 @@ byte correctionAFRClosedLoop()
if( (currentStatus.runSecs > configPage6.ego_sdelay) || (configPage2.incorporateAFR == true) ) { currentStatus.afrTarget = get3DTableValue(&afrTable, currentStatus.fuelLoad, currentStatus.RPM); } //Perform the target lookup if( (currentStatus.runSecs > configPage6.ego_sdelay) || (configPage2.incorporateAFR == true) ) { currentStatus.afrTarget = get3DTableValue(&afrTable, currentStatus.fuelLoad, currentStatus.RPM); } //Perform the target lookup
} }
if( configPage6.egoType > 0 ) //egoType of 0 means no O2 sensor if((configPage6.egoType > 0) & (BIT_CHECK(currentStatus.status1, BIT_STATUS1_DFCO) != 1 ) ) //egoType of 0 means no O2 sensor. If DFCO is active do not run the ego controllers to prevent interator wind-up.
{ {
AFRValue = currentStatus.egoCorrection; //Need to record this here, just to make sure the correction stays 'on' even if the nextCycle count isn't ready AFRValue = currentStatus.egoCorrection; //Need to record this here, just to make sure the correction stays 'on' even if the nextCycle count isn't ready

View File

@ -54,21 +54,21 @@ bool PID::Compute()
/*Compute all the working error variables*/ /*Compute all the working error variables*/
long input = *myInput; long input = *myInput;
long error = *mySetpoint - input; long error = *mySetpoint - input;
ITerm += (ki * error)/100; ITerm += (ki * error);
if(ITerm > outMax) ITerm= outMax; if(ITerm > outMax) ITerm= outMax;
else if(ITerm < outMin) ITerm= outMin; else if(ITerm < outMin) ITerm = outMin;
long dInput = (input - lastInput); long dInput = (input - lastInput);
/*Compute PID Output*/ /*Compute PID Output*/
long output = (kp * error)/100 + ITerm- (kd * dInput)/100; long output = (kp * error) + ITerm- (kd * dInput);
if(output > outMax) { output = outMax; } if(output > outMax) { output = outMax; }
else if(output < outMin) { output = outMin; } else if(output < outMin) { output = outMin; }
*myOutput = output; *myOutput = output/1000;
/*Remember some variables for next time*/ /*Remember some variables for next time*/
lastInput = input; lastInput = input;
//lastTime = now; lastTime = now;
return true; return true;
} }
//else return false; //else return false;
@ -90,10 +90,10 @@ void PID::SetTunings(byte Kp, byte Ki, byte Kd)
ki = Ki * SampleTimeInSec; ki = Ki * SampleTimeInSec;
kd = Kd / SampleTimeInSec; kd = Kd / SampleTimeInSec;
*/ */
long InverseSampleTimeInSec = 100000 / SampleTime; long InverseSampleTimeInSec = 100;
kp = Kp; kp = Kp;
ki = (Ki * 100) / InverseSampleTimeInSec; ki = Ki;
kd = (Kd * InverseSampleTimeInSec) / 100; kd = Kd * 10;
if(controllerDirection ==REVERSE) if(controllerDirection ==REVERSE)
{ {
@ -129,8 +129,8 @@ void PID::SetSampleTime(int NewSampleTime)
void PID::SetOutputLimits(long Min, long Max) void PID::SetOutputLimits(long Min, long Max)
{ {
if(Min >= Max) return; if(Min >= Max) return;
outMin = Min; outMin = Min*1000;
outMax = Max; outMax = Max*1000;
if(inAuto) if(inAuto)
{ {