Skip to content

Commit 663b6a6

Browse files
Matthew Wegnerbkleiner
authored andcommitted
input_throttle_calc() uses Betaflight throttle curve
"Midpoint" is expo origin/pivot, not a remap where X=0.5 results in Y=mid
1 parent fbcb66f commit 663b6a6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/flight/input.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,18 @@ vec3_t input_rates_calc() {
156156
}
157157

158158
float input_throttle_calc(float throttle) {
159-
const float n = (throttle * 2.f - 1.f);
160159
const float expo = profile.rate.throttle_expo;
161160
const float mid = profile.rate.throttle_mid;
162-
return constrain((n * n * n * expo + n * (1.f - expo) + 1.f) * mid, 0.0f, 1.0f);
161+
const float throttle_minus_mid = throttle - mid;
162+
163+
float divisor = 1;
164+
if (throttle_minus_mid > 0.0f) {
165+
divisor = 1 - mid;
166+
}
167+
if (throttle_minus_mid < 0.0f) {
168+
divisor = mid;
169+
}
170+
171+
// betaflight's throttle curve: https://github.com/betaflight/betaflight/blob/c513b102b6f2af9aa0390cfa7ef908ec652552fc/src/main/fc/rc.c#L838
172+
return constrain(mid + throttle_minus_mid * (1 - expo + expo * (throttle_minus_mid * throttle_minus_mid) / (divisor * divisor)), 0.0f, 1.0f);
163173
}

0 commit comments

Comments
 (0)