Pixhawk 2.1 Twitchy Loiter despite stable AltHold

I am running 3.5.4 on PH2.1 with Here GPS. The 5kg x8 flies as expected in AltHold and Stab. Autotune ran as expected but gains were tuned down to reduce oscillations.

The problem begins when I switch to Loiter. The aircraft is unable to maintain position and “twitches” in order to maintain position. When I push on the sticks to track a horizontal speed, the copter heads in the right direction but twitches back to near 0 attitude at approximately once every two seconds, before proceeding to the desired vel. Running out of options and any help will be greatly appreciated.
I have checked

  • Vib under control
  • Compass calibrated (#3 was disabled due to high offsets)
  • Declination ok
  • Tuning satisfactory
  • Compass points in the right direction

Log file below
https://drive.google.com/file/d/11qQra4ELisag-Uyk_EBig4-3TDyMBMKe/view?usp=sharing

Thank you for your help

Autotune will tune the XY stability, but it does not attempt to tune the navigation controller, which has its own PIDs. From your log:

In Loiter, there is constant pitch and roll oscillations, as you mentioned. The copter is actually responding very well to the flight controller’s desired attitude; the problem is that the FC is commanding that crazy twitching in the first place. This implicates the navigation controller as the culprit.

Try tuning your navigation/loiter PIDs. Here’s some documentation on it.. And here’s a complete list of loiter tuning parameters. Anything that starts with VEL_XY or POS_XY is relevant.

The other potential culprit would be a problem with the copter’s position estimate.


Here, the copter’s position largely agrees with the GPS reading (GPS is the primary input, after all). But the position estimate shows the wobbles from the twitching you observe. What is not established is the cause and effect: is the position changing because of the twitching, or is the copter twitching to correct the estimated position wobbles?

I can’t tell, but I think the first case is more likely, as your IMU vibrations are acceptable, which is the other major input for position estimation. I would start with trying to tune the loiter controller.

Thank you Anubis, The most interesting effects are when I command a constant forward velocity. The copter heads in the right direction but almost sawtooths its way. I tried bringing up the gains on VEL XY and reducing POS XY gains without much success.

I have tried gains from 0.6 to 1.6 but maybe it needs higher gains? It feels counter intuitive given I am seeing oscillations. WPNAV parameters including Jerk haven’t helped much either. I will try less conservative steps but worried about saturation.

I am also seeing in flight yaw alignment messages in the log that I haven’t seen before. Is this a new EKF feature?

Did you try flying in Loiter before autotuning with the default tuning parameters? Maybe try that, it will at least tell us whether it is being caused by one of the autotuned parameters.