mirror of https://github.com/rusefi/rusefi-1.git
use phase computation (#2152)
This commit is contained in:
parent
1d4ccfff3f
commit
c8ee9fcf3f
|
@ -305,40 +305,20 @@ static void undoIdleBlipIfNeeded() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isOutOfAutomaticIdleCondition(float rpm, int targetRpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|
||||||
// first, check the pedal threshold
|
|
||||||
if (CONFIG(throttlePedalUpPin) != GPIO_UNASSIGNED) {
|
|
||||||
if (!engine->engineState.idle.throttlePedalUpState) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const auto [valid, pos] = Sensor::get(SensorType::DriverThrottleIntent);
|
|
||||||
|
|
||||||
// Disable auto idle in case of TPS/Pedal failure
|
|
||||||
if (!valid) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pos > CONFIG(idlePidDeactivationTpsThreshold))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// then, check the RPM threshold (if in coasting mode)
|
|
||||||
if (CONFIG(idlePidRpmUpperLimit) > 0) {
|
|
||||||
int idlePidLowerRpm = targetRpm + CONFIG(idlePidRpmDeadZone);
|
|
||||||
int upperRpmLimit = idlePidLowerRpm + CONFIG(idlePidRpmUpperLimit);
|
|
||||||
if (rpm > upperRpmLimit) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return idle valve position percentage for automatic closed loop mode
|
* @return idle valve position percentage for automatic closed loop mode
|
||||||
*/
|
*/
|
||||||
static percent_t automaticIdleController(float tpsPos, float rpm, int targetRpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
static percent_t automaticIdleController(float tpsPos, float rpm, int targetRpm, IIdleController::Phase phase DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
|
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 (getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->getIntegration() <= 0 || mustResetPid) {
|
||||||
|
getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->reset();
|
||||||
|
mustResetPid = false;
|
||||||
|
}
|
||||||
|
// alternatorPidResetCounter++;
|
||||||
|
shouldResetPid = false;
|
||||||
|
wasResetPid = true;
|
||||||
|
}
|
||||||
|
|
||||||
// todo: move this to pid_s one day
|
// todo: move this to pid_s one day
|
||||||
industrialWithOverrideIdlePid.antiwindupFreq = engineConfiguration->idle_antiwindupFreq;
|
industrialWithOverrideIdlePid.antiwindupFreq = engineConfiguration->idle_antiwindupFreq;
|
||||||
|
@ -346,7 +326,7 @@ static percent_t automaticIdleController(float tpsPos, float rpm, int targetRpm
|
||||||
|
|
||||||
efitimeus_t nowUs = getTimeNowUs();
|
efitimeus_t nowUs = getTimeNowUs();
|
||||||
|
|
||||||
if (isOutOfAutomaticIdleCondition(rpm, targetRpm PASS_ENGINE_PARAMETER_SUFFIX)) {
|
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 (mightResetPid) {
|
if (mightResetPid) {
|
||||||
|
@ -453,6 +433,9 @@ static percent_t automaticIdleController(float tpsPos, float rpm, int targetRpm
|
||||||
// Compute the target we're shooting for
|
// Compute the target we're shooting for
|
||||||
auto targetRpm = getTargetRpm(clt);
|
auto targetRpm = getTargetRpm(clt);
|
||||||
|
|
||||||
|
// Determine what operation phase we're in - idling or not
|
||||||
|
auto phase = determinePhase(rpm, targetRpm, tps);
|
||||||
|
|
||||||
engine->engineState.isAutomaticIdle = tps.Valid && engineConfiguration->idleMode == IM_AUTO;
|
engine->engineState.isAutomaticIdle = tps.Valid && engineConfiguration->idleMode == IM_AUTO;
|
||||||
|
|
||||||
if (engineConfiguration->isVerboseIAC && engine->engineState.isAutomaticIdle) {
|
if (engineConfiguration->isVerboseIAC && engine->engineState.isAutomaticIdle) {
|
||||||
|
@ -460,29 +443,13 @@ static percent_t automaticIdleController(float tpsPos, float rpm, int targetRpm
|
||||||
getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->showPidStatus(logger, "idle");
|
getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->showPidStatus(logger, "idle");
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->getIntegration() <= 0 || mustResetPid) {
|
|
||||||
getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->reset();
|
|
||||||
mustResetPid = false;
|
|
||||||
}
|
|
||||||
// alternatorPidResetCounter++;
|
|
||||||
shouldResetPid = false;
|
|
||||||
wasResetPid = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
finishIdleTestIfNeeded();
|
finishIdleTestIfNeeded();
|
||||||
undoIdleBlipIfNeeded();
|
undoIdleBlipIfNeeded();
|
||||||
|
|
||||||
#if EFI_SHAFT_POSITION_INPUT
|
|
||||||
bool isRunning = engine->rpmCalculator.isRunning();
|
|
||||||
#else
|
|
||||||
bool isRunning = false;
|
|
||||||
#endif /* EFI_SHAFT_POSITION_INPUT */
|
|
||||||
// cltCorrection is used only for cranking or running in manual mode
|
// cltCorrection is used only for cranking or running in manual mode
|
||||||
float cltCorrection;
|
float cltCorrection;
|
||||||
// Use separate CLT correction table for cranking
|
// Use separate CLT correction table for cranking
|
||||||
if (engineConfiguration->overrideCrankingIacSetting && !isRunning) {
|
if (engineConfiguration->overrideCrankingIacSetting && phase == IIdleController::Phase::Cranking) {
|
||||||
cltCorrection = interpolate2d("cltCrankingT", clt, config->cltCrankingCorrBins, config->cltCrankingCorr);
|
cltCorrection = interpolate2d("cltCrankingT", clt, config->cltCrankingCorrBins, config->cltCrankingCorr);
|
||||||
} else {
|
} else {
|
||||||
// this value would be ignored if running in AUTO mode
|
// this value would be ignored if running in AUTO mode
|
||||||
|
@ -496,7 +463,7 @@ static percent_t automaticIdleController(float tpsPos, float rpm, int targetRpm
|
||||||
iacPosition = blipIdlePosition;
|
iacPosition = blipIdlePosition;
|
||||||
engine->engineState.idle.baseIdlePosition = iacPosition;
|
engine->engineState.idle.baseIdlePosition = iacPosition;
|
||||||
engine->engineState.idle.idleState = BLIP;
|
engine->engineState.idle.idleState = BLIP;
|
||||||
} else if (!isRunning) {
|
} else if (phase == IIdleController::Phase::Cranking) {
|
||||||
// during cranking it's always manual mode, PID would make no sense during cranking
|
// during cranking it's always manual mode, PID would make no sense during cranking
|
||||||
iacPosition = clampPercentValue(cltCorrection * engineConfiguration->crankingIACposition);
|
iacPosition = clampPercentValue(cltCorrection * engineConfiguration->crankingIACposition);
|
||||||
// save cranking position & cycles counter for taper transition
|
// save cranking position & cycles counter for taper transition
|
||||||
|
@ -508,7 +475,7 @@ static percent_t automaticIdleController(float tpsPos, float rpm, int targetRpm
|
||||||
// let's re-apply CLT correction
|
// let's re-apply CLT correction
|
||||||
iacPosition = manualIdleController(cltCorrection PASS_ENGINE_PARAMETER_SUFFIX);
|
iacPosition = manualIdleController(cltCorrection PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
} else {
|
} else {
|
||||||
iacPosition = automaticIdleController(tps.Value, rpm, targetRpm PASS_ENGINE_PARAMETER_SUFFIX);
|
iacPosition = automaticIdleController(tps.Value, rpm, targetRpm, phase PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
iacPosition = clampPercentValue(iacPosition);
|
iacPosition = clampPercentValue(iacPosition);
|
||||||
|
|
Loading…
Reference in New Issue