From f87da51b37a15d9671632018bef00b309f090589 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Oct 2014 12:46:20 +1100 Subject: [PATCH] Plane: prevent calling jump_to_landing_sequence() too often --- ArduPlane/ArduPlane.pde | 14 ++++++++++++-- ArduPlane/system.pde | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ArduPlane/ArduPlane.pde b/ArduPlane/ArduPlane.pde index 061eb9d7c8..194ff3fff0 100644 --- a/ArduPlane/ArduPlane.pde +++ b/ArduPlane/ArduPlane.pde @@ -546,6 +546,9 @@ static struct { // in FBWA taildragger takeoff mode bool fbwa_tdrag_takeoff_mode:1; + // have we checked for an auto-land? + bool checked_for_autoland:1; + // Altitude threshold to complete a takeoff command in autonomous modes. Centimeters int32_t takeoff_altitude_cm; @@ -574,6 +577,7 @@ static struct { next_wp_no_crosstrack : true, no_crosstrack : true, fbwa_tdrag_takeoff_mode : false, + checked_for_autoland : false, takeoff_altitude_cm : 0, takeoff_pitch_cd : 0, highest_airspeed : 0, @@ -1421,12 +1425,18 @@ static void update_navigation() case RTL: if (g.rtl_autoland && + !auto_state.checked_for_autoland && nav_controller->reached_loiter_target() && labs(altitude_error_cm) < 1000) { - if (mission.jump_to_landing_sequence()) { - gcs_send_text_P(PSTR("Starting auto landing")); + // we've reached the RTL point, see if we have a landing sequence + if (!auto_state.checked_for_autoland && + mission.jump_to_landing_sequence()) { + gcs_send_text_P(SEVERITY_LOW, PSTR("Starting auto landing")); set_mode(AUTO); } + // prevent running the expensive jump_to_landing_sequence + // on every loop + auto_state.checked_for_autoland = true; } // fall through to LOITER diff --git a/ArduPlane/system.pde b/ArduPlane/system.pde index 66252d2682..723e237328 100644 --- a/ArduPlane/system.pde +++ b/ArduPlane/system.pde @@ -297,6 +297,9 @@ static void set_mode(enum FlightMode mode) // don't cross-track when starting a mission auto_state.next_wp_no_crosstrack = true; + // reset landing check + auto_state.checked_for_autoland = false; + // zero locked course steer_state.locked_course_err = 0;