From 11ad9d5a2d03547afb77986d6c496bebbd63b267 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 5 May 2013 17:09:59 +1000 Subject: [PATCH] Plane: auto-invert pitch control when upside down this helps to recover when flying inverted, for example when in manual and hitting the lower altitude geofence --- ArduPlane/Attitude.pde | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ArduPlane/Attitude.pde b/ArduPlane/Attitude.pde index 8ba9bdb431..a9fae3374d 100644 --- a/ArduPlane/Attitude.pde +++ b/ArduPlane/Attitude.pde @@ -105,18 +105,19 @@ static void stabilize_pitch(float speed_scaler) g.flybywire_airspeed_min, g.flybywire_airspeed_max); break; - default: + default: { int32_t tempcalc = nav_pitch_cd + fabsf(ahrs.roll_sensor * g.kff_pitch_compensation) + (g.channel_throttle.servo_out * g.kff_throttle_to_pitch) - (ahrs.pitch_sensor - g.pitch_trim_cd); - if (inverted_flight) { + if (abs(ahrs.roll_sensor) > 9000) { // when flying upside down the elevator control is inverted tempcalc = -tempcalc; } g.channel_pitch.servo_out = g.pidServoPitch.get_pid_4500(tempcalc, speed_scaler); break; } + } } /*