Skip to content

Commit

Permalink
inverted crash detection
Browse files Browse the repository at this point in the history
  • Loading branch information
breadoven committed Jun 2, 2024
1 parent 9db7d61 commit b976458
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
10 changes: 10 additions & 0 deletions docs/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -3582,6 +3582,16 @@ Multicopter hover throttle hint for altitude controller. Should be set to approx

---

### nav_mc_inverted_crash_detection

Setting a value > 0 enables inverted crash detection for multirotors. It is intended for situations where the multirotor has crashed inverted on the ground and can't be manually disarmed due to loss of control. When enabled the setting defines the additional number of seconds before disarm beyond a minimum fixed time delay such that the minimum possible time delay before disarm is 3s.

| Default | Min | Max |
| --- | --- | --- |
| 0 | 0 | 15 |

---

### nav_mc_manual_climb_rate

Maximum climb/descent rate firmware is allowed when processing pilot input for ALTHOLD control mode [cm/s]
Expand Down
6 changes: 6 additions & 0 deletions src/main/fc/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,12 @@ groups:
default_value: OFF
field: general.flags.landing_bump_detection
type: bool
- name: nav_mc_inverted_crash_detection
description: "Setting a value > 0 enables inverted crash detection for multirotors. It is intended for situations where the multirotor has crashed inverted on the ground and can't be manually disarmed due to loss of control. When enabled the setting defines the additional number of seconds before disarm beyond a minimum fixed time delay such that the minimum possible time delay before disarm is 3s."
default_value: 0
field: mc.inverted_crash_detection
min: 0
max: 15
- name: nav_mc_althold_throttle
description: "If set to STICK the FC remembers the throttle stick position when enabling ALTHOLD and treats it as the neutral midpoint for holding altitude. If set to MID_STICK or HOVER the neutral midpoint is set to the mid stick position or the hover throttle position respectively."
default_value: "STICK"
Expand Down
11 changes: 6 additions & 5 deletions src/main/navigation/navigation.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ PG_RESET_TEMPLATE(navConfig_t, navConfig,
.land_detect_sensitivity = SETTING_NAV_LAND_DETECT_SENSITIVITY_DEFAULT, // Changes sensitivity of landing detection
.auto_disarm_delay = SETTING_NAV_AUTO_DISARM_DELAY_DEFAULT, // 2000 ms - time delay to disarm when auto disarm after landing enabled
.rth_linear_descent_start_distance = SETTING_NAV_RTH_LINEAR_DESCENT_START_DISTANCE_DEFAULT,
.cruise_yaw_rate = SETTING_NAV_CRUISE_YAW_RATE_DEFAULT, // 20dps
.cruise_yaw_rate = SETTING_NAV_CRUISE_YAW_RATE_DEFAULT, // 20dps
.rth_fs_landing_delay = SETTING_NAV_RTH_FS_LANDING_DELAY_DEFAULT, // Delay before landing in FS. 0 = immedate landing
},

Expand All @@ -193,13 +193,14 @@ PG_RESET_TEMPLATE(navConfig_t, navConfig,
.braking_boost_timeout = SETTING_NAV_MC_BRAKING_BOOST_TIMEOUT_DEFAULT, // Timout boost after 750ms
.braking_boost_speed_threshold = SETTING_NAV_MC_BRAKING_BOOST_SPEED_THRESHOLD_DEFAULT, // Boost can happen only above 1.5m/s
.braking_boost_disengage_speed = SETTING_NAV_MC_BRAKING_BOOST_DISENGAGE_SPEED_DEFAULT, // Disable boost at 1m/s
.braking_bank_angle = SETTING_NAV_MC_BRAKING_BANK_ANGLE_DEFAULT, // Max braking angle
.braking_bank_angle = SETTING_NAV_MC_BRAKING_BANK_ANGLE_DEFAULT, // Max braking angle
#endif

.posDecelerationTime = SETTING_NAV_MC_POS_DECELERATION_TIME_DEFAULT, // posDecelerationTime * 100
.posResponseExpo = SETTING_NAV_MC_POS_EXPO_DEFAULT, // posResponseExpo * 100
.posDecelerationTime = SETTING_NAV_MC_POS_DECELERATION_TIME_DEFAULT, // posDecelerationTime * 100
.posResponseExpo = SETTING_NAV_MC_POS_EXPO_DEFAULT, // posResponseExpo * 100
.slowDownForTurning = SETTING_NAV_MC_WP_SLOWDOWN_DEFAULT,
.althold_throttle_type = SETTING_NAV_MC_ALTHOLD_THROTTLE_DEFAULT, // STICK
.althold_throttle_type = SETTING_NAV_MC_ALTHOLD_THROTTLE_DEFAULT, // STICK
.inverted_crash_detection = SETTING_NAV_MC_INVERTED_CRASH_DETECTION_DEFAULT, // 0 - disarm time delay for inverted crash detection
},

// Fixed wing
Expand Down
1 change: 1 addition & 0 deletions src/main/navigation/navigation.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ typedef struct navConfig_s {
uint8_t posResponseExpo; // Position controller expo (taret vel expo for MC)
bool slowDownForTurning; // Slow down during WP missions when changing heading on next waypoint
uint8_t althold_throttle_type; // throttle zero datum type for alt hold
uint8_t inverted_crash_detection; // Enables inverted crash detection, setting defines disarm time delay (0 = disabled)
} mc;

struct {
Expand Down
26 changes: 26 additions & 0 deletions src/main/navigation/navigation_multicopter.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "sensors/boardalignment.h"
#include "sensors/gyro.h"

#include "fc/fc_core.h"
#include "fc/config.h"
#include "fc/rc_controls.h"
#include "fc/rc_curves.h"
Expand Down Expand Up @@ -794,11 +795,36 @@ static bool isLandingGbumpDetected(timeMs_t currentTimeMs)
return false;
}
#endif
bool isMulticopterCrashedInverted(void)
{
static timeMs_t startTime = 0;

if ((ABS(attitude.values.roll) > 1000 || ABS(attitude.values.pitch) > 700) && fabsf(navGetCurrentActualPositionAndVelocity()->vel.z) < MC_LAND_CHECK_VEL_Z_MOVING) {
if (startTime == 0) {
startTime = millis();
} else {
/* minimum 2s disarm delay + extra user set delay time. Min time of 3s given min user setting is 1s if enabled */
uint16_t disarmTimeDelay = 2000 + S2MS(navConfig()->mc.inverted_crash_detection);

return millis() - startTime > disarmTimeDelay;
}
} else {
startTime = 0;
}

return false;
}

bool isMulticopterLandingDetected(void)
{
DEBUG_SET(DEBUG_LANDING, 4, 0);
DEBUG_SET(DEBUG_LANDING, 3, averageAbsGyroRates() * 100);

if (navConfig()->mc.inverted_crash_detection && isMulticopterCrashedInverted()) {
ENABLE_ARMING_FLAG(ARMING_DISABLED_LANDING_DETECTED);
disarm(DISARM_LANDING);
}

const timeMs_t currentTimeMs = millis();

#if defined(USE_BARO)
Expand Down

0 comments on commit b976458

Please sign in to comment.