better field name

This commit is contained in:
rusefi 2017-11-06 22:29:39 -05:00
parent 286964563c
commit f839afeb54
6 changed files with 42 additions and 32 deletions

View File

@ -141,7 +141,7 @@ void Engine::reset() {
timeOfLastKnockEvent = 0;
fuelMs = 0;
injectionDuration = 0;
clutchDownState = clutchUpState = brakePedalState = false;
memset(&m, 0, sizeof(m));
@ -427,7 +427,7 @@ void Engine::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
engineState.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
engine->m.beforeFuelCalc = GET_TIMESTAMP();
ENGINE(fuelMs) = getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX);
ENGINE(injectionDuration) = getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX);
engine->m.fuelCalcTime = GET_TIMESTAMP() - engine->m.beforeFuelCalc;
}

View File

@ -346,8 +346,9 @@ public:
/**
* Each individual fuel injection duration for current engine cycle, without wall wetting
* including everything including injector lag, both cranking and running
* @see getInjectionDuration()
*/
floatms_t fuelMs;
floatms_t injectionDuration;
/**
* fuel injection time correction to account for wall wetting effect, for current cycle
*/

View File

@ -70,7 +70,10 @@ float getRealMafFuel(float airSpeed, int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
return 1000 * fuelMassGramm / injectorFlowRate;
}
// todo: rename this method since it's now base+TPSaccel
/**
* per-cylinder fuel amount
* todo: rename this method since it's now base+TPSaccel
*/
floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
floatms_t tpsAccelEnrich = ENGINE(tpsAccelEnrichment.getTpsEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE));
efiAssert(!cisnan(tpsAccelEnrich), "NaN tpsAccelEnrich", 0);
@ -101,18 +104,18 @@ angle_t getinjectionOffset(float rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
}
/**
* Number of injections into each cylinder per engine cycle
* Number of injections using each injector per engine cycle
* @see getNumberOfSparks
*/
int getNumberOfInjections(injection_mode_e mode DECLARE_ENGINE_PARAMETER_SUFFIX) {
switch (mode) {
case IM_SIMULTANEOUS:
return engineConfiguration->specs.cylindersCount;
case IM_SEQUENTIAL:
case IM_SINGLE_POINT:
return 1;
return engineConfiguration->specs.cylindersCount;
case IM_BATCH:
return 2;
case IM_SEQUENTIAL:
return 1;
default:
firmwareError(CUSTOM_ERR_INVALID_INJECTION_MODE, "Unexpected injection_mode_e %d", mode);
return 1;
@ -123,37 +126,43 @@ int getNumberOfInjections(injection_mode_e mode DECLARE_ENGINE_PARAMETER_SUFFIX)
* @see getCoilDutyCycle
*/
percent_t getInjectorDutyCycle(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
floatms_t totalPerCycle = getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX) * getNumberOfInjections(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER_SUFFIX);
floatms_t totalInjectiorAmountPerCycle = getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX) * getNumberOfInjections(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER_SUFFIX);
floatms_t engineCycleDuration = getEngineCycleDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX);
return 100 * totalPerCycle / engineCycleDuration;
return 100 * totalInjectiorAmountPerCycle / engineCycleDuration;
}
/**
* @returns Length of each individual fuel injection, in milliseconds
* in case of single point injection mode the amount of fuel into all cylinders, otherwise the amount for one cylinder
*/
floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
float theoreticalInjectionLength;
bool isCranking = ENGINE(rpmCalculator).isCranking(PASS_ENGINE_PARAMETER_SIGNATURE);
int numberOfInjections = getNumberOfInjections(isCranking ?
injection_mode_e mode = isCranking ?
engineConfiguration->crankingInjectionMode :
engineConfiguration->injectionMode PASS_ENGINE_PARAMETER_SUFFIX);
engineConfiguration->injectionMode;
int numberOfInjections = getNumberOfInjections(mode PASS_ENGINE_PARAMETER_SUFFIX);
if (numberOfInjections == 0) {
warning(CUSTOM_CONFIG_NOT_READY, "config not ready");
return 0; // we can end up here during configuration reset
}
floatms_t fuelPerCycle;
if (isCranking) {
theoreticalInjectionLength = getCrankingFuel(PASS_ENGINE_PARAMETER_SIGNATURE) / numberOfInjections;
efiAssert(!cisnan(theoreticalInjectionLength), "NaN cranking theoreticalInjectionLength", 0);
fuelPerCycle = getCrankingFuel(PASS_ENGINE_PARAMETER_SIGNATURE);
efiAssert(!cisnan(fuelPerCycle), "NaN cranking fuelPerCycle", 0);
} else {
floatms_t baseFuel = getBaseFuel(rpm PASS_ENGINE_PARAMETER_SUFFIX);
floatms_t fuelPerCycle = getRunningFuel(baseFuel PASS_ENGINE_PARAMETER_SUFFIX);
theoreticalInjectionLength = fuelPerCycle / numberOfInjections;
efiAssert(!cisnan(theoreticalInjectionLength), "NaN fuelPerCycle", 0);
fuelPerCycle = getRunningFuel(baseFuel PASS_ENGINE_PARAMETER_SUFFIX);
efiAssert(!cisnan(fuelPerCycle), "NaN fuelPerCycle", 0);
#if EFI_PRINTF_FUEL_DETAILS || defined(__DOXYGEN__)
printf("baseFuel=%f fuelPerCycle=%f theoreticalInjectionLength=%f\t\n",
baseFuel, fuelPerCycle, theoreticalInjectionLength);
printf("baseFuel=%f fuelPerCycle=%f \t\n",
baseFuel, fuelPerCycle);
#endif /*EFI_PRINTF_FUEL_DETAILS */
}
if (mode == IM_SINGLE_POINT) {
// here we convert per-cylinder fuel amount into total engine amount since the single injector serves all cylinders
fuelPerCycle *= engineConfiguration->specs.cylindersCount;
}
floatms_t theoreticalInjectionLength = fuelPerCycle / numberOfInjections;
floatms_t injectorLag = ENGINE(engineState.injectorLag);
if (cisnan(injectorLag)) {
warning(CUSTOM_ERR_INJECTOR_LAG, "injectorLag not ready");

View File

@ -124,7 +124,7 @@ bool FuelSchedule::addFuelEventsForCylinder(int i DECLARE_ENGINE_PARAMETER_SUFF
* todo: since this method is not invoked within trigger event handler and
* engineState.injectionOffset is calculated from the same utility timer should we more that logic here?
*/
floatms_t fuelMs = ENGINE(fuelMs);
floatms_t fuelMs = ENGINE(injectionDuration);
efiAssert(!cisnan(fuelMs), "NaN fuelMs", false);
angle_t injectionDuration = MS2US(fuelMs) / oneDegreeUs;
efiAssert(!cisnan(injectionDuration), "NaN injectionDuration", false);

View File

@ -212,9 +212,9 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE
* wetting coefficient works the same way for any injection mode, or is something
* x2 or /2?
*/
const floatms_t injectionDuration = ENGINE(wallFuel).adjust(event->outputs[0]->injectorIndex, ENGINE(fuelMs) PASS_ENGINE_PARAMETER_SUFFIX);
const floatms_t injectionDuration = ENGINE(wallFuel).adjust(event->outputs[0]->injectorIndex, ENGINE(injectionDuration) PASS_ENGINE_PARAMETER_SUFFIX);
#if EFI_PRINTF_FUEL_DETAILS || defined(__DOXYGEN__)
printf("fuel fuelMs=%f adjusted=%f\t\n", ENGINE(fuelMs), injectionDuration);
printf("fuel injectionDuration=%f adjusted=%f\t\n", ENGINE(injectionDuration), injectionDuration);
#endif /*EFI_PRINTF_FUEL_DETAILS */
bool isCranking = ENGINE(rpmCalculator).isCranking(PASS_ENGINE_PARAMETER_SIGNATURE);
@ -376,7 +376,7 @@ static ALWAYS_INLINE void handleFuel(const bool limitedFuel, uint32_t trgEventIn
ENGINE(tpsAccelEnrichment.onNewValue(getTPS(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX));
ENGINE(engineLoadAccelEnrichment.onEngineCycle(PASS_ENGINE_PARAMETER_SIGNATURE));
ENGINE(fuelMs) = getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX);
ENGINE(injectionDuration) = getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX);
for (int injEventIndex = 0; injEventIndex < CONFIG(specs.cylindersCount); injEventIndex++) {
InjectionEvent *event = &fs->elements[injEventIndex];

View File

@ -350,7 +350,7 @@ void testRpmCalculator(void) {
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("fuel #1", 4.5450, eth.engine.fuelMs);
assertEqualsM("fuel #1", 4.5450, eth.engine.injectionDuration);
InjectionEvent *ie0 = &eth.engine.injectionEvents.elements[0];
assertEqualsM("injection angle", 31.365, ie0->injectionStart.angleOffset);
@ -358,7 +358,7 @@ void testRpmCalculator(void) {
assertEquals(1500, eth.engine.rpmCalculator.rpmValue);
assertEqualsM("dwell", 4.5, eth.engine.engineState.dwellAngle);
assertEqualsM("fuel #2", 4.5450, eth.engine.fuelMs);
assertEqualsM("fuel #2", 4.5450, eth.engine.injectionDuration);
assertEqualsM("one degree", 111.1111, eth.engine.rpmCalculator.oneDegreeUs);
assertEqualsM("size #2", 1, ilist->isReady);
assertEqualsM("dwell angle", 0, ilist->elements[0].dwellPosition.eventAngle);
@ -411,7 +411,7 @@ void testRpmCalculator(void) {
assertEqualsM("queue size 4.3", 4, schedulingQueue.size());
assertEqualsM("dwell", 4.5, eth.engine.engineState.dwellAngle);
assertEqualsM("fuel #3", 4.5450, eth.engine.fuelMs);
assertEqualsM("fuel #3", 4.5450, eth.engine.injectionDuration);
assertEquals(1500, eth.engine.rpmCalculator.rpmValue);
assertInjectorUpEvent("ev 0/2", 0, -4849, 2);
@ -755,7 +755,7 @@ static void setTestBug299(EngineTestHelper *eth) {
assertEqualsM("RPM", 3000, engine->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE));
assertEqualsM("fuel#1", 1.5, engine->fuelMs);
assertEqualsM("fuel#1", 1.5, engine->injectionDuration);
assertEqualsM("duty for maf=0", 7.5, getInjectorDutyCycle(engine->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX));
@ -786,7 +786,7 @@ void testFuelSchedulerBug299smallAndMedium(void) {
setArrayValues(fuelMap.pointers[engineLoadIndex + 1], FUEL_RPM_COUNT, 25);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("fuel#2", 12.5, engine->fuelMs);
assertEqualsM("fuel#2", 12.5, engine->injectionDuration);
assertEqualsM("duty for maf=3", 62.5, getInjectorDutyCycle(eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX));
assertEqualsM("qs#1", 4, schedulingQueue.size());
@ -947,7 +947,7 @@ void testFuelSchedulerBug299smallAndMedium(void) {
setArrayValues(fuelMap.pointers[engineLoadIndex], FUEL_RPM_COUNT, 35);
setArrayValues(fuelMap.pointers[engineLoadIndex + 1], FUEL_RPM_COUNT, 35);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("fuel#3", 17.5, engine->fuelMs);
assertEqualsM("fuel#3", 17.5, engine->injectionDuration);
// duty cycle above 75% is a special use-case because 'special' fuel event overlappes the next normal event in batch mode
assertEqualsM("duty for maf=3", 87.5, getInjectorDutyCycle(eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX));
@ -1027,7 +1027,7 @@ void testFuelSchedulerBug299smallAndLarge(void) {
setArrayValues(fuelMap.pointers[engineLoadIndex + 1], FUEL_RPM_COUNT, 35);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("Lfuel#2", 17.5, engine->fuelMs);
assertEqualsM("Lfuel#2", 17.5, engine->injectionDuration);
assertEqualsM("Lduty for maf=3", 87.5, getInjectorDutyCycle(eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX));
@ -1091,7 +1091,7 @@ void testFuelSchedulerBug299smallAndLarge(void) {
setArrayValues(fuelMap.pointers[engineLoadIndex + 1], FUEL_RPM_COUNT, 4);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("Lfuel#4", 2, engine->fuelMs);
assertEqualsM("Lfuel#4", 2, engine->injectionDuration);
assertEqualsM("Lduty for maf=3", 10, getInjectorDutyCycle(eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX));