PixHawk roll problems in loiter mode only, very confusing

Hello and thank you for taking the time to have a look at this.

The log I have is from a very short set of three flights, lasting no more than a couple of minutes collectively.
I have tried to analyze the problem myself and have been unable to figure out why the system behaved as it did.

Specs: Pixhawk and Ublox gps/compass module sold by 3dr, running Autopilot 3.1.5. The copter we have is a fairly standard 800mm hexacopter, the only difference being this copter is much more top heavy than most due to a large heavy sensor array mounted on a tower on top of the drone.

It was a fairly windy day but not as bad as many days that the system has been flown on before. The copter flew perfectly in stabilize, no wobbling or incorrect movements whatsoever. As soon as loiter mode is engaged during the first two flights the system began swinging back and forth violently before i switched the system back to stabilize. On the second flight I tried reducing the loiter p value because I couldn’t think of anything else that could cause this behavior in loiter mode exclusively (Loiter had worked fine on previous flights with the same tuning). The problem persisted so I set the value back for the third flight and the system loitered fine for a short time then promptly flipped over and flew straight into the ground.

Here is an example of the roll position/des. roll to illustrate:

Any help with this problem would be appreciated,

Do an autotune on roll and pitch with the copter in its minimum flying weight configuration and NO gimbals or loose mass.

If that doesn’t work, halve LOITER_[LAT|LON]P and HLD[LAT|LON]P and LOITER[LAT|LON]_I.

Edit: Your gains are just crazy on everything. I’d start over with default settings, take a bottom up approach (get the sensor calibrations right, then the attitude control, then the altitude control, then the position and velocity control). You’re setting gains on things like ACCEL_D and YAW_D which are fairly experimental. Just get it flying decently, then play with things like that if you want.

It is also possible that a flip could be the result of a motor sync issue. Your first order of business is testing that on the ground and making sure it can’t happen.

Make sure it doesn’t flip in stabilize if you thrash the stick from one side to the other. If it does, you need to reduce ANGLE_RATE_MAX