1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-13 19:40:31 +03:00

TPA optimisations (#12721)

* TPA optimisations

* improvement, thanks @ledvinap

* update following review comments, thanks karatebrot and ledvinap

* include rx.h in pid_init.c to get PWM_RANGE_MIN

* review suggestion
This commit is contained in:
ctzsnooze 2023-05-12 02:38:15 +10:00 committed by GitHub
parent c6b3a1e129
commit 10067ad6ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 15 deletions

View file

@ -1223,7 +1223,7 @@ const clivalue_t valueTable[] = {
{ PARAM_NAME_TPA_MODE, VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_TPA_MODE }, PG_PID_PROFILE, offsetof(pidProfile_t, tpa_mode) }, { PARAM_NAME_TPA_MODE, VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_TPA_MODE }, PG_PID_PROFILE, offsetof(pidProfile_t, tpa_mode) },
#endif #endif
{ PARAM_NAME_TPA_RATE, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, TPA_MAX}, PG_PID_PROFILE, offsetof(pidProfile_t, tpa_rate) }, { PARAM_NAME_TPA_RATE, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, TPA_MAX}, PG_PID_PROFILE, offsetof(pidProfile_t, tpa_rate) },
{ PARAM_NAME_TPA_BREAKPOINT, VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { PWM_PULSE_MIN, PWM_PULSE_MAX }, PG_PID_PROFILE, offsetof(pidProfile_t, tpa_breakpoint) }, { PARAM_NAME_TPA_BREAKPOINT, VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { PWM_RANGE_MIN, PWM_RANGE_MAX }, PG_PID_PROFILE, offsetof(pidProfile_t, tpa_breakpoint) },
// PG_TELEMETRY_CONFIG // PG_TELEMETRY_CONFIG
#ifdef USE_TELEMETRY #ifdef USE_TELEMETRY

View file

@ -277,20 +277,9 @@ void pidResetIterm(void)
void pidUpdateTpaFactor(float throttle) void pidUpdateTpaFactor(float throttle)
{ {
pidProfile_t *currentPidProfile; const float throttleTemp = fminf(throttle, 1.0f); // don't permit throttle > 1 ? is this needed ? can throttle be > 1 at this point ?
const float throttleDifference = fmaxf(throttleTemp - pidRuntime.tpaBreakpoint, 0.0f);
currentPidProfile = pidProfilesMutable(systemConfig()->pidProfileIndex); pidRuntime.tpaFactor = 1.0f - throttleDifference * pidRuntime.tpaMultiplier;
const float tpaBreakpoint = (currentPidProfile->tpa_breakpoint - 1000) / 1000.0f;
float tpaRate = currentPidProfile->tpa_rate / 100.0f;
if (throttle > tpaBreakpoint) {
if (throttle < 1.0f) {
tpaRate *= (throttle - tpaBreakpoint) / (1.0f - tpaBreakpoint);
}
} else {
tpaRate = 0.0f;
}
pidRuntime.tpaFactor = 1.0f - tpaRate;
} }
void pidUpdateAntiGravityThrottleFilter(float throttle) void pidUpdateAntiGravityThrottleFilter(float throttle)

View file

@ -322,6 +322,8 @@ typedef struct pidRuntime_s {
bool zeroThrottleItermReset; bool zeroThrottleItermReset;
bool levelRaceMode; bool levelRaceMode;
float tpaFactor; float tpaFactor;
float tpaBreakpoint;
float tpaMultiplier;
#ifdef USE_ITERM_RELAX #ifdef USE_ITERM_RELAX
pt1Filter_t windupLpf[XYZ_AXIS_COUNT]; pt1Filter_t windupLpf[XYZ_AXIS_COUNT];

View file

@ -40,6 +40,8 @@
#include "flight/pid.h" #include "flight/pid.h"
#include "flight/rpm_filter.h" #include "flight/rpm_filter.h"
#include "rx/rx.h"
#include "sensors/gyro.h" #include "sensors/gyro.h"
#include "sensors/sensors.h" #include "sensors/sensors.h"
@ -423,6 +425,9 @@ void pidInitConfig(const pidProfile_t *pidProfile)
#endif #endif
pidRuntime.levelRaceMode = pidProfile->level_race_mode; pidRuntime.levelRaceMode = pidProfile->level_race_mode;
pidRuntime.tpaBreakpoint = constrainf((pidProfile->tpa_breakpoint - PWM_RANGE_MIN) / 1000.0f, 0.0f, 0.99f);
// default of 1350 returns 0.35. range limited to 0 to 0.99
pidRuntime.tpaMultiplier = (pidProfile->tpa_rate / 100.0f) / (1.0f - pidRuntime.tpaBreakpoint);
} }
void pidCopyProfile(uint8_t dstPidProfileIndex, uint8_t srcPidProfileIndex) void pidCopyProfile(uint8_t dstPidProfileIndex, uint8_t srcPidProfileIndex)