From 23919daf118888c03e9688565dc5f1edf14e9871 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 9 Aug 2017 21:22:15 +1000 Subject: [PATCH] Plane: use arming check_failed function --- ArduPlane/AP_Arming.cpp | 64 ++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 43 deletions(-) diff --git a/ArduPlane/AP_Arming.cpp b/ArduPlane/AP_Arming.cpp index a52a86ad19..0bae9256eb 100644 --- a/ArduPlane/AP_Arming.cpp +++ b/ArduPlane/AP_Arming.cpp @@ -22,80 +22,61 @@ const AP_Param::GroupInfo AP_Arming_Plane::var_info[] = { additional arming checks for plane */ -bool AP_Arming_Plane::pre_arm_checks(bool report) +bool AP_Arming_Plane::pre_arm_checks(bool display_failure) { // call parent class checks - bool ret = AP_Arming::pre_arm_checks(report); + bool ret = AP_Arming::pre_arm_checks(display_failure); // Check airspeed sensor - ret &= AP_Arming::airspeed_checks(report); + ret &= AP_Arming::airspeed_checks(display_failure); if (plane.g.fs_timeout_long < plane.g.fs_timeout_short && plane.g.fs_action_short != FS_ACTION_SHORT_DISABLED) { - if (report) { - gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: FS_LONG_TIMEOUT < FS_SHORT_TIMEOUT"); - } + check_failed(ARMING_CHECK_NONE, display_failure, "FS_LONG_TIMEOUT < FS_SHORT_TIMEOUT"); ret = false; } if (plane.aparm.roll_limit_cd < 300) { - if (report) { - gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: LIM_ROLL_CD too small (%u)", plane.aparm.roll_limit_cd); - } - ret = false; + check_failed(ARMING_CHECK_NONE, display_failure, "LIM_ROLL_CD too small (%u)", plane.aparm.roll_limit_cd); + ret = false; } if (plane.aparm.pitch_limit_max_cd < 300) { - if (report) { - gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: LIM_PITCH_MAX too small (%u)", plane.aparm.pitch_limit_max_cd); - } - ret = false; + check_failed(ARMING_CHECK_NONE, display_failure, "LIM_PITCH_MAX too small (%u)", plane.aparm.pitch_limit_max_cd); + ret = false; } if (plane.aparm.pitch_limit_min_cd > -300) { - if (report) { - gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: LIM_PITCH_MIN too large (%u)", plane.aparm.pitch_limit_min_cd); - } - ret = false; + check_failed(ARMING_CHECK_NONE, display_failure, "LIM_PITCH_MIN too large (%u)", plane.aparm.pitch_limit_min_cd); + ret = false; } if (plane.channel_throttle->get_reverse() && plane.g.throttle_fs_enabled && plane.g.throttle_fs_value < plane.channel_throttle->get_radio_max()) { - if (report) { - gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: Invalid THR_FS_VALUE for rev throttle"); - } + check_failed(ARMING_CHECK_NONE, display_failure, "Invalid THR_FS_VALUE for rev throttle"); ret = false; } if (plane.quadplane.available() && plane.scheduler.get_loop_rate_hz() < 100) { - if (report) { - gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: quadplane needs SCHED_LOOP_RATE > 100"); - } + check_failed(ARMING_CHECK_NONE, display_failure, "quadplane needs SCHED_LOOP_RATE >= 100"); ret = false; } if (plane.control_mode == AUTO && plane.mission.num_commands() <= 1) { - if (report) { - gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: No mission loaded"); - } + check_failed(ARMING_CHECK_NONE, display_failure, "No mission loaded"); ret = false; } // check adsb avoidance failsafe if (plane.failsafe.adsb) { - if (report) { - gcs().send_text(MAV_SEVERITY_CRITICAL,"PreArm: ADSB threat detected"); - } + check_failed(ARMING_CHECK_NONE, display_failure, "ADSB threat detected"); ret = false; } #if HAVE_PX4_MIXER if (plane.last_mixer_crc == -1) { - if (report) { - // if you ever get this error, a reboot is recommended. - gcs().send_text(MAV_SEVERITY_CRITICAL,"PreArm: Mixer error"); - } + check_failed(ARMING_CHECK_NONE, display_failure, "Mixer error"); ret = false; } #endif // CONFIG_HAL_BOARD @@ -103,10 +84,10 @@ bool AP_Arming_Plane::pre_arm_checks(bool report) return ret; } -bool AP_Arming_Plane::ins_checks(bool report) +bool AP_Arming_Plane::ins_checks(bool display_failure) { // call parent class checks - if (!AP_Arming::ins_checks(report)) { + if (!AP_Arming::ins_checks(display_failure)) { return false; } @@ -114,14 +95,11 @@ bool AP_Arming_Plane::ins_checks(bool report) if ((checks_to_perform & ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_INS)) { if (!ahrs.healthy()) { - if (report) { - const char *reason = ahrs.prearm_failure_reason(); - if (reason) { - gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: %s", reason); - } else { - gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: AHRS not healthy"); - } + const char *reason = ahrs.prearm_failure_reason(); + if (reason == nullptr) { + reason = "AHRS not healthy"; } + check_failed(ARMING_CHECK_INS, display_failure, "%s", reason); return false; } }