This commit is contained in:
parent
db63471651
commit
af518d7978
|
@ -500,9 +500,9 @@ static void showFuelInfo2(float rpm, float engineLoad) {
|
|||
|
||||
float baseFuelMs = getBaseTableFuel((int) rpm, engineLoad);
|
||||
|
||||
float magicAir = getCylinderAirMass(engineConfiguration, 1, 100, convertCelsiusToKelvin(20));
|
||||
float magicAir = getCylinderAirMass(1, 100, convertCelsiusToKelvin(20) PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
scheduleMsg(&logger, "SD magic fuel %.2f", sdMath(engineConfiguration, magicAir, 14.7));
|
||||
scheduleMsg(&logger, "SD magic fuel %.2f", sdMath(magicAir, 14.7 PASS_ENGINE_PARAMETER_SUFFIX));
|
||||
scheduleMsg(&logger, "inj flow %.2fcc/min displacement %.2fL", engineConfiguration->injector.flow,
|
||||
engineConfiguration->specs.displacement);
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ float getTCharge(int rpm, float tps, float coolantTemp, float airTemp DECLARE_EN
|
|||
if (CONFIG(tChargeMode) == TCHARGE_MODE_AIR_INTERP) {
|
||||
const floatms_t gramsPerMsToKgPerHour = (3600.0f * 1000.0f) / 1000.0f;
|
||||
// We're actually using an 'old' airMass calculated for the previous cycle, but it's ok, we're not having any self-excitaton issues
|
||||
floatms_t airMassForEngine = engine->engineState.airMass * engineConfiguration->specs.cylindersCount;
|
||||
floatms_t airMassForEngine = engine->engineState.airMass * CONFIG(specs.cylindersCount);
|
||||
// airMass is in grams per 1 cycle for 1 cyl. Convert it to airFlow in kg/h for the engine.
|
||||
// And if the engine is stopped (0 rpm), then airFlow is also zero (avoiding NaN division)
|
||||
floatms_t airFlow = (rpm == 0) ? 0 : airMassForEngine * gramsPerMsToKgPerHour / getEngineCycleDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
@ -49,10 +49,10 @@ float getTCharge(int rpm, float tps, float coolantTemp, float airTemp DECLARE_EN
|
|||
engine->engineState.airFlow = airFlow;
|
||||
} else {
|
||||
// TCHARGE_MODE_RPM_TPS
|
||||
float minRpmKcurrentTPS = interpolateMsg("minRpm", tpMin, engineConfiguration->tChargeMinRpmMinTps, tpMax,
|
||||
engineConfiguration->tChargeMinRpmMaxTps, tps);
|
||||
float maxRpmKcurrentTPS = interpolateMsg("maxRpm", tpMin, engineConfiguration->tChargeMaxRpmMinTps, tpMax,
|
||||
engineConfiguration->tChargeMaxRpmMaxTps, tps);
|
||||
float minRpmKcurrentTPS = interpolateMsg("minRpm", tpMin, CONFIG(tChargeMinRpmMinTps), tpMax,
|
||||
CONFIG(tChargeMinRpmMaxTps), tps);
|
||||
float maxRpmKcurrentTPS = interpolateMsg("maxRpm", tpMin, CONFIG(tChargeMaxRpmMinTps), tpMax,
|
||||
CONFIG(tChargeMaxRpmMaxTps), tps);
|
||||
|
||||
Tcharge_coff = interpolateMsg("Kcurr", rpmMin, minRpmKcurrentTPS, rpmMax, maxRpmKcurrentTPS, rpm);
|
||||
}
|
||||
|
@ -82,26 +82,26 @@ float getTCharge(int rpm, float tps, float coolantTemp, float airTemp DECLARE_EN
|
|||
/**
|
||||
* @return air mass in grams
|
||||
*/
|
||||
float getCycleAirMass(engine_configuration_s *engineConfiguration, float VE, float MAP, float tempK) {
|
||||
static float getCycleAirMass(float VE, float MAP, float tempK DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
// todo: pre-calculate cylinder displacement to save one division
|
||||
float cylinderDisplacement = engineConfiguration->specs.displacement;
|
||||
float cylinderDisplacement = CONFIG(specs.displacement);
|
||||
return (cylinderDisplacement * VE * MAP) / (GAS_R * tempK);
|
||||
}
|
||||
|
||||
float getCylinderAirMass(engine_configuration_s *engineConfiguration, float VE, float MAP, float tempK) {
|
||||
return getCycleAirMass(engineConfiguration, VE, MAP, tempK) / engineConfiguration->specs.cylindersCount;
|
||||
float getCylinderAirMass(float VE, float MAP, float tempK DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
return getCycleAirMass(VE, MAP, tempK PASS_ENGINE_PARAMETER_SUFFIX) / CONFIG(specs.cylindersCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return per cylinder injection time, in seconds
|
||||
*/
|
||||
float sdMath(engine_configuration_s *engineConfiguration, float airMass, float AFR) {
|
||||
float sdMath(float airMass, float AFR DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
|
||||
/**
|
||||
* todo: pre-calculate gramm/second injector flow to save one multiplication
|
||||
* open question if that's needed since that's just a multiplication
|
||||
*/
|
||||
float injectorFlowRate = cc_minute_to_gramm_second(engineConfiguration->injector.flow);
|
||||
float injectorFlowRate = cc_minute_to_gramm_second(CONFIG(injector.flow));
|
||||
/**
|
||||
* injection_pulse_duration = fuel_mass / injector_flow
|
||||
* fuel_mass = air_mass / target_afr
|
||||
|
@ -131,7 +131,7 @@ floatms_t getSpeedDensityFuel(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
float adjustedMap = map + engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(adjustedMap), "NaN adjustedMap", 0);
|
||||
|
||||
float airMass = getCylinderAirMass(engineConfiguration, ENGINE(engineState.currentVE), adjustedMap, tChargeK);
|
||||
float airMass = getCylinderAirMass(ENGINE(engineState.currentVE), adjustedMap, tChargeK PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
if (cisnan(airMass)) {
|
||||
warning(CUSTOM_ERR_6685, "NaN airMass");
|
||||
return 0;
|
||||
|
@ -142,7 +142,7 @@ floatms_t getSpeedDensityFuel(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
#endif /*EFI_PRINTF_FUEL_DETAILS */
|
||||
|
||||
engine->engineState.airMass = airMass;
|
||||
return sdMath(engineConfiguration, airMass, ENGINE(engineState.targetAFR)) * 1000;
|
||||
return sdMath(airMass, ENGINE(engineState.targetAFR) PASS_ENGINE_PARAMETER_SUFFIX) * 1000;
|
||||
}
|
||||
|
||||
static const baro_corr_table_t default_baro_corr = {
|
||||
|
|
|
@ -9,16 +9,13 @@
|
|||
|
||||
#include "engine.h"
|
||||
|
||||
float getTCharge(int rpm, float tps, float coolantTemp, float airTemp DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void setDetaultVETable(persistent_config_s *config);
|
||||
float getCylinderAirMass(engine_configuration_s *engineConfiguration, float VE, float MAP, float tempK);
|
||||
float getCycleAirMass(engine_configuration_s *engineConfiguration, float VE, float MAP, float tempK);
|
||||
float sdMath(engine_configuration_s *engineConfiguration, float airMass, float AFR);
|
||||
|
||||
#define gramm_second_to_cc_minute(gs) ((gs) / 0.0119997981)
|
||||
|
||||
#define cc_minute_to_gramm_second(ccm) ((ccm) * 0.0119997981)
|
||||
|
||||
float getTCharge(int rpm, float tps, float coolantTemp, float airTemp DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
float getCylinderAirMass(float VE, float MAP, float tempK DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
float sdMath(float airMass, float AFR DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
void setDefaultVETable(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void initSpeedDensity(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
floatms_t getSpeedDensityFuel(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
|
|
@ -49,7 +49,7 @@ TEST(misc, testEngineMath) {
|
|||
engineConfiguration->tChargeAirCoefMax = 0.902f;
|
||||
engineConfiguration->tChargeAirFlowMax = 153.6f;
|
||||
// calc. some airMass given the engine displacement=1.839 and 4 cylinders (FORD_ESCORT_GT)
|
||||
engine->engineState.airMass = getCylinderAirMass(engineConfiguration, /*VE*/1.0f, /*MAP*/100.0f, /*tChargeK*/273.15f + 20.0f);
|
||||
engine->engineState.airMass = getCylinderAirMass(/*VE*/1.0f, /*MAP*/100.0f, /*tChargeK*/273.15f + 20.0f PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
ASSERT_NEAR(0.5464f, engine->engineState.airMass, EPS4D);
|
||||
// calc. airFlow using airMass, and find tCharge
|
||||
ASSERT_FLOAT_EQ(59.1175f, getTCharge(/*RPM*/1000, /*TPS*/0, /*CLT*/90.0f, /*IAT*/20.0f PASS_ENGINE_PARAMETER_SUFFIX));
|
||||
|
|
|
@ -25,10 +25,10 @@ TEST(big, testSpeedDensity) {
|
|||
|
||||
engineConfiguration->injector.flow = gramm_second_to_cc_minute(5.303);
|
||||
|
||||
float airMass = getCylinderAirMass(engineConfiguration, 0.92, 98, 293.16);
|
||||
float airMass = getCylinderAirMass(0.92, 98, 293.16 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
ASSERT_FLOAT_EQ(0.9371106624, airMass);
|
||||
|
||||
// 0.01414 sec or 14.14 ms
|
||||
ASSERT_FLOAT_EQ(0.014137065038, sdMath(engineConfiguration, airMass, 12.5));
|
||||
ASSERT_FLOAT_EQ(0.014137065038, sdMath(airMass, 12.5 PASS_ENGINE_PARAMETER_SUFFIX));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue