Skip to content

Commit 7e8c3dc

Browse files
authored
Merge pull request #7904 from breadoven/abo_add_landing_debug
Add LANDING debug
2 parents 739f537 + 288015a commit 7e8c3dc

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

src/main/build/debug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,6 @@ typedef enum {
8686
DEBUG_AUTOTRIM,
8787
DEBUG_AUTOTUNE,
8888
DEBUG_RATE_DYNAMICS,
89+
DEBUG_LANDING,
8990
DEBUG_COUNT
9091
} debugType_e;

src/main/fc/settings.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ tables:
9696
"VIBE", "CRUISE", "REM_FLIGHT_TIME", "SMARTAUDIO", "ACC",
9797
"ERPM", "RPM_FILTER", "RPM_FREQ", "NAV_YAW", "DYNAMIC_FILTER", "DYNAMIC_FILTER_FREQUENCY",
9898
"IRLOCK", "KALMAN_GAIN", "PID_MEASUREMENT", "SPM_CELLS", "SPM_VS600", "SPM_VARIO", "PCF8574", "DYN_GYRO_LPF", "AUTOLEVEL", "IMU2", "ALTITUDE",
99-
"SMITH_PREDICTOR", "AUTOTRIM", "AUTOTUNE", "RATE_DYNAMICS"]
99+
"SMITH_PREDICTOR", "AUTOTRIM", "AUTOTUNE", "RATE_DYNAMICS", "LANDING"]
100100
- name: async_mode
101101
values: ["NONE", "GYRO", "ALL"]
102102
- name: aux_operator

src/main/navigation/navigation.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,6 +2601,9 @@ void updateLandingStatus(void)
26012601

26022602
static bool landingDetectorIsActive;
26032603

