Skip to content

Commit

Permalink
Change ez_landing setting values and refactoring
Browse files Browse the repository at this point in the history
- Halve defaul ez_landing_threshold setting and double in init instead.
  Now stick deflection equal to ez_landing_threshold should give approimately full authority.
  Previously it was the point where the mixer was allowed to raise the throttle to 100 % (which wouuld never be required)
- Increase ez_landing_threshold maximum to 200 (from 100) to allow settings that increase authority by a little at full stick deflection
- Increase ez_landing_limit maximum to 75 which is the point where EzLanding should act identical to the Legacy mixer with airmode on
- remove throttle percent from
- simplify calculation of , since throttle stick deflection is no longer involved
- update/remove outdated comments
  • Loading branch information
tbolin committed Dec 6, 2023
1 parent f5fe02e commit aa33149
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/main/cli/settings.c
Expand Up @@ -1259,8 +1259,8 @@ const clivalue_t valueTable[] = {
{ PARAM_NAME_TPA_BREAKPOINT_LOWER, VAR_UINT16 | PROFILE_VALUE, .config.minmaxUnsigned = { PWM_RANGE_MIN, PWM_RANGE_MAX }, PG_PID_PROFILE, offsetof(pidProfile_t, tpa_breakpoint_lower) },
{ PARAM_NAME_TPA_BREAKPOINT_LOWER_FADE, VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_PID_PROFILE, offsetof(pidProfile_t, tpa_breakpoint_lower_fade) },

{ PARAM_NAME_EZ_LANDING_THRESHOLD, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_PID_PROFILE, offsetof(pidProfile_t, ez_landing_threshold) },
{ PARAM_NAME_EZ_LANDING_LIMIT, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 50 }, PG_PID_PROFILE, offsetof(pidProfile_t, ez_landing_limit) },
{ PARAM_NAME_EZ_LANDING_THRESHOLD, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, ez_landing_threshold) },
{ PARAM_NAME_EZ_LANDING_LIMIT, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 75 }, PG_PID_PROFILE, offsetof(pidProfile_t, ez_landing_limit) },

// PG_TELEMETRY_CONFIG
#ifdef USE_TELEMETRY
Expand Down
31 changes: 14 additions & 17 deletions src/main/flight/mixer.c
Expand Up @@ -97,21 +97,6 @@ void stopMotors(void)
delay(50); // give the timers and ESCs a chance to react.
}

static float calcEzLandStrength(float throttlePercent, float maxDeflection)
{
// easy landing code, limits motor output when sticks and throttle are below threshold
float ezLandAttenuator = 0.0f;
if (throttlePercent < mixerRuntime.ezLandingThreshold
&& maxDeflection < mixerRuntime.ezLandingThreshold) { // throttle low
// all sticks, including throttle, under threshold
ezLandAttenuator = fmaxf(maxDeflection, throttlePercent); // value range 0 -> threshold
ezLandAttenuator /= mixerRuntime.ezLandingThreshold; // normalised 0 - 1
ezLandAttenuator = 1.0f - ezLandAttenuator; // 1 -> 0
ezLandAttenuator *= mixerRuntime.ezLandingLimit; // eg 0.9 -> 0.0 if limit is 10
}
return constrainf(ezLandAttenuator, 0.0f, 1.0f);
}

static FAST_DATA_ZERO_INIT float throttle = 0;
static FAST_DATA_ZERO_INIT float mixerThrottle = 0;
static FAST_DATA_ZERO_INIT float motorOutputMin;
Expand Down Expand Up @@ -515,6 +500,18 @@ static void applyMixerAdjustmentLinear(float *motorMix, const bool airmodeEnable
throttle = constrainf(throttle, -minMotor, 1.0f - maxMotor);
}

static float calcEzLandLimit(float maxDeflection)
{
// calculate limit to where the mixer can raise the throttle based on RPY stick deflection
// 0.0 = no increas allowed, 1.0 = 100% increase allowed
float ezLandLimit = 1.0f;
if (maxDeflection < mixerRuntime.ezLandingThreshold) { // roll, pitch and yaw sticks under threshold
ezLandLimit = maxDeflection / mixerRuntime.ezLandingThreshold; // normalised 0 - 1
ezLandLimit = fmaxf(ezLandLimit, mixerRuntime.ezLandingLimit); // stay above the minimum
}
return ezLandLimit;
}

static void applyMixerAdjustmentEzLand(float *motorMix, const float motorMixMin, const float motorMixMax)
{
// Calculate factor for normalizing motor mix range to <= 1.0
Expand All @@ -523,8 +520,8 @@ static void applyMixerAdjustmentEzLand(float *motorMix, const float motorMixMin,
const float normalizedMotorMixMax = motorMixMax * baseNormalizationFactor;

// Upper throttle limit
// range default 0.1 - 1.0 with ezLandingLimit = 10, no stick deflection -> 0.1
const float ezLandLimit = 1.0f - calcEzLandStrength(0.0f, getMaxRcDeflectionAbs());
// range default 0.05 - 1.0 with ezLandingLimit = 5, no stick deflection -> 0.05
const float ezLandLimit = calcEzLandLimit(getMaxRcDeflectionAbs());
// use the largest of throttle and limit calculated from RPY stick positions
float upperLimit = fmaxf(ezLandLimit, throttle);
// limit throttle to avoid clipping the highest motor output
Expand Down
4 changes: 2 additions & 2 deletions src/main/flight/mixer_init.c
Expand Up @@ -365,8 +365,8 @@ void mixerInitProfile(void)
mixerResetRpmLimiter();
#endif

mixerRuntime.ezLandingThreshold = currentPidProfile->ez_landing_threshold / 100.0f;
mixerRuntime.ezLandingLimit = 1.0f - currentPidProfile->ez_landing_limit / 100.0f;
mixerRuntime.ezLandingThreshold = 2.0f * currentPidProfile->ez_landing_threshold / 100.0f;
mixerRuntime.ezLandingLimit = currentPidProfile->ez_landing_limit / 100.0f;
}

#ifdef USE_RPM_LIMIT
Expand Down
2 changes: 1 addition & 1 deletion src/main/flight/pid.c
Expand Up @@ -227,7 +227,7 @@ void resetPidProfile(pidProfile_t *pidProfile)
.tpa_rate_lower = 20,
.tpa_breakpoint_lower = 1050,
.tpa_breakpoint_lower_fade = 1,
.ez_landing_threshold = 50,
.ez_landing_threshold = 25,
.ez_landing_limit = 5,
);

Expand Down

0 comments on commit aa33149

Please sign in to comment.