This commit is contained in:
rusefi 2020-04-12 17:47:49 -04:00
commit 78a6026f54
2 changed files with 19 additions and 13 deletions

View File

@ -145,23 +145,29 @@ floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_SUFFIX) {
* @return total duration of fuel injection per engine cycle, in milliseconds * @return total duration of fuel injection per engine cycle, in milliseconds
*/ */
float getRealMafFuel(float airSpeed, int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { float getRealMafFuel(float airSpeed, int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
if (rpm == 0) // If the engine is stopped, MAF is meaningless
if (rpm == 0) {
return 0; return 0;
// duration of engine cycle, in hours }
float engineCycleDurationHr = 1.0 / 60 / rpm;
float airMassKg = airSpeed * engineCycleDurationHr; // kg/hr -> g/s
float gramPerSecond = airSpeed * 1000 / 3600;
/** // 1/min -> 1/s
* todo: pre-calculate gramm/second injector flow to save one multiplication float revsPerSecond = rpm / 60.0f;
* open question if that's needed since that's just a multiplication
*/
float injectorFlowRate = cc_minute_to_gramm_second(engineConfiguration->injector.flow);
float afr = afrMap.getValue(rpm, airSpeed); float airPerRevolution = gramPerSecond / revsPerSecond;
float fuelMassGramm = airMassKg / afr * 1000;
return 1000 * fuelMassGramm / injectorFlowRate; // Now we have to divide among cylinders - on a 4 stroke, half of the cylinders happen every rev
// This math is floating point to work properly on engines with odd cyl count
float halfCylCount = CONFIG(specs.cylindersCount) / 2.0f;
float cylinderAirmass = airPerRevolution / halfCylCount;
float fuelMassGram = cylinderAirmass / afrMap.getValue(rpm, airSpeed);
float pulseWidthSeconds = fuelMassGram / cc_minute_to_gramm_second(engineConfiguration->injector.flow);
// Convert to ms
return 1000 * pulseWidthSeconds;
} }
/** /**

View File

@ -27,7 +27,7 @@ TEST(misc, testMafFuelMath) {
setAfrMap(config->afrTable, 13); setAfrMap(config->afrTable, 13);
float fuelMs = getRealMafFuel(300, 6000 PASS_ENGINE_PARAMETER_SUFFIX); float fuelMs = getRealMafFuel(300, 6000 PASS_ENGINE_PARAMETER_SUFFIX);
assertEqualsM("fuelMs", 26.7099, fuelMs); assertEqualsM("fuelMs", 13.3550, fuelMs);
} }
TEST(misc, testFuelMap) { TEST(misc, testFuelMap) {