From 357d19aa05eb2081f2f6d2fa91e13953fad05a86 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Fri, 9 Nov 2018 08:05:40 -0500 Subject: [PATCH] Move parameter from PID profile to rate profile --- src/main/fc/controlrate_profile.c | 3 ++- src/main/fc/controlrate_profile.h | 7 +++++++ src/main/flight/pid.c | 12 ++---------- src/main/flight/pid.h | 6 ------ src/main/interface/settings.c | 7 +++---- 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/main/fc/controlrate_profile.c b/src/main/fc/controlrate_profile.c index 0d6b330343..85deeba34a 100644 --- a/src/main/fc/controlrate_profile.c +++ b/src/main/fc/controlrate_profile.c @@ -61,7 +61,8 @@ void pgResetFn_controlRateProfiles(controlRateConfig_t *controlRateConfig) .throttle_limit_percent = 100, .rate_limit[FD_ROLL] = CONTROL_RATE_CONFIG_RATE_LIMIT_MAX, .rate_limit[FD_PITCH] = CONTROL_RATE_CONFIG_RATE_LIMIT_MAX, - .rate_limit[FD_YAW] = CONTROL_RATE_CONFIG_RATE_LIMIT_MAX + .rate_limit[FD_YAW] = CONTROL_RATE_CONFIG_RATE_LIMIT_MAX, + .tpaMode = TPA_MODE_PD, ); } } diff --git a/src/main/fc/controlrate_profile.h b/src/main/fc/controlrate_profile.h index 865d1787b8..36d2f211f5 100644 --- a/src/main/fc/controlrate_profile.h +++ b/src/main/fc/controlrate_profile.h @@ -37,6 +37,12 @@ typedef enum { THROTTLE_LIMIT_TYPE_CLIP, } throttleLimitType_e; + +typedef enum { + TPA_MODE_PD, + TPA_MODE_D +} tpaMode_e; + typedef struct controlRateConfig_s { uint8_t thrMid8; uint8_t thrExpo8; @@ -49,6 +55,7 @@ typedef struct controlRateConfig_s { uint8_t throttle_limit_type; // Sets the throttle limiting type - off, scale or clip uint8_t throttle_limit_percent; // Sets the maximum pilot commanded throttle limit uint16_t rate_limit[3]; // Sets the maximum rate for the axes + uint8_t tpaMode; // Controls which PID terms TPA effects } controlRateConfig_t; PG_DECLARE_ARRAY(controlRateConfig_t, CONTROL_RATE_PROFILE_COUNT, controlRateProfiles); diff --git a/src/main/flight/pid.c b/src/main/flight/pid.c index 43ec546d7a..b8d202acd1 100644 --- a/src/main/flight/pid.c +++ b/src/main/flight/pid.c @@ -39,6 +39,7 @@ #include "drivers/sound_beeper.h" #include "drivers/time.h" +#include "fc/controlrate_profile.h" #include "fc/core.h" #include "fc/rc.h" @@ -175,7 +176,6 @@ void resetPidProfile(pidProfile_t *pidProfile) .launchControlAngleLimit = 0, .launchControlGain = 40, .launchControlAllowTriggerReset = true, - .tpaMode = TPA_MODE_PD, ); #ifdef USE_DYN_LPF pidProfile->dterm_lowpass_hz = 120; @@ -435,10 +435,6 @@ 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++) { @@ -581,10 +577,6 @@ 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) @@ -1058,7 +1050,7 @@ 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; + const float tpaFactorKp = (currentControlRateProfile->tpaMode == TPA_MODE_PD) ? tpaFactor : 1.0f; #else const float tpaFactorKp = tpaFactor; #endif diff --git a/src/main/flight/pid.h b/src/main/flight/pid.h index 5b017922c4..329fbb773e 100644 --- a/src/main/flight/pid.h +++ b/src/main/flight/pid.h @@ -97,11 +97,6 @@ typedef enum { ITERM_RELAX_SETPOINT } itermRelaxType_e; -typedef enum { - TPA_MODE_PD, - TPA_MODE_D -} tpaMode_e; - typedef struct pidProfile_s { uint16_t yaw_lowpass_hz; // Additional yaw filter when yaw axis too noisy uint16_t dterm_lowpass_hz; // Delta Filter in hz @@ -161,7 +156,6 @@ typedef struct pidProfile_s { uint8_t launchControlAngleLimit; // Optional launch control angle limit (requires ACC) uint8_t launchControlGain; // Iterm gain used while launch control is active uint8_t launchControlAllowTriggerReset; // Controls trigger behavior and whether the trigger can be reset - uint8_t tpaMode; // Controls which PID terms TPA effects } pidProfile_t; PG_DECLARE_ARRAY(pidProfile_t, MAX_PROFILE_COUNT, pidProfiles); diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index ee1356da15..3819c4b70d 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -787,6 +787,9 @@ const clivalue_t valueTable[] = { { "yaw_srate", VAR_UINT8 | PROFILE_RATE_VALUE, .config.minmax = { 0, CONTROL_RATE_CONFIG_RATE_MAX }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, rates[FD_YAW]) }, { "tpa_rate", VAR_UINT8 | PROFILE_RATE_VALUE, .config.minmax = { 0, CONTROL_RATE_CONFIG_TPA_MAX}, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, dynThrPID) }, { "tpa_breakpoint", VAR_UINT16 | PROFILE_RATE_VALUE, .config.minmax = { PWM_PULSE_MIN, PWM_PULSE_MAX }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, tpa_breakpoint) }, +#ifdef USE_TPA_MODE + { "tpa_mode", VAR_UINT8 | PROFILE_RATE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_TPA_MODE }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, tpaMode) }, +#endif { "throttle_limit_type", VAR_UINT8 | PROFILE_RATE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_THROTTLE_LIMIT_TYPE }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, throttle_limit_type) }, { "throttle_limit_percent", VAR_UINT8 | PROFILE_RATE_VALUE, .config.minmax = { 25, 100 }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, throttle_limit_percent) }, { "roll_rate_limit", VAR_UINT16 | PROFILE_RATE_VALUE, .config.minmax = { CONTROL_RATE_CONFIG_RATE_LIMIT_MIN, CONTROL_RATE_CONFIG_RATE_LIMIT_MAX }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, rate_limit[FD_ROLL]) }, @@ -938,10 +941,6 @@ const clivalue_t valueTable[] = { { "launch_control_gain", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, launchControlGain) }, #endif -#ifdef USE_TPA_MODE - { "tpa_mode", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_TPA_MODE }, PG_PID_PROFILE, offsetof(pidProfile_t, tpaMode) }, -#endif - // PG_TELEMETRY_CONFIG #ifdef USE_TELEMETRY { "tlm_inverted", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, telemetry_inverted) },