diff --git a/firmware/config/engines/custom_engine.cpp b/firmware/config/engines/custom_engine.cpp index 0c8c0c6229..7e83b58f0a 100644 --- a/firmware/config/engines/custom_engine.cpp +++ b/firmware/config/engines/custom_engine.cpp @@ -350,7 +350,25 @@ void setTle8888TestConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { boardConfiguration->fuelPumpPin = TLE8888_PIN_20; engineConfiguration->tpsAdcChannel = EFI_ADC_3; // PA3 - engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_4; // PA4 + engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_7; // PA7 + + engineConfiguration->etb.pFactor = 1.07; + engineConfiguration->etb.iFactor = 0.18; + engineConfiguration->etb.dFactor = 0.24; + engineConfiguration->etb.offset = 80; +#if EFI_PROD_CODE + engineConfiguration->etb.periodMs = (1000 / DEFAULT_ETB_LOOP_FREQUENCY); + engineConfiguration->etbFreq = DEFAULT_ETB_PWM_FREQUENCY; +#endif + engineConfiguration->etb_iTermMin = -300; + engineConfiguration->etb_iTermMax = 300; + + // VAG test ETB, no divider on red board - direct 3v TPS sensor + // set tps_min 332 + engineConfiguration->tpsMin = 332; + // by the way this ETB has default position of ADC=74 which is about 4% + // set tps_max 540 + engineConfiguration->tpsMax = 799; } #endif /* CONFIG_ENGINES_CUSTOM_ENGINE_CPP_ */ diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index d66e619b53..ae6c2bca91 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -232,7 +232,7 @@ private: } */ currentEtbDuty = feedForward + - pid.getOutput(targetPosition, actualThrottlePosition); + pid.getOutput(targetPosition, actualThrottlePosition, engineConfiguration->etb.periodMs / 1000.0); etb1.dcMotor.Set(PERCENT_TO_DUTY(currentEtbDuty)); /* @@ -349,8 +349,8 @@ void setDefaultEtbParameters(DECLARE_ENGINE_PARAMETER_SIGNATURE) { engineConfiguration->etb.pFactor = 1; engineConfiguration->etb.iFactor = 0.05; engineConfiguration->etb.dFactor = 0.0; - engineConfiguration->etb.periodMs = 100; - engineConfiguration->etbFreq = 300; + engineConfiguration->etb.periodMs = (1000 / DEFAULT_ETB_LOOP_FREQUENCY); + engineConfiguration->etbFreq = DEFAULT_ETB_PWM_FREQUENCY; engineConfiguration->etb_iTermMin = -300; engineConfiguration->etb_iTermMax = 300; diff --git a/firmware/controllers/actuators/electronic_throttle.h b/firmware/controllers/actuators/electronic_throttle.h index 8485c02e71..ba295f80a1 100644 --- a/firmware/controllers/actuators/electronic_throttle.h +++ b/firmware/controllers/actuators/electronic_throttle.h @@ -8,6 +8,10 @@ #ifndef ELECTRONIC_THROTTLE_H_ #define ELECTRONIC_THROTTLE_H_ +// https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem +#define DEFAULT_ETB_LOOP_FREQUENCY 200 +#define DEFAULT_ETB_PWM_FREQUENCY 300 + #include "engine.h" void initElectronicThrottle(void); void setDefaultEtbBiasCurve(DECLARE_ENGINE_PARAMETER_SIGNATURE); diff --git a/firmware/util/math/pid.cpp b/firmware/util/math/pid.cpp index 8514897686..14495ed7b1 100644 --- a/firmware/util/math/pid.cpp +++ b/firmware/util/math/pid.cpp @@ -56,6 +56,9 @@ float Pid::getUnclampedOutput(float target, float input, float dTime) { return pTerm + iTerm + dTerm + pid->offset; } +/** + * @param dTime seconds probably? :) + */ float Pid::getOutput(float target, float input, float dTime) { float output = getUnclampedOutput(target, input, dTime);