mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 14:25:20 +03:00
Little optimisation PID.c
Hi, I know, it's not a huge optimisation but I just switched the condition of the IF condition (line 425). Given that the YAW axis occur one time in the FOR loop (line 366), the IF(axis == YAW) condition will be called one time whereas the IF(axis != YAW) condition will be called two times. Check first the most used condition in an IF condition is a good thing to do in a code source. I just don't know if it will be a major improvement, I let you judge.
This commit is contained in:
parent
2f14f61190
commit
0f1b00520f
1 changed files with 14 additions and 14 deletions
|
@ -422,20 +422,7 @@ static void pidLegacy(const pidProfile_t *pidProfile, uint16_t max_angle_inclina
|
||||||
ITerm = errorGyroI[axis] >> 13;
|
ITerm = errorGyroI[axis] >> 13;
|
||||||
|
|
||||||
//-----calculate D-term
|
//-----calculate D-term
|
||||||
if (axis == YAW) {
|
if (axis != YAW) {
|
||||||
if (pidProfile->yaw_lpf_hz) PTerm = pt1FilterApply4(&yawFilter, PTerm, pidProfile->yaw_lpf_hz, getdT());
|
|
||||||
|
|
||||||
axisPID[axis] = PTerm + ITerm;
|
|
||||||
|
|
||||||
if (motorCount >= 4) {
|
|
||||||
int16_t yaw_jump_prevention_limit = constrain(YAW_JUMP_PREVENTION_LIMIT_HIGH - (pidProfile->D8[axis] << 3), YAW_JUMP_PREVENTION_LIMIT_LOW, YAW_JUMP_PREVENTION_LIMIT_HIGH);
|
|
||||||
|
|
||||||
// prevent "yaw jump" during yaw correction
|
|
||||||
axisPID[YAW] = constrain(axisPID[YAW], -yaw_jump_prevention_limit - ABS(rcCommand[YAW]), yaw_jump_prevention_limit + ABS(rcCommand[YAW]));
|
|
||||||
}
|
|
||||||
|
|
||||||
DTerm = 0; // needed for blackbox
|
|
||||||
} else {
|
|
||||||
if (pidProfile->deltaMethod == DELTA_FROM_ERROR) {
|
if (pidProfile->deltaMethod == DELTA_FROM_ERROR) {
|
||||||
delta = RateError - lastRateError[axis];
|
delta = RateError - lastRateError[axis];
|
||||||
lastRateError[axis] = RateError;
|
lastRateError[axis] = RateError;
|
||||||
|
@ -464,6 +451,19 @@ static void pidLegacy(const pidProfile_t *pidProfile, uint16_t max_angle_inclina
|
||||||
|
|
||||||
// -----calculate total PID output
|
// -----calculate total PID output
|
||||||
axisPID[axis] = PTerm + ITerm + DTerm;
|
axisPID[axis] = PTerm + ITerm + DTerm;
|
||||||
|
} else {
|
||||||
|
if (pidProfile->yaw_lpf_hz) PTerm = pt1FilterApply4(&yawFilter, PTerm, pidProfile->yaw_lpf_hz, getdT());
|
||||||
|
|
||||||
|
axisPID[axis] = PTerm + ITerm;
|
||||||
|
|
||||||
|
if (motorCount >= 4) {
|
||||||
|
int16_t yaw_jump_prevention_limit = constrain(YAW_JUMP_PREVENTION_LIMIT_HIGH - (pidProfile->D8[axis] << 3), YAW_JUMP_PREVENTION_LIMIT_LOW, YAW_JUMP_PREVENTION_LIMIT_HIGH);
|
||||||
|
|
||||||
|
// prevent "yaw jump" during yaw correction
|
||||||
|
axisPID[YAW] = constrain(axisPID[YAW], -yaw_jump_prevention_limit - ABS(rcCommand[YAW]), yaw_jump_prevention_limit + ABS(rcCommand[YAW]));
|
||||||
|
}
|
||||||
|
|
||||||
|
DTerm = 0; // needed for blackbox
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pidStabilisationEnabled) axisPID[axis] = 0;
|
if (!pidStabilisationEnabled) axisPID[axis] = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue