better constraint validation & refacoting
This commit is contained in:
parent
7a76a83695
commit
8c6253f198
|
@ -494,7 +494,7 @@ void updateDevConsoleState(void) {
|
||||||
|
|
||||||
static void showFuelInfo2(float rpm, float engineLoad) {
|
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));
|
float magicAir = getAirMass(engineConfiguration, 1, 100, convertCelsiusToKelvin(20));
|
||||||
|
|
||||||
|
|
|
@ -230,9 +230,8 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) {
|
||||||
currentVE = baroCorrection * veMap.getValue(rpm, map) * 0.01;
|
currentVE = baroCorrection * veMap.getValue(rpm, map) * 0.01;
|
||||||
targetAFR = afrMap.getValue(rpm, map);
|
targetAFR = afrMap.getValue(rpm, map);
|
||||||
} else {
|
} else {
|
||||||
baseTableFuel = getBaseTableFuel(engineConfiguration, rpm, engineLoad);
|
baseTableFuel = getBaseTableFuel(rpm, engineLoad);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -79,13 +79,15 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_S) {
|
||||||
floatms_t baseFuel;
|
floatms_t baseFuel;
|
||||||
if (CONFIG(fuelAlgorithm) == LM_SPEED_DENSITY) {
|
if (CONFIG(fuelAlgorithm) == LM_SPEED_DENSITY) {
|
||||||
baseFuel = getSpeedDensityFuel(PASS_ENGINE_PARAMETER_F);
|
baseFuel = getSpeedDensityFuel(PASS_ENGINE_PARAMETER_F);
|
||||||
|
efiAssert(!cisnan(baseFuel), "NaN sd baseFuel", 0);
|
||||||
} else if (engineConfiguration->fuelAlgorithm == LM_REAL_MAF) {
|
} else if (engineConfiguration->fuelAlgorithm == LM_REAL_MAF) {
|
||||||
float maf = getRealMaf(PASS_ENGINE_PARAMETER_F) + engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_F);
|
float maf = getRealMaf(PASS_ENGINE_PARAMETER_F) + engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_F);
|
||||||
baseFuel = getRealMafFuel(maf, rpm PASS_ENGINE_PARAMETER);
|
baseFuel = getRealMafFuel(maf, rpm PASS_ENGINE_PARAMETER);
|
||||||
|
efiAssert(!cisnan(baseFuel), "NaN rm baseFuel", 0);
|
||||||
} else {
|
} else {
|
||||||
baseFuel = engine->engineState.baseTableFuel;
|
baseFuel = engine->engineState.baseTableFuel;
|
||||||
|
efiAssert(!cisnan(baseFuel), "NaN bt baseFuel", 0);
|
||||||
}
|
}
|
||||||
efiAssert(!cisnan(baseFuel), "NaN baseFuel", 0);
|
|
||||||
engine->engineState.baseFuel = baseFuel;
|
engine->engineState.baseFuel = baseFuel;
|
||||||
|
|
||||||
return tpsAccelEnrich + 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
|
* @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)) {
|
if (cisnan(engineLoad)) {
|
||||||
warning(CUSTOM_NAN_ENGINE_LOAD_2, "NaN engine load");
|
warning(CUSTOM_NAN_ENGINE_LOAD_2, "NaN engine load");
|
||||||
return NAN;
|
return NAN;
|
||||||
|
|
|
@ -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 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);
|
float getBaroCorrection(DECLARE_ENGINE_PARAMETER_F);
|
||||||
int getNumberOfInjections(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S);
|
int getNumberOfInjections(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S);
|
||||||
angle_t getinjectionOffset(float rpm DECLARE_ENGINE_PARAMETER_S);
|
angle_t getinjectionOffset(float rpm DECLARE_ENGINE_PARAMETER_S);
|
||||||
|
|
|
@ -80,17 +80,22 @@ floatms_t getSpeedDensityFuel(DECLARE_ENGINE_PARAMETER_F) {
|
||||||
* most of the values are pre-calculated for performance reasons
|
* most of the values are pre-calculated for performance reasons
|
||||||
*/
|
*/
|
||||||
float tChargeK = ENGINE(engineState.tChargeK);
|
float tChargeK = ENGINE(engineState.tChargeK);
|
||||||
|
efiAssert(!cisnan(tChargeK), "NaN tChargeK", 0);
|
||||||
float map = getMap();
|
float map = getMap();
|
||||||
|
efiAssert(!cisnan(map), "NaN map", 0);
|
||||||
|
|
||||||
float adjustedMap = map + engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_F);
|
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__)
|
#if EFI_PRINTF_FUEL_DETAILS || defined(__DOXYGEN__)
|
||||||
printf("map=%f adjustedMap=%f airMass=%f\t\n",
|
printf("map=%f adjustedMap=%f airMass=%f\t\n",
|
||||||
map, adjustedMap, engine->engineState.airMass);
|
map, adjustedMap, engine->engineState.airMass);
|
||||||
#endif /*EFI_PRINTF_FUEL_DETAILS */
|
#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 = {
|
static const baro_corr_table_t default_baro_corr = {
|
||||||
|
|
|
@ -51,7 +51,7 @@ void testFuelMap(void) {
|
||||||
for (int i = 0; i < FUEL_RPM_COUNT; i++)
|
for (int i = 0; i < FUEL_RPM_COUNT; i++)
|
||||||
eth.engine.config->fuelRpmBins[i] = 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");
|
printf("*************************************************** initThermistors\r\n");
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ void testFuelMap(void) {
|
||||||
// because all the correction tables are zero
|
// because all the correction tables are zero
|
||||||
printf("*************************************************** getRunningFuel 1\r\n");
|
printf("*************************************************** getRunningFuel 1\r\n");
|
||||||
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_F);
|
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));
|
assertEqualsM("base fuel", 5.05, getRunningFuel(baseFuel PASS_ENGINE_PARAMETER));
|
||||||
|
|
||||||
printf("*************************************************** setting IAT table\r\n");
|
printf("*************************************************** setting IAT table\r\n");
|
||||||
|
@ -102,7 +102,7 @@ void testFuelMap(void) {
|
||||||
// 1005 * 2 for IAT correction
|
// 1005 * 2 for IAT correction
|
||||||
printf("*************************************************** getRunningFuel 2\r\n");
|
printf("*************************************************** getRunningFuel 2\r\n");
|
||||||
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_F);
|
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));
|
assertEqualsM("v1", 30150, getRunningFuel(baseFuel PASS_ENGINE_PARAMETER));
|
||||||
|
|
||||||
testMafValue = 0;
|
testMafValue = 0;
|
||||||
|
|
Loading…
Reference in New Issue