From 3e7adb5ea6935c07791fc54163d5f8421ee03a77 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Thu, 21 Sep 2017 23:21:03 -0400 Subject: [PATCH] ETB auto-tune --- firmware/controllers/electronic_throttle.cpp | 32 ++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/firmware/controllers/electronic_throttle.cpp b/firmware/controllers/electronic_throttle.cpp index 6975bc48a7..bf80f0e271 100644 --- a/firmware/controllers/electronic_throttle.cpp +++ b/firmware/controllers/electronic_throttle.cpp @@ -59,9 +59,12 @@ #if EFI_ELECTRONIC_THROTTLE_BODY || defined(__DOXYGEN__) #include "pin_repository.h" #include "pwm_generator.h" +#include "pid_auto_tune.h" extern TunerStudioOutputChannels tsOutputChannels; static bool shouldResetPid = false; +static PID_AutoTune autoTune; + static LoggingWithStorage logger("ETB"); /** * @brief Control Thread stack @@ -82,7 +85,7 @@ static Pid pid(&engineConfiguration->etb); static float prevTps; -static float currentEtbDuty; +static percent_t currentEtbDuty; static bool wasEtbBraking = false; @@ -95,6 +98,15 @@ static msg_t etbThread(void *arg) { shouldResetPid = false; } + if (engine->etbAutoTune) { + autoTune.Runtime(&logger); + + etbPwmUp.setSimplePwmDutyCycle(autoTune.output); + + pid.sleep(); + continue; + } + percent_t throttlePedal = getPedalPosition(PASS_ENGINE_PARAMETER_SIGNATURE); percent_t tps = getTPS(); @@ -142,6 +154,9 @@ static void setThrottleConsole(int level) { static void showEthInfo(void) { static char pinNameBuffer[16]; + scheduleMsg(&logger, "etbAutoTune=%d", + engine->etbAutoTune); + scheduleMsg(&logger, "throttlePedal=%f %f/%f @%s", getPedalPosition(), engineConfiguration->throttlePedalUpVoltage, @@ -227,6 +242,16 @@ void startETBPins(void) { outputDirectionClose.initPin("etb dir close", boardConfiguration->etbDirectionPin2); } +static void setTempOutput(float value) { + autoTune.output = value; + +} + +static void setTempStep(float value) { + autoTune.oStep = value; + +} + void initElectronicThrottle(void) { // these two lines are controlling direction // outputPinRegister("etb1", ELECTRONIC_THROTTLE_CONTROL_1, ETB_CONTROL_LINE_1_PORT, ETB_CONTROL_LINE_1_PIN); @@ -239,7 +264,10 @@ void initElectronicThrottle(void) { startETBPins(); - addConsoleActionI("e", setThrottleConsole); + addConsoleActionI("set_etb", setThrottleConsole); + + addConsoleActionF("set_etb_output", setTempOutput); + addConsoleActionF("set_etb_step", setTempStep); apply();