diff --git a/firmware/ChibiOS-Contrib b/firmware/ChibiOS-Contrib index fe95e90b80..b5321c7e0e 160000 --- a/firmware/ChibiOS-Contrib +++ b/firmware/ChibiOS-Contrib @@ -1 +1 @@ -Subproject commit fe95e90b80a28dd2f40bfee1ad90822b99519c6a +Subproject commit b5321c7e0ef470ed2dbb50dc1322c1252dea2d50 diff --git a/firmware/controllers/electronic_throttle.cpp b/firmware/controllers/electronic_throttle.cpp index 81dd78c36f..83255ffba1 100644 --- a/firmware/controllers/electronic_throttle.cpp +++ b/firmware/controllers/electronic_throttle.cpp @@ -75,6 +75,7 @@ static THD_WORKING_AREA(etbTreadStack, UTILITY_THREAD_STACK_SIZE); * @brief Pulse-Width Modulation state */ static SimplePwm etbPwmUp CCM_OPTIONAL; +static float valueOverride = NAN; /* static SimplePwm etbPwmDown CCM_OPTIONAL; static OutputPin outputDirectionOpen CCM_OPTIONAL; @@ -85,8 +86,6 @@ EXTERN_ENGINE; static Pid pid(&engineConfiguration->etb); -//static float prevTps; - static percent_t currentEtbDuty; static bool wasEtbBraking = false; @@ -94,12 +93,23 @@ static bool wasEtbBraking = false; static msg_t etbThread(void *arg) { UNUSED(arg); while (true) { + if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE_PID) { + pid.postState(&tsOutputChannels); + } else if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE_EXTRA) { + tsOutputChannels.debugFloatField1 = valueOverride; + } + if (shouldResetPid) { pid.reset(); -// alternatorPidResetCounter++; shouldResetPid = false; } + if (!cisnan(valueOverride)) { + etbPwmUp.setSimplePwmDutyCycle(valueOverride); + pid.sleep(); + continue; + } + if (engine->etbAutoTune) { autoTune.Runtime(&logger); @@ -127,19 +137,11 @@ static msg_t etbThread(void *arg) { outputDirectionClose.setValue(needEtbBraking); } - if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE_PID) { - pid.postState(&tsOutputChannels); - } if (engineConfiguration->isVerboseETB) { pid.showPidStatus(&logger, "ETB"); } -// if (tps != prevTps) { -// prevTps = tps; -// scheduleMsg(&logger, "tps=%d", (int) tps); -// } - // this thread is activated 10 times per second pid.sleep(); } @@ -149,12 +151,14 @@ static msg_t etbThread(void *arg) { } /** - * manual duty cycle control without PID + * manual duty cycle control without PID. Percent value from 0 to 100 */ -static void setThrottleDutyCycle(int level) { - scheduleMsg(&logger, "setting throttle=%d", level); +static void setThrottleDutyCycle(float level) { + scheduleMsg(&logger, "setting ETB duty=%f", level); - float dc = 0.01 + (minI(level, 98)) / 100.0; + float dc = (minI(level, 98)) / 100.0; + dc = maxF(dc, 0.00001); // todo: need to fix PWM so that it supports zero duty cycle + valueOverride = dc; etbPwmUp.setSimplePwmDutyCycle(dc); print("etb duty = %.2f\r\n", dc); } @@ -276,7 +280,7 @@ void initElectronicThrottle(void) { startETBPins(); // - addConsoleActionI("set_etb", setThrottleDutyCycle); + addConsoleActionF("set_etb", setThrottleDutyCycle); addConsoleActionF("set_etb_output", setTempOutput); addConsoleActionF("set_etb_step", setTempStep); diff --git a/firmware/controllers/system/pwm_generator_logic.cpp b/firmware/controllers/system/pwm_generator_logic.cpp index 0ada70b286..65d8cf6131 100644 --- a/firmware/controllers/system/pwm_generator_logic.cpp +++ b/firmware/controllers/system/pwm_generator_logic.cpp @@ -53,8 +53,10 @@ void PwmConfig::init(float *st, single_wave_s *waves) { */ void SimplePwm::setSimplePwmDutyCycle(float dutyCycle) { if (dutyCycle < 0 || dutyCycle > 1) { - firmwareError(CUSTOM_ERR_6579, "spwd:dutyCycle %.2f", dutyCycle); + warning(CUSTOM_ERR_6579, "spwd:dutyCycle %.2f", dutyCycle); + return; } + // todo: need to fix PWM so that it supports zero duty cycle multiWave.setSwitchTime(0, dutyCycle); } diff --git a/java_console/.idea/runConfigurations/Launcher.xml b/java_console/.idea/runConfigurations/Launcher.xml index 8daa03a849..489f5348da 100644 --- a/java_console/.idea/runConfigurations/Launcher.xml +++ b/java_console/.idea/runConfigurations/Launcher.xml @@ -6,7 +6,7 @@