mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 05:15:25 +03:00
Make TPA configurable to affect P/D or D only
Adds a new `tpa_mode` parameter that accepts `PD` (default) and `D`. Allows the user to configer to affect P/D as it always has, or switch to D-only mode. Note: the `tpa_mode` parameter was added to the PID Profile instead of rate profiles with the other TPA parameters. This can be discussed, but I didn't think it made sense to have this be part of rate profiles as it affects PID tuning (the same argument could be made for the other TPA parameters). Code is wrapped in `USE_TPA_MODE` so it can be disabled if needed.
This commit is contained in:
parent
49e2c4d312
commit
fc189e5850
5 changed files with 39 additions and 1 deletions
|
@ -175,6 +175,7 @@ void resetPidProfile(pidProfile_t *pidProfile)
|
|||
.launchControlAngleLimit = 0,
|
||||
.launchControlGain = 40,
|
||||
.launchControlAllowTriggerReset = true,
|
||||
.tpaMode = TPA_MODE_PD,
|
||||
);
|
||||
#ifdef USE_DYN_LPF
|
||||
pidProfile->dterm_lowpass_hz = 120;
|
||||
|
@ -434,6 +435,10 @@ static FAST_RAM_ZERO_INIT uint8_t launchControlAngleLimit;
|
|||
static FAST_RAM_ZERO_INIT float launchControlKi;
|
||||
#endif
|
||||
|
||||
#ifdef USE_TPA_MODE
|
||||
static FAST_RAM_ZERO_INIT uint8_t tpaMode;
|
||||
#endif
|
||||
|
||||
void pidResetIterm(void)
|
||||
{
|
||||
for (int axis = 0; axis < 3; axis++) {
|
||||
|
@ -576,6 +581,10 @@ void pidInitConfig(const pidProfile_t *pidProfile)
|
|||
}
|
||||
launchControlKi = ITERM_SCALE * pidProfile->launchControlGain;
|
||||
#endif
|
||||
|
||||
#ifdef USE_TPA_MODE
|
||||
tpaMode = pidProfile->tpaMode;
|
||||
#endif
|
||||
}
|
||||
|
||||
void pidInit(const pidProfile_t *pidProfile)
|
||||
|
@ -1048,6 +1057,12 @@ void FAST_CODE pidController(const pidProfile_t *pidProfile, const rollAndPitchT
|
|||
|
||||
const float tpaFactor = getThrottlePIDAttenuation();
|
||||
|
||||
#ifdef USE_TPA_MODE
|
||||
const float tpaFactorKp = (tpaMode == TPA_MODE_PD) ? tpaFactor : 1.0f;
|
||||
#else
|
||||
const float tpaFactorKp = tpaFactor;
|
||||
#endif
|
||||
|
||||
#ifdef USE_YAW_SPIN_RECOVERY
|
||||
const bool yawSpinActive = gyroYawSpinDetected();
|
||||
#endif
|
||||
|
@ -1145,7 +1160,7 @@ void FAST_CODE pidController(const pidProfile_t *pidProfile, const rollAndPitchT
|
|||
// b = 1 and only c (feedforward weight) can be tuned (amount derivative on measurement or error).
|
||||
|
||||
// -----calculate P component
|
||||
pidData[axis].P = pidCoefficient[axis].Kp * errorRate * tpaFactor;
|
||||
pidData[axis].P = pidCoefficient[axis].Kp * errorRate * tpaFactorKp;
|
||||
if (axis == FD_YAW) {
|
||||
pidData[axis].P = ptermYawLowpassApplyFn((filter_t *) &ptermYawLowpass, pidData[axis].P);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue