Skip to content

Commit

Permalink
Keep I-terms at zero throttle for fixed wings (#13127)
Browse files Browse the repository at this point in the history
* Keep Iterms at zero throttle for fixed wing mixer

* Ctz suggestions

* Update src/main/fc/core.c based on ladvinap suggestion

Co-authored-by: Petr Ledvina <ledvinap@gmail.com>

---------

Co-authored-by: Petr Ledvina <ledvinap@gmail.com>
  • Loading branch information
limonspb and ledvinap committed Dec 5, 2023
1 parent efe1825 commit dd198b2
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/main/fc/core.c
Expand Up @@ -768,30 +768,17 @@ bool processRx(timeUs_t currentTimeUs)
failsafeStartMonitoring();
}

const throttleStatus_e throttleStatus = calculateThrottleStatus();
const bool throttleActive = calculateThrottleStatus() != THROTTLE_LOW;
const uint8_t throttlePercent = calculateThrottlePercentAbs();

const bool launchControlActive = isLaunchControlActive();
airmodeIsActivated = airmodeIsEnabled() && ARMING_FLAG(ARMED) && throttlePercent >= rxConfig()->airModeActivateThreshold && !launchControlActive;

if (airmodeIsEnabled() && ARMING_FLAG(ARMED) && !launchControlActive) {
if (throttlePercent >= rxConfig()->airModeActivateThreshold) {
airmodeIsActivated = true; // Prevent iterm from being reset
}
} else {
airmodeIsActivated = false;
}

/* In airmode iterm should be prevented to grow when Low thottle and Roll + Pitch Centered.
This is needed to prevent iterm winding on the ground, but keep full stabilisation on 0 throttle while in air */
if (throttleStatus == THROTTLE_LOW && !airmodeIsActivated && !launchControlActive) {
pidSetItermReset(true);
if (currentPidProfile->pidAtMinThrottle)
pidStabilisationState(PID_STABILISATION_ON);
else
pidStabilisationState(PID_STABILISATION_OFF);
} else {
if (ARMING_FLAG(ARMED) && (airmodeIsActivated || throttleActive || launchControlActive || isFixedWing())) {
pidSetItermReset(false);
pidStabilisationState(PID_STABILISATION_ON);
} else {
pidSetItermReset(true);
pidStabilisationState(currentPidProfile->pidAtMinThrottle ? PID_STABILISATION_ON : PID_STABILISATION_OFF);
}

#ifdef USE_RUNAWAY_TAKEOFF
Expand All @@ -814,7 +801,7 @@ bool processRx(timeUs_t currentTimeUs)
// - sticks are active and have deflection greater than runaway_takeoff_deactivate_stick_percent
// - pidSum on all axis is less then runaway_takeoff_deactivate_pidlimit
bool inStableFlight = false;
if (!featureIsEnabled(FEATURE_MOTOR_STOP) || airmodeIsEnabled() || (throttleStatus != THROTTLE_LOW)) { // are motors running?
if (!featureIsEnabled(FEATURE_MOTOR_STOP) || airmodeIsEnabled() || throttleActive) { // are motors running?
const uint8_t lowThrottleLimit = pidConfig()->runaway_takeoff_deactivate_throttle;
const uint8_t midThrottleLimit = constrain(lowThrottleLimit * 2, lowThrottleLimit * 2, RUNAWAY_TAKEOFF_HIGH_THROTTLE_PERCENT);
if ((((throttlePercent >= lowThrottleLimit) && areSticksActive(RUNAWAY_TAKEOFF_DEACTIVATE_STICK_PERCENT)) || (throttlePercent >= midThrottleLimit))
Expand Down

0 comments on commit dd198b2

Please sign in to comment.