We are occasionally seeing an uncommanded yaw motion of our aircraft shortly after takeoff. It seems to happen at about 1.5m in the air, which is the trigger height for the EKF2_MAG_TYPE=0 switch from magnetometer->heading to magnetometer->3D vector.
There are two logs showing this behavior:
https://logs.px4.io/plot_app?log=51cbc618-7bbb-47fd-9091-1eaa92a1baf4
https://logs.px4.io/plot_app?log=11c49798-526a-4fe7-b8f9-648265bd34c5
You can see that right at the beginning of the flight, there is a step change in both the Yaw setpoint and the yaw estimate. However the yaw estimate then diverges and then comes back down to the setpoint. On the aircraft, this resulted in a ~30 deg yaw of the aircraft.
It looks to me like the heading estimate was updated because of the switch to using the full 3D magnetometer vector, and the setpoint was changed too to prevent a yaw error signal from being generated. However something appears to cause an overshoot which commands a yaw change.
There is also a pitch and roll bump in the estimate at the same time. It seems like their is a discontinuity when the EKF2_MAG_TYPE mode changes. I can’t explain why it only happens some flights and not others. Could calibration be a problem? Or the EKF isn’t fully “aligned” when this happens, so there is a transient?
Platform:
Octorotor with custom PX4 version branched at 1.7.3, running on a Pixhawk 2.1 cube with HERE2 GPS antenna.
*NOTE this has happened on two different aircraft.
We are aware that 1.7.3 does not support the external magnetometer in the HERE2, and we are using the internal magnetometers. In one of the logs above, we have CAL_MAG0_EN set to 0 to force use of the second magnetometer, because the MPU9250 which is MAG0 shows periodic spikes in its readings. MAG1 does not show these spikes but this did not seem to affect the results.
Any insight on what causes this discontinuity when switching from heading to 3D would be helpful. Thanks!