From 1e3f37908c6263bfe203d46c589d1cfa2d61eb01 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 4 Aug 2022 13:03:16 +1000 Subject: [PATCH] Copter: factor out an rc_throttle_failsafe_checks method NFC, preparing to call this from elsewhere --- ArduCopter/AP_Arming.cpp | 38 ++++++++++++++++++++++++++++++++------ ArduCopter/AP_Arming.h | 1 + 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/ArduCopter/AP_Arming.cpp b/ArduCopter/AP_Arming.cpp index 2f1f3a0756..dbcc7523d5 100644 --- a/ArduCopter/AP_Arming.cpp +++ b/ArduCopter/AP_Arming.cpp @@ -63,6 +63,34 @@ bool AP_Arming_Copter::run_pre_arm_checks(bool display_failure) & AP_Arming::pre_arm_checks(display_failure); } +bool AP_Arming_Copter::rc_throttle_failsafe_checks(bool display_failure) const +{ + // throttle failsafe. In this case the parameter also gates the + // no-pulses RC failure case - the radio-in value can be zero due + // to not having received any RC pulses at all. Note that if we + // have ever seen RC and then we *lose* RC then these checks are + // likely to pass if the user is relying on no-pulses to detect RC + // failure. However, arming is precluded in that case by being in + // RC failsafe. + if (copter.g.failsafe_throttle == FS_THR_DISABLED) { + return true; + } + +#if FRAME_CONFIG == HELI_FRAME + const char *rc_item = "Collective"; +#else + const char *rc_item = "Throttle"; +#endif + + // check throttle is not too low - must be above failsafe throttle + if (copter.channel_throttle->get_radio_in() < copter.g.failsafe_throttle_value) { + check_failed(ARMING_CHECK_RC, true, "%s below failsafe", rc_item); + return false; + } + + return true; +} + bool AP_Arming_Copter::barometer_checks(bool display_failure) { if (!AP_Arming::barometer_checks(display_failure)) { @@ -597,17 +625,15 @@ bool AP_Arming_Copter::arm_checks(AP_Arming::Method method) // check throttle if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_RC)) { + if (!rc_throttle_failsafe_checks(true)) { + return false; + } + #if FRAME_CONFIG == HELI_FRAME const char *rc_item = "Collective"; #else const char *rc_item = "Throttle"; #endif - // check throttle is not too low - must be above failsafe throttle - if (copter.g.failsafe_throttle != FS_THR_DISABLED && copter.channel_throttle->get_radio_in() < copter.g.failsafe_throttle_value) { - check_failed(ARMING_CHECK_RC, true, "%s below failsafe", rc_item); - return false; - } - // check throttle is not too high - skips checks if arming from GCS in Guided if (!(method == AP_Arming::Method::MAVLINK && (copter.flightmode->mode_number() == Mode::Number::GUIDED || copter.flightmode->mode_number() == Mode::Number::GUIDED_NOGPS))) { // above top of deadband is too always high diff --git a/ArduCopter/AP_Arming.h b/ArduCopter/AP_Arming.h index 58f8e78670..b0b90ef9e1 100644 --- a/ArduCopter/AP_Arming.h +++ b/ArduCopter/AP_Arming.h @@ -48,6 +48,7 @@ protected: bool gcs_failsafe_check(bool display_failure); bool winch_checks(bool display_failure) const; bool alt_checks(bool display_failure); + bool rc_throttle_failsafe_checks(bool display_failure) const; void set_pre_arm_check(bool b);