diff --git a/src/main/fc/fc_core.c b/src/main/fc/fc_core.c index cc9cd02972..2a9e1aec57 100644 --- a/src/main/fc/fc_core.c +++ b/src/main/fc/fc_core.c @@ -221,6 +221,7 @@ void updateArmingStatus(void) /* Ignore ARMING_DISABLED_THROTTLE (once arm switch is on) if we are in 3D mode */ bool ignoreThrottle = feature(FEATURE_3D) && !IS_RC_MODE_ACTIVE(BOX3DDISABLE) + && !isModeActivationConditionPresent(BOX3DONASWITCH) && !(getArmingDisableFlags() & ~(ARMING_DISABLED_ARM_SWITCH | ARMING_DISABLED_THROTTLE)); // If arming is disabled and the ARM switch is on diff --git a/src/test/unit/arming_prevention_unittest.cc b/src/test/unit/arming_prevention_unittest.cc index 787013b497..0814908f97 100644 --- a/src/test/unit/arming_prevention_unittest.cc +++ b/src/test/unit/arming_prevention_unittest.cc @@ -369,10 +369,7 @@ TEST(ArmingPreventionTest, In3DModeAllowArmingWhenEnteringThrottleDeadband) // and rcData[THROTTLE] = 1400; ENABLE_STATE(SMALL_ANGLE); - - // and - // RX has no link to radio - simulationHaveRx = false; + simulationHaveRx = true; // and // arm channel has a safe default value @@ -441,10 +438,7 @@ TEST(ArmingPreventionTest, When3DModeDisabledThenNormalThrottleArmingConditionAp // safe throttle value for 3D mode rcData[THROTTLE] = 1500; ENABLE_STATE(SMALL_ANGLE); - - // and - // RX has no link to radio - simulationHaveRx = false; + simulationHaveRx = true; // and // arm channel has a safe default value @@ -518,6 +512,100 @@ TEST(ArmingPreventionTest, When3DModeDisabledThenNormalThrottleArmingConditionAp EXPECT_EQ(0, getArmingDisableFlags()); } +TEST(ArmingPreventionTest, WhenUsingSwitched3DModeThenNormalThrottleArmingConditionApplies) +{ + // given + simulationFeatureFlags = FEATURE_3D; // Using 3D mode + simulationTime = 30e6; // 30 seconds after boot + gyroCalibDone = true; + + // and + modeActivationConditionsMutable(0)->auxChannelIndex = 0; + modeActivationConditionsMutable(0)->modeId = BOXARM; + modeActivationConditionsMutable(0)->range.startStep = CHANNEL_VALUE_TO_STEP(1750); + modeActivationConditionsMutable(0)->range.endStep = CHANNEL_VALUE_TO_STEP(CHANNEL_RANGE_MAX); + modeActivationConditionsMutable(1)->auxChannelIndex = 1; + modeActivationConditionsMutable(1)->modeId = BOX3DONASWITCH; + modeActivationConditionsMutable(1)->range.startStep = CHANNEL_VALUE_TO_STEP(1750); + modeActivationConditionsMutable(1)->range.endStep = CHANNEL_VALUE_TO_STEP(CHANNEL_RANGE_MAX); + useRcControlsConfig(NULL); + + // and + rxConfigMutable()->mincheck = 1050; + + // and + rcData[THROTTLE] = 1000; + ENABLE_STATE(SMALL_ANGLE); + simulationHaveRx = true; + + // and + // arm channel has a safe default value + rcData[4] = 1100; + + // when + updateActivatedModes(); + updateArmingStatus(); + + // expect + // ok to arm in 3D mode + EXPECT_FALSE(isUsingSticksForArming()); + EXPECT_FALSE(isArmingDisabled()); + EXPECT_EQ(0, getArmingDisableFlags()); + + // given + // raise throttle to unsafe position + rcData[THROTTLE] = 1500; + + // when + updateActivatedModes(); + updateArmingStatus(); + + // expect + // ok to arm in 3D mode + EXPECT_FALSE(isUsingSticksForArming()); + EXPECT_TRUE(isArmingDisabled()); + EXPECT_EQ(ARMING_DISABLED_THROTTLE, getArmingDisableFlags()); + + // given + // attempt to arm + rcData[4] = 1800; + + // when + updateActivatedModes(); + updateArmingStatus(); + + // expect + EXPECT_FALSE(isUsingSticksForArming()); + EXPECT_TRUE(isArmingDisabled()); + EXPECT_EQ(ARMING_DISABLED_THROTTLE | ARMING_DISABLED_ARM_SWITCH, getArmingDisableFlags()); + + // given + // throttle moved low + rcData[THROTTLE] = 1000; + + // when + updateActivatedModes(); + updateArmingStatus(); + + // expect + EXPECT_FALSE(isUsingSticksForArming()); + EXPECT_TRUE(isArmingDisabled()); + EXPECT_EQ(ARMING_DISABLED_ARM_SWITCH, getArmingDisableFlags()); + + // given + // arm switch turned off + rcData[4] = 1000; + + // when + updateActivatedModes(); + updateArmingStatus(); + + // expect + EXPECT_FALSE(isUsingSticksForArming()); + EXPECT_FALSE(isArmingDisabled()); + EXPECT_EQ(0, getArmingDisableFlags()); +} + // STUBS extern "C" { uint32_t micros(void) { return simulationTime; }