diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 0698a55ceb..243f9b53fd 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -162,6 +162,11 @@ void incrementGlobalConfigurationVersion(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #if EFI_ALTERNATOR_CONTROL || defined(__DOXYGEN__) onConfigurationChangeAlternatorCallback(&activeConfiguration); #endif /* EFI_ALTERNATOR_CONTROL */ +#if EFI_ELECTRONIC_THROTTLE_BODY || defined(__DOXYGEN__) + onConfigurationChangeElectronicThrottleCallback(&activeConfiguration); +#endif /* EFI_ELECTRONIC_THROTTLE_BODY */ + + rememberCurrentConfiguration(); } diff --git a/firmware/controllers/electronic_throttle.cpp b/firmware/controllers/electronic_throttle.cpp index ec2e331deb..426c65862b 100644 --- a/firmware/controllers/electronic_throttle.cpp +++ b/firmware/controllers/electronic_throttle.cpp @@ -55,6 +55,7 @@ #include "pin_repository.h" #include "pwm_generator.h" extern TunerStudioOutputChannels tsOutputChannels; +static bool shouldResetPid = false; #define ETB_FREQ 400 @@ -72,20 +73,26 @@ static SimplePwm etbPwmDown CCM_OPTIONAL; static OutputPin outputDirectionOpen CCM_OPTIONAL; static OutputPin outputDirectionClose CCM_OPTIONAL; -static pid_s etbS; -static Pid pid(&etbS, 0, 100); +EXTERN_ENGINE; + +static Pid pid(&engineConfiguration->etb, 0, 100); static float prevTps; static float currentEtbDuty; -EXTERN_ENGINE; - static bool wasEtbBraking = false; static msg_t etbThread(void *arg) { UNUSED(arg); while (true) { + if (shouldResetPid) { + pid.reset(); +// alternatorPidResetCounter++; + shouldResetPid = false; + } + + percent_t pedal = getPedalPosition(PASS_ENGINE_PARAMETER_SIGNATURE); percent_t tps = getTPS(); @@ -176,6 +183,11 @@ void stopETBPins(void) { unmarkPin(activeConfiguration.bc.etbDirectionPin2); } +void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *previousConfiguration) { + shouldResetPid = !pid.isSame(&engineConfiguration->etb); + +} + void startETBPins(void) { // this line used for PWM startSimplePwmExt(&etbPwmUp, "etb1", diff --git a/firmware/controllers/electronic_throttle.h b/firmware/controllers/electronic_throttle.h index c56f0a5344..3605929ca3 100644 --- a/firmware/controllers/electronic_throttle.h +++ b/firmware/controllers/electronic_throttle.h @@ -8,11 +8,13 @@ #ifndef ELECTRONIC_THROTTLE_H_ #define ELECTRONIC_THROTTLE_H_ +#include "engine.h" void initElectronicThrottle(void); void setDefaultEtbParameters(void); void setEtbPFactor(float value); void setEtbIFactor(float value); void stopETBPins(void); void startETBPins(void); +void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *previousConfiguration); #endif /* ELECTRONIC_THROTTLE_H_ */ diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 9b6e577cde..71f152fcaa 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -251,5 +251,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20170527; + return 20170528; }