refactor Thrust Linear to initialise throttleCompensateAmount in pid_init.c

Maybe this could avoid recaculating throttleCompensateAmount every PID loop?
This commit is contained in:
ctzsnooze 2020-07-07 15:11:17 +10:00
parent 41fa8754bc
commit 9a65b766a2
3 changed files with 3 additions and 2 deletions

View File

@ -294,9 +294,8 @@ float pidCompensateThrustLinearization(float throttle)
{
if (pidRuntime.thrustLinearization != 0.0f) {
// for whoops where a lot of TL is needed, allow more throttle boost
const float throttleCompensateAmount = (1.0f - 0.5f * pidRuntime.thrustLinearization);
const float throttleReversed = (1.0f - throttle);
throttle /= 1.0f + throttleCompensateAmount * powerf(throttleReversed, 2) * pidRuntime.thrustLinearization;
throttle /= 1.0f + pidRuntime.throttleCompensateAmount * powerf(throttleReversed, 2) * pidRuntime.thrustLinearization;
}
return throttle;
}

View File

@ -351,6 +351,7 @@ typedef struct pidRuntime_s {
#ifdef USE_THRUST_LINEARIZATION
float thrustLinearization;
float throttleCompensateAmount;
#endif
#ifdef USE_AIRMODE_LPF

View File

@ -375,6 +375,7 @@ void pidInitConfig(const pidProfile_t *pidProfile)
#ifdef USE_THRUST_LINEARIZATION
pidRuntime.thrustLinearization = pidProfile->thrustLinearization / 100.0f;
pidRuntime.throttleCompensateAmount = (1.0f - 0.5f * pidRuntime.thrustLinearization);
#endif
#if defined(USE_D_MIN)
for (int axis = FD_ROLL; axis <= FD_YAW; ++axis) {