mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-24 00:35:34 +03:00
pid windup backcalc fix
This commit is contained in:
parent
57bba67f86
commit
ecad9fe749
2 changed files with 7 additions and 1 deletions
|
@ -91,6 +91,7 @@
|
||||||
)
|
)
|
||||||
#define MIN(a, b) _CHOOSE(<, a, b)
|
#define MIN(a, b) _CHOOSE(<, a, b)
|
||||||
#define MAX(a, b) _CHOOSE(>, a, b)
|
#define MAX(a, b) _CHOOSE(>, a, b)
|
||||||
|
#define SIGN(a) ((a >= 0) ? 1 : -1)
|
||||||
|
|
||||||
#define _ABS_II(x, var) \
|
#define _ABS_II(x, var) \
|
||||||
( __extension__ ({ \
|
( __extension__ ({ \
|
||||||
|
|
|
@ -816,6 +816,11 @@ static void FAST_CODE NOINLINE pidApplyMulticopterRateController(pidState_t *pid
|
||||||
const float newOutput = newPTerm + newDTerm + pidState->errorGyroIf + newCDTerm;
|
const float newOutput = newPTerm + newDTerm + pidState->errorGyroIf + newCDTerm;
|
||||||
const float newOutputLimited = constrainf(newOutput, -pidState->pidSumLimit, +pidState->pidSumLimit);
|
const float newOutputLimited = constrainf(newOutput, -pidState->pidSumLimit, +pidState->pidSumLimit);
|
||||||
|
|
||||||
|
float backCalc = newOutputLimited - newOutput;//back-calculation anti-windup
|
||||||
|
if (SIGN(backCalc) == SIGN(pidState->errorGyroIf)) {
|
||||||
|
//back calculation anti-windup can only shrink integrator, will not push it to the opposite direction
|
||||||
|
backCalc = 0.0f;
|
||||||
|
}
|
||||||
float itermErrorRate = applyItermRelax(axis, rateTarget, rateError);
|
float itermErrorRate = applyItermRelax(axis, rateTarget, rateError);
|
||||||
|
|
||||||
#ifdef USE_ANTIGRAVITY
|
#ifdef USE_ANTIGRAVITY
|
||||||
|
@ -824,7 +829,7 @@ static void FAST_CODE NOINLINE pidApplyMulticopterRateController(pidState_t *pid
|
||||||
|
|
||||||
if (!pidState->itermFreezeActive) {
|
if (!pidState->itermFreezeActive) {
|
||||||
pidState->errorGyroIf += (itermErrorRate * pidState->kI * antiWindupScaler * dT)
|
pidState->errorGyroIf += (itermErrorRate * pidState->kI * antiWindupScaler * dT)
|
||||||
+ ((newOutputLimited - newOutput) * pidState->kT * antiWindupScaler * dT);
|
+ (backCalc * pidState->kT * antiWindupScaler * dT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pidProfile()->pidItermLimitPercent != 0){
|
if (pidProfile()->pidItermLimitPercent != 0){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue