From c533990d6ac81be740d37818d080b5910c456075 Mon Sep 17 00:00:00 2001 From: Kevin Plaizier <46289813+Quick-Flash@users.noreply.github.com> Date: Mon, 26 Sep 2022 23:25:46 -0600 Subject: [PATCH] Fix the normal airmode mixer https://github.com/betaflight/betaflight/issues/11854 Should fix this. Didn't realize that it was actually possible for it to somewhat act wrong. --- src/main/flight/mixer.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/flight/mixer.c b/src/main/flight/mixer.c index 8d73134fa2..da989dcbf5 100644 --- a/src/main/flight/mixer.c +++ b/src/main/flight/mixer.c @@ -445,22 +445,20 @@ static void applyMixerAdjustment(float *motorMix, const float motorMixMin, const throttle += pidGetAirmodeThrottleOffset(); float airmodeThrottleChange = 0; #endif + + const float motorMixNormalizationFactor = motorMixRange > 1.0f ? motorMixRange : 1.0f; - if (motorMixRange > 1.0f) { - for (int i = 0; i < mixerRuntime.motorCount; i++) { - motorMix[i] /= motorMixRange; - } - // Get the maximum correction by setting offset to center when airmode enabled - if (airmodeEnabled) { - throttle = 0.5f; - } - } else { - if (airmodeEnabled || throttle > 0.5f) { - throttle = constrainf(throttle, -motorMixMin, 1.0f - motorMixMax); + for (int i = 0; i < mixerRuntime.motorCount; i++) { + motorMix[i] /= motorMixNormalizationFactor; + } + + if (airmodeEnabled || throttle > 0.5f) { + float normalizedMotorMixMin = motorMixMin / motorMixNormalizationFactor; + float normalizedMotorMixMax = motorMixMax / motorMixNormalizationFactor; + throttle = constrainf(throttle, -normalizedMotorMixMin, 1.0f - normalizedMotorMixMax); #ifdef USE_AIRMODE_LPF - airmodeThrottleChange = constrainf(unadjustedThrottle, -motorMixMin, 1.0f - motorMixMax) - unadjustedThrottle; + airmodeThrottleChange = constrainf(unadjustedThrottle, -normalizedMotorMixMin, 1.0f - normalizedMotorMixMax) - unadjustedThrottle; #endif - } } #ifdef USE_AIRMODE_LPF