From 1f253c521791d02ac165ca11a07ae23c2031e69f Mon Sep 17 00:00:00 2001
From: rmackay9 <rmackay9@yahoo.com>
Date: Fri, 23 Mar 2012 23:48:24 +0900
Subject: [PATCH] ArduCopter - altitude hold - ensure throttle_avg is
 initialised from g.throttle_cruise parameter

---
 ArduCopter/ArduCopter.pde | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/ArduCopter/ArduCopter.pde b/ArduCopter/ArduCopter.pde
index 3ef0b5af9..529e020f1 100644
--- a/ArduCopter/ArduCopter.pde
+++ b/ArduCopter/ArduCopter.pde
@@ -1580,7 +1580,7 @@ void update_throttle_mode(void)
 	int16_t throttle_out;
 
 	#if AUTO_THROTTLE_HOLD != 0
-	static float throttle_avg = THROTTLE_CRUISE;
+	static float throttle_avg = 0;  // this is initialised to g.throttle_cruise later
 	#endif
 
 	switch(throttle_mode){
@@ -1598,6 +1598,10 @@ void update_throttle_mode(void)
 				#endif
 
 				#if AUTO_THROTTLE_HOLD != 0
+				// ensure throttle_avg has been initialised
+				if( throttle_avg == 0 ) {
+				    throttle_avg = g.throttle_cruise;
+				}
 				// calc average throttle
 				if ((g.rc_3.control_in > MINIMUM_THROTTLE) && abs(climb_rate) < 60){
 					throttle_avg = throttle_avg * .98 + (float)g.rc_3.control_in * .02;
-- 
GitLab