From e362844532280fb41c7a8e692534c86f9b1c730b Mon Sep 17 00:00:00 2001
From: Randy Mackay <rmackay9@yahoo.com>
Date: Mon, 14 Jan 2013 13:58:53 +0900
Subject: [PATCH] Copter: added CH7 switch to enabling/disable the sonar in
 flight

This indirectly switches surface tracking on/off which is useful to
avoid tracking the tops of uneven objects when far above the ground
---
 ArduCopter/control_modes.pde | 5 +++++
 ArduCopter/defines.h         | 1 +
 ArduCopter/options.cmake     | 3 ++-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ArduCopter/control_modes.pde b/ArduCopter/control_modes.pde
index f03d4b3d2..781457cf5 100644
--- a/ArduCopter/control_modes.pde
+++ b/ArduCopter/control_modes.pde
@@ -164,6 +164,11 @@ static void read_trim_switch()
             }
             break;
 #endif
+
+        case CH7_SONAR:
+            // enable or disable the sonar
+            g.sonar_enabled = ap_system.CH7_flag;
+            break;
     }
 }
 
diff --git a/ArduCopter/defines.h b/ArduCopter/defines.h
index 053e2f8a7..8fe53cb93 100644
--- a/ArduCopter/defines.h
+++ b/ArduCopter/defines.h
@@ -64,6 +64,7 @@
 #define CH7_SAVE_WP 7
 #define CH7_MULTI_MODE 8
 #define CH7_CAMERA_TRIGGER 9
+#define CH7_SONAR 10            // allow enabling or disabling sonar in flight which helps avoid surface tracking when you are far above the ground
 
 
 
diff --git a/ArduCopter/options.cmake b/ArduCopter/options.cmake
index a0c899bff..b96c27067 100644
--- a/ArduCopter/options.cmake
+++ b/ArduCopter/options.cmake
@@ -159,7 +159,8 @@ apm_option("CH7_OPTION" TYPE STRING
         "CH7_DO_NOTHING"
         "CH7_SAVE_WP"
         "CH7_DO_NOTHING"
-        "CH7_CAMERA_TRIGGER")
+        "CH7_CAMERA_TRIGGER"
+        "CH7_SONAR")
 
 apm_option("ACCEL_ALT_HOLD" TYPE BOOL ADVANCED
     DESCRIPTION "Disabled by default, work in progress."
-- 
GitLab