From c47bc09a3c659ec0fd7c8f7cd69736e9bdf7e0b0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 12 Apr 2013 12:47:59 +1000 Subject: [PATCH] Plane: avoid doing radio trim if less than 20% of travel available this prevents problems with awful trim on bootup due to RC TX being off --- ArduPlane/radio.pde | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ArduPlane/radio.pde b/ArduPlane/radio.pde index 01c21dfb4f..d268b9a641 100644 --- a/ArduPlane/radio.pde +++ b/ArduPlane/radio.pde @@ -173,6 +173,19 @@ static void control_failsafe(uint16_t pwm) static void trim_control_surfaces() { read_radio(); + int16_t trim_roll_range = (g.channel_roll.radio_max - g.channel_roll.radio_min)/5; + int16_t trim_pitch_range = (g.channel_pitch.radio_max - g.channel_pitch.radio_min)/5; + if (g.channel_roll.radio_in < g.channel_roll.radio_min+trim_roll_range || + g.channel_roll.radio_in > g.channel_roll.radio_max-trim_roll_range || + g.channel_pitch.radio_in < g.channel_pitch.radio_min+trim_pitch_range || + g.channel_pitch.radio_in > g.channel_pitch.radio_max-trim_pitch_range) { + // don't trim for extreme values - if we attempt to trim so + // there is less than 20 percent range left then assume the + // sticks are not properly centered. This also prevents + // problems with starting APM with the TX off + return; + } + // Store control surface trim values // --------------------------------- if(g.mix_mode == 0) {