1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-20 23:05:17 +03:00

Use an STATE() flag instead of an static variable in navigation.c

Also, make the check for setting the STATE() flag clearer. Previous
implementation was a bit confusing.
This commit is contained in:
Alberto García Hierro 2019-04-25 13:59:20 +01:00
parent dc6d002bdc
commit 20fac46ee0
4 changed files with 23 additions and 30 deletions

View file

@ -375,12 +375,14 @@ void tryArm(void)
}
#if defined(USE_NAV)
// Check if we need to make the navigation safety
// bypass permanent until power off. See documentation
// for these functions.
// If nav_extra_arming_safety was bypassed we always
// allow bypassing it even without the sticks set
// in the correct position to allow re-arming quickly
// in case of a mid-air accidental disarm.
bool usedBypass = false;
if (navigationIsBlockingArming(&usedBypass)) {
navigationSetBlockingArmingBypassWithoutSticks(true);
navigationIsBlockingArming(&usedBypass);
if (usedBypass) {
ENABLE_STATE(NAV_EXTRA_ARMING_SAFETY_BYPASSED);
}
#endif

View file

@ -89,20 +89,21 @@ extern uint32_t flightModeFlags;
#define FLIGHT_MODE(mask) (flightModeFlags & (mask))
typedef enum {
GPS_FIX_HOME = (1 << 0),
GPS_FIX = (1 << 1),
CALIBRATE_MAG = (1 << 2),
SMALL_ANGLE = (1 << 3),
FIXED_WING = (1 << 4), // set when in flying_wing or airplane mode. currently used by althold selection code
ANTI_WINDUP = (1 << 5),
FLAPERON_AVAILABLE = (1 << 6),
NAV_MOTOR_STOP_OR_IDLE = (1 << 7), // navigation requests MOTOR_STOP or motor idle regardless of throttle stick, will only activate if MOTOR_STOP feature is available
COMPASS_CALIBRATED = (1 << 8),
ACCELEROMETER_CALIBRATED = (1 << 9),
PWM_DRIVER_AVAILABLE = (1 << 10),
NAV_CRUISE_BRAKING = (1 << 11),
NAV_CRUISE_BRAKING_BOOST = (1 << 12),
NAV_CRUISE_BRAKING_LOCKED = (1 << 13),
GPS_FIX_HOME = (1 << 0),
GPS_FIX = (1 << 1),
CALIBRATE_MAG = (1 << 2),
SMALL_ANGLE = (1 << 3),
FIXED_WING = (1 << 4), // set when in flying_wing or airplane mode. currently used by althold selection code
ANTI_WINDUP = (1 << 5),
FLAPERON_AVAILABLE = (1 << 6),
NAV_MOTOR_STOP_OR_IDLE = (1 << 7), // navigation requests MOTOR_STOP or motor idle regardless of throttle stick, will only activate if MOTOR_STOP feature is available
COMPASS_CALIBRATED = (1 << 8),
ACCELEROMETER_CALIBRATED = (1 << 9),
PWM_DRIVER_AVAILABLE = (1 << 10),
NAV_CRUISE_BRAKING = (1 << 11),
NAV_CRUISE_BRAKING_BOOST = (1 << 12),
NAV_CRUISE_BRAKING_LOCKED = (1 << 13),
NAV_EXTRA_ARMING_SAFETY_BYPASSED = (1 << 14), // nav_extra_arming_safey was bypassed. Keep it until power cycle.
} stateFlags_t;
#define DISABLE_STATE(mask) (stateFlags &= ~(mask))

View file

@ -167,7 +167,6 @@ PG_RESET_TEMPLATE(navConfig_t, navConfig,
navigationPosControl_t posControl;
navSystemStatus_t NAV_Status;
static bool blockingArmingBypassWithoutSticks;
#if defined(NAV_BLACKBOX)
int16_t navCurrentState;
@ -2938,7 +2937,7 @@ navArmingBlocker_e navigationIsBlockingArming(bool *usedBypass)
// 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))) {
if (navConfig()->general.flags.extra_arming_safety == NAV_EXTRA_ARMING_SAFETY_ALLOW_BYPASS &&
(blockingArmingBypassWithoutSticks || rxGetChannelValue(YAW) > 1750)) {
(STATE(NAV_EXTRA_ARMING_SAFETY_BYPASSED) || rxGetChannelValue(YAW) > 1750)) {
if (usedBypass) {
*usedBypass = true;
}
@ -2967,11 +2966,6 @@ navArmingBlocker_e navigationIsBlockingArming(bool *usedBypass)
return NAV_ARMING_BLOCKER_NONE;
}
void navigationSetBlockingArmingBypassWithoutSticks(bool allow)
{
blockingArmingBypassWithoutSticks = allow;
}
bool navigationPositionEstimateIsHealthy(void)
{
return (posControl.flags.estPosStatus >= EST_USABLE) && STATE(GPS_FIX_HOME);

View file

@ -369,10 +369,6 @@ int8_t navigationGetHeadingControlState(void);
// 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);