Skip to content

Commit af51b3e

Browse files
authored
Merge pull request #9169 from breadoven/abo_mc_emerglanding_fix
Multicopter emergency landing improvement/fix
2 parents 3c74377 + fcc4ad0 commit af51b3e

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

src/main/navigation/navigation_multicopter.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,15 @@ static void updateAltitudeVelocityController_MC(timeDelta_t deltaMicros)
113113
static void updateAltitudeThrottleController_MC(timeDelta_t deltaMicros)
114114
{
115115
// Calculate min and max throttle boundaries (to compensate for integral windup)
116-
const int16_t thrAdjustmentMin = (int16_t)getThrottleIdleValue() - (int16_t)currentBatteryProfile->nav.mc.hover_throttle;
117-
const int16_t thrAdjustmentMax = (int16_t)motorConfig()->maxthrottle - (int16_t)currentBatteryProfile->nav.mc.hover_throttle;
116+
const int16_t thrCorrectionMin = getThrottleIdleValue() - currentBatteryProfile->nav.mc.hover_throttle;
117+
const int16_t thrCorrectionMax = motorConfig()->maxthrottle - currentBatteryProfile->nav.mc.hover_throttle;
118118

119-
float velocity_controller = navPidApply2(&posControl.pids.vel[Z], posControl.desiredState.vel.z, navGetCurrentActualPositionAndVelocity()->vel.z, US2S(deltaMicros), thrAdjustmentMin, thrAdjustmentMax, 0);
119+
float velocity_controller = navPidApply2(&posControl.pids.vel[Z], posControl.desiredState.vel.z, navGetCurrentActualPositionAndVelocity()->vel.z, US2S(deltaMicros), thrCorrectionMin, thrCorrectionMax, 0);
120120

121-
posControl.rcAdjustment[THROTTLE] = pt1FilterApply4(&altholdThrottleFilterState, velocity_controller, NAV_THROTTLE_CUTOFF_FREQENCY_HZ, US2S(deltaMicros));
121+
int16_t rcThrottleCorrection = pt1FilterApply4(&altholdThrottleFilterState, velocity_controller, NAV_THROTTLE_CUTOFF_FREQENCY_HZ, US2S(deltaMicros));
122+
rcThrottleCorrection = constrain(rcThrottleCorrection, thrCorrectionMin, thrCorrectionMax);
122123

123-
posControl.rcAdjustment[THROTTLE] = constrain(posControl.rcAdjustment[THROTTLE], thrAdjustmentMin, thrAdjustmentMax);
124-
125-
posControl.rcAdjustment[THROTTLE] = constrain((int16_t)currentBatteryProfile->nav.mc.hover_throttle + posControl.rcAdjustment[THROTTLE], getThrottleIdleValue(), motorConfig()->maxthrottle);
124+
posControl.rcAdjustment[THROTTLE] = constrain(currentBatteryProfile->nav.mc.hover_throttle + rcThrottleCorrection, getThrottleIdleValue(), motorConfig()->maxthrottle);
126125
}
127126

128127
bool adjustMulticopterAltitudeFromRCInput(void)
@@ -213,7 +212,7 @@ void resetMulticopterAltitudeController(void)
213212
navPidReset(&posControl.pids.vel[Z]);
214213
navPidReset(&posControl.pids.surface);
215214

216-
posControl.rcAdjustment[THROTTLE] = 0;
215+
posControl.rcAdjustment[THROTTLE] = currentBatteryProfile->nav.mc.hover_throttle;
217216

218217
posControl.desiredState.vel.z = posToUse->vel.z; // Gradually transition from current climb
219218

@@ -869,20 +868,19 @@ static void applyMulticopterEmergencyLandingController(timeUs_t currentTimeUs)
869868

870869
/* Attempt to stabilise */
871870
rcCommand[YAW] = 0;
871+
rcCommand[ROLL] = 0;
872+
rcCommand[PITCH] = 0;
873+
rcCommand[THROTTLE] = currentBatteryProfile->failsafe_throttle;
872874

873-
if ((posControl.flags.estAltStatus < EST_USABLE)) {
874-
/* Sensors has gone haywire, attempt to land regardless */
875+
/* Altitude sensors gone haywire, attempt to land regardless */
876+
if (posControl.flags.estAltStatus < EST_USABLE) {
875877
if (failsafeConfig()->failsafe_procedure == FAILSAFE_PROCEDURE_DROP_IT) {
876878
rcCommand[THROTTLE] = getThrottleIdleValue();
877879
}
878-
else {
879-
rcCommand[THROTTLE] = currentBatteryProfile->failsafe_throttle;
880-
}
881-
882880
return;
883881
}
884882

885-
// Normal sensor data
883+
// Normal sensor data available, use controlled landing descent
886884
if (posControl.flags.verticalPositionDataNew) {
887885
const timeDeltaLarge_t deltaMicrosPositionUpdate = currentTimeUs - previousTimePositionUpdate;
888886
previousTimePositionUpdate = currentTimeUs;
@@ -903,15 +901,12 @@ static void applyMulticopterEmergencyLandingController(timeUs_t currentTimeUs)
903901
posControl.flags.verticalPositionDataConsumed = true;
904902
}
905903

906-
// Update throttle controller
904+
// Update throttle
907905
rcCommand[THROTTLE] = posControl.rcAdjustment[THROTTLE];
908906

909907
// Hold position if possible
910908
if ((posControl.flags.estPosStatus >= EST_USABLE)) {
911909
applyMulticopterPositionController(currentTimeUs);
912-
} else {
913-
rcCommand[ROLL] = 0;
914-
rcCommand[PITCH] = 0;
915910
}
916911
}
917912

0 commit comments

Comments
 (0)