RE usability: live data for idle controller

This commit is contained in:
rusefillc 2022-01-10 19:48:45 -05:00
parent e064beb840
commit 6ee0a55eaf
5 changed files with 31 additions and 32 deletions

View File

@ -212,7 +212,7 @@ static const void * getStructAddr(live_data_e structId) {
// return static_cast<pid_state_s*>(getIdlePid()); // return static_cast<pid_state_s*>(getIdlePid());
//#endif /* EFI_IDLE_CONTROL */ //#endif /* EFI_IDLE_CONTROL */
case LDS_idle_state: case LDS_idle_state:
return static_cast<idle_state_s*>(&engine->idle); return static_cast<idle_state_s*>(&engine->module<IdleController>().unmock());
case LDS_tps_accel_state: case LDS_tps_accel_state:
return static_cast<tps_accel_state_s*>(&engine->tpsAccelEnrichment); return static_cast<tps_accel_state_s*>(&engine->tpsAccelEnrichment);
case LDS_main_relay: case LDS_main_relay:

View File

@ -118,7 +118,7 @@ void setIdleMode(idle_mode_e value) {
} }
percent_t getIdlePosition() { percent_t getIdlePosition() {
return engine->idle.currentIdlePosition; return engine->module<IdleController>().unmock().currentIdlePosition;
} }
void setManualIdleValvePosition(int positionPercent) { void setManualIdleValvePosition(int positionPercent) {
@ -135,9 +135,9 @@ void setManualIdleValvePosition(int positionPercent) {
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
void IdleController::init(pid_s* idlePidConfig) { void IdleController::init(pid_s* idlePidConfig) {
engine->idle.shouldResetPid = false; shouldResetPid = false;
engine->idle.mightResetPid = false; mightResetPid = false;
engine->idle.wasResetPid = false; wasResetPid = false;
m_timingPid.initPidClass(idlePidConfig); m_timingPid.initPidClass(idlePidConfig);
} }
@ -302,15 +302,15 @@ static void undoIdleBlipIfNeeded() {
float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos, int rpm, int targetRpm) { float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos, int rpm, int targetRpm) {
auto idlePid = getIdlePid(); 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 // 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(); idlePid->reset();
engine->idle.mustResetPid = false; mustResetPid = false;
} }
// alternatorPidResetCounter++; // alternatorPidResetCounter++;
engine->idle.shouldResetPid = false; shouldResetPid = false;
engine->idle.wasResetPid = true; wasResetPid = true;
} }
// todo: move this to pid_s one day // 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) { if (phase != IIdleController::Phase::Idling) {
// 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.
// Otherwise they will affect the idle position much later, when the throttle is closed. // Otherwise they will affect the idle position much later, when the throttle is closed.
if (engine->idle.mightResetPid) { if (mightResetPid) {
engine->idle.mightResetPid = false; mightResetPid = false;
engine->idle.shouldResetPid = true; 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. // We aren't idling, so don't apply any correction. A positive correction could inhibit a return to idle.
m_lastAutomaticPosition = 0; m_lastAutomaticPosition = 0;
@ -338,7 +338,7 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos,
bool acToggleJustTouched = (nowUs - engine->acSwitchLastChangeTime) < MS2US(500); bool acToggleJustTouched = (nowUs - engine->acSwitchLastChangeTime) < MS2US(500);
// check if within the dead zone // check if within the dead zone
if (!acToggleJustTouched && absI(rpm - targetRpm) <= engineConfiguration->idlePidRpmDeadZone) { 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 // current RPM is close enough, no need to change anything
return m_lastAutomaticPosition; 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 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; restoreAfterPidResetTimeUs = nowUs;
engine->idle.wasResetPid = false; wasResetPid = false;
} }
// increase the errorAmpCoef slowly to restore the process correctly after the PID reset // increase the errorAmpCoef slowly to restore the process correctly after the PID reset
// todo: move restoreAfterPidResetTimeUs to idle? // todo: move restoreAfterPidResetTimeUs to idle?
@ -364,10 +364,10 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos,
idlePid->setErrorAmplification(errorAmpCoef); idlePid->setErrorAmplification(errorAmpCoef);
percent_t newValue = idlePid->getOutput(targetRpm, rpm, SLOW_CALLBACK_PERIOD_MS / 1000.0f); 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) // 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 // Apply PID Multiplier if used
if (engineConfiguration->useIacPidMultTable) { if (engineConfiguration->useIacPidMultTable) {
@ -434,7 +434,7 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos,
bool isAutomaticIdle = tps.Valid && engineConfiguration->idleMode == IM_AUTO; bool isAutomaticIdle = tps.Valid && engineConfiguration->idleMode == IM_AUTO;
if (engineConfiguration->isVerboseIAC && isAutomaticIdle) { 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"); getIdlePid()->showPidStatus("idle");
} }
@ -445,11 +445,11 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos,
if (engine->timeToStopBlip != 0) { if (engine->timeToStopBlip != 0) {
iacPosition = engine->blipIdlePosition; iacPosition = engine->blipIdlePosition;
engine->idle.idleState = BLIP; idleState = BLIP;
} else { } else {
// Always apply closed loop correction // Always apply closed loop correction
iacPosition = getOpenLoop(phase, clt, tps, crankingTaper); 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 is working and automatic mode enabled, add any automatic correction
if (tps.Valid && engineConfiguration->idleMode == IM_AUTO) { if (tps.Valid && engineConfiguration->idleMode == IM_AUTO) {
@ -466,7 +466,7 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos,
if (engineConfiguration->idleMode == IM_AUTO) { if (engineConfiguration->idleMode == IM_AUTO) {
// see also tsOutputChannels->idlePosition // see also tsOutputChannels->idlePosition
getIdlePid()->postState(&engine->outputChannels.idleStatus); getIdlePid()->postState(&engine->outputChannels.idleStatus);
engine->outputChannels.idleState = engine->idle.idleState; engine->outputChannels.idleState = idleState;
} else { } else {
engine->outputChannels.idleCurrentPosition = iacPosition; engine->outputChannels.idleCurrentPosition = iacPosition;
extern StepperMotor iacMotor; extern StepperMotor iacMotor;
@ -474,7 +474,7 @@ float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos,
} }
#endif /* EFI_TUNER_STUDIO */ #endif /* EFI_TUNER_STUDIO */
engine->idle.currentIdlePosition = iacPosition; currentIdlePosition = iacPosition;
return iacPosition; return iacPosition;
} }
@ -511,8 +511,8 @@ void setDefaultIdleParameters() {
void IdleController::onConfigurationChange(engine_configuration_s const * previousConfiguration) { void IdleController::onConfigurationChange(engine_configuration_s const * previousConfiguration) {
#if ! EFI_UNIT_TEST #if ! EFI_UNIT_TEST
engine->idle.shouldResetPid = !getIdlePid()->isSame(&previousConfiguration->idleRpmPid); shouldResetPid = !getIdlePid()->isSame(&previousConfiguration->idleRpmPid);
engine->idle.mustResetPid = engine->idle.shouldResetPid; mustResetPid = shouldResetPid;
#endif #endif
} }
@ -569,9 +569,9 @@ void startIdleThread() {
initIdleHardware(); initIdleHardware();
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
engine->idle.idleState = INIT; engine->module<IdleController>().unmock().idleState = INIT;
engine->idle.baseIdlePosition = -100.0f; engine->module<IdleController>().unmock().baseIdlePosition = -100.0f;
engine->idle.currentIdlePosition = -100.0f; engine->module<IdleController>().unmock().currentIdlePosition = -100.0f;
#if ! EFI_UNIT_TEST #if ! EFI_UNIT_TEST

View File

@ -31,7 +31,7 @@ struct IIdleController {
virtual float getCrankingTaperFraction() const = 0; virtual float getCrankingTaperFraction() const = 0;
}; };
class IdleController : public IIdleController, public EngineModule { class IdleController : public IIdleController, public EngineModule, public idle_state_s {
public: public:
typedef IIdleController interface_t; typedef IIdleController interface_t;

View File

@ -343,7 +343,7 @@ void Engine::updateSwitchInputs() {
engine->clutchUpState = getClutchUpState(); engine->clutchUpState = getClutchUpState();
if (isBrainPinValid(engineConfiguration->throttlePedalUpPin)) { if (isBrainPinValid(engineConfiguration->throttlePedalUpPin)) {
engine->idle.throttlePedalUpState = efiReadPin(engineConfiguration->throttlePedalUpPin); engine->module<IdleController>().unmock().throttlePedalUpState = efiReadPin(engineConfiguration->throttlePedalUpPin);
} }
engine->brakePedalState = getBrakePedalState(); engine->brakePedalState = getBrakePedalState();

View File

@ -385,7 +385,6 @@ public:
*/ */
void onTriggerSignalEvent(); void onTriggerSignalEvent();
EngineState engineState; 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 * idle blip is a development tool: alternator PID research for instance have benefited from a repetitive change of RPM
*/ */