From 63d0cddfa4e8909b2533dbbf234ef3015c8bdb43 Mon Sep 17 00:00:00 2001
From: Randy Mackay <rmackay9@yahoo.com>
Date: Mon, 25 Aug 2014 17:25:32 +0900
Subject: [PATCH] Copter: make landing detector more strict

Made more strict by requiring 50 consecutive iterations where the climb
rate is below +- 40cm/s.  Previously it was 50 cumulative.

Removed check of failsafe.radio when clearing the land flag because it
could result in the vehicle taking off if the user picked it up.
---
 ArduCopter/control_land.pde | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/ArduCopter/control_land.pde b/ArduCopter/control_land.pde
index b85e44c84..45d29e4f9 100644
--- a/ArduCopter/control_land.pde
+++ b/ArduCopter/control_land.pde
@@ -188,13 +188,13 @@ static float get_throttle_land()
 }
 
 // update_land_detector - checks if we have landed and updates the ap.land_complete flag
-// returns true if we have landed
-static bool update_land_detector()
+// called at 50hz
+static void update_land_detector()
 {
     // detect whether we have landed by watching for low climb rate and minimum throttle
     if (abs(climb_rate) < 40 && motors.limit.throttle_lower) {
         if (!ap.land_complete) {
-            // run throttle controller if accel based throttle controller is enabled and active (active means it has been given a target)
+            // increase counter until we hit the trigger then set land complete flag
             if( land_detector < LAND_DETECTOR_TRIGGER) {
                 land_detector++;
             }else{
@@ -202,16 +202,14 @@ static bool update_land_detector()
                 land_detector = 0;
             }
         }
-    } else if ((motors.get_throttle_out() > get_non_takeoff_throttle()) || failsafe.radio) {
+    } else {
         // we've sensed movement up or down so reset land_detector
         land_detector = 0;
-        if(ap.land_complete) {
+        // if throttle output is high then clear landing flag
+        if (motors.get_throttle_out() > get_non_takeoff_throttle()) {
             set_land_complete(false);
         }
     }
-
-    // return current state of landing
-    return ap.land_complete;
 }
 
 // land_do_not_use_GPS - forces land-mode to not use the GPS but instead rely on pilot input for roll and pitch
-- 
GitLab