From 06f92807cc7b353fc1a77eca8051903f474d7c5c Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 19 Oct 2020 05:04:27 -0700 Subject: [PATCH] second PID config for wastegate (#1889) * remove * cleanup * implement ETB parts * hook up to boost controller * tests * consume * add cfg field * ui maybe * fix * fix * add wastegate config test --- .../actuators/electronic_throttle.cpp | 10 +++++++- firmware/integration/rusefi_config.txt | 3 ++- firmware/tunerstudio/rusefi.input | 15 +++++++++-- unit_tests/tests/test_etb.cpp | 25 +++++++++++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 532ab74344..497f4b12e9 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -820,6 +820,13 @@ void unregisterEtbPins() { // todo: we probably need an implementation here?! } +static pid_s* getEtbPidForFunction(etb_function_e function DECLARE_ENGINE_PARAMETER_SUFFIX) { + switch (function) { + case ETB_Wastegate: return &CONFIG(etbWastegatePid); + default: return &CONFIG(etb); + } +} + void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) { efiAssertVoid(OBD_PCM_Processor_Fault, engine->etbControllers != NULL, "etbControllers NULL"); #if EFI_PROD_CODE @@ -845,8 +852,9 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } auto func = CONFIG(etbFunctions[i]); + auto pid = getEtbPidForFunction(func PASS_ENGINE_PARAMETER_SUFFIX); - anyEtbConfigured |= controller->init(func, motor, &engineConfiguration->etb, &pedal2tpsMap); + anyEtbConfigured |= controller->init(func, motor, pid, &pedal2tpsMap); INJECT_ENGINE_REFERENCE(engine->etbControllers[i]); } } diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 047ecd1203..a092f8fcbf 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -1246,7 +1246,8 @@ tle8888_mode_e tle8888mode; ThermistorConf auxTempSensor2;todo: finish implementation #332 uint8_t[6] unused2508;;"units", 1, 0, -20, 100, 0 int16_t etbFreq;;"Hz", 1, 0, 0, 30000, 0 - uint8_t[24] unused2516;;"units", 1, 0, -20, 100, 0 + pid_s etbWastegatePid; + uint8_t[4] unused2536;;"units", 1, 0, -20, 100, 0 custom cfg_float_t_1f 4 scalar, F32, @OFFSET@, "Val", 1, 0, -20000000, 20000000, 1 cfg_float_t_1f[IGNITION_PIN_COUNT iterate] timing_offset_cylinder;per-cylinder timing correction diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 47c4674b75..33754a8a36 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -1340,7 +1340,8 @@ menuDialog = main menu = "&Advanced" subMenu = boostDialog, "Boost Control" - subMenu = boostPidDialog, "Closed Loop Boost", { boostType == 1 } + subMenu = boostPidDialog, "Closed Loop Boost", { isBoostControlEnabled && boostType == 1 } + subMenu = boostEtbPid, "ETB-style Wastegate Actuator", { isBoostControlEnabled } subMenu = std_separator subMenu = gppwm1, "General Purpose PWM 1" @@ -2985,7 +2986,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00" ;Boost Closed Loop dialog = boostPidleft, "" - field = "P Gain", boostPid_pFactor, { isBoostControlEnabled && boostType == 1 } + field = "P Gain", boostPid_pFactor, { isBoostControlEnabled && boostType == 1 } field = "I Gain", boostPid_iFactor, { isBoostControlEnabled && boostType == 1 } field = "D Gain", boostPid_dFactor, { isBoostControlEnabled && boostType == 1 } field = "Control Period", boostPid_periodMs, { isBoostControlEnabled && boostType == 1 } @@ -2999,6 +3000,16 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00" panel = boostPidleft, West panel = boostTableDialog, Center + dialog = boostEtbPid, "" + field = "!This section is for advanced users only!" + field = "H-Bridge #1 function", etbFunctions1 + field = "H-Bridge #2 function", etbFunctions2 + field = "P gain", etbWastegatePid_pFactor, { isBoostControlEnabled } + field = "I gain", etbWastegatePid_iFactor, { isBoostControlEnabled } + field = "D gain", etbWastegatePid_dFactor, { isBoostControlEnabled } + field = "PID min", etbWastegatePid_minValue, { isBoostControlEnabled } + field = "PID max", etbWastegatePid_maxValue, { isBoostControlEnabled } + help = veTableDialogHelp, "Volumetric Efficiency" text = "Volumetric Efficiency is used to calculate fuel in Speed Density mode" webHelp = "https://rusefi.com/s/fuel" diff --git a/unit_tests/tests/test_etb.cpp b/unit_tests/tests/test_etb.cpp index 83186448c4..10ea1209d6 100644 --- a/unit_tests/tests/test_etb.cpp +++ b/unit_tests/tests/test_etb.cpp @@ -135,6 +135,31 @@ TEST(etb, initializationDualThrottle) { doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE); } +TEST(etb, initializationWastegate) { + StrictMock mocks[ETB_COUNT]; + + WITH_ENGINE_TEST_HELPER(TEST_ENGINE); + + for (int i = 0; i < ETB_COUNT; i++) { + engine->etbControllers[i] = &mocks[i]; + } + + // Must have a sensor configured before init + Sensor::setMockValue(SensorType::AcceleratorPedal, 0); + Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0); + + engineConfiguration->etbFunctions[0] = ETB_Wastegate; + engineConfiguration->etbFunctions[1] = ETB_None; + + // Expect mock0 to be init as throttle 1, and PID wastegate params + EXPECT_CALL(mocks[0], init(ETB_Wastegate, _, &engineConfiguration->etbWastegatePid, Ne(nullptr))).WillOnce(Return(true)); + + // Expect mock1 to be init as none + EXPECT_CALL(mocks[1], init(ETB_None, _, _, _)).WillOnce(Return(true)); + + doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE); +} + TEST(etb, initializationNoFunction) { StrictMock motor;