mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 06:15:16 +03:00
Merge pull request #7924 from mikeller/add_crash_recovery_disarm
Added 'disarm' option to crash recovery.
This commit is contained in:
commit
b468b94995
10 changed files with 38 additions and 27 deletions
|
@ -150,7 +150,7 @@ static const char * const lookupTableOffOn[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * const lookupTableCrashRecovery[] = {
|
static const char * const lookupTableCrashRecovery[] = {
|
||||||
"OFF", "ON" ,"BEEP"
|
"OFF", "ON" ,"BEEP", "DISARM"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * const lookupTableUnit[] = {
|
static const char * const lookupTableUnit[] = {
|
||||||
|
|
|
@ -318,11 +318,12 @@ void updateArmingStatus(void)
|
||||||
&& !flight3DConfig()->switched_mode3d
|
&& !flight3DConfig()->switched_mode3d
|
||||||
&& !(getArmingDisableFlags() & ~(ARMING_DISABLED_ARM_SWITCH | ARMING_DISABLED_THROTTLE));
|
&& !(getArmingDisableFlags() & ~(ARMING_DISABLED_ARM_SWITCH | ARMING_DISABLED_THROTTLE));
|
||||||
|
|
||||||
#ifdef USE_RUNAWAY_TAKEOFF
|
|
||||||
if (!IS_RC_MODE_ACTIVE(BOXARM)) {
|
if (!IS_RC_MODE_ACTIVE(BOXARM)) {
|
||||||
|
#ifdef USE_RUNAWAY_TAKEOFF
|
||||||
unsetArmingDisabled(ARMING_DISABLED_RUNAWAY_TAKEOFF);
|
unsetArmingDisabled(ARMING_DISABLED_RUNAWAY_TAKEOFF);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
unsetArmingDisabled(ARMING_DISABLED_CRASH_DETECTED);
|
||||||
|
}
|
||||||
|
|
||||||
// If arming is disabled and the ARM switch is on
|
// If arming is disabled and the ARM switch is on
|
||||||
if (isArmingDisabled()
|
if (isArmingDisabled()
|
||||||
|
@ -371,7 +372,7 @@ void disarm(void)
|
||||||
flipOverAfterCrashActive = false;
|
flipOverAfterCrashActive = false;
|
||||||
|
|
||||||
// if ARMING_DISABLED_RUNAWAY_TAKEOFF is set then we want to play it's beep pattern instead
|
// if ARMING_DISABLED_RUNAWAY_TAKEOFF is set then we want to play it's beep pattern instead
|
||||||
if (!(getArmingDisableFlags() & ARMING_DISABLED_RUNAWAY_TAKEOFF)) {
|
if (!(getArmingDisableFlags() & (ARMING_DISABLED_RUNAWAY_TAKEOFF | ARMING_DISABLED_CRASH_DETECTED))) {
|
||||||
beeper(BEEPER_DISARMING); // emit disarm tone
|
beeper(BEEPER_DISARMING); // emit disarm tone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,6 +208,7 @@ void processRcStickPositions()
|
||||||
// before they're able to rearm
|
// before they're able to rearm
|
||||||
unsetArmingDisabled(ARMING_DISABLED_RUNAWAY_TAKEOFF);
|
unsetArmingDisabled(ARMING_DISABLED_RUNAWAY_TAKEOFF);
|
||||||
#endif
|
#endif
|
||||||
|
unsetArmingDisabled(ARMING_DISABLED_CRASH_DETECTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -230,7 +231,7 @@ void processRcStickPositions()
|
||||||
resetTryingToArm();
|
resetTryingToArm();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ARMING_FLAG(ARMED) || doNotRepeat || rcDelayMs <= STICK_DELAY_MS || (getArmingDisableFlags() & ARMING_DISABLED_RUNAWAY_TAKEOFF)) {
|
if (ARMING_FLAG(ARMED) || doNotRepeat || rcDelayMs <= STICK_DELAY_MS || (getArmingDisableFlags() & (ARMING_DISABLED_RUNAWAY_TAKEOFF | ARMING_DISABLED_CRASH_DETECTED))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
doNotRepeat = true;
|
doNotRepeat = true;
|
||||||
|
|
|
@ -40,6 +40,7 @@ const char *armingDisableFlagNames[]= {
|
||||||
"BADRX",
|
"BADRX",
|
||||||
"BOXFAILSAFE",
|
"BOXFAILSAFE",
|
||||||
"RUNAWAY",
|
"RUNAWAY",
|
||||||
|
"CRASH",
|
||||||
"THROTTLE",
|
"THROTTLE",
|
||||||
"ANGLE",
|
"ANGLE",
|
||||||
"BOOTGRACE",
|
"BOOTGRACE",
|
||||||
|
|
|
@ -46,21 +46,22 @@ typedef enum {
|
||||||
ARMING_DISABLED_BAD_RX_RECOVERY = (1 << 3),
|
ARMING_DISABLED_BAD_RX_RECOVERY = (1 << 3),
|
||||||
ARMING_DISABLED_BOXFAILSAFE = (1 << 4),
|
ARMING_DISABLED_BOXFAILSAFE = (1 << 4),
|
||||||
ARMING_DISABLED_RUNAWAY_TAKEOFF = (1 << 5),
|
ARMING_DISABLED_RUNAWAY_TAKEOFF = (1 << 5),
|
||||||
ARMING_DISABLED_THROTTLE = (1 << 6),
|
ARMING_DISABLED_CRASH_DETECTED = (1 << 6),
|
||||||
ARMING_DISABLED_ANGLE = (1 << 7),
|
ARMING_DISABLED_THROTTLE = (1 << 7),
|
||||||
ARMING_DISABLED_BOOT_GRACE_TIME = (1 << 8),
|
ARMING_DISABLED_ANGLE = (1 << 8),
|
||||||
ARMING_DISABLED_NOPREARM = (1 << 9),
|
ARMING_DISABLED_BOOT_GRACE_TIME = (1 << 9),
|
||||||
ARMING_DISABLED_LOAD = (1 << 10),
|
ARMING_DISABLED_NOPREARM = (1 << 10),
|
||||||
ARMING_DISABLED_CALIBRATING = (1 << 11),
|
ARMING_DISABLED_LOAD = (1 << 11),
|
||||||
ARMING_DISABLED_CLI = (1 << 12),
|
ARMING_DISABLED_CALIBRATING = (1 << 12),
|
||||||
ARMING_DISABLED_CMS_MENU = (1 << 13),
|
ARMING_DISABLED_CLI = (1 << 13),
|
||||||
ARMING_DISABLED_BST = (1 << 14),
|
ARMING_DISABLED_CMS_MENU = (1 << 14),
|
||||||
ARMING_DISABLED_MSP = (1 << 15),
|
ARMING_DISABLED_BST = (1 << 15),
|
||||||
ARMING_DISABLED_PARALYZE = (1 << 16),
|
ARMING_DISABLED_MSP = (1 << 16),
|
||||||
ARMING_DISABLED_GPS = (1 << 17),
|
ARMING_DISABLED_PARALYZE = (1 << 17),
|
||||||
ARMING_DISABLED_RESC = (1 << 18),
|
ARMING_DISABLED_GPS = (1 << 18),
|
||||||
ARMING_DISABLED_RPMFILTER = (1 << 19),
|
ARMING_DISABLED_RESC = (1 << 19),
|
||||||
ARMING_DISABLED_ARM_SWITCH = (1 << 20), // Needs to be the last element, since it's always activated if one of the others is active when arming
|
ARMING_DISABLED_RPMFILTER = (1 << 20),
|
||||||
|
ARMING_DISABLED_ARM_SWITCH = (1 << 21), // Needs to be the last element, since it's always activated if one of the others is active when arming
|
||||||
} armingDisableFlags_e;
|
} armingDisableFlags_e;
|
||||||
|
|
||||||
#define ARMING_DISABLE_FLAGS_COUNT (LOG2(ARMING_DISABLED_ARM_SWITCH) + 1)
|
#define ARMING_DISABLE_FLAGS_COUNT (LOG2(ARMING_DISABLED_ARM_SWITCH) + 1)
|
||||||
|
|
|
@ -877,8 +877,13 @@ static void detectAndSetCrashRecovery(
|
||||||
&& fabsf(delta) > crashDtermThreshold
|
&& fabsf(delta) > crashDtermThreshold
|
||||||
&& fabsf(errorRate) > crashGyroThreshold
|
&& fabsf(errorRate) > crashGyroThreshold
|
||||||
&& fabsf(getSetpointRate(axis)) < crashSetpointThreshold) {
|
&& fabsf(getSetpointRate(axis)) < crashSetpointThreshold) {
|
||||||
inCrashRecoveryMode = true;
|
if (crash_recovery == PID_CRASH_RECOVERY_DISARM) {
|
||||||
crashDetectedAtUs = currentTimeUs;
|
setArmingDisabled(ARMING_DISABLED_CRASH_DETECTED);
|
||||||
|
disarm();
|
||||||
|
} else {
|
||||||
|
inCrashRecoveryMode = true;
|
||||||
|
crashDetectedAtUs = currentTimeUs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (inCrashRecoveryMode && cmpTimeUs(currentTimeUs, crashDetectedAtUs) < crashTimeDelayUs && (fabsf(errorRate) < crashGyroThreshold
|
if (inCrashRecoveryMode && cmpTimeUs(currentTimeUs, crashDetectedAtUs) < crashTimeDelayUs && (fabsf(errorRate) < crashGyroThreshold
|
||||||
|| fabsf(getSetpointRate(axis)) > crashSetpointThreshold)) {
|
|| fabsf(getSetpointRate(axis)) > crashSetpointThreshold)) {
|
||||||
|
|
|
@ -71,7 +71,8 @@ typedef enum {
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PID_CRASH_RECOVERY_OFF = 0,
|
PID_CRASH_RECOVERY_OFF = 0,
|
||||||
PID_CRASH_RECOVERY_ON,
|
PID_CRASH_RECOVERY_ON,
|
||||||
PID_CRASH_RECOVERY_BEEP
|
PID_CRASH_RECOVERY_BEEP,
|
||||||
|
PID_CRASH_RECOVERY_DISARM,
|
||||||
} pidCrashRecovery_e;
|
} pidCrashRecovery_e;
|
||||||
|
|
||||||
typedef struct pidf_s {
|
typedef struct pidf_s {
|
||||||
|
|
|
@ -89,7 +89,7 @@ static void rcdeviceCameraControlProcess(void)
|
||||||
// avoid display wifi page when arming, in the next firmware(>2.0) of rcsplit we have change the wifi page logic:
|
// avoid display wifi page when arming, in the next firmware(>2.0) of rcsplit we have change the wifi page logic:
|
||||||
// when the wifi was turn on it won't turn off the analog video output,
|
// when the wifi was turn on it won't turn off the analog video output,
|
||||||
// and just put a wifi indicator on the right top of the video output. here is for the old split firmware
|
// and just put a wifi indicator on the right top of the video output. here is for the old split firmware
|
||||||
if (!ARMING_FLAG(ARMED) && ((getArmingDisableFlags() & ARMING_DISABLED_RUNAWAY_TAKEOFF) == 0)) {
|
if (!ARMING_FLAG(ARMED) && !(getArmingDisableFlags() & (ARMING_DISABLED_RUNAWAY_TAKEOFF | ARMING_DISABLED_CRASH_DETECTED))) {
|
||||||
behavior = RCDEVICE_PROTOCOL_CAM_CTRL_SIMULATE_WIFI_BTN;
|
behavior = RCDEVICE_PROTOCOL_CAM_CTRL_SIMULATE_WIFI_BTN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ static void rcdeviceCameraControlProcess(void)
|
||||||
case BOXCAMERA3:
|
case BOXCAMERA3:
|
||||||
if (isFeatureSupported(RCDEVICE_PROTOCOL_FEATURE_CHANGE_MODE)) {
|
if (isFeatureSupported(RCDEVICE_PROTOCOL_FEATURE_CHANGE_MODE)) {
|
||||||
// avoid change camera mode when arming
|
// avoid change camera mode when arming
|
||||||
if (!ARMING_FLAG(ARMED) && ((getArmingDisableFlags() & ARMING_DISABLED_RUNAWAY_TAKEOFF) == 0)) {
|
if (!ARMING_FLAG(ARMED) && !(getArmingDisableFlags() & (ARMING_DISABLED_RUNAWAY_TAKEOFF | ARMING_DISABLED_CRASH_DETECTED))) {
|
||||||
behavior = RCDEVICE_PROTOCOL_CAM_CTRL_CHANGE_MODE;
|
behavior = RCDEVICE_PROTOCOL_CAM_CTRL_CHANGE_MODE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ static void rcdevice5KeySimulationProcess(timeUs_t currentTimeUs)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ARMING_FLAG(ARMED) || getArmingDisableFlags() & ARMING_DISABLED_RUNAWAY_TAKEOFF) {
|
if (ARMING_FLAG(ARMED) || (getArmingDisableFlags() & (ARMING_DISABLED_RUNAWAY_TAKEOFF | ARMING_DISABLED_CRASH_DETECTED))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -629,7 +629,7 @@ STATIC_UNIT_TESTED void osdRefresh(timeUs_t currentTimeUs)
|
||||||
resumeRefreshAt = currentTimeUs + (REFRESH_1S / 2);
|
resumeRefreshAt = currentTimeUs + (REFRESH_1S / 2);
|
||||||
} else if (isSomeStatEnabled()
|
} else if (isSomeStatEnabled()
|
||||||
&& !suppressStatsDisplay
|
&& !suppressStatsDisplay
|
||||||
&& (!(getArmingDisableFlags() & ARMING_DISABLED_RUNAWAY_TAKEOFF)
|
&& (!(getArmingDisableFlags() & (ARMING_DISABLED_RUNAWAY_TAKEOFF | ARMING_DISABLED_CRASH_DETECTED))
|
||||||
|| !VISIBLE(osdConfig()->item_pos[OSD_WARNINGS]))) { // suppress stats if runaway takeoff triggered disarm and WARNINGS element is visible
|
|| !VISIBLE(osdConfig()->item_pos[OSD_WARNINGS]))) { // suppress stats if runaway takeoff triggered disarm and WARNINGS element is visible
|
||||||
osdStatsEnabled = true;
|
osdStatsEnabled = true;
|
||||||
resumeRefreshAt = currentTimeUs + (60 * REFRESH_1S);
|
resumeRefreshAt = currentTimeUs + (60 * REFRESH_1S);
|
||||||
|
|
|
@ -79,6 +79,7 @@ extern "C" {
|
||||||
float getRcDeflection(int axis) { return simulatedRcDeflection[axis]; }
|
float getRcDeflection(int axis) { return simulatedRcDeflection[axis]; }
|
||||||
void beeperConfirmationBeeps(uint8_t) { }
|
void beeperConfirmationBeeps(uint8_t) { }
|
||||||
bool isLaunchControlActive(void) {return unitLaunchControlActive; }
|
bool isLaunchControlActive(void) {return unitLaunchControlActive; }
|
||||||
|
void disarm(void) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
pidProfile_t *pidProfile;
|
pidProfile_t *pidProfile;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue