better constraint validation & refacoting

This commit is contained in:
rusefi 2017-04-12 23:25:58 -04:00
parent 7a76a83695
commit 8c6253f198
6 changed files with 17 additions and 11 deletions

View File

@ -494,7 +494,7 @@ void updateDevConsoleState(void) {
static void showFuelInfo2(float rpm, float engineLoad) {
float baseFuelMs = getBaseTableFuel(engineConfiguration, (int) rpm, engineLoad);
float baseFuelMs = getBaseTableFuel((int) rpm, engineLoad);
float magicAir = getAirMass(engineConfiguration, 1, 100, convertCelsiusToKelvin(20));

View File

@ -230,9 +230,8 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) {
currentVE = baroCorrection * veMap.getValue(rpm, map) * 0.01;
targetAFR = afrMap.getValue(rpm, map);
} else {
baseTableFuel = getBaseTableFuel(engineConfiguration, rpm, engineLoad);
baseTableFuel = getBaseTableFuel(rpm, engineLoad);
}
}

View File

@ -79,13 +79,15 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_S) {
floatms_t baseFuel;
if (CONFIG(fuelAlgorithm) == LM_SPEED_DENSITY) {
baseFuel = getSpeedDensityFuel(PASS_ENGINE_PARAMETER_F);
efiAssert(!cisnan(baseFuel), "NaN sd baseFuel", 0);
} else if (engineConfiguration->fuelAlgorithm == LM_REAL_MAF) {
float maf = getRealMaf(PASS_ENGINE_PARAMETER_F) + engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_F);
baseFuel = getRealMafFuel(maf, rpm PASS_ENGINE_PARAMETER);
efiAssert(!cisnan(baseFuel), "NaN rm baseFuel", 0);
} else {
baseFuel = engine->engineState.baseTableFuel;
efiAssert(!cisnan(baseFuel), "NaN bt baseFuel", 0);
}
efiAssert(!cisnan(baseFuel), "NaN baseFuel", 0);
engine->engineState.baseFuel = baseFuel;
return tpsAccelEnrich + baseFuel;
@ -215,7 +217,7 @@ float getIatFuelCorrection(float iat DECLARE_ENGINE_PARAMETER_S) {
/**
* @return Fuel injection duration injection as specified in the fuel map, in milliseconds
*/
floatms_t getBaseTableFuel(engine_configuration_s *engineConfiguration, int rpm, float engineLoad) {
floatms_t getBaseTableFuel(int rpm, float engineLoad) {
if (cisnan(engineLoad)) {
warning(CUSTOM_NAN_ENGINE_LOAD_2, "NaN engine load");
return NAN;

View File

@ -24,7 +24,7 @@ floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_S);
floatms_t getRealMafFuel(float airMass, int rpm DECLARE_ENGINE_PARAMETER_S);
floatms_t getBaseTableFuel(engine_configuration_s *engineConfiguration, int rpm, float engineLoad);
floatms_t getBaseTableFuel(int rpm, float engineLoad);
float getBaroCorrection(DECLARE_ENGINE_PARAMETER_F);
int getNumberOfInjections(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S);
angle_t getinjectionOffset(float rpm DECLARE_ENGINE_PARAMETER_S);

View File

@ -80,17 +80,22 @@ floatms_t getSpeedDensityFuel(DECLARE_ENGINE_PARAMETER_F) {
* most of the values are pre-calculated for performance reasons
*/
float tChargeK = ENGINE(engineState.tChargeK);
efiAssert(!cisnan(tChargeK), "NaN tChargeK", 0);
float map = getMap();
efiAssert(!cisnan(map), "NaN map", 0);
float adjustedMap = map + engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_F);
efiAssert(!cisnan(adjustedMap), "NaN adjustedMap", 0);
engine->engineState.airMass = getAirMass(engineConfiguration, ENGINE(engineState.currentVE), adjustedMap, tChargeK);
float airMass = getAirMass(engineConfiguration, ENGINE(engineState.currentVE), adjustedMap, tChargeK);
efiAssert(!cisnan(airMass), "NaN airMass", 0);
#if EFI_PRINTF_FUEL_DETAILS || defined(__DOXYGEN__)
printf("map=%f adjustedMap=%f airMass=%f\t\n",
map, adjustedMap, engine->engineState.airMass);
#endif /*EFI_PRINTF_FUEL_DETAILS */
return sdMath(engineConfiguration, engine->engineState.airMass, ENGINE(engineState.targetAFR)) * 1000;
engine->engineState.airMass = airMass;
return sdMath(engineConfiguration, airMass, ENGINE(engineState.targetAFR)) * 1000;
}
static const baro_corr_table_t default_baro_corr = {

View File

@ -51,7 +51,7 @@ void testFuelMap(void) {
for (int i = 0; i < FUEL_RPM_COUNT; i++)
eth.engine.config->fuelRpmBins[i] = i;
assertEqualsM("base fuel table", 1005, getBaseTableFuel(eth.engine.engineConfiguration, 5, 5));
assertEqualsM("base fuel table", 1005, getBaseTableFuel(5, 5));
printf("*************************************************** initThermistors\r\n");
@ -70,7 +70,7 @@ void testFuelMap(void) {
// because all the correction tables are zero
printf("*************************************************** getRunningFuel 1\r\n");
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_F);
float baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(PASS_ENGINE_PARAMETER_F));
float baseFuel = getBaseTableFuel(5, getEngineLoadT(PASS_ENGINE_PARAMETER_F));
assertEqualsM("base fuel", 5.05, getRunningFuel(baseFuel PASS_ENGINE_PARAMETER));
printf("*************************************************** setting IAT table\r\n");
@ -102,7 +102,7 @@ void testFuelMap(void) {
// 1005 * 2 for IAT correction
printf("*************************************************** getRunningFuel 2\r\n");
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_F);
baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(PASS_ENGINE_PARAMETER_F));
baseFuel = getBaseTableFuel(5, getEngineLoadT(PASS_ENGINE_PARAMETER_F));
assertEqualsM("v1", 30150, getRunningFuel(baseFuel PASS_ENGINE_PARAMETER));
testMafValue = 0;