mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +03:00
Fix 3D arming checks for BOX3DDISABLE
When FEATURE_3D is on and BOX3DDISABLE is on then the normal throttle arming check is performed. When FEATURE_3D is on and BOX3DDISABLE is off then the reduced 3D throttle arming check is performed.
This commit is contained in:
parent
eadcf42650
commit
0315005445
3 changed files with 115 additions and 8 deletions
|
@ -215,10 +215,13 @@ void updateArmingStatus(void)
|
||||||
|
|
||||||
if (!isUsingSticksForArming()) {
|
if (!isUsingSticksForArming()) {
|
||||||
/* Ignore ARMING_DISABLED_CALIBRATING if we are going to calibrate gyro on first arm */
|
/* Ignore ARMING_DISABLED_CALIBRATING if we are going to calibrate gyro on first arm */
|
||||||
bool ignoreGyro = armingConfig()->gyro_cal_on_first_arm && !(getArmingDisableFlags() & ~(ARMING_DISABLED_ARM_SWITCH | ARMING_DISABLED_CALIBRATING));
|
bool ignoreGyro = armingConfig()->gyro_cal_on_first_arm
|
||||||
|
&& !(getArmingDisableFlags() & ~(ARMING_DISABLED_ARM_SWITCH | ARMING_DISABLED_CALIBRATING));
|
||||||
|
|
||||||
/* Ignore ARMING_DISABLED_THROTTLE (once arm switch is on) if we are in 3D mode */
|
/* Ignore ARMING_DISABLED_THROTTLE (once arm switch is on) if we are in 3D mode */
|
||||||
bool ignoreThrottle = feature(FEATURE_3D) && !(getArmingDisableFlags() & ~(ARMING_DISABLED_ARM_SWITCH | ARMING_DISABLED_THROTTLE));
|
bool ignoreThrottle = feature(FEATURE_3D)
|
||||||
|
&& !IS_RC_MODE_ACTIVE(BOX3DDISABLE)
|
||||||
|
&& !(getArmingDisableFlags() & ~(ARMING_DISABLED_ARM_SWITCH | ARMING_DISABLED_THROTTLE));
|
||||||
|
|
||||||
// If arming is disabled and the ARM switch is on
|
// If arming is disabled and the ARM switch is on
|
||||||
if (isArmingDisabled()
|
if (isArmingDisabled()
|
||||||
|
|
|
@ -110,15 +110,14 @@ throttleStatus_e calculateThrottleStatus(void)
|
||||||
{
|
{
|
||||||
if (feature(FEATURE_3D)) {
|
if (feature(FEATURE_3D)) {
|
||||||
if (IS_RC_MODE_ACTIVE(BOX3DDISABLE) || isModeActivationConditionPresent(BOX3DONASWITCH)) {
|
if (IS_RC_MODE_ACTIVE(BOX3DDISABLE) || isModeActivationConditionPresent(BOX3DONASWITCH)) {
|
||||||
if (rcData[THROTTLE] < rxConfig()->mincheck)
|
|
||||||
return THROTTLE_LOW;
|
|
||||||
} else if ((rcData[THROTTLE] > (rxConfig()->midrc - flight3DConfig()->deadband3d_throttle) && rcData[THROTTLE] < (rxConfig()->midrc + flight3DConfig()->deadband3d_throttle))) {
|
|
||||||
return THROTTLE_LOW;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (rcData[THROTTLE] < rxConfig()->mincheck) {
|
if (rcData[THROTTLE] < rxConfig()->mincheck) {
|
||||||
return THROTTLE_LOW;
|
return THROTTLE_LOW;
|
||||||
}
|
}
|
||||||
|
} else if ((rcData[THROTTLE] > (rxConfig()->midrc - flight3DConfig()->deadband3d_throttle) && rcData[THROTTLE] < (rxConfig()->midrc + flight3DConfig()->deadband3d_throttle))) {
|
||||||
|
return THROTTLE_LOW;
|
||||||
|
}
|
||||||
|
} else if (rcData[THROTTLE] < rxConfig()->mincheck) {
|
||||||
|
return THROTTLE_LOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
return THROTTLE_HIGH;
|
return THROTTLE_HIGH;
|
||||||
|
|
|
@ -161,6 +161,7 @@ TEST(ArmingPreventionTest, CalibrationPowerOnGraceAngleThrottleArmSwitch)
|
||||||
EXPECT_EQ(0, getArmingDisableFlags());
|
EXPECT_EQ(0, getArmingDisableFlags());
|
||||||
EXPECT_FALSE(isArmingDisabled());
|
EXPECT_FALSE(isArmingDisabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ArmingPreventionTest, ArmingGuardRadioLeftOnAndArmed)
|
TEST(ArmingPreventionTest, ArmingGuardRadioLeftOnAndArmed)
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
|
@ -347,7 +348,7 @@ TEST(ArmingPreventionTest, RadioTurnedOnAtAnyTimeArmed)
|
||||||
EXPECT_EQ(0, getArmingDisableFlags());
|
EXPECT_EQ(0, getArmingDisableFlags());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ArmingPreventionTest, In3DModeAllowArmingWhenEnteringThrottleDeadbandFromNegativeSide)
|
TEST(ArmingPreventionTest, In3DModeAllowArmingWhenEnteringThrottleDeadband)
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
simulationFeatureFlags = FEATURE_3D; // Using 3D mode
|
simulationFeatureFlags = FEATURE_3D; // Using 3D mode
|
||||||
|
@ -413,6 +414,110 @@ TEST(ArmingPreventionTest, In3DModeAllowArmingWhenEnteringThrottleDeadbandFromNe
|
||||||
EXPECT_EQ(0, getArmingDisableFlags());
|
EXPECT_EQ(0, getArmingDisableFlags());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ArmingPreventionTest, When3DModeDisabledThenNormalThrottleArmingConditionApplies)
|
||||||
|
{
|
||||||
|
// 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 = BOX3DDISABLE;
|
||||||
|
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;
|
||||||
|
rxConfigMutable()->midrc = 1500;
|
||||||
|
flight3DConfigMutable()->deadband3d_throttle = 5;
|
||||||
|
|
||||||
|
// and
|
||||||
|
// safe throttle value for 3D mode
|
||||||
|
rcData[THROTTLE] = 1500;
|
||||||
|
ENABLE_STATE(SMALL_ANGLE);
|
||||||
|
|
||||||
|
// and
|
||||||
|
// RX has no link to radio
|
||||||
|
simulationHaveRx = false;
|
||||||
|
|
||||||
|
// and
|
||||||
|
// arm channel has a safe default value
|
||||||
|
rcData[4] = 1100;
|
||||||
|
|
||||||
|
// and
|
||||||
|
// disable 3D mode is off (i.e. 3D mode is on)
|
||||||
|
rcData[5] = 1100;
|
||||||
|
|
||||||
|
// when
|
||||||
|
updateActivatedModes();
|
||||||
|
updateArmingStatus();
|
||||||
|
|
||||||
|
// expect
|
||||||
|
// ok to arm in 3D mode
|
||||||
|
EXPECT_FALSE(isUsingSticksForArming());
|
||||||
|
EXPECT_FALSE(isArmingDisabled());
|
||||||
|
EXPECT_EQ(0, getArmingDisableFlags());
|
||||||
|
|
||||||
|
// given
|
||||||
|
// disable 3D mode
|
||||||
|
rcData[5] = 1800;
|
||||||
|
|
||||||
|
// 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
|
// STUBS
|
||||||
extern "C" {
|
extern "C" {
|
||||||
uint32_t micros(void) { return simulationTime; }
|
uint32_t micros(void) { return simulationTime; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue