- knock fuel trim + diasble suppression then deceleration (#7017)
* - knock fuel trim - knock disable suppression then deceleration * - knock disable suppression then deceleration syntax fix * - knock disable suppression for test reapply * - knock disable suppression for test reapply fix --------- Co-authored-by: 3er0.1ive <3er0.1ive@veeroute.com>
This commit is contained in:
parent
b25d5e635f
commit
cd404d4f47
|
@ -202,9 +202,10 @@ void EngineState::periodicFastCallback() {
|
|||
uint8_t bankIndex = engineConfiguration->cylinderBankSelect[i];
|
||||
auto bankTrim = engine->engineState.stftCorrection[bankIndex];
|
||||
auto cylinderTrim = getCylinderFuelTrim(i, rpm, fuelLoad);
|
||||
auto knockTrim = engine->module<KnockController>()->getFuelTrimMultiplier();
|
||||
|
||||
// Apply both per-bank and per-cylinder trims
|
||||
engine->engineState.injectionMass[i] = untrimmedInjectionMass * bankTrim * cylinderTrim;
|
||||
engine->engineState.injectionMass[i] = untrimmedInjectionMass * bankTrim * cylinderTrim * knockTrim;
|
||||
// todo: is it OK to apply cylinder trim with FIXED timing?
|
||||
timingAdvance[i] = correctedIgnitionAdvance + getCylinderIgnitionTrim(i, rpm, l_ignitionLoad);
|
||||
}
|
||||
|
|
|
@ -66,11 +66,20 @@ void KnockControllerBase::onKnockSenseCompleted(uint8_t cylinderNumber, float db
|
|||
auto retardFraction = engineConfiguration->knockRetardAggression * 0.01f;
|
||||
auto retardAmount = distToMinimum * retardFraction;
|
||||
|
||||
auto trimFuelFraction = engineConfiguration->knockFuelTrimAggression * 0.01f;
|
||||
float trimFuelPersent = clampF(0.0, (float)engineConfiguration->knockFuelTrim, 30.0);
|
||||
float trimFuelCoeff = (trimFuelPersent / 100.f);
|
||||
float trimFuelAmount = trimFuelCoeff * trimFuelFraction;
|
||||
|
||||
{
|
||||
// Adjust knock retard under lock
|
||||
chibios_rt::CriticalSectionLocker csl;
|
||||
|
||||
auto newRetard = m_knockRetard + retardAmount;
|
||||
m_knockRetard = clampF(0, newRetard, m_maximumRetard);
|
||||
|
||||
auto newFuelTrim = m_knockFuelTrimMultiplier + trimFuelAmount;
|
||||
m_knockFuelTrimMultiplier = clampF(0.0, newFuelTrim, 0.3); // TODO: remove magic 30%
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,20 +92,35 @@ uint32_t KnockControllerBase::getKnockCount() const {
|
|||
return m_knockCount;
|
||||
}
|
||||
|
||||
float KnockControllerBase::getFuelTrimMultiplier() const {
|
||||
return 1.0 + m_knockFuelTrimMultiplier;
|
||||
}
|
||||
|
||||
void KnockControllerBase::onFastCallback() {
|
||||
m_knockThreshold = getKnockThreshold();
|
||||
m_maximumRetard = getMaximumRetard();
|
||||
|
||||
constexpr auto callbackPeriodSeconds = FAST_CALLBACK_PERIOD_MS / 1000.0f;
|
||||
|
||||
auto applyAmount = engineConfiguration->knockRetardReapplyRate * callbackPeriodSeconds;
|
||||
auto applyRetardAmount = engineConfiguration->knockRetardReapplyRate * callbackPeriodSeconds;
|
||||
auto applyFuelAmount = engineConfiguration->knockFuelTrimReapplyRate * callbackPeriodSeconds;
|
||||
|
||||
// disable knock suppression then deceleration
|
||||
auto TPSValue = Sensor::getOrZero(SensorType::Tps1);
|
||||
|
||||
{
|
||||
// Adjust knock retard under lock
|
||||
chibios_rt::CriticalSectionLocker csl;
|
||||
|
||||
|
||||
if(TPSValue < engineConfiguration->knockSuppressMinTps) {
|
||||
m_knockRetard = 0.0;
|
||||
m_knockFuelTrimMultiplier = 0.0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Reduce knock retard at the requested rate
|
||||
float newRetard = m_knockRetard - applyAmount;
|
||||
float newRetard = m_knockRetard - applyRetardAmount;
|
||||
|
||||
// don't allow retard to go negative
|
||||
if (newRetard < 0) {
|
||||
|
@ -104,6 +128,16 @@ void KnockControllerBase::onFastCallback() {
|
|||
} else {
|
||||
m_knockRetard = newRetard;
|
||||
}
|
||||
|
||||
// Reduce fuel trim at the requested rate
|
||||
float newTrim = m_knockFuelTrimMultiplier - applyFuelAmount;
|
||||
|
||||
// don't allow retard to go negative
|
||||
if (newTrim < 0) {
|
||||
m_knockFuelTrimMultiplier = 0;
|
||||
} else {
|
||||
m_knockFuelTrimMultiplier = newTrim;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
// onKnockSenseCompleted is the callback from the knock sense driver to report a sensed knock level
|
||||
void onKnockSenseCompleted(uint8_t cylinderNumber, float dbv, efitick_t lastKnockTime);
|
||||
|
||||
float getFuelTrimMultiplier() const;
|
||||
float getKnockRetard() const;
|
||||
uint32_t getKnockCount() const;
|
||||
|
||||
|
|
|
@ -63,6 +63,9 @@ TEST(Knock, Reapply) {
|
|||
// Apply 1 degree/second
|
||||
engineConfiguration->knockRetardReapplyRate = 1;
|
||||
|
||||
// disable suppress for test
|
||||
engineConfiguration->knockSuppressMinTps = 0;
|
||||
|
||||
// Send a strong knock!
|
||||
dut.onKnockSenseCompleted(0, 30, 0);
|
||||
|
||||
|
|
Loading…
Reference in New Issue