From c53979a01799e41e37ecc1e1a94445263325f7b0 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Fri, 21 Aug 2020 16:43:30 -0700 Subject: [PATCH] Configurable stoichiometric ratio (#1710) * configurable stoich ratio * afr table always in gas afr * default * typo * use defined ratio * do it in config too * missed a spot * oops wrong one Co-authored-by: Matthew Kennedy --- firmware/controllers/algo/engine_configuration.cpp | 3 ++- firmware/controllers/algo/fuel/fuel_computer.cpp | 11 +++++++++-- firmware/controllers/math/speed_density.cpp | 2 +- firmware/integration/rusefi_config.txt | 5 +++-- firmware/tunerstudio/rusefi.input | 4 ++++ firmware/util/containers/table_helper.h | 5 ----- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index ff464237aa..72460a5a9d 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -250,7 +250,7 @@ void setConstantDwell(floatms_t dwellMs DECLARE_CONFIG_PARAMETER_SUFFIX) { void setAfrMap(afr_table_t table, float value) { for (int l = 0; l < FUEL_LOAD_COUNT; l++) { for (int rpmIndex = 0; rpmIndex < FUEL_RPM_COUNT; rpmIndex++) { - table[l][rpmIndex] = (int)(value * AFR_STORAGE_MULT); + table[l][rpmIndex] = (int)(value * PACK_MULT_AFR_CFG); } } } @@ -832,6 +832,7 @@ static void setDefaultEngineConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { setLinearCurve(engineConfiguration->map.samplingWindow, 50, 50, 1); setAfrMap(config->afrTable, 14.7); + engineConfiguration->stoichRatioPrimary = 14.7f / PACK_MULT_AFR_CFG; setDefaultVETable(PASS_ENGINE_PARAMETER_SIGNATURE); diff --git a/firmware/controllers/algo/fuel/fuel_computer.cpp b/firmware/controllers/algo/fuel/fuel_computer.cpp index 98d4153722..4c1fdab256 100644 --- a/firmware/controllers/algo/fuel/fuel_computer.cpp +++ b/firmware/controllers/algo/fuel/fuel_computer.cpp @@ -16,12 +16,19 @@ FuelComputer::FuelComputer(const ValueProvider3D& afrTable) : m_afrTable(&afrTab float FuelComputer::getStoichiometricRatio() const { // TODO: vary this with ethanol content/configured setting/whatever - return 14.7f; + float rawConfig = (float)CONFIG(stoichRatioPrimary) / PACK_MULT_AFR_CFG; + + // Config compatibility: this field may be zero on ECUs with old defaults + if (rawConfig < 5) { + return 14.7f; + } + + return rawConfig; } float FuelComputer::getTargetLambda(int rpm, float load) const { efiAssert(OBD_PCM_Processor_Fault, m_afrTable != nullptr, "AFR table null", 0); // TODO: set the table value in lambda instead of afr - return m_afrTable->getValue(rpm, load) / getStoichiometricRatio(); + return m_afrTable->getValue(rpm, load) / 14.7f; }; diff --git a/firmware/controllers/math/speed_density.cpp b/firmware/controllers/math/speed_density.cpp index 0a29656399..ec97e15fad 100644 --- a/firmware/controllers/math/speed_density.cpp +++ b/firmware/controllers/math/speed_density.cpp @@ -28,7 +28,7 @@ EXTERN_ENGINE; fuel_Map3D_t veMap("VE"); fuel_Map3D_t ve2Map("VE2"); -afr_Map3D_t afrMap("AFR", 1.0 / AFR_STORAGE_MULT); +afr_Map3D_t afrMap("AFR", 1.0f / PACK_MULT_AFR_CFG); baroCorr_Map3D_t baroCorrMap("baro"); #define tpMin 0 diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 669aee4167..c5a09f4e90 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -173,6 +173,7 @@ struct_no_prefix engine_configuration_s #define PACK_MULT_MASS_FLOW 10 #define TPS_1_BYTE_PACKING_MULT 2 #define LOAD_1_BYTE_PACKING_MULT 2 +#define PACK_MULT_AFR_CFG 10 #define FSIO_TABLE_8 8 #define FSIO_CURVE_8 8 @@ -196,7 +197,7 @@ struct_no_prefix engine_configuration_s custom fuel_table_t 4*@@FUEL_RPM_COUNT@@x@@FUEL_LOAD_COUNT@@ array, F32, @OFFSET@, [@@FUEL_RPM_COUNT@@x@@FUEL_LOAD_COUNT@@],"ms", 1, 0, 0.0, 500.0, 2 custom ve_table_t 4*@@FUEL_RPM_COUNT@@x@@FUEL_LOAD_COUNT@@ array, F32, @OFFSET@, [@@FUEL_RPM_COUNT@@x@@FUEL_LOAD_COUNT@@],"%", 1, 0, 0, 999.0, 2 -custom afr_table_t @@FUEL_RPM_COUNT@@x@@FUEL_LOAD_COUNT@@ array, U08, @OFFSET@, [@@FUEL_RPM_COUNT@@x@@FUEL_LOAD_COUNT@@],"deg", 0.1, 0, 0, 25.0, 1 +custom afr_table_t @@FUEL_RPM_COUNT@@x@@FUEL_LOAD_COUNT@@ array, U08, @OFFSET@, [@@FUEL_RPM_COUNT@@x@@FUEL_LOAD_COUNT@@],"deg", {1/PACK_MULT_AFR_CFG}, 0, 0, 25.0, 1 custom fsio_table_8x8_u8t @@FSIO_TABLE_8@@x@@FSIO_TABLE_8@@ array, U08, @OFFSET@, [@@FSIO_TABLE_8@@x@@FSIO_TABLE_8@@],"value", 1, 0, 0.0, 255.0, 0 custom fsio_table_8x8_f32t 4*@@FSIO_TABLE_8@@x@@FSIO_TABLE_8@@ array, F32, @OFFSET@, [@@FSIO_TABLE_8@@x@@FSIO_TABLE_8@@],"value", 1, 0, 0.0, 30000.0, 2 @@ -1317,7 +1318,7 @@ tChargeMode_e tChargeMode; int16_t idlerpmpid_iTermMin;iTerm min value;"", 1, 0, -30000, 30000.0, 0 spi_device_e tle6240spiDevice; - uint8_t[1] unusedSpiPadding7;;"units", 1, 0, -20, 100, 0 + uint8_t stoichRatioPrimary;+Stoichiometric ratio for your primary fuel.;":1", {1/PACK_MULT_AFR_CFG},0, 5, 25.0, 1 int16_t idlerpmpid_iTermMax;iTerm max value;"", 1, 0, -30000, 30000.0, 0 spi_device_e mc33972spiDevice; diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 0a2ea5cc78..b292880847 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -1604,6 +1604,9 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00" dialog = injChars, "Injector Settings", yAxis field = "Injector Flow", injector_flow, {isInjectionEnabled == 1} + dialog = fuelParams, "Fuel characteristics", yAxis + field = "Stoichiometric ratio", stoichRatioPrimary, {isInjectionEnabled == 1} + dialog = injectorOutputSettings, "Injector Outputs", yAxis field = "Use only first half of pins for batch mode" field = "Injection Pin 1", injectionPins1, {isInjectionEnabled == 1} @@ -1651,6 +1654,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00" topicHelp = "fuelHelp" panel = baseInjection panel = injChars + panel = fuelParams panel = injectorsDeadTime dialog = ignitionCylExtra, "Ignition Cylinder Extra Timing" diff --git a/firmware/util/containers/table_helper.h b/firmware/util/containers/table_helper.h index 46a9262a50..ee887b19e9 100644 --- a/firmware/util/containers/table_helper.h +++ b/firmware/util/containers/table_helper.h @@ -143,11 +143,6 @@ void copy2DTable(const vType source[LOAD_BIN_SIZE][RPM_BIN_SIZE], vType destinat } } -/** - * AFR value is packed into uint8_t with a multiplier of 10 - */ -#define AFR_STORAGE_MULT 10 - typedef Map3D afr_Map3D_t; typedef Map3D ign_Map3D_t; typedef Map3D fuel_Map3D_t;