From 4b4e68395781b55662fcbe216e7f4ae9326047a6 Mon Sep 17 00:00:00 2001 From: 960 Date: Sun, 2 Feb 2020 09:56:21 +0100 Subject: [PATCH] Boost pr (#1114) * boost control * cleanup * Delete rusefi_config.txt * Add files via upload * Delete rusefi_config.txt * Add files via upload * Update rusefi.input * Update boost_control.cpp --- firmware/config/stm32f7ems/efifeatures.h | 1 + .../controllers/actuators/boost_control.cpp | 194 ++++++++++++++++++ .../controllers/algo/engine_configuration.cpp | 9 +- firmware/controllers/controllers.mk | 1 + firmware/controllers/engine_controller.cpp | 4 + firmware/controllers/system/efi_gpio.cpp | 1 + firmware/hw_layer/hardware.cpp | 8 +- firmware/tunerstudio/rusefi.input | 46 ++++- 8 files changed, 261 insertions(+), 3 deletions(-) create mode 100644 firmware/controllers/actuators/boost_control.cpp diff --git a/firmware/config/stm32f7ems/efifeatures.h b/firmware/config/stm32f7ems/efifeatures.h index dcfeacf284..ff9956cc80 100644 --- a/firmware/config/stm32f7ems/efifeatures.h +++ b/firmware/config/stm32f7ems/efifeatures.h @@ -13,6 +13,7 @@ #include "../stm32f4ems/efifeatures.h" #pragma once +#define EFI_BOOST_CONTROL TRUE // Warning! This is a test config! diff --git a/firmware/controllers/actuators/boost_control.cpp b/firmware/controllers/actuators/boost_control.cpp new file mode 100644 index 0000000000..e7c62f4133 --- /dev/null +++ b/firmware/controllers/actuators/boost_control.cpp @@ -0,0 +1,194 @@ +/* + * boost_control.cpp + * + * Created on: 13. des. 2019 + * Author: Ola Ruud + */ +#include "global.h" + +#if EFI_BOOST_CONTROL + +#if EFI_TUNER_STUDIO +#include "tunerstudio_configuration.h" +#endif /* EFI_TUNER_STUDIO */ +#include "engine.h" +#include "boost_control.h" +#include "tps.h" +#include "map.h" +#include "io_pins.h" +#include "engine_configuration.h" +#include "pwm_generator_logic.h" +#include "pid.h" +#include "engine_controller.h" +#include "periodic_task.h" +#include "pin_repository.h" +#include "pwm_generator.h" +#include "pid_auto_tune.h" +#include "local_version_holder.h" +#define NO_PIN_PERIOD 500 + +#if defined(HAS_OS_ACCESS) +#error "Unexpected OS ACCESS HERE" +#endif + +EXTERN_ENGINE; + +static Logging *logger; +static boostOpenLoop_Map3D_t boostMapOpen("boostmapopen", 1); +static boostOpenLoop_Map3D_t boostMapClosed("boostmapclosed", 1); +static SimplePwm boostPwmControl("boost"); +static pid_s *boostPidS = &persistentState.persistentConfiguration.engineConfiguration.boostPid; +static Pid boostControlPid(boostPidS); + + +static bool shouldResetPid = false; + +#if EFI_TUNER_STUDIO +extern TunerStudioOutputChannels tsOutputChannels; +#endif /* EFI_TUNER_STUDIO */ + + +static void pidReset(void) { + boostControlPid.reset(); +} + + +class BoostControl: public PeriodicTimerController { + int getPeriodMs() + override { + return GET_PERIOD_LIMITED(&engineConfiguration->boostPid); + } + void PeriodicTask() override { + if (shouldResetPid) { + pidReset(); + shouldResetPid = false; + } + +#if EFI_TUNER_STUDIO + boostControlPid.postState(&tsOutputChannels); +#endif /* EFI_TUNER_STUDIO */ + float rpm = GET_RPM_VALUE; + float mapValue = getMap(PASS_ENGINE_PARAMETER_SIGNATURE); + + if (!engineConfiguration->isBoostControlEnabled) + return; + bool enabledAtEngineRunning = rpm > engineConfiguration->cranking.rpm; + if (!enabledAtEngineRunning) { + boostControlPid.reset(); + return; + } + + + percent_t openLoopDuty = boostMapOpen.getValue(rpm / RPM_1_BYTE_PACKING_MULT, mapValue/ LOAD_1_BYTE_PACKING_MULT) * LOAD_1_BYTE_PACKING_MULT; + percent_t duty, closedLoopDuty = 0; + + if (engineConfiguration->boostType == OPEN_LOOP) { + duty = openLoopDuty; + } + else if (engineConfiguration->boostType == CLOSED_LOOP) { + float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE); + float targetBoost = boostMapClosed.getValue(rpm / RPM_1_BYTE_PACKING_MULT, tps / TPS_1_BYTE_PACKING_MULT) * LOAD_1_BYTE_PACKING_MULT; + closedLoopDuty = openLoopDuty + boostControlPid.getOutput(targetBoost, mapValue); + duty = closedLoopDuty; + } + + + boostControlPid.iTermMin = -50; + boostControlPid.iTermMax = 50; + + if (engineConfiguration->debugMode == DBG_BOOST) { + #if EFI_TUNER_STUDIO + tsOutputChannels.debugFloatField1 = openLoopDuty; + tsOutputChannels.debugFloatField7 = closedLoopDuty; + #endif /* EFI_TUNER_STUDIO */ + } + boostPwmControl.setSimplePwmDutyCycle(PERCENT_TO_DUTY(duty)); + + } + + +}; + +static BoostControl BoostController; + + +void setBoostPFactor(float value) { + engineConfiguration->boostPid.pFactor = value; + boostControlPid.reset(); + +} + +void setBoostIFactor(float value) { + engineConfiguration->boostPid.iFactor = value; + boostControlPid.reset(); +} + + +void setBoostDFactor(float value) { + engineConfiguration->boostPid.dFactor = value; + boostControlPid.reset(); +} + +void setDefaultBoostParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) { + + + engineConfiguration->isBoostControlEnabled = true; + engineConfiguration->boostPwmFrequency = 55; + engineConfiguration->boostPid.offset = 0; + engineConfiguration->boostPid.pFactor = 0.5; + engineConfiguration->boostPid.iFactor = 0.3; + engineConfiguration->boostPid.periodMs = 100; + engineConfiguration->boostPid.maxValue = 99; + engineConfiguration->boostPid.minValue = -99; + engineConfiguration->boostControlPin = GPIO_UNASSIGNED; + engineConfiguration->boostControlPinMode = OM_DEFAULT; + + setLinearCurve(config->boostRpmBins, 0, 8000 / RPM_1_BYTE_PACKING_MULT, 1); + setLinearCurve(config->boostMapBins, 0, 300 / LOAD_1_BYTE_PACKING_MULT, 1); + for (int loadIndex = 0;loadIndexboostTableOpenLoop[loadIndex][rpmIndex] = config->boostMapBins[loadIndex]; + } + } + setLinearCurve(config->boostTpsBins, 0, 100 / TPS_1_BYTE_PACKING_MULT, 1); + for (int loadIndex = 0;loadIndexboostTableClosedLoop[loadIndex][rpmIndex] = config->boostTpsBins[loadIndex]; + } + } +} + +static void turnBoostPidOn() { + if (CONFIG(boostControlPin) == GPIO_UNASSIGNED){ + return; + } + startSimplePwmExt(&boostPwmControl, "Boost", &engine->executor, + CONFIG(boostControlPin), &enginePins.boostPin, + engineConfiguration->boostPwmFrequency, 0.5f, + (pwm_gen_callback*) applyPinState); +} + +void startBoostPin(void) { + + turnBoostPidOn(); + +} +void stopBoostPin(void) { + brain_pin_markUnused(activeConfiguration.boostControlPin); +} + +void onConfigurationChangeBoostCallback(engine_configuration_s *previousConfiguration) { + shouldResetPid = !boostControlPid.isSame(&previousConfiguration->boostPid); +} + +void initBoostCtrl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX){ + logger = sharedLogger; + boostMapOpen.init(config->boostTableOpenLoop, config->boostMapBins, config->boostRpmBins); + boostMapClosed.init(config->boostTableClosedLoop, config->boostTpsBins, config->boostRpmBins); + boostControlPid.reset(); + startBoostPin(); + BoostController.Start(); + +} + +#endif diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 6e0894962f..6cb4fbf98b 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -76,7 +76,7 @@ #include "lada_kalina.h" #include "zil130.h" #include "honda_600.h" - +#include "boost_control.h" #if EFI_IDLE_CONTROL #include "idle_thread.h" #endif /* EFI_IDLE_CONTROL */ @@ -183,6 +183,10 @@ void incrementGlobalConfigurationVersion(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #if EFI_ALTERNATOR_CONTROL onConfigurationChangeAlternatorCallback(&activeConfiguration); #endif /* EFI_ALTERNATOR_CONTROL */ + +#if EFI_BOOST_CONTROL + onConfigurationChangeBoostCallback(&activeConfiguration); +#endif #if EFI_ELECTRONIC_THROTTLE_BODY onConfigurationChangeElectronicThrottleCallback(&activeConfiguration); #endif /* EFI_ELECTRONIC_THROTTLE_BODY */ @@ -646,6 +650,9 @@ static void setDefaultEngineConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { setDefaultEtbParameters(PASS_CONFIG_PARAMETER_SIGNATURE); setDefaultEtbBiasCurve(PASS_CONFIG_PARAMETER_SIGNATURE); #endif /* EFI_ELECTRONIC_THROTTLE_BODY */ +#if EFI_BOOST_CONTROL + setDefaultBoostParameters(PASS_CONFIG_PARAMETER_SIGNATURE); +#endif CONFIG(mafSensorType) = Bosch0280218037; setBosch0280218037(config); diff --git a/firmware/controllers/controllers.mk b/firmware/controllers/controllers.mk index 56783f376a..a2f6683766 100644 --- a/firmware/controllers/controllers.mk +++ b/firmware/controllers/controllers.mk @@ -13,6 +13,7 @@ CONTROLLERSSRC = CONTROLLERS_SRC_CPP = \ $(CONTROLLERS_DIR)/actuators/electronic_throttle.cpp \ $(CONTROLLERS_DIR)/actuators/alternator_controller.cpp \ + $(CONTROLLERS_DIR)/actuators/boost_control.cpp \ $(CONTROLLERS_DIR)/actuators/idle_thread.cpp \ $(CONTROLLERS_DIR)/actuators/pwm_tester.cpp \ $(CONTROLLERS_DIR)/actuators/algo/aux_pid.cpp \ diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index fcccc19246..67ce64b99c 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -53,6 +53,7 @@ #include "accelerometer.h" #include "counter64.h" #include "perf_trace.h" +#include "boost_control.h" #if EFI_SENSOR_CHART #include "sensor_chart.h" @@ -787,6 +788,9 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) initAlternatorCtrl(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX); #endif +#if EFI_BOOST_CONTROL + initBoostCtrl(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX); +#endif #if EFI_AUX_PID initAuxPid(sharedLogger); #endif diff --git a/firmware/controllers/system/efi_gpio.cpp b/firmware/controllers/system/efi_gpio.cpp index 5592f1b999..175cd2bb98 100644 --- a/firmware/controllers/system/efi_gpio.cpp +++ b/firmware/controllers/system/efi_gpio.cpp @@ -142,6 +142,7 @@ void EnginePins::unregisterPins() { unregisterOutputIfPinChanged(fsioOutputs[i], fsioOutputPins[i]); } + unregisterOutputIfPinOrModeChanged(boostPin, boostControlPin, boostControlPinMode); unregisterOutputIfPinOrModeChanged(alternatorPin, alternatorControlPin, alternatorControlPinMode); unregisterOutputIfPinOrModeChanged(mainRelay, mainRelayPin, mainRelayPinMode); unregisterOutputIfPinOrModeChanged(starterRelay, starterRelayPin, starterRelayPinMode); diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 3b5f7f2514..3a87c09798 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -49,7 +49,7 @@ #include "engine_configuration.h" #include "aux_pid.h" #include "perf_trace.h" - +#include "boost_control.h" #if EFI_MC33816 #include "mc33816.h" #endif /* EFI_MC33816 */ @@ -345,6 +345,9 @@ void applyNewHardwareSettings(void) { stopHD44780_pins(); #endif /* #if EFI_HD44780_LCD */ +#if EFI_BOOST_CONTROL + stopBoostPin(); +#endif if (isPinOrModeChanged(clutchUpPin, clutchUpPinMode)) brain_pin_markUnused(activeConfiguration.clutchUpPin); @@ -390,6 +393,9 @@ void applyNewHardwareSettings(void) { startVSSPins(); #endif /* EFI_VEHICLE_SPEED */ +#if EFI_BOOST_CONTROL + startBoostPin(); +#endif #if EFI_AUX_PID startAuxPins(); #endif /* EFI_AUX_PID */ diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 328279a1e6..778aa69118 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -667,6 +667,17 @@ fileVersion = { @@TS_FILE_VERSION@@ } xBins = tpsTpsAccelFromRpmBins, TPSValue yBins = tpsTpsAccelToRpmBins, TPSValue zBins = tpsTpsAccelTable + + table = boostTableTbl, boostMapOpen, "", 1 + xBins = boostRpmBins, RPMValue + yBins = boostMapBins, MAPValue + zBins = boostTableOpenLoop + + table = boostTable2Tbl, boostMapClosed, "", 1 + xBins = boostRpmBins, RPMValue + yBins = boostTpsBins, TPSValue + zBins = boostTableClosedLoop + table = fsioTable1Tbl, fsioTable1Map, "FSIO Table #1", 1 @@ -1214,7 +1225,10 @@ menuDialog = main subMenu = cltIdleCurve, "CLT multiplier" subMenu = iacCoastingCurve, "Coasting IAC Position for Auto-Idle", 0, {useIacTableForCoasting == 1} - menu = "&FSIO" + menu = "&Advanced" + subMenu = boostDialog, "Boost Control" + subMenu = boostPidDialog, "Closed Loop Boost", { boostType == 1 } + subMenu = std_separator subMenu = fsioInputsDialog, "FSIO inputs" subMenu = auxPidDialog, "Aux PID" subMenu = fsioOutputsDialog, "FSIO outputs" @@ -2496,6 +2510,36 @@ cmd_set_engine_type_default = "w\x00\x31\x00\x00" field = "ADC #2", fsioAdc2 field = "ADC #3", fsioAdc3 field = "ADC #4", fsioAdc4 + +;Boost Open Loop + + dialog = boost_left, "" + field = "Enable", isBoostControlEnabled + field = "Control Mode", boostType, { isBoostControlEnabled } + field = "Output", boostControlPin, { isBoostControlEnabled } + field = "Output Mode", boostControlPinMode, { isBoostControlEnabled } + field = "Frequency", boostPwmFrequency, { isBoostControlEnabled } + + dialog = boostDialog, "", border + panel = boost_left, West + panel = boostTableTbl, Center + +;Boost Closed Loop + + dialog = boostPidleft, "" + 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 } + field = "Min Duty", boostPid_minValue, { isBoostControlEnabled && boostType == 1 } + field = "Max Duty", boostPid_maxValue, { isBoostControlEnabled && boostType == 1 } + + dialog = boostTableDialog, "", card + panel = boostTable2Tbl + + dialog = boostPidDialog, "", border + panel = boostPidleft, West + panel = boostTableDialog, Center help = veTableDialogHelp, "Volumetric Efficiency" text = "Volumetric Efficiency is used to calculate fuel in Speed Density mode"