From 5b57df5d1c316c9182fcab7dcf4172c3815ba832 Mon Sep 17 00:00:00 2001 From: Jason Short Date: Thu, 22 Sep 2011 17:38:39 -0700 Subject: [PATCH] Refined Throttle Timer reset Reduced Loiter I gain to decrease overshoot. --- ArduCopter/ArduCopter.pde | 2 ++ ArduCopter/Attitude.pde | 17 +++++++++++------ ArduCopter/config.h | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ArduCopter/ArduCopter.pde b/ArduCopter/ArduCopter.pde index 445bfdb7be..f5a955e3b1 100644 --- a/ArduCopter/ArduCopter.pde +++ b/ArduCopter/ArduCopter.pde @@ -1095,6 +1095,8 @@ void update_throttle_mode(void) }else{ g.rc_3.servo_out = 0; } + // reset the timer to throttle so that we never get fast I term run-ups + throttle_timer = 0; break; case THROTTLE_HOLD: diff --git a/ArduCopter/Attitude.pde b/ArduCopter/Attitude.pde index 1a85a44d23..8200e98452 100644 --- a/ArduCopter/Attitude.pde +++ b/ArduCopter/Attitude.pde @@ -100,9 +100,17 @@ get_nav_throttle(long z_error, int target_speed) rate_error = target_speed - altitude_rate; rate_error = constrain(rate_error, -110, 110); - long timer = millis(); - float delta_throttle = (float)(timer - throttle_timer)/1000.0; - throttle_timer = timer; + float delta_throttle; + + // is the throttle_timer uninitialized? + if(throttle_timer == 0){ + throttle_timer = millis(); + delta_throttle = 0; + }else{ + long timer = millis(); + delta_throttle = (float)(timer - throttle_timer)/1000.0; + throttle_timer = timer; + } return (int)g.pi_throttle.get_pi(rate_error, delta_throttle); } @@ -162,9 +170,6 @@ static void reset_nav(void) nav_throttle = 0; invalid_throttle = true; - // clear the throttle timer - throttle_timer = millis(); - g.pi_nav_lat.reset_I(); g.pi_nav_lon.reset_I(); diff --git a/ArduCopter/config.h b/ArduCopter/config.h index 68eafe7845..e973722592 100644 --- a/ArduCopter/config.h +++ b/ArduCopter/config.h @@ -485,7 +485,7 @@ # define LOITER_P .4 // #endif #ifndef LOITER_I -# define LOITER_I 0.04 // +# define LOITER_I 0.01 // #endif #ifndef LOITER_IMAX # define LOITER_IMAX 12 // degreesĀ° @@ -513,7 +513,7 @@ # define THROTTLE_P 0.6 // #endif #ifndef THROTTLE_I -# define THROTTLE_I 0.03 // with 4m error, 12.5s windup +# define THROTTLE_I 0.02 // with 4m error, 8 PWM gain/s #endif #ifndef THROTTLE_IMAX # define THROTTLE_IMAX 300