iNavFlight / inav

INAV: Navigation-enabled flight control software
https://inavflight.github.io
GNU General Public License v3.0
3.19k stars 1.49k forks source link

Continous Auto Trim active during maneuvers #9912

Open b14ckyy opened 7 months ago

b14ckyy commented 7 months ago

Current Behavior

If Continuous Servo Trim is enabled on fixed wings, it is constantly trimming even when not flying level or when flying slow or fast maneuvers. This leads to a few seconds of strongly out of trim plane behavior after long rolls or turns as well as loops and can in worst case cause a crash at a low altitude loop. It also causes a lot of false trim during landing when the pilot does a flare maneuver at low airspeed.

Steps to Reproduce

  1. Enable Continous Auto Trim in Features
  2. Fly in acro mode and fly level until plane flies dead straight with no stick input
  3. Do a long continous bank 180° or more turn or fly a spiral
  4. quickly level off and release the sticks Result: the plane will be heavily out of trim so that a low I-Term cannot compensate anymore and it takes a few seconds to recover

Expected behavior

Continous Servo Trim should only trim the plane if the rate setpoint is very close to 0 in Autolevel modes or within stick deadband in acro mode. The trim should be locked while the pilot or autopilot is doing any maneuvers, turns or altitude changes.

Suggested solution(s)

I checked the code as far as I was able to understand it and found that the Continous Servo trim has multiple sanity checks before it should get active.

planeIsFlyingStraight && 
noRotationCommanded && 
planeIsFlyingLevel &&
sticksAreCentered &&
!FLIGHT_MODE(MANUAL_MODE) && 
isGPSHeadingValid() // TODO: proper flying detection

I think one or more of these sanity checks are not properly working.

Additional context

The issue must be in INAV for a long time. I just noticed it intensively while testing other stuff and investigated a bit more. Here are 3 flight logs I did for a test of https://github.com/iNavFlight/inav/pull/9905 on a 8.0 build: LOG_2.zip

LOG 33 is with Continous servo trim enabled. You clearly see after a long turn, that Integral is pushing hard to keep the pitch rate at 0 and settles slowly as trim is corrected. LOG 34 I disabled CST and did a classic autotrim with the trim mode, clearly does not show this same LOG 35 is another flight after saving the trim and just redoing autotune again to validate the correct rates and FF with a persistent trim.


Yury-MonZon commented 6 months ago

Few lines above the mentioned if statement we have:

const bool planeIsFlyingStraight = rotRateMagnitudeFiltered <= DEGREES_TO_RADIANS(servoConfig()->servo_autotrim_rotation_limit);
const bool noRotationCommanded = targetRateMagnitudeFiltered <= servoConfig()->servo_autotrim_rotation_limit;

And by default servo_autotrim_rotation_limit is 15 deg/s. Could this be the problem source?

Also is targetRateMagnitudeFiltered in degrees/s and not in radians/s?