From 522920ddabc7f324286401693a42ca19c772ae90 Mon Sep 17 00:00:00 2001 From: Nathan Schulte Date: Thu, 16 Jan 2025 20:55:04 -0600 Subject: [PATCH 1/6] remove defunct veTableDialog3D TS dialog config --- firmware/tunerstudio/tunerstudio.template.ini | 4 ---- 1 file changed, 4 deletions(-) diff --git a/firmware/tunerstudio/tunerstudio.template.ini b/firmware/tunerstudio/tunerstudio.template.ini index 7b9ffe3302..c9ebce7ef0 100644 --- a/firmware/tunerstudio/tunerstudio.template.ini +++ b/firmware/tunerstudio/tunerstudio.template.ini @@ -4221,10 +4221,6 @@ dialog = tcuControls, "Transmission Settings" topicHelp = "veTableDialogHelp" panel = veTableTbl, South - dialog = veTableDialog3D, "VE Table" - topicHelp = "veTableDialogHelp" - panel = veTableMap, South - dialog = etbPidDialog, "PID settings" field = "pFactor", etb_pFactor field = "iFactor", etb_iFactor From c14a997fe0e93e63355f4bc44249e3d5aaa74044 Mon Sep 17 00:00:00 2001 From: Nathan Schulte Date: Thu, 16 Jan 2025 21:33:29 -0600 Subject: [PATCH 2/6] idleVeTableTbl map3d name suffix with Map like the others to avoid confusion --- firmware/tunerstudio/tunerstudio.template.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/tunerstudio/tunerstudio.template.ini b/firmware/tunerstudio/tunerstudio.template.ini index c9ebce7ef0..ae688a5ef4 100644 --- a/firmware/tunerstudio/tunerstudio.template.ini +++ b/firmware/tunerstudio/tunerstudio.template.ini @@ -988,7 +988,7 @@ curve = 32Curve, "3-2 Shift Solenoid Percent by Speed" gridOrient = 250, 0, 340 ; Space 123 rotation of grid in degrees. upDownLabel = "(RICHER)", "(LEANER)" - table = idleVeTableTbl, idleVeTable, "Idle VE" + table = idleVeTableTbl, idleVeTableMap, "Idle VE" xyLabels = "RPM", "load" xBins = idleVeRpmBins, RPMValue yBins = idleVeLoadBins, idleVeTableYAxis From 7c7dea54caa526a8ce4be7f9a1e5148a3990ba46 Mon Sep 17 00:00:00 2001 From: Nathan Schulte Date: Thu, 16 Jan 2025 21:37:02 -0600 Subject: [PATCH 3/6] independent VE tables per fuel strategy --- firmware/tunerstudio/tunerstudio.template.ini | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/firmware/tunerstudio/tunerstudio.template.ini b/firmware/tunerstudio/tunerstudio.template.ini index ae688a5ef4..02a5e3b499 100644 --- a/firmware/tunerstudio/tunerstudio.template.ini +++ b/firmware/tunerstudio/tunerstudio.template.ini @@ -979,11 +979,29 @@ curve = 32Curve, "3-2 Shift Solenoid Percent by Speed" gridOrient = 250, 0, 340 ; Space 123 rotation of grid in degrees. upDownLabel = "(RICHER)", "(LEANER)" - table = veTableTbl, veTableMap, "VE Table", 1 + table = veTableSdTbl, veTableSdMap, "VE Table: Speed Density", 1 xyLabels = "RPM", "load" xBins = veRpmBins, RPMValue yBins = veLoadBins, veTableYAxis - zBins = veTable + zBins = veTableSd +; gridHeight = 2.0 + gridOrient = 250, 0, 340 ; Space 123 rotation of grid in degrees. + upDownLabel = "(RICHER)", "(LEANER)" + + table = veTableMafTbl, veTableMafMap, "VE Table: MAF", 1 + xyLabels = "RPM", "load" + xBins = veRpmBins, RPMValue + yBins = veLoadBins, veTableYAxis + zBins = veTableMaf +; gridHeight = 2.0 + gridOrient = 250, 0, 340 ; Space 123 rotation of grid in degrees. + upDownLabel = "(RICHER)", "(LEANER)" + + table = veTableAlphaNTbl, veTableAlphaNMap, "VE Table: Alpha-N", 1 + xyLabels = "RPM", "load" + xBins = veRpmBins, RPMValue + yBins = veLoadBins, veTableYAxis + zBins = veTableAlphaN ; gridHeight = 2.0 gridOrient = 250, 0, 340 ; Space 123 rotation of grid in degrees. upDownLabel = "(RICHER)", "(LEANER)" @@ -4219,7 +4237,11 @@ dialog = tcuControls, "Transmission Settings" dialog = veTableDialog topicHelp = "veTableDialogHelp" - panel = veTableTbl, South + field = "Fuel strategy", fuelAlgorithm + ; TODO(nms): a button to copy current fuelAlgorithm's veTable to the others + panel = veTableSdTbl, fuelAlgorithm == 0, South + panel = veTableMafTbl, fuelAlgorithm == 1, South + panel = veTableAlphaNTbl, fuelAlgorithm == 2, South dialog = etbPidDialog, "PID settings" field = "pFactor", etb_pFactor From c42a27f9281cc45ff56c9cad6a1fa3b1c1183341 Mon Sep 17 00:00:00 2001 From: Nathan Schulte Date: Thu, 16 Jan 2025 22:08:45 -0600 Subject: [PATCH 4/6] finish off veTable --- firmware/config/engines/bmw_m73.cpp | 2 +- firmware/config/engines/dodge_neon.cpp | 2 +- firmware/config/engines/mazda_miata_1_6.cpp | 4 +++- .../engines/mazda_miata_custom_hunchback.cpp | 4 +++- firmware/config/engines/mazda_miata_vvt.cpp | 4 +++- firmware/config/engines/vw_b6.cpp | 4 +++- firmware/controllers/algo/airmass/airmass.cpp | 21 ++++++++++++++++++- .../algo/defaults/default_fuel.cpp | 4 +++- firmware/integration/rusefi_config.txt | 4 +++- 9 files changed, 40 insertions(+), 9 deletions(-) diff --git a/firmware/config/engines/bmw_m73.cpp b/firmware/config/engines/bmw_m73.cpp index 77821ed96e..78a43479ca 100644 --- a/firmware/config/engines/bmw_m73.cpp +++ b/firmware/config/engines/bmw_m73.cpp @@ -113,7 +113,7 @@ void m73engine() { engineConfiguration->cranking.baseFuel = 27; engineConfiguration->crankingTimingAngle = 15; - setTable(config->veTable, 45); + setTable(config->veTableAlphaN, 45); engineConfiguration->cylinderBore = 85.0; } diff --git a/firmware/config/engines/dodge_neon.cpp b/firmware/config/engines/dodge_neon.cpp index a68e218034..ccab572559 100644 --- a/firmware/config/engines/dodge_neon.cpp +++ b/firmware/config/engines/dodge_neon.cpp @@ -106,7 +106,7 @@ void setDodgeNeonNGCEngineConfiguration() { */ //setWholeTimingTable_d(12); - //setMap(config->veTable, 50); + //setMap(config->veTableAlphaN, 50); // set cranking_timing_angle 710 engineConfiguration->crankingTimingAngle = -710; diff --git a/firmware/config/engines/mazda_miata_1_6.cpp b/firmware/config/engines/mazda_miata_1_6.cpp index 697cd7cc34..2f7659e74b 100644 --- a/firmware/config/engines/mazda_miata_1_6.cpp +++ b/firmware/config/engines/mazda_miata_1_6.cpp @@ -47,7 +47,9 @@ static const uint8_t hardCodedveTable[16][16] = { static void setMapVeTable() { copyArray(config->veLoadBins, hardCodedveLoadBins); copyArray(config->veRpmBins, hardCodedveRpmBins); - copyTable(config->veTable, hardCodedveTable); + copyTable(config->veTableSd, hardCodedveTable); + copyTable(config->veTableMaf, hardCodedveTable); + copyTable(config->veTableAlphaN, hardCodedveTable); } #if IGN_LOAD_COUNT == DEFAULT_IGN_LOAD_COUNT diff --git a/firmware/config/engines/mazda_miata_custom_hunchback.cpp b/firmware/config/engines/mazda_miata_custom_hunchback.cpp index b077d97bc7..4fcda76628 100644 --- a/firmware/config/engines/mazda_miata_custom_hunchback.cpp +++ b/firmware/config/engines/mazda_miata_custom_hunchback.cpp @@ -87,7 +87,9 @@ void setMazdaMiata2003EngineConfigurationNaFuelRail() { copyArray(config->veRpmBins, mazda_miata_nb2_RpmBins); copyArray(config->veLoadBins, mazda_miata_nb2_LoadBins); - copyTable(config->veTable, mapBased18vvtVeTable_NA_fuel_rail); + copyTable(config->veTableSd, mapBased18vvtVeTable_NA_fuel_rail); + copyTable(config->veTableMaf, mapBased18vvtVeTable_NA_fuel_rail); + copyTable(config->veTableAlphaN, mapBased18vvtVeTable_NA_fuel_rail); engineConfiguration->vvtOffsets[0] = 83; // 2002 green car value diff --git a/firmware/config/engines/mazda_miata_vvt.cpp b/firmware/config/engines/mazda_miata_vvt.cpp index 910159ab01..61f4f5cd75 100644 --- a/firmware/config/engines/mazda_miata_vvt.cpp +++ b/firmware/config/engines/mazda_miata_vvt.cpp @@ -334,7 +334,9 @@ static void setCommonMazdaNB() { // Tables copyArray(config->veRpmBins, mazda_miata_nb2_RpmBins); copyArray(config->veLoadBins, mazda_miata_nb2_LoadBins); - copyTable(config->veTable, mapBased18vvtVeTable_NB_fuel_rail); + copyTable(config->veTableSd, mapBased18vvtVeTable_NB_fuel_rail); + copyTable(config->veTableMaf, mapBased18vvtVeTable_NB_fuel_rail); + copyTable(config->veTableAlphaN, mapBased18vvtVeTable_NB_fuel_rail); copyArray(config->ignitionRpmBins, ignition18vvtRpmBins); copyArray(config->ignitionLoadBins, ignition18vvtLoadBins); diff --git a/firmware/config/engines/vw_b6.cpp b/firmware/config/engines/vw_b6.cpp index f816908088..dfff00d200 100644 --- a/firmware/config/engines/vw_b6.cpp +++ b/firmware/config/engines/vw_b6.cpp @@ -115,7 +115,9 @@ static inline void commonPassatB6() { engineConfiguration->hpfpPeakPos = 10; - setTable(config->veTable, 55); + setTable(config->veTableSd, 55); + setTable(config->veTableMaf, 55); + setTable(config->veTableAlphaN, 55); setBoschVAGETB(); // random number just to take position away from zero diff --git a/firmware/controllers/algo/airmass/airmass.cpp b/firmware/controllers/algo/airmass/airmass.cpp index f440f3c45e..be9b5d2023 100644 --- a/firmware/controllers/algo/airmass/airmass.cpp +++ b/firmware/controllers/algo/airmass/airmass.cpp @@ -74,8 +74,27 @@ float AirmassVeModelBase::getVe(float rpm, float load, bool postState) const { } float AirmassVeModelBase::getVeImpl(float rpm, percent_t load) const { + const ValueProvider3D * veTable = nullptr; + + switch (engineConfiguration->fuelAlgorithm) { + case LM_SPEED_DENSITY: + veTable = config->veTableSd; + break; + case LM_REAL_MAF: + veTable = config->veTableMaf; + break; + case LM_ALPHA_N: + veTable = config->veTableAlphaN; + break; + // case LM_LUA: // #if EFI_LUA + // case LM_MOCK: // #if EFI_UNIT_TEST + default: + firmwareError(ObdCode::CUSTOM_ERR_ASSERT, "Invalid airmass mode %d", engineConfiguration->fuelAlgorithm); + return 0; + } + return interpolate3d( - config->veTable, + veTable, config->veLoadBins, load, config->veRpmBins, rpm ); diff --git a/firmware/controllers/algo/defaults/default_fuel.cpp b/firmware/controllers/algo/defaults/default_fuel.cpp index ad7b7acd87..310ce0701e 100644 --- a/firmware/controllers/algo/defaults/default_fuel.cpp +++ b/firmware/controllers/algo/defaults/default_fuel.cpp @@ -79,7 +79,9 @@ static void setDefaultWarmupFuelEnrichment() { static void setDefaultVETable() { setRpmTableBin(config->veRpmBins); - setTable(config->veTable, 80); + setTable(config->veTableSd, 80); + setTable(config->veTableMaf, 80); + setTable(config->veTableAlphaN, 80); setRpmTableBin(config->baroCorrRpmBins); setLinearCurve(config->baroCorrPressureBins, 75, 105, 1); diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index e42136105b..886b48a1f1 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -1532,7 +1532,9 @@ int16_t[IGN_RPM_COUNT x IGN_LOAD_COUNT] autoscale ignitionTable;;"deg", 0.1, 0, uint16_t[IGN_LOAD_COUNT] ignitionLoadBins;;"Load", 1, 0, 0, 1000, 0 uint16_t[IGN_RPM_COUNT] ignitionRpmBins;;"RPM", 1, 0, 0, 18000, 0 -uint16_t[FUEL_RPM_COUNT x FUEL_LOAD_COUNT] autoscale veTable;;"%", 0.1, 0, 0, 999, 1 +uint16_t[FUEL_RPM_COUNT x FUEL_LOAD_COUNT] autoscale veTableSd;VE table used with speed-density fuel strategy;"%", 0.1, 0, 0, 999, 1 +uint16_t[FUEL_RPM_COUNT x FUEL_LOAD_COUNT] autoscale veTableMaf;VE table used with MAF fuel strategy;"%", 0.1, 0, 0, 999, 1 +uint16_t[FUEL_RPM_COUNT x FUEL_LOAD_COUNT] autoscale veTableAlphaN;VE table used with Alpha-N fuel strategy;"%", 0.1, 0, 0, 999, 1 uint16_t[FUEL_LOAD_COUNT] veLoadBins;;"kPa", 1, 0, 0, 1000, 0 uint16_t[FUEL_RPM_COUNT] veRpmBins;;"RPM", 1, 0, 0, 18000, 0 From 0533db4a6c6b9dd2c1ca3bba5611fc20206a24ed Mon Sep 17 00:00:00 2001 From: Nathan Schulte Date: Thu, 16 Jan 2025 23:53:05 -0600 Subject: [PATCH 5/6] final veTable, and TS things trial --- firmware/config/engines/ford_festiva.cpp | 4 +++- firmware/controllers/algo/airmass/airmass.cpp | 18 +++++++++++------- firmware/controllers/algo/fuel_math.cpp | 1 - firmware/tunerstudio/tunerstudio.template.ini | 14 ++++++++------ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/firmware/config/engines/ford_festiva.cpp b/firmware/config/engines/ford_festiva.cpp index 6c956284ee..fda17aef1b 100644 --- a/firmware/config/engines/ford_festiva.cpp +++ b/firmware/config/engines/ford_festiva.cpp @@ -95,7 +95,9 @@ void setFordEscortGt() { copyArray(config->veRpmBins, veRpmBins); - copyTable(config->veTable, racingFestivaVeTable); + copyTable(config->veTableSd, racingFestivaVeTable); + copyTable(config->veTableMaf, racingFestivaVeTable); + copyTable(config->veTableAlphaN, racingFestivaVeTable); // engineConfiguration->triggerInputPins[0] = Gpio::C6; // 2G YEL/BLU // engineConfiguration->triggerInputPins[1] = Gpio::A5; // 2E White CKP diff --git a/firmware/controllers/algo/airmass/airmass.cpp b/firmware/controllers/algo/airmass/airmass.cpp index be9b5d2023..fd1fb48602 100644 --- a/firmware/controllers/algo/airmass/airmass.cpp +++ b/firmware/controllers/algo/airmass/airmass.cpp @@ -1,7 +1,10 @@ +#include "engine_configuration.h" +#include "engine_configuration_generated_structures.h" #include "pch.h" #include "airmass.h" #include "idle_thread.h" +#include "table_helper.h" AirmassVeModelBase::AirmassVeModelBase(const ValueProvider3D* veTable) : m_veTable(veTable) {} @@ -74,27 +77,28 @@ float AirmassVeModelBase::getVe(float rpm, float load, bool postState) const { } float AirmassVeModelBase::getVeImpl(float rpm, percent_t load) const { - const ValueProvider3D * veTable = nullptr; + auto veTable = &config->veTableSd; switch (engineConfiguration->fuelAlgorithm) { case LM_SPEED_DENSITY: - veTable = config->veTableSd; + veTable = &config->veTableSd; break; case LM_REAL_MAF: - veTable = config->veTableMaf; + veTable = &config->veTableMaf; break; case LM_ALPHA_N: - veTable = config->veTableAlphaN; + veTable = &config->veTableAlphaN; break; // case LM_LUA: // #if EFI_LUA // case LM_MOCK: // #if EFI_UNIT_TEST default: - firmwareError(ObdCode::CUSTOM_ERR_ASSERT, "Invalid airmass mode %d", engineConfiguration->fuelAlgorithm); - return 0; + // firmwareError(ObdCode::CUSTOM_ERR_ASSERT, "Invalid airmass mode %d", engineConfiguration->fuelAlgorithm); + // return 0; + break; } return interpolate3d( - veTable, + *veTable, config->veLoadBins, load, config->veRpmBins, rpm ); diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 89647e734a..17ab8a34ea 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -30,7 +30,6 @@ #include "fuel_math.h" #include "fuel_computer.h" #include "injector_model.h" -#include "speed_density.h" #include "speed_density_base.h" #include "lua_hooks.h" diff --git a/firmware/tunerstudio/tunerstudio.template.ini b/firmware/tunerstudio/tunerstudio.template.ini index 02a5e3b499..c453997743 100644 --- a/firmware/tunerstudio/tunerstudio.template.ini +++ b/firmware/tunerstudio/tunerstudio.template.ini @@ -147,10 +147,10 @@ enable2ndByteCanID = false ; tableName, lambdaTargetTableName, lambdaChannel, egoCorrectionChannel, activeCondition #if LAMBDA - veAnalyzeMap = veTableTbl, lambdaTableTbl, lambdaValues1, egoCorrectionForVeAnalyze, { 1 } + veAnalyzeMap = veTableSdTbl, veTableMafTbl, veTableAlphaNTbl, lambdaTableTbl, lambdaValues1, egoCorrectionForVeAnalyze, { 1 } lambdaTargetTables = lambdaTableTbl, afrTSCustom #else - veAnalyzeMap = veTableTbl, afrTableTbl, afrGasolineScale, egoCorrectionForVeAnalyze, { 1 } + veAnalyzeMap = veTableSdTbl, veTableMafTbl, veTableAlphaNTbl, afrTableTbl, afrGasolineScale, egoCorrectionForVeAnalyze, { 1 } lambdaTargetTables = afrTableTbl, afrTSCustom #endif @@ -4239,9 +4239,9 @@ dialog = tcuControls, "Transmission Settings" topicHelp = "veTableDialogHelp" field = "Fuel strategy", fuelAlgorithm ; TODO(nms): a button to copy current fuelAlgorithm's veTable to the others - panel = veTableSdTbl, fuelAlgorithm == 0, South - panel = veTableMafTbl, fuelAlgorithm == 1, South - panel = veTableAlphaNTbl, fuelAlgorithm == 2, South + panel = veTableSdTbl, { fuelAlgorithm == 0 }, South + panel = veTableMafTbl, { fuelAlgorithm == 1 }, South + panel = veTableAlphaNTbl, { fuelAlgorithm == 2 }, South dialog = etbPidDialog, "PID settings" field = "pFactor", etb_pFactor @@ -4726,7 +4726,9 @@ dialog = tcuControls, "Transmission Settings" [Tools] ;addTool = toolName, PanelName - addTool = veTableGenerator, "VE Table Generator", veTableTbl + addTool = veTableGenerator, "VE Table Generator: Speed Density", veTableSdTbl + addTool = veTableGenerator, "VE Table Generator: MAF", veTableMafTbl + addTool = veTableGenerator, "VE Table Generator: Alpha-N", veTableAlphaNTbl #if LAMBDA #else addTool = afrTableGenerator, "AFR Table Generator", afrTableTbl From 61110735fc15380b712edb87f10c4eaf28663823 Mon Sep 17 00:00:00 2001 From: Nathan Schulte Date: Fri, 17 Jan 2025 00:04:59 -0600 Subject: [PATCH 6/6] fix TS --- firmware/tunerstudio/tunerstudio.template.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firmware/tunerstudio/tunerstudio.template.ini b/firmware/tunerstudio/tunerstudio.template.ini index c453997743..360d6e216c 100644 --- a/firmware/tunerstudio/tunerstudio.template.ini +++ b/firmware/tunerstudio/tunerstudio.template.ini @@ -4239,9 +4239,9 @@ dialog = tcuControls, "Transmission Settings" topicHelp = "veTableDialogHelp" field = "Fuel strategy", fuelAlgorithm ; TODO(nms): a button to copy current fuelAlgorithm's veTable to the others - panel = veTableSdTbl, { fuelAlgorithm == 0 }, South - panel = veTableMafTbl, { fuelAlgorithm == 1 }, South - panel = veTableAlphaNTbl, { fuelAlgorithm == 2 }, South + panel = veTableSdTbl, South, { fuelAlgorithm == @@engine_load_mode_e_LM_SPEED_DENSITY@@ } + panel = veTableMafTbl, South, { fuelAlgorithm == @@engine_load_mode_e_LM_REAL_MAF@@ } + panel = veTableAlphaNTbl, South, { fuelAlgorithm == @@engine_load_mode_e_LM_ALPHA_N@@ } dialog = etbPidDialog, "PID settings" field = "pFactor", etb_pFactor