Analyzing log for uncontrolled yaw and position change in Loiter

Trying to find the root cause of this issue that lead to a crash from this log.

Aircraft is set up with GPS yaw and also had an RTK fix before flight. This is worth mentioning as the logged location of the aircraft is off by a good few meters from real life. My guess is base station location was offset somewhat, RCTM messages weren’t being logged anywhere so that data isn’t available unfortunately.

Below are a timeline of notable events:

Aircraft was hovering fine in Loiter for a couple of minutes after takeoff.

At time 13.41.58.921 - CompassLearn was set to 3 which is about the time odd things started to occur.
At this same time the ground speed starts increasing, the aircraft starts an abrupt yaw.

13.42.00.401 Altitude starts decreasing

13.42.01.126 Pilot control input is started to correct for these unwanted movements

13.42.01.804 EKF Primary changed and 2nd EKF has become primary

13.42.02.026 Motor kill input

13.42.02.246 First accel spike, in line with the first point of contact with the ground

13.42.02.321 Motors Emergency Stop

From then on it’s a cascade of errors that mostly stem from ground contact

13.42.02.291 Compass Unhealthy : failed to read from the sensor
13.42.03.313 Radio Late Frame : no updates received from receiver for two seconds
13.42.03.313 Radio Failsafe Failsafe Triggered
13.42.07.225 EKF Primary changed 1st EKF has become primary
13.42.10.255 EKF Check Bad Variance (position estimate bad)
13.42.10.255 EKF Failsafe Failsafe Triggered

During the time between pilot control input and motor kill it looks as though the inputs from the Tx are not being actioned on by the FC.
Ground speed continues to smoothly increase at an increasing rate during pitch and roll inputs.
Altitude continues to smoothly decrease at an increasing rate during throttle input.
Heading continues to smoothly change at an increasing rate during yaw input.

This is correlated by the pilot noting that the initial yaw movement and position change were uncommanded and it felt as though there was no control.

I’ve looked into the Compass learn and in different parts of the documentation it is noted as:
While InFlight learning is running you cannot use position control modes.
and
Position control modes (Loiter, Auto, etc.) should not be used while the offsets are being learned.

If anyone with knowledge of the underlying code could clarify what interaction could be expected if Compass learn was enabled while in a position control mode that would be good to rule that interacting in or out.

Links to the respective sections of documentation:
https://ardupilot.org/copter/docs/parameters.html#compass-learn-learn-compass-offsets-automatically
https://ardupilot.org/copter/docs/common-compass-setup-advanced.html#automatic-offset-calibration

The Logged position not matching what was observed is odd. The aircraft having an uncommanded position change while in lotier is similar to when you move an RTK base station while an aircraft is in flight. Some form of GPS glitch does come to mind but without the RTCM messages being logged we can’t know if the correction data was at fault or not. There is no GPS related errors and the fix type stays at 6 during the airbourne time.

Are there any other factors that would cause control inputs to be logged but not acted on as expected? There was a failsafe event with RTL but it was considerably after ground contact. RC control between the ground and the aircraft is is via Mavlink if this makes any difference.

Log

Maybe related to : AP_NavEKF3: don't look at compass learning with GPS yaw by tridge · Pull Request #26762 · ArduPilot/ardupilot · GitHub ?

ahhhh a possible clue! Good spotting. I’ll keep an eye on the that issue and see what comes up