2604+
DEBUG_SET(DEBUG_LANDING, 0, landingDetectorIsActive);
2605+
DEBUG_SET(DEBUG_LANDING, 1, STATE(LANDING_DETECTED));
2606+
26042607
if (!ARMING_FLAG(ARMED)) {
26052608
resetLandingDetector();
26062609
landingDetectorIsActive = false;

src/main/navigation/navigation_fixedwing.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ bool isFixedWingFlying(void)
612612
*-----------------------------------------------------------*/
613613
bool isFixedWingLandingDetected(void)
614614
{
615+
DEBUG_SET(DEBUG_LANDING, 4, 0);
615616
static bool fixAxisCheck = false;
616617
const bool throttleIsLow = calculateThrottleStatus(THROTTLE_STATUS_TYPE_RC) == THROTTLE_LOW;
617618

@@ -623,6 +624,7 @@ bool isFixedWingLandingDetected(void)
623624
if (!startCondition || posControl.flags.resetLandingDetector) {
624625
return fixAxisCheck = posControl.flags.resetLandingDetector = false;
625626
}
627+
DEBUG_SET(DEBUG_LANDING, 4, 1);
626628

627629
static timeMs_t fwLandingTimerStartAt;
628630
static int16_t fwLandSetRollDatum;
@@ -634,8 +636,12 @@ bool isFixedWingLandingDetected(void)
634636
bool velCondition = fabsf(navGetCurrentActualPositionAndVelocity()->vel.z) < 50.0f && posControl.actualState.velXY < 100.0f;
635637
// Check angular rates are low (degs/s)
636638
bool gyroCondition = averageAbsGyroRates() < 2.0f;
639+
DEBUG_SET(DEBUG_LANDING, 2, velCondition);
640+
DEBUG_SET(DEBUG_LANDING, 3, gyroCondition);
637641

638642
if (velCondition && gyroCondition){
643+
DEBUG_SET(DEBUG_LANDING, 4, 2);
644+
DEBUG_SET(DEBUG_LANDING, 5, fixAxisCheck);
639645
if (!fixAxisCheck) { // capture roll and pitch angles to be used as datums to check for absolute change
640646
fwLandSetRollDatum = attitude.values.roll; //0.1 deg increments
641647
fwLandSetPitchDatum = attitude.values.pitch;
@@ -644,6 +650,8 @@ bool isFixedWingLandingDetected(void)
644650
} else {
645651
bool isRollAxisStatic = ABS(fwLandSetRollDatum - attitude.values.roll) < 5;
646652
bool isPitchAxisStatic = ABS(fwLandSetPitchDatum - attitude.values.pitch) < 5;
653+
DEBUG_SET(DEBUG_LANDING, 6, isRollAxisStatic);
654+
DEBUG_SET(DEBUG_LANDING, 7, isPitchAxisStatic);
647655
if (isRollAxisStatic && isPitchAxisStatic) {
648656
// Probably landed, low horizontal and vertical velocities and no axis rotation in Roll and Pitch
649657
timeMs_t safetyTimeDelay = 2000 + navConfig()->fw.auto_disarm_delay;

src/main/navigation/navigation_multicopter.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static void updateAltitudeVelocityController_MC(timeDelta_t deltaMicros)
7676
);
7777

7878
posControl.desiredState.pos.z = pos_desired_z;
79-
79+
8080
// hard limit desired target velocity to max_climb_rate
8181
float vel_max_z = 0.0f;
8282

@@ -119,11 +119,11 @@ static void updateAltitudeThrottleController_MC(timeDelta_t deltaMicros)
119119
// Calculate min and max throttle boundaries (to compensate for integral windup)
120120
const int16_t thrAdjustmentMin = (int16_t)getThrottleIdleValue() - (int16_t)currentBatteryProfile->nav.mc.hover_throttle;
121121
const int16_t thrAdjustmentMax = (int16_t)motorConfig()->maxthrottle - (int16_t)currentBatteryProfile->nav.mc.hover_throttle;
122-
122+
123123
float velocity_controller = navPidApply2(&posControl.pids.vel[Z], posControl.desiredState.vel.z, navGetCurrentActualPositionAndVelocity()->vel.z, US2S(deltaMicros), thrAdjustmentMin, thrAdjustmentMax, 0);
124-
124+
125125
posControl.rcAdjustment[THROTTLE] = pt1FilterApply4(&altholdThrottleFilterState, velocity_controller, NAV_THROTTLE_CUTOFF_FREQENCY_HZ, US2S(deltaMicros));
126-
126+
127127
posControl.rcAdjustment[THROTTLE] = constrain(posControl.rcAdjustment[THROTTLE], thrAdjustmentMin, thrAdjustmentMax);
128128

129129
posControl.rcAdjustment[THROTTLE] = constrain((int16_t)currentBatteryProfile->nav.mc.hover_throttle + posControl.rcAdjustment[THROTTLE], getThrottleIdleValue(), motorConfig()->maxthrottle);
@@ -224,7 +224,7 @@ void resetMulticopterAltitudeController(void)
224224
pt1FilterReset(&altholdThrottleFilterState, 0.0f);
225225
pt1FilterReset(&posControl.pids.vel[Z].error_filter_state, 0.0f);
226226
pt1FilterReset(&posControl.pids.vel[Z].dterm_filter_state, 0.0f);
227-
227+
228228
if (FLIGHT_MODE(FAILSAFE_MODE) || FLIGHT_MODE(NAV_RTH_MODE) || FLIGHT_MODE(NAV_WP_MODE) || navigationIsExecutingAnEmergencyLanding()) {
229229
const float maxSpeed = getActiveWaypointSpeed();
230230
nav_speed_up = maxSpeed;
@@ -239,8 +239,8 @@ void resetMulticopterAltitudeController(void)
239239
sqrtControllerInit(
240240
&alt_hold_sqrt_controller,
241241
posControl.pids.pos[Z].param.kP,
242-
-fabsf(nav_speed_down),
243-
nav_speed_up,
242+
-fabsf(nav_speed_down),
243+
nav_speed_up,
244244
nav_accel_z
245245
);
246246
}
@@ -546,7 +546,7 @@ static void updatePositionAccelController_MC(timeDelta_t deltaMicros, float maxA
546546
// Calculate XY-acceleration limit according to velocity error limit
547547
float accelLimitX, accelLimitY;
548548
const float velErrorMagnitude = calc_length_pythagorean_2D(velErrorX, velErrorY);
549-
549+
550550
if (velErrorMagnitude > 0.1f) {
551551
accelLimitX = maxAccelLimit / velErrorMagnitude * fabsf(velErrorX);
552552
accelLimitY = maxAccelLimit / velErrorMagnitude * fabsf(velErrorY);
@@ -726,6 +726,7 @@ bool isMulticopterFlying(void)
726726
*-----------------------------------------------------------*/
727727
bool isMulticopterLandingDetected(void)
728728
{
729+
DEBUG_SET(DEBUG_LANDING, 4, 0);
729730
static timeUs_t landingDetectorStartedAt;
730731
const bool throttleIsLow = calculateThrottleStatus(THROTTLE_STATUS_TYPE_RC) == THROTTLE_LOW;
731732

@@ -745,6 +746,8 @@ bool isMulticopterLandingDetected(void)
745746
posControl.actualState.velXY < MC_LAND_CHECK_VEL_XY_MOVING;
746747
// check gyro rates are low (degs/s)
747748
bool gyroCondition = averageAbsGyroRates() < 2.0f;
749+
DEBUG_SET(DEBUG_LANDING, 2, velCondition);
750+
DEBUG_SET(DEBUG_LANDING, 3, gyroCondition);
748751

749752
bool possibleLandingDetected = false;
750753
const timeUs_t currentTimeUs = micros();
@@ -753,6 +756,7 @@ bool isMulticopterLandingDetected(void)
753756
// We have likely landed if throttle is 40 units below average descend throttle
754757
// We use rcCommandAdjustedThrottle to keep track of NAV corrected throttle (isLandingDetected is executed
755758
// from processRx() and rcCommand at that moment holds rc input, not adjusted values from NAV core)
759+
DEBUG_SET(DEBUG_LANDING, 4, 1);
756760

757761
static int32_t landingThrSum;
758762
static int32_t landingThrSamples;
@@ -774,7 +778,11 @@ bool isMulticopterLandingDetected(void)
774778
isAtMinimalThrust = rcCommandAdjustedThrottle < (landingThrSum / landingThrSamples - MC_LAND_DESCEND_THROTTLE);
775779

776780
possibleLandingDetected = isAtMinimalThrust && velCondition;
781+
782+
DEBUG_SET(DEBUG_LANDING, 6, rcCommandAdjustedThrottle);
783+
DEBUG_SET(DEBUG_LANDING, 7, landingThrSum / landingThrSamples - MC_LAND_DESCEND_THROTTLE);
777784
} else { // non autonomous and emergency landing
785+
DEBUG_SET(DEBUG_LANDING, 4, 2);
778786
if (landingDetectorStartedAt) {
779787
possibleLandingDetected = velCondition && gyroCondition;
780788
} else {
@@ -790,6 +798,7 @@ bool isMulticopterLandingDetected(void)
790798
// surfaceMin is our ground reference. If we are less than 5cm above the ground - we are likely landed
791799
possibleLandingDetected = possibleLandingDetected && (posControl.actualState.agl.pos.z <= (posControl.actualState.surfaceMin + MC_LAND_SAFE_SURFACE));
792800
}
801+
DEBUG_SET(DEBUG_LANDING, 5, possibleLandingDetected);
793802

794803
if (possibleLandingDetected) {
795804
timeUs_t safetyTimeDelay = MS2US(2000 + navConfig()->mc.auto_disarm_delay); // check conditions stable for 2s + optional extra delay

0 commit comments

Comments
 (0)