EFI_IDLE_INCREMENTAL_PID_CIC should be a runtime parameter #806

This commit is contained in:
rusefi 2020-07-12 21:35:01 -04:00
parent 6811117961
commit 5feb91dc8f
3 changed files with 31 additions and 28 deletions

View File

@ -29,6 +29,8 @@ static void setPrometheusDefaults(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
//engineConfiguration->useOnlyRisingEdgeForTrigger = true; //engineConfiguration->useOnlyRisingEdgeForTrigger = true;
setAlgorithm(LM_SPEED_DENSITY PASS_CONFIG_PARAMETER_SUFFIX); setAlgorithm(LM_SPEED_DENSITY PASS_CONFIG_PARAMETER_SUFFIX);
CONFIG(useCicPidForIdle) = true;
engineConfiguration->specs.cylindersCount = 4; engineConfiguration->specs.cylindersCount = 4;
engineConfiguration->specs.firingOrder = FO_1_3_4_2; engineConfiguration->specs.firingOrder = FO_1_3_4_2;

View File

@ -70,12 +70,6 @@ static bool shouldResetPid = false;
// See automaticIdleController(). // See automaticIdleController().
static bool mightResetPid = false; static bool mightResetPid = false;
#if EFI_IDLE_PID_CIC
// Use new PID with CIC integrator
static PidCic idlePid;
#else
class PidWithOverrides : public PidIndustrial { class PidWithOverrides : public PidIndustrial {
public: public:
float getOffset() const override { float getOffset() const override {
@ -107,19 +101,28 @@ public:
} }
}; };
static PidWithOverrides idlePid; static PidWithOverrides industrialWithOverrideIdlePid;
#endif /* EFI_IDLE_PID_CIC */
Pid * getIdlePid() { #if EFI_IDLE_PID_CIC
return &idlePid; // Use PID with CIC integrator
static PidCic idleCicPid;
#endif //EFI_IDLE_PID_CIC
Pid * getIdlePid(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if EFI_IDLE_PID_CIC
if (CONFIG(useCicPidForIdle)) {
return &idleCicPid;
}
#endif /* EFI_IDLE_PID_CIC */
return &industrialWithOverrideIdlePid;
} }
float getIdlePidOffset(DECLARE_ENGINE_PARAMETER_SIGNATURE) { float getIdlePidOffset(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return getIdlePid()->getOffset(); return getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->getOffset();
} }
float getIdlePidMinValue(DECLARE_ENGINE_PARAMETER_SIGNATURE) { float getIdlePidMinValue(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return getIdlePid()->getMinValue(); return getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->getMinValue();
} }
// todo: extract interface for idle valve hardware, with solenoid and stepper implementations? // todo: extract interface for idle valve hardware, with solenoid and stepper implementations?
@ -181,7 +184,7 @@ static void showIdleInfo(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
} }
if (engineConfiguration->idleMode == IM_AUTO) { if (engineConfiguration->idleMode == IM_AUTO) {
getIdlePid()->showPidStatus(logger, "idle"); getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->showPidStatus(logger, "idle");
} }
} }
@ -300,11 +303,9 @@ static bool isOutOfAutomaticIdleCondition(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
*/ */
static percent_t automaticIdleController(float tpsPos DECLARE_ENGINE_PARAMETER_SUFFIX) { static percent_t automaticIdleController(float tpsPos DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if !EFI_IDLE_PID_CIC
// todo: move this to pid_s one day // todo: move this to pid_s one day
idlePid.antiwindupFreq = engineConfiguration->idle_antiwindupFreq; industrialWithOverrideIdlePid.antiwindupFreq = engineConfiguration->idle_antiwindupFreq;
idlePid.derivativeFilterLoss = engineConfiguration->idle_derivativeFilterLoss; industrialWithOverrideIdlePid.derivativeFilterLoss = engineConfiguration->idle_derivativeFilterLoss;
#endif
if (isOutOfAutomaticIdleCondition(PASS_ENGINE_PARAMETER_SIGNATURE)) { if (isOutOfAutomaticIdleCondition(PASS_ENGINE_PARAMETER_SIGNATURE)) {
// Don't store old I and D terms if PID doesn't work anymore. // Don't store old I and D terms if PID doesn't work anymore.
@ -347,9 +348,9 @@ static percent_t automaticIdleController(float tpsPos DECLARE_ENGINE_PARAMETER_S
if (rpm < targetRpm) if (rpm < targetRpm)
errorAmpCoef += (float)CONFIG(pidExtraForLowRpm) / PERCENT_MULT; errorAmpCoef += (float)CONFIG(pidExtraForLowRpm) / PERCENT_MULT;
// If errorAmpCoef > 1.0, then PID thinks that RPM is lower than it is, and controls IAC more aggressively // If errorAmpCoef > 1.0, then PID thinks that RPM is lower than it is, and controls IAC more aggressively
getIdlePid()->setErrorAmplification(errorAmpCoef); getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->setErrorAmplification(errorAmpCoef);
percent_t newValue = getIdlePid()->getOutput(targetRpm, rpm); percent_t newValue = getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->getOutput(targetRpm, rpm);
engine->engineState.idle.idleState = PID_VALUE; engine->engineState.idle.idleState = PID_VALUE;
// the state of PID has been changed, so we might reset it now, but only when needed (see idlePidDeactivationTpsThreshold) // the state of PID has been changed, so we might reset it now, but only when needed (see idlePidDeactivationTpsThreshold)
@ -400,8 +401,8 @@ static percent_t automaticIdleController(float tpsPos DECLARE_ENGINE_PARAMETER_S
* @see stepper.cpp * @see stepper.cpp
*/ */
getIdlePid()->iTermMin = engineConfiguration->idlerpmpid_iTermMin; getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->iTermMin = engineConfiguration->idlerpmpid_iTermMin;
getIdlePid()->iTermMax = engineConfiguration->idlerpmpid_iTermMax; getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->iTermMax = engineConfiguration->idlerpmpid_iTermMax;
SensorResult tps = Sensor::get(SensorType::DriverThrottleIntent); SensorResult tps = Sensor::get(SensorType::DriverThrottleIntent);
@ -410,11 +411,11 @@ static percent_t automaticIdleController(float tpsPos DECLARE_ENGINE_PARAMETER_S
if (engineConfiguration->isVerboseIAC && engine->engineState.isAutomaticIdle) { if (engineConfiguration->isVerboseIAC && engine->engineState.isAutomaticIdle) {
scheduleMsg(logger, "Idle state %s%s", getIdle_state_e(engine->engineState.idle.idleState), scheduleMsg(logger, "Idle state %s%s", getIdle_state_e(engine->engineState.idle.idleState),
(prettyClose ? " pretty close" : "")); (prettyClose ? " pretty close" : ""));
getIdlePid()->showPidStatus(logger, "idle"); getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->showPidStatus(logger, "idle");
} }
if (shouldResetPid) { if (shouldResetPid) {
getIdlePid()->reset(); getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->reset();
// alternatorPidResetCounter++; // alternatorPidResetCounter++;
shouldResetPid = false; shouldResetPid = false;
} }
@ -511,7 +512,7 @@ static percent_t automaticIdleController(float tpsPos DECLARE_ENGINE_PARAMETER_S
if (engineConfiguration->idleMode == IM_AUTO) { if (engineConfiguration->idleMode == IM_AUTO) {
#if EFI_TUNER_STUDIO #if EFI_TUNER_STUDIO
// see also tsOutputChannels->idlePosition // see also tsOutputChannels->idlePosition
getIdlePid()->postState(&tsOutputChannels, 1000000); getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->postState(&tsOutputChannels, 1000000);
tsOutputChannels.debugIntField4 = engine->engineState.idle.idleState; tsOutputChannels.debugIntField4 = engine->engineState.idle.idleState;
#endif /* EFI_TUNER_STUDIO */ #endif /* EFI_TUNER_STUDIO */
} else { } else {
@ -538,7 +539,7 @@ static percent_t automaticIdleController(float tpsPos DECLARE_ENGINE_PARAMETER_S
IdleController idleControllerInstance; IdleController idleControllerInstance;
static void applyPidSettings(DECLARE_ENGINE_PARAMETER_SIGNATURE) { static void applyPidSettings(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
getIdlePid()->updateFactors(engineConfiguration->idleRpmPid.pFactor, engineConfiguration->idleRpmPid.iFactor, engineConfiguration->idleRpmPid.dFactor); getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->updateFactors(engineConfiguration->idleRpmPid.pFactor, engineConfiguration->idleRpmPid.iFactor, engineConfiguration->idleRpmPid.dFactor);
iacPidMultMap.init(CONFIG(iacPidMultTable), CONFIG(iacPidMultLoadBins), CONFIG(iacPidMultRpmBins)); iacPidMultMap.init(CONFIG(iacPidMultTable), CONFIG(iacPidMultLoadBins), CONFIG(iacPidMultRpmBins));
} }
@ -555,7 +556,7 @@ void setDefaultIdleParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
#if ! EFI_UNIT_TEST #if ! EFI_UNIT_TEST
void onConfigurationChangeIdleCallback(engine_configuration_s *previousConfiguration) { void onConfigurationChangeIdleCallback(engine_configuration_s *previousConfiguration) {
shouldResetPid = !getIdlePid()->isSame(&previousConfiguration->idleRpmPid); shouldResetPid = !getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->isSame(&previousConfiguration->idleRpmPid);
idleSolenoidOpen.setFrequency(CONFIG(idle).solenoidFrequency); idleSolenoidOpen.setFrequency(CONFIG(idle).solenoidFrequency);
idleSolenoidClose.setFrequency(CONFIG(idle).solenoidFrequency); idleSolenoidClose.setFrequency(CONFIG(idle).solenoidFrequency);
} }
@ -711,7 +712,7 @@ void startIdleThread(Logging*sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
logger = sharedLogger; logger = sharedLogger;
INJECT_ENGINE_REFERENCE(&idleControllerInstance); INJECT_ENGINE_REFERENCE(&idleControllerInstance);
getIdlePid()->initPidClass(&engineConfiguration->idleRpmPid); getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->initPidClass(&engineConfiguration->idleRpmPid);
#if ! EFI_UNIT_TEST #if ! EFI_UNIT_TEST
// todo: we still have to explicitly init all hardware on start in addition to handling configuration change via // todo: we still have to explicitly init all hardware on start in addition to handling configuration change via

View File

@ -37,5 +37,5 @@ void initIdleHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE);
bool isIdleHardwareRestartNeeded(); bool isIdleHardwareRestartNeeded();
void onConfigurationChangeIdleCallback(engine_configuration_s *previousConfiguration); void onConfigurationChangeIdleCallback(engine_configuration_s *previousConfiguration);
float getIdlePidOffset(DECLARE_ENGINE_PARAMETER_SIGNATURE); float getIdlePidOffset(DECLARE_ENGINE_PARAMETER_SIGNATURE);
Pid * getIdlePid(); Pid * getIdlePid(DECLARE_ENGINE_PARAMETER_SIGNATURE);
float getIdlePidMinValue(DECLARE_ENGINE_PARAMETER_SIGNATURE); float getIdlePidMinValue(DECLARE_ENGINE_PARAMETER_SIGNATURE);