Skip to content

Commit

Permalink
Add support for bypassing extra arming safety
Browse files Browse the repository at this point in the history
In order to bypass the checks, users must set the new
nav_extra_arming_safety value ALLOW_BYPASS and arm with a switch
while holding yaw high. If this is used to arm the craft, the checks
are skipped until the next power cycle in order to allow rearming
quickly in case of an accidental mid air disarm.

Also, the "NAVIGATION IS UNSAFE" OSD message has been replaced
with more specific messages which tell the user the exact reason
why the navigation system is blocking arming.
  • Loading branch information
fiam committed Apr 18, 2019
1 parent 6544d50 commit 582676e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/Cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ After restoring it's always a good idea to `dump` or `diff` the settings once ag
| name | Empty string | Craft name |
| nav_disarm_on_landing | OFF | If set to ON, iNav disarms the FC after landing |
| nav_use_midthr_for_althold | OFF | If set to OFF, the FC remembers your throttle stick position when enabling ALTHOLD and treats it as a neutral midpoint for holding altitude |
| nav_extra_arming_safety | ON | If set to ON drone won't arm if no GPS fix and any navigation mode like RTH or POSHOLD is configured |
| nav_extra_arming_safety | ON | If set to ON drone won't arm if no GPS fix and any navigation mode like RTH or POSHOLD is configured. ALLOW_BYPASS allows the user to momentarily disable this check by holding yaw high (left stick held at the bottom right in mode 2) when switch arming is used |
| nav_user_control_mode | ATTI | Defines how Pitch/Roll input from RC receiver affects flight in POSHOLD mode: ATTI - right stick controls attitude like in ANGLE mode; CRUISE - right stick controls velocity in forward and right direction. |
| nav_position_timeout | 5 | If GPS fails wait for this much seconds before switching to emergency landing mode (0 - disable) |
| nav_wp_radius | 100 | Waypoint radius [cm]. Waypoint would be considered reached if machine is within this radius |
Expand Down
12 changes: 11 additions & 1 deletion src/main/fc/fc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static void updateArmingStatus(void)

#if defined(USE_NAV)
/* CHECK: Navigation safety */
if (navigationBlockArming()) {
if (navigationIsBlockingArming(NULL) != NAV_ARMING_BLOCKER_NONE) {
ENABLE_ARMING_FLAG(ARMING_DISABLED_NAVIGATION_UNSAFE);
}
else {
Expand Down Expand Up @@ -378,6 +378,16 @@ void tryArm(void)
return;
}

#if defined(USE_NAV)
// Check if we need to make the navigation safety
// bypass permanent until power off. See documentation
// for these functions.
bool usedBypass = false;
if (navigationIsBlockingArming(&usedBypass)) {
navigationSetBlockingArmingBypassWithoutSticks(true);
}
#endif

lastDisarmReason = DISARM_NONE;

ENABLE_ARMING_FLAG(ARMED);
Expand Down
5 changes: 4 additions & 1 deletion src/main/fc/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ tables:
values: ["PT1", "BIQUAD"]
- name: log_level
values: ["ERROR", "WARNING", "INFO", "VERBOSE", "DEBUG"]
- name: nav_extra_arming_safety
values: ["OFF", "ON", "ALLOW_BYPASS"]
enum: navExtraArmingSafety_e

groups:
- name: PG_GYRO_CONFIG
Expand Down Expand Up @@ -1241,7 +1244,7 @@ groups:
type: bool
- name: nav_extra_arming_safety
field: general.flags.extra_arming_safety
type: bool
table: nav_extra_arming_safety
- name: nav_user_control_mode
field: general.flags.user_control_mode
table: nav_user_control_mode
Expand Down
15 changes: 14 additions & 1 deletion src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,20 @@ static const char * osdArmingDisabledReasonMessage(void)
case ARMING_DISABLED_SYSTEM_OVERLOADED:
return OSD_MESSAGE_STR("SYSTEM OVERLOADED");
case ARMING_DISABLED_NAVIGATION_UNSAFE:
return OSD_MESSAGE_STR("NAVIGATION IS UNSAFE");
#if defined(USE_NAV)
// Check the exact reason
switch (navigationIsBlockingArming(NULL)) {
case NAV_ARMING_BLOCKER_NONE:
break;
case NAV_ARMING_BLOCKER_MISSING_GPS_FIX:
return OSD_MESSAGE_STR("WAITING FOR GPS FIX");
case NAV_ARMING_BLOCKER_NAV_IS_ALREADY_ACTIVE:
return OSD_MESSAGE_STR("DISABLE NAVIGATION FIRST");
case NAV_ARMING_BLOCKER_FIRST_WAYPOINT_TOO_FAR:
return OSD_MESSAGE_STR("FIRST WAYPOINT IS TOO FAR");
}
#endif
break;
case ARMING_DISABLED_COMPASS_NOT_CALIBRATED:
return OSD_MESSAGE_STR("COMPASS NOT CALIBRATED");
case ARMING_DISABLED_ACCELEROMETER_NOT_CALIBRATED:
Expand Down
36 changes: 27 additions & 9 deletions src/main/navigation/navigation.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#include "navigation/navigation.h"
#include "navigation/navigation_private.h"

#include "rx/rx.h"

#include "sensors/sensors.h"
#include "sensors/acceleration.h"
#include "sensors/boardalignment.h"
Expand Down Expand Up @@ -83,7 +85,7 @@ PG_RESET_TEMPLATE(navConfig_t, navConfig,

.flags = {
.use_thr_mid_for_althold = 0,
.extra_arming_safety = 1,
.extra_arming_safety = NAV_EXTRA_ARMING_SAFETY_ON,
.user_control_mode = NAV_GPS_ATTI,
.rth_alt_control_mode = NAV_RTH_AT_LEAST_ALT,
.rth_climb_first = 1, // Climb first, turn after reaching safe altitude
Expand Down Expand Up @@ -165,6 +167,7 @@ PG_RESET_TEMPLATE(navConfig_t, navConfig,

navigationPosControl_t posControl;
navSystemStatus_t NAV_Status;
static bool blockingArmingBypassWithoutSticks;

#if defined(NAV_BLACKBOX)
int16_t navCurrentState;
Expand Down Expand Up @@ -2927,23 +2930,34 @@ bool navigationTerrainFollowingEnabled(void)
return posControl.flags.isTerrainFollowEnabled;
}

bool navigationBlockArming(void)
navArmingBlocker_e navigationIsBlockingArming(bool *usedBypass)
{
const bool navBoxModesEnabled = IS_RC_MODE_ACTIVE(BOXNAVRTH) || IS_RC_MODE_ACTIVE(BOXNAVWP) || IS_RC_MODE_ACTIVE(BOXNAVPOSHOLD) || (STATE(FIXED_WING) && IS_RC_MODE_ACTIVE(BOXNAVALTHOLD)) || (STATE(FIXED_WING) && IS_RC_MODE_ACTIVE(BOXNAVCRUISE));
const bool navLaunchComboModesEnabled = isNavLaunchEnabled() && (IS_RC_MODE_ACTIVE(BOXNAVRTH) || IS_RC_MODE_ACTIVE(BOXNAVWP) || IS_RC_MODE_ACTIVE(BOXNAVALTHOLD) || IS_RC_MODE_ACTIVE(BOXNAVCRUISE));
bool shouldBlockArming = false;

if (!navConfig()->general.flags.extra_arming_safety)
return false;
if (usedBypass) {
*usedBypass = false;
}

if (navConfig()->general.flags.extra_arming_safety == NAV_EXTRA_ARMING_SAFETY_OFF) {
return NAV_ARMING_BLOCKER_NONE;
}

// Apply extra arming safety only if pilot has any of GPS modes configured
if ((isUsingNavigationModes() || failsafeMayRequireNavigationMode()) && !((posControl.flags.estPosStatus >= EST_USABLE) && STATE(GPS_FIX_HOME))) {
shouldBlockArming = true;
if (navConfig()->general.flags.extra_arming_safety == NAV_EXTRA_ARMING_SAFETY_ALLOW_BYPASS &&
(blockingArmingBypassWithoutSticks || rxGetChannelValue(YAW) > 1750)) {
if (usedBypass) {
*usedBypass = true;
}
return NAV_ARMING_BLOCKER_NONE;
}
return NAV_ARMING_BLOCKER_MISSING_GPS_FIX;
}

// Don't allow arming if any of NAV modes is active
if (!ARMING_FLAG(ARMED) && navBoxModesEnabled && !navLaunchComboModesEnabled) {
shouldBlockArming = true;
return NAV_ARMING_BLOCKER_NAV_IS_ALREADY_ACTIVE;
}

// Don't allow arming if first waypoint is farther than configured safe distance
Expand All @@ -2954,13 +2968,17 @@ bool navigationBlockArming(void)
const bool navWpMissionStartTooFar = calculateDistanceToDestination(&startingWaypointPos) > navConfig()->general.waypoint_safe_distance;

if (navWpMissionStartTooFar) {
shouldBlockArming = true;
return NAV_ARMING_BLOCKER_FIRST_WAYPOINT_TOO_FAR;
}
}

return shouldBlockArming;
return NAV_ARMING_BLOCKER_NONE;
}

void navigationSetBlockingArmingBypassWithoutSticks(bool allow)
{
blockingArmingBypassWithoutSticks = allow;
}

bool navigationPositionEstimateIsHealthy(void)
{
Expand Down
24 changes: 22 additions & 2 deletions src/main/navigation/navigation.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ typedef enum {
NAV_RTH_ALLOW_LANDING_FS_ONLY = 2, // Allow landing only if RTH was triggered by failsafe
} navRTHAllowLanding_e;

typedef enum {
NAV_EXTRA_ARMING_SAFETY_OFF = 0,
NAV_EXTRA_ARMING_SAFETY_ON = 1,
NAV_EXTRA_ARMING_SAFETY_ALLOW_BYPASS = 2, // Allow disabling by holding THR+YAW low
} navExtraArmingSafety_e;

typedef enum {
NAV_ARMING_BLOCKER_NONE = 0,
NAV_ARMING_BLOCKER_MISSING_GPS_FIX = 1,
NAV_ARMING_BLOCKER_NAV_IS_ALREADY_ACTIVE = 2,
NAV_ARMING_BLOCKER_FIRST_WAYPOINT_TOO_FAR = 3,
} navArmingBlocker_e;

typedef struct positionEstimationConfig_s {
uint8_t automatic_mag_declination;
uint8_t reset_altitude_type; // from nav_reset_type_e
Expand Down Expand Up @@ -128,7 +141,7 @@ typedef struct navConfig_s {
struct {
struct {
uint8_t use_thr_mid_for_althold; // Don't remember throttle when althold was initiated, assume that throttle is at Thr Mid = zero climb rate
uint8_t extra_arming_safety; // Forcibly apply 100% throttle tilt compensation
uint8_t extra_arming_safety; // from navExtraArmingSafety_e
uint8_t user_control_mode; // NAV_GPS_ATTI or NAV_GPS_CRUISE
uint8_t rth_alt_control_mode; // Controls the logic for choosing the RTH altitude
uint8_t rth_climb_first; // Controls the logic for initial RTH climbout
Expand Down Expand Up @@ -357,7 +370,14 @@ bool navigationRequiresAngleMode(void);
bool navigationRequiresThrottleTiltCompensation(void);
bool navigationRequiresTurnAssistance(void);
int8_t navigationGetHeadingControlState(void);
bool navigationBlockArming(void);
// Returns wether arming is blocked by the navigation system.
// If usedBypass is provided, it will indicate wether any checks
// were bypassed due to user input.
navArmingBlocker_e navigationIsBlockingArming(bool *usedBypass);
// If navigation arming block bypass is used for arming, it's kept
// until power off. This allows rearming quickly in case of an
// accidentatal mid-air disarm.
void navigationSetBlockingArmingBypassWithoutSticks(bool allow);
bool navigationPositionEstimateIsHealthy(void);
bool navIsCalibrationComplete(void);
bool navigationTerrainFollowingEnabled(void);
Expand Down

0 comments on commit 582676e

Please sign in to comment.