mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 15:25:36 +03:00
Fix TPA (#11969)
This commit is contained in:
parent
b44129f38d
commit
139210e403
6 changed files with 18 additions and 15 deletions
|
@ -1327,6 +1327,7 @@ static bool blackboxWriteSysinfo(void)
|
||||||
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_PID_PROCESS_DENOM, "%d", activePidLoopDenom);
|
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_PID_PROCESS_DENOM, "%d", activePidLoopDenom);
|
||||||
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_THR_MID, "%d", currentControlRateProfile->thrMid8);
|
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_THR_MID, "%d", currentControlRateProfile->thrMid8);
|
||||||
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_THR_EXPO, "%d", currentControlRateProfile->thrExpo8);
|
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_THR_EXPO, "%d", currentControlRateProfile->thrExpo8);
|
||||||
|
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_TPA_MODE, "%d", currentPidProfile->tpa_mode);
|
||||||
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_TPA_RATE, "%d", currentPidProfile->tpa_rate);
|
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_TPA_RATE, "%d", currentPidProfile->tpa_rate);
|
||||||
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_TPA_BREAKPOINT, "%d", currentPidProfile->tpa_breakpoint);
|
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_TPA_BREAKPOINT, "%d", currentPidProfile->tpa_breakpoint);
|
||||||
BLACKBOX_PRINT_HEADER_LINE("rc_rates", "%d,%d,%d", currentControlRateProfile->rcRates[ROLL],
|
BLACKBOX_PRINT_HEADER_LINE("rc_rates", "%d,%d,%d", currentControlRateProfile->rcRates[ROLL],
|
||||||
|
|
|
@ -1059,9 +1059,6 @@ const clivalue_t valueTable[] = {
|
||||||
{ "runaway_takeoff_deactivate_delay", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 100, 1000 }, PG_PID_CONFIG, offsetof(pidConfig_t, runaway_takeoff_deactivate_delay) }, // deactivate time in ms
|
{ "runaway_takeoff_deactivate_delay", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 100, 1000 }, PG_PID_CONFIG, offsetof(pidConfig_t, runaway_takeoff_deactivate_delay) }, // deactivate time in ms
|
||||||
{ "runaway_takeoff_deactivate_throttle_percent", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_PID_CONFIG, offsetof(pidConfig_t, runaway_takeoff_deactivate_throttle) }, // minimum throttle percentage during deactivation phase
|
{ "runaway_takeoff_deactivate_throttle_percent", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_PID_CONFIG, offsetof(pidConfig_t, runaway_takeoff_deactivate_throttle) }, // minimum throttle percentage during deactivation phase
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_TPA_MODE
|
|
||||||
{ PARAM_NAME_TPA_MODE, VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_TPA_MODE }, PG_PID_CONFIG, offsetof(pidConfig_t, tpaMode) },
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// PG_PID_PROFILE
|
// PG_PID_PROFILE
|
||||||
#ifdef USE_PROFILE_NAMES
|
#ifdef USE_PROFILE_NAMES
|
||||||
|
@ -1216,6 +1213,9 @@ const clivalue_t valueTable[] = {
|
||||||
|
|
||||||
{ PARAM_NAME_SIMPLIFIED_GYRO_FILTER, VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, simplified_gyro_filter) },
|
{ PARAM_NAME_SIMPLIFIED_GYRO_FILTER, VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, simplified_gyro_filter) },
|
||||||
{ PARAM_NAME_SIMPLIFIED_GYRO_FILTER_MULTIPLIER, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { SIMPLIFIED_TUNING_FILTERS_MIN, SIMPLIFIED_TUNING_MAX }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, simplified_gyro_filter_multiplier) },
|
{ PARAM_NAME_SIMPLIFIED_GYRO_FILTER_MULTIPLIER, VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { SIMPLIFIED_TUNING_FILTERS_MIN, SIMPLIFIED_TUNING_MAX }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, simplified_gyro_filter_multiplier) },
|
||||||
|
#endif
|
||||||
|
#ifdef USE_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_PULSE_MIN, PWM_PULSE_MAX }, PG_PID_PROFILE, offsetof(pidProfile_t, tpa_breakpoint) },
|
||||||
|
|
|
@ -530,6 +530,9 @@ static uint8_t cmsx_feedforward_smooth_factor;
|
||||||
static uint8_t cmsx_feedforward_jitter_factor;
|
static uint8_t cmsx_feedforward_jitter_factor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static uint8_t cmsx_tpa_rate;
|
||||||
|
static uint16_t cmsx_tpa_breakpoint;
|
||||||
|
|
||||||
static const void *cmsx_profileOtherOnEnter(displayPort_t *pDisp)
|
static const void *cmsx_profileOtherOnEnter(displayPort_t *pDisp)
|
||||||
{
|
{
|
||||||
UNUSED(pDisp);
|
UNUSED(pDisp);
|
||||||
|
@ -575,6 +578,8 @@ static const void *cmsx_profileOtherOnEnter(displayPort_t *pDisp)
|
||||||
#ifdef USE_BATTERY_VOLTAGE_SAG_COMPENSATION
|
#ifdef USE_BATTERY_VOLTAGE_SAG_COMPENSATION
|
||||||
cmsx_vbat_sag_compensation = pidProfile->vbat_sag_compensation;
|
cmsx_vbat_sag_compensation = pidProfile->vbat_sag_compensation;
|
||||||
#endif
|
#endif
|
||||||
|
cmsx_tpa_rate = pidProfile->tpa_rate;
|
||||||
|
cmsx_tpa_breakpoint = pidProfile->tpa_breakpoint;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -624,7 +629,6 @@ static const void *cmsx_profileOtherOnExit(displayPort_t *pDisp, const OSD_Entry
|
||||||
#ifdef USE_BATTERY_VOLTAGE_SAG_COMPENSATION
|
#ifdef USE_BATTERY_VOLTAGE_SAG_COMPENSATION
|
||||||
pidProfile->vbat_sag_compensation = cmsx_vbat_sag_compensation;
|
pidProfile->vbat_sag_compensation = cmsx_vbat_sag_compensation;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pidProfile->tpa_rate = cmsx_tpa_rate;
|
pidProfile->tpa_rate = cmsx_tpa_rate;
|
||||||
pidProfile->tpa_breakpoint = cmsx_tpa_breakpoint;
|
pidProfile->tpa_breakpoint = cmsx_tpa_breakpoint;
|
||||||
|
|
||||||
|
@ -678,7 +682,7 @@ static const OSD_Entry cmsx_menuProfileOtherEntries[] = {
|
||||||
{ "VBAT_SAG_COMP", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_vbat_sag_compensation, 0, 150, 1 } },
|
{ "VBAT_SAG_COMP", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_vbat_sag_compensation, 0, 150, 1 } },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ "THRPID ATT", OME_FLOAT, NULL, &(OSD_FLOAT_t) { &cmsx_tpa_rate, 0, 100, 1, 10} },
|
{ "TPA RATE", OME_FLOAT, NULL, &(OSD_FLOAT_t) { &cmsx_tpa_rate, 0, 100, 1, 10} },
|
||||||
{ "TPA BRKPT", OME_UINT16, NULL, &(OSD_UINT16_t){ &cmsx_tpa_breakpoint, 1000, 2000, 10} },
|
{ "TPA BRKPT", OME_UINT16, NULL, &(OSD_UINT16_t){ &cmsx_tpa_breakpoint, 1000, 2000, 10} },
|
||||||
|
|
||||||
{ "BACK", OME_Back, NULL, NULL },
|
{ "BACK", OME_Back, NULL, NULL },
|
||||||
|
|
|
@ -89,7 +89,7 @@ FAST_DATA_ZERO_INIT float throttleBoost;
|
||||||
pt1Filter_t throttleLpf;
|
pt1Filter_t throttleLpf;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PG_REGISTER_WITH_RESET_TEMPLATE(pidConfig_t, pidConfig, PG_PID_CONFIG, 4);
|
PG_REGISTER_WITH_RESET_TEMPLATE(pidConfig_t, pidConfig, PG_PID_CONFIG, 3);
|
||||||
|
|
||||||
#if defined(STM32F411xE)
|
#if defined(STM32F411xE)
|
||||||
#define PID_PROCESS_DENOM_DEFAULT 2
|
#define PID_PROCESS_DENOM_DEFAULT 2
|
||||||
|
@ -103,12 +103,10 @@ PG_RESET_TEMPLATE(pidConfig_t, pidConfig,
|
||||||
.runaway_takeoff_prevention = true,
|
.runaway_takeoff_prevention = true,
|
||||||
.runaway_takeoff_deactivate_throttle = 20, // throttle level % needed to accumulate deactivation time
|
.runaway_takeoff_deactivate_throttle = 20, // throttle level % needed to accumulate deactivation time
|
||||||
.runaway_takeoff_deactivate_delay = 500, // Accumulated time (in milliseconds) before deactivation in successful takeoff
|
.runaway_takeoff_deactivate_delay = 500, // Accumulated time (in milliseconds) before deactivation in successful takeoff
|
||||||
.tpaMode = TPA_MODE_D
|
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
PG_RESET_TEMPLATE(pidConfig_t, pidConfig,
|
PG_RESET_TEMPLATE(pidConfig_t, pidConfig,
|
||||||
.pid_process_denom = PID_PROCESS_DENOM_DEFAULT,
|
.pid_process_denom = PID_PROCESS_DENOM_DEFAULT,
|
||||||
.tpaMode = TPA_MODE_D
|
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -222,6 +220,7 @@ void resetPidProfile(pidProfile_t *pidProfile)
|
||||||
.simplified_dterm_filter_multiplier = SIMPLIFIED_TUNING_DEFAULT,
|
.simplified_dterm_filter_multiplier = SIMPLIFIED_TUNING_DEFAULT,
|
||||||
.anti_gravity_cutoff_hz = 5,
|
.anti_gravity_cutoff_hz = 5,
|
||||||
.anti_gravity_p_gain = 100,
|
.anti_gravity_p_gain = 100,
|
||||||
|
.tpa_mode = TPA_MODE_D,
|
||||||
.tpa_rate = 65,
|
.tpa_rate = 65,
|
||||||
.tpa_breakpoint = 1350,
|
.tpa_breakpoint = 1350,
|
||||||
);
|
);
|
||||||
|
@ -835,7 +834,7 @@ void FAST_CODE pidController(const pidProfile_t *pidProfile, timeUs_t currentTim
|
||||||
static float previousRawGyroRateDterm[XYZ_AXIS_COUNT];
|
static float previousRawGyroRateDterm[XYZ_AXIS_COUNT];
|
||||||
|
|
||||||
#ifdef USE_TPA_MODE
|
#ifdef USE_TPA_MODE
|
||||||
const float tpaFactorKp = (pidConfig()->tpaMode == TPA_MODE_PD) ? pidRuntime.tpaFactor : 1.0f;
|
const float tpaFactorKp = (pidProfile->tpa_mode == TPA_MODE_PD) ? pidRuntime.tpaFactor : 1.0f;
|
||||||
#else
|
#else
|
||||||
const float tpaFactorKp = pidRuntime.tpaFactor;
|
const float tpaFactorKp = pidRuntime.tpaFactor;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -230,6 +230,7 @@ typedef struct pidProfile_s {
|
||||||
|
|
||||||
uint8_t anti_gravity_cutoff_hz;
|
uint8_t anti_gravity_cutoff_hz;
|
||||||
uint8_t anti_gravity_p_gain;
|
uint8_t anti_gravity_p_gain;
|
||||||
|
uint8_t tpa_mode; // Controls which PID terms TPA effects
|
||||||
uint8_t tpa_rate; // Percent reduction in P or D at full throttle
|
uint8_t tpa_rate; // Percent reduction in P or D at full throttle
|
||||||
uint16_t tpa_breakpoint; // Breakpoint where TPA is activated
|
uint16_t tpa_breakpoint; // Breakpoint where TPA is activated
|
||||||
} pidProfile_t;
|
} pidProfile_t;
|
||||||
|
@ -241,7 +242,6 @@ typedef struct pidConfig_s {
|
||||||
uint8_t runaway_takeoff_prevention; // off, on - enables pidsum runaway disarm logic
|
uint8_t runaway_takeoff_prevention; // off, on - enables pidsum runaway disarm logic
|
||||||
uint16_t runaway_takeoff_deactivate_delay; // delay in ms for "in-flight" conditions before deactivation (successful flight)
|
uint16_t runaway_takeoff_deactivate_delay; // delay in ms for "in-flight" conditions before deactivation (successful flight)
|
||||||
uint8_t runaway_takeoff_deactivate_throttle; // minimum throttle percent required during deactivation phase
|
uint8_t runaway_takeoff_deactivate_throttle; // minimum throttle percent required during deactivation phase
|
||||||
uint8_t tpaMode; // Controls which PID terms TPA effects
|
|
||||||
} pidConfig_t;
|
} pidConfig_t;
|
||||||
|
|
||||||
PG_DECLARE(pidConfig_t, pidConfig);
|
PG_DECLARE(pidConfig_t, pidConfig);
|
||||||
|
@ -400,8 +400,6 @@ typedef struct pidRuntime_s {
|
||||||
#ifdef USE_ACC
|
#ifdef USE_ACC
|
||||||
pt3Filter_t attitudeFilter[2]; // Only for ROLL and PITCH
|
pt3Filter_t attitudeFilter[2]; // Only for ROLL and PITCH
|
||||||
#endif
|
#endif
|
||||||
uint8_t tpa_rate;
|
|
||||||
uint16_t tpa_breakpoint;
|
|
||||||
} pidRuntime_t;
|
} pidRuntime_t;
|
||||||
|
|
||||||
extern pidRuntime_t pidRuntime;
|
extern pidRuntime_t pidRuntime;
|
||||||
|
|
|
@ -2020,6 +2020,7 @@ static bool mspProcessOutCommand(mspDescriptor_t srcDesc, int16_t cmdMSP, sbuf_t
|
||||||
#else
|
#else
|
||||||
sbufWriteU8(dst, 0);
|
sbufWriteU8(dst, 0);
|
||||||
#endif
|
#endif
|
||||||
|
sbufWriteU8(dst, currentPidProfile->tpa_mode);
|
||||||
sbufWriteU8(dst, currentPidProfile->tpa_rate);
|
sbufWriteU8(dst, currentPidProfile->tpa_rate);
|
||||||
sbufWriteU16(dst, currentPidProfile->tpa_breakpoint); // was currentControlRateProfile->tpa_breakpoint
|
sbufWriteU16(dst, currentPidProfile->tpa_breakpoint); // was currentControlRateProfile->tpa_breakpoint
|
||||||
break;
|
break;
|
||||||
|
@ -3168,10 +3169,10 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP,
|
||||||
sbufReadU8(src);
|
sbufReadU8(src);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (sbufBytesRemaining(src) >= 3) {
|
if (sbufBytesRemaining(src) >= 4) {
|
||||||
// Added in API 1.45
|
// Added in API 1.45
|
||||||
value = sbufReadU8(src);
|
currentPidProfile->tpa_mode = sbufReadU8(src);
|
||||||
currentPidProfile->tpa_rate = MIN(value, TPA_MAX);
|
currentPidProfile->tpa_rate = MIN(sbufReadU8(src), TPA_MAX);
|
||||||
currentPidProfile->tpa_breakpoint = sbufReadU16(src);
|
currentPidProfile->tpa_breakpoint = sbufReadU16(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue