From 54873240ce887a5232fb4e5a928f9523eeec1ed6 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Thu, 5 Jan 2017 21:12:06 -0500 Subject: [PATCH] auto-sync --- firmware/console/status_loop.cpp | 9 ++++++--- firmware/controllers/algo/advance_map.cpp | 10 +++++++++- firmware/controllers/algo/engine.cpp | 5 ++++- firmware/controllers/algo/engine.h | 5 +++++ firmware/controllers/algo/fuel_math.cpp | 9 ++++++++- firmware/controllers/algo/fuel_math.h | 3 ++- firmware/controllers/algo/rusefi_enums.h | 2 +- firmware/hw_layer/io_pins.cpp | 1 - firmware/tunerstudio/rusefi.ini | 11 ++++++++++- firmware/tunerstudio/rusefi.input | 9 +++++++++ unit_tests/test_fuel_map.cpp | 2 +- 11 files changed, 55 insertions(+), 11 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index b27c0db763..84b80a6e5c 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -527,14 +527,17 @@ static OutputPin communicationPin; OutputPin warningPin; OutputPin runningPin; -static OutputPin *leds[] = { &warningPin, &runningPin, &enginePins.errorLedPin, &communicationPin, &enginePins.checkEnginePin }; +static OutputPin *leds[] = { &warningPin, &runningPin, &enginePins.checkEnginePin, + &enginePins.errorLedPin, &communicationPin, &enginePins.checkEnginePin }; extern pin_output_mode_e DEFAULT_OUTPUT; -static void initStatisLeds() { +static void initStatusLeds(void) { #if EFI_PROD_CODE || defined(__DOXYGEN__) outputPinRegisterExt2("led: comm status", &communicationPin, engineConfiguration->communicationPin, &DEFAULT_OUTPUT); + // we initialize this here so that we can blink it on start-up + outputPinRegisterExt2("MalfunctionIndicator", &enginePins.checkEnginePin, boardConfiguration->malfunctionIndicatorPin, &DEFAULT_OUTPUT); #endif #if EFI_WARNING_LED || defined(__DOXYGEN__) @@ -829,7 +832,7 @@ void startStatusThreads(Engine *engine) { // todo: refactoring needed, this file should probably be split into pieces chThdCreateStatic(lcdThreadStack, sizeof(lcdThreadStack), NORMALPRIO, (tfunc_t) lcdThread, engine); #if EFI_PROD_CODE || defined(__DOXYGEN__) - initStatisLeds(); + initStatusLeds(); chThdCreateStatic(blinkingStack, sizeof(blinkingStack), NORMALPRIO, (tfunc_t) blinkingThread, NULL); #endif /* EFI_PROD_CODE */ } diff --git a/firmware/controllers/algo/advance_map.cpp b/firmware/controllers/algo/advance_map.cpp index 2c986387b6..edcdc264dd 100644 --- a/firmware/controllers/algo/advance_map.cpp +++ b/firmware/controllers/algo/advance_map.cpp @@ -27,6 +27,8 @@ EXTERN_ENGINE; +extern TunerStudioOutputChannels tsOutputChannels; + static ign_Map3D_t advanceMap("advance"); static ign_Map3D_t iatAdvanceCorrectionMap("iat corr"); @@ -80,8 +82,14 @@ static angle_t getRunningAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAME } else { iatCorrection = iatAdvanceCorrectionMap.getValue((float) rpm, engine->engineState.iat); } + if (engineConfiguration->debugMode == DBG_TIMING) { + tsOutputChannels.debugFloatField1 = iatCorrection; + tsOutputChannels.debugFloatField2 = engine->engineState.cltTimingCorrection; + } - float result = advanceMap.getValue((float) rpm, engineLoad) + iatCorrection + float result = advanceMap.getValue((float) rpm, engineLoad) + + iatCorrection + + engine->engineState.cltTimingCorrection // todo: uncomment once we get useable knock - engine->knockCount ; engine->m.advanceLookupTime = GET_TIMESTAMP() - engine->m.beforeAdvance; diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 4ba39366cc..c862050f29 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -139,6 +139,7 @@ EngineState::EngineState() { targetAFR = 0; tpsAccelEnrich = 0; tChargeK = 0; + cltTimingCorrection = 0; runningFuel = baseFuel = currentVE = 0; timeOfPreviousWarning = -10; baseTableFuel = iat = iatFuelCorrection = 0; @@ -188,9 +189,11 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { #endif } else { - cltFuelCorrection = getCltCorrection(clt PASS_ENGINE_PARAMETER); + cltFuelCorrection = getCltFuelCorrection(clt PASS_ENGINE_PARAMETER); } + cltTimingCorrection = getCltTimingCorrection(clt PASS_ENGINE_PARAMETER); + engineNoiseHipLevel = interpolate2d(rpm, engineConfiguration->knockNoiseRpmBins, engineConfiguration->knockNoise, ENGINE_NOISE_CURVE_SIZE); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index a92d692a24..777e450ad2 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -91,6 +91,9 @@ public: int lastErrorCode; efitimesec_t timeOfPreviousWarning; + /** + * speed-density logic, calculated air mass in gramms + */ float airMass; float engineNoiseHipLevel; @@ -118,6 +121,8 @@ public: */ angle_t dwellAngle; + angle_t cltTimingCorrection; + // fuel-related; float iatFuelCorrection; float cltFuelCorrection; diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 7a4e54b717..216cee2ff1 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -174,12 +174,19 @@ void prepareFuelMap(DECLARE_ENGINE_PARAMETER_F) { /** * @brief Engine warm-up fuel correction. */ -float getCltCorrection(float clt DECLARE_ENGINE_PARAMETER_S) { +float getCltFuelCorrection(float clt DECLARE_ENGINE_PARAMETER_S) { if (cisnan(clt)) return 1; // this error should be already reported somewhere else, let's just handle it return interpolate2d(clt, config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE) / PERCENT_MULT; } +angle_t getCltTimingCorrection(float clt DECLARE_ENGINE_PARAMETER_S) { + if (cisnan(clt)) + return 0; // this error should be already reported somewhere else, let's just handle it + return interpolate2d(clt, engineConfiguration->cltTimingBins, engineConfiguration->cltTimingExtra, CLT_TIMING_CURVE_SIZE); +} + + float getIatCorrection(float iat DECLARE_ENGINE_PARAMETER_S) { if (cisnan(iat)) return 1; // this error should be already reported somewhere else, let's just handle it diff --git a/firmware/controllers/algo/fuel_math.h b/firmware/controllers/algo/fuel_math.h index 64f2d58f25..e2832d6bfc 100644 --- a/firmware/controllers/algo/fuel_math.h +++ b/firmware/controllers/algo/fuel_math.h @@ -30,7 +30,8 @@ int getNumberOfInjections(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S); angle_t getinjectionOffset(float rpm DECLARE_ENGINE_PARAMETER_S); float getIatCorrection(float iat DECLARE_ENGINE_PARAMETER_S); floatms_t getInjectorLag(float vBatt DECLARE_ENGINE_PARAMETER_S); -float getCltCorrection(float clt DECLARE_ENGINE_PARAMETER_S); +float getCltFuelCorrection(float clt DECLARE_ENGINE_PARAMETER_S); +angle_t getCltTimingCorrection(float clt DECLARE_ENGINE_PARAMETER_S); floatms_t getCrankingFuel(DECLARE_ENGINE_PARAMETER_F); floatms_t getCrankingFuel3(float coolantTemperature, uint32_t revolutionCounterSinceStart DECLARE_ENGINE_PARAMETER_S); floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_S); diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index 95b740f65c..4c3dd97440 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -652,7 +652,7 @@ typedef enum { AUX_PID_1 = 7, DBG_VVT = 8, DBG_POST_CRANKING_ENRICH = 9, - DM_10 = 10, + DBG_TIMING = 10, DM_11 = 11, DM_12 = 12, DM_13 = 13, diff --git a/firmware/hw_layer/io_pins.cpp b/firmware/hw_layer/io_pins.cpp index 574e052746..8feaf95c33 100644 --- a/firmware/hw_layer/io_pins.cpp +++ b/firmware/hw_layer/io_pins.cpp @@ -110,7 +110,6 @@ void initOutputPins(void) { // outputPinRegister("ext led 2", LED_EXT_2, EXTRA_LED_2_PORT, EXTRA_LED_2_PIN); // outputPinRegister("ext led 3", LED_EXT_3, EXTRA_LED_2_PORT, EXTRA_LED_3_PIN); // outputPinRegister("alive1", LED_DEBUG, GPIOD, 6); - outputPinRegisterExt2("MalfunctionIndicator", &enginePins.checkEnginePin, boardConfiguration->malfunctionIndicatorPin, &DEFAULT_OUTPUT); // todo: are these needed here? todo: make configurable // outputPinRegister("spi CS1", SPI_CS_1, SPI_CS1_PORT, SPI_CS1_PIN); diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index 7e03c02a91..ea1cc3e069 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -42,7 +42,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Mon Jan 02 18:37:17 EST 2017 +; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Jan 05 20:49:12 EST 2017 pageSize = 16376 page = 1 @@ -980,6 +980,14 @@ fileVersion = { 20161225 } yBins = iatFuelCorr gauge = IATGauge + curve = cltTimingCorrCurve, "Warmup timing correction" + columnLabel = "Coolant", "Extra" + xAxis = -40, 120, 10 + yAxis = 0, 50, 100 + xBins = cltTimingBins, coolant + yBins = cltTimingExtra + gauge = CLTGauge + curve = cltFuelCorrCurve, "Warmup fuel manual Multiplier" columnLabel = "Coolant", "Multiplier" xAxis = -40, 120, 10 @@ -1388,6 +1396,7 @@ fileVersion = { 20161225 } subMenu = cltFuelCorrCurve, "Warmup fuel manual Multiplier", 0, {useWarmupPidAfr == 0} subMenu = warmupTargetAfrCurve, "Warmup fuel auto correction AFR target", 0, {useWarmupPidAfr == 1} subMenu = cltIdleCurve, "Warmup IAC position manual Multiplier" + subMenu = cltTimingCorrCurve, "Warmup timing correction" subMenu = std_separator subMenu = fuelTableTbl, "Fuel Table", 0, {fuelAlgorithm != 3} subMenu = veTableTbl, "VE Table", 0, {fuelAlgorithm == 3} diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 289827bbfb..f2ea752e4b 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -925,6 +925,14 @@ fileVersion = { 20161225 } yBins = iatFuelCorr gauge = IATGauge + curve = cltTimingCorrCurve, "Warmup timing correction" + columnLabel = "Coolant", "Extra" + xAxis = -40, 120, 10 + yAxis = 0, 50, 100 + xBins = cltTimingBins, coolant + yBins = cltTimingExtra + gauge = CLTGauge + curve = cltFuelCorrCurve, "Warmup fuel manual Multiplier" columnLabel = "Coolant", "Multiplier" xAxis = -40, 120, 10 @@ -1333,6 +1341,7 @@ fileVersion = { 20161225 } subMenu = cltFuelCorrCurve, "Warmup fuel manual Multiplier", 0, {useWarmupPidAfr == 0} subMenu = warmupTargetAfrCurve, "Warmup fuel auto correction AFR target", 0, {useWarmupPidAfr == 1} subMenu = cltIdleCurve, "Warmup IAC position manual Multiplier" + subMenu = cltTimingCorrCurve, "Warmup timing correction" subMenu = std_separator subMenu = fuelTableTbl, "Fuel Table", 0, {fuelAlgorithm != 3} subMenu = veTableTbl, "VE Table", 0, {fuelAlgorithm == 3} diff --git a/unit_tests/test_fuel_map.cpp b/unit_tests/test_fuel_map.cpp index 8127cb8fd4..d7a2b7433f 100644 --- a/unit_tests/test_fuel_map.cpp +++ b/unit_tests/test_fuel_map.cpp @@ -90,7 +90,7 @@ void testFuelMap(void) { assertEquals(NAN, getIntakeAirTemperature(PASS_ENGINE_PARAMETER_F)); float iatCorrection = getIatCorrection(-KELV PASS_ENGINE_PARAMETER); assertEqualsM("IAT", 2, iatCorrection); - float cltCorrection = getCltCorrection(getCoolantTemperature(PASS_ENGINE_PARAMETER_F) PASS_ENGINE_PARAMETER); + float cltCorrection = getCltFuelCorrection(getCoolantTemperature(PASS_ENGINE_PARAMETER_F) PASS_ENGINE_PARAMETER); assertEqualsM("CLT", 1, cltCorrection); float injectorLag = getInjectorLag(getVBatt(PASS_ENGINE_PARAMETER_F) PASS_ENGINE_PARAMETER); assertEqualsM("injectorLag", 0, injectorLag);