mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 21:05:35 +03:00
Optimze pidSum calculation by storing the value rather than recalculating in multiple places.
Saves 72 bytes. Will save at least that additionally when incorporated into Runaway Takeoff Prevention (which also calculates the pidSum in two places). Additionally adds a slight performance improvement by not repeating the floating point additions to calculate the pidSum in multiple places. Effectively replaces 2 calculations with 1 (4 with 1 with Runaway Takeoff Prevention).
This commit is contained in:
parent
6efe34d4da
commit
fba0b2cea3
4 changed files with 12 additions and 7 deletions
|
@ -694,11 +694,11 @@ void mixTable(timeUs_t currentTimeUs, uint8_t vbatPidCompensation)
|
|||
|
||||
// Calculate and Limit the PIDsum
|
||||
const float scaledAxisPidRoll =
|
||||
constrainf(axisPID_P[FD_ROLL] + axisPID_I[FD_ROLL] + axisPID_D[FD_ROLL], -currentPidProfile->pidSumLimit, currentPidProfile->pidSumLimit) / PID_MIXER_SCALING;
|
||||
constrainf(axisPIDSum[FD_ROLL], -currentPidProfile->pidSumLimit, currentPidProfile->pidSumLimit) / PID_MIXER_SCALING;
|
||||
const float scaledAxisPidPitch =
|
||||
constrainf(axisPID_P[FD_PITCH] + axisPID_I[FD_PITCH] + axisPID_D[FD_PITCH], -currentPidProfile->pidSumLimit, currentPidProfile->pidSumLimit) / PID_MIXER_SCALING;
|
||||
constrainf(axisPIDSum[FD_PITCH], -currentPidProfile->pidSumLimit, currentPidProfile->pidSumLimit) / PID_MIXER_SCALING;
|
||||
float scaledAxisPidYaw =
|
||||
constrainf(axisPID_P[FD_YAW] + axisPID_I[FD_YAW], -currentPidProfile->pidSumLimitYaw, currentPidProfile->pidSumLimitYaw) / PID_MIXER_SCALING;
|
||||
constrainf(axisPIDSum[FD_YAW], -currentPidProfile->pidSumLimitYaw, currentPidProfile->pidSumLimitYaw) / PID_MIXER_SCALING;
|
||||
if (!mixerConfig()->yaw_motors_reversed) {
|
||||
scaledAxisPidYaw = -scaledAxisPidYaw;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue