From 6ee0a55eafb783ba99d357ed1c2e848be84a9b23 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Mon, 10 Jan 2022 19:48:45 -0500 Subject: [PATCH] RE usability: live data for idle controller --- firmware/console/binary/tunerstudio.cpp | 2 +- .../controllers/actuators/idle_thread.cpp | 56 +++++++++---------- firmware/controllers/actuators/idle_thread.h | 2 +- firmware/controllers/algo/engine.cpp | 2 +- firmware/controllers/algo/engine.h | 1 - 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index 8bf837bd5e..91f478ec42 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -212,7 +212,7 @@ static const void * getStructAddr(live_data_e structId) { // return static_cast(getIdlePid()); //#endif /* EFI_IDLE_CONTROL */ case LDS_idle_state: - return static_cast(&engine->idle); + return static_cast(&engine->module().unmock()); case LDS_tps_accel_state: return static_cast(&engine->tpsAccelEnrichment); case LDS_main_relay: diff --git a/firmware/controllers/actuators/idle_thread.cpp b/firmware/controllers/actuators/idle_thread.cpp index b32d17f2e8..91551bf508 100644 --- a/firmware/controllers/actuators/idle_thread.cpp +++ b/firmware/controllers/actuators/idle_thread.cpp @@ -118,7 +118,7 @@ void setIdleMode(idle_mode_e value) { } percent_t getIdlePosition() { - return engine->idle.currentIdlePosition; + return engine->module().unmock().currentIdlePosition; } void setManualIdleValvePosition(int positionPercent) { @@ -135,9 +135,9 @@ void setManualIdleValvePosition(int positionPercent) { #endif /* EFI_UNIT_TEST */ void IdleController::init(pid_s* idlePidConfig) { - engine->idle.shouldResetPid = false; - engine->idle.mightResetPid = false; - engine->idle.wasResetPid = false; + shouldResetPid = false; + mightResetPid = false; + wasResetPid = false; m_timingPid.initPidClass(idlePidConfig); } @@ -302,15 +302,15 @@ static void undoIdleBlipIfNeeded() { float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos, int rpm, int targetRpm) { auto idlePid = getIdlePid(); - if (engine->idle.shouldResetPid) { + if (shouldResetPid) { // we reset only if I-term is negative, because the positive I-term is good - it keeps RPM from dropping too low - if (idlePid->getIntegration() <= 0 || engine->idle.mustResetPid) { + if (idlePid->getIntegration() <= 0 || mustResetPid) { idlePid->reset(); - engine->idle.mustResetPid = false; + mustResetPid = false; } // alternatorPidResetCounter++; - engine->idle.shouldResetPid = false; - engine->idle.wasResetPid = true; + shouldResetPid = false; + wasResetPid = true; } // todo: move this to pid_s one day @@ -322,12 +322,12 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos, if (phase != IIdleController::Phase::Idling) { // Don't store old I and D terms if PID doesn't work anymore. // Otherwise they will affect the idle position much later, when the throttle is closed. - if (engine->idle.mightResetPid) { - engine->idle.mightResetPid = false; - engine->idle.shouldResetPid = true; + if (mightResetPid) { + mightResetPid = false; + shouldResetPid = true; } - engine->idle.idleState = TPS_THRESHOLD; + idleState = TPS_THRESHOLD; // We aren't idling, so don't apply any correction. A positive correction could inhibit a return to idle. m_lastAutomaticPosition = 0; @@ -338,7 +338,7 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos, bool acToggleJustTouched = (nowUs - engine->acSwitchLastChangeTime) < MS2US(500); // check if within the dead zone if (!acToggleJustTouched && absI(rpm - targetRpm) <= engineConfiguration->idlePidRpmDeadZone) { - engine->idle.idleState = RPM_DEAD_ZONE; + idleState = RPM_DEAD_ZONE; // current RPM is close enough, no need to change anything return m_lastAutomaticPosition; } @@ -351,9 +351,9 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos, } // if PID was previously reset, we store the time when it turned on back (see errorAmpCoef correction below) - if (engine->idle.wasResetPid) { + if (wasResetPid) { restoreAfterPidResetTimeUs = nowUs; - engine->idle.wasResetPid = false; + wasResetPid = false; } // increase the errorAmpCoef slowly to restore the process correctly after the PID reset // todo: move restoreAfterPidResetTimeUs to idle? @@ -364,10 +364,10 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos, idlePid->setErrorAmplification(errorAmpCoef); percent_t newValue = idlePid->getOutput(targetRpm, rpm, SLOW_CALLBACK_PERIOD_MS / 1000.0f); - engine->idle.idleState = PID_VALUE; + idleState = PID_VALUE; // the state of PID has been changed, so we might reset it now, but only when needed (see idlePidDeactivationTpsThreshold) - engine->idle.mightResetPid = true; + mightResetPid = true; // Apply PID Multiplier if used if (engineConfiguration->useIacPidMultTable) { @@ -434,7 +434,7 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos, bool isAutomaticIdle = tps.Valid && engineConfiguration->idleMode == IM_AUTO; if (engineConfiguration->isVerboseIAC && isAutomaticIdle) { - efiPrintf("Idle state %s", getIdle_state_e(engine->idle.idleState)); + efiPrintf("Idle state %s", getIdle_state_e(idleState)); getIdlePid()->showPidStatus("idle"); } @@ -445,11 +445,11 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos, if (engine->timeToStopBlip != 0) { iacPosition = engine->blipIdlePosition; - engine->idle.idleState = BLIP; + idleState = BLIP; } else { // Always apply closed loop correction iacPosition = getOpenLoop(phase, clt, tps, crankingTaper); - engine->idle.baseIdlePosition = iacPosition; + baseIdlePosition = iacPosition; // If TPS is working and automatic mode enabled, add any automatic correction if (tps.Valid && engineConfiguration->idleMode == IM_AUTO) { @@ -466,7 +466,7 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos, if (engineConfiguration->idleMode == IM_AUTO) { // see also tsOutputChannels->idlePosition getIdlePid()->postState(&engine->outputChannels.idleStatus); - engine->outputChannels.idleState = engine->idle.idleState; + engine->outputChannels.idleState = idleState; } else { engine->outputChannels.idleCurrentPosition = iacPosition; extern StepperMotor iacMotor; @@ -474,7 +474,7 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos, } #endif /* EFI_TUNER_STUDIO */ - engine->idle.currentIdlePosition = iacPosition; + currentIdlePosition = iacPosition; return iacPosition; } @@ -511,8 +511,8 @@ void setDefaultIdleParameters() { void IdleController::onConfigurationChange(engine_configuration_s const * previousConfiguration) { #if ! EFI_UNIT_TEST - engine->idle.shouldResetPid = !getIdlePid()->isSame(&previousConfiguration->idleRpmPid); - engine->idle.mustResetPid = engine->idle.shouldResetPid; + shouldResetPid = !getIdlePid()->isSame(&previousConfiguration->idleRpmPid); + mustResetPid = shouldResetPid; #endif } @@ -569,9 +569,9 @@ void startIdleThread() { initIdleHardware(); #endif /* EFI_UNIT_TEST */ - engine->idle.idleState = INIT; - engine->idle.baseIdlePosition = -100.0f; - engine->idle.currentIdlePosition = -100.0f; + engine->module().unmock().idleState = INIT; + engine->module().unmock().baseIdlePosition = -100.0f; + engine->module().unmock().currentIdlePosition = -100.0f; #if ! EFI_UNIT_TEST diff --git a/firmware/controllers/actuators/idle_thread.h b/firmware/controllers/actuators/idle_thread.h index 07769daf35..345bbef74a 100644 --- a/firmware/controllers/actuators/idle_thread.h +++ b/firmware/controllers/actuators/idle_thread.h @@ -31,7 +31,7 @@ struct IIdleController { virtual float getCrankingTaperFraction() const = 0; }; -class IdleController : public IIdleController, public EngineModule { +class IdleController : public IIdleController, public EngineModule, public idle_state_s { public: typedef IIdleController interface_t; diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 9aad45aee8..b0e4ab232e 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -343,7 +343,7 @@ void Engine::updateSwitchInputs() { engine->clutchUpState = getClutchUpState(); if (isBrainPinValid(engineConfiguration->throttlePedalUpPin)) { - engine->idle.throttlePedalUpState = efiReadPin(engineConfiguration->throttlePedalUpPin); + engine->module().unmock().throttlePedalUpState = efiReadPin(engineConfiguration->throttlePedalUpPin); } engine->brakePedalState = getBrakePedalState(); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index e13615350d..9de6f36763 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -385,7 +385,6 @@ public: */ void onTriggerSignalEvent(); EngineState engineState; - idle_state_s idle; /** * idle blip is a development tool: alternator PID research for instance have benefited from a repetitive change of RPM */