Loiter, yaw and toiletbowling

We’ve all read the documentation regarding compass interference and the infamous toilet bowl effect when in loiter mode. I am flying a custom frame with a Navio 2 board, and have been trying to chase down the cause of this problem, and may have discovered something interesting.

In the attached log file, I took off and entered loiter mode somewhere near log line 45,000. The copter loitered perfectly for several minutes, maintaining altitude and position. So far, so good. At around log line 82,000, I noticed that the copter had changed heading slightly. As soon as this heading change occurred, the copter started to spiral anticlockwise in ever increasing circles. I took control and landed before any damage was done.

When reviewing the logs, I noticed that the attitude controller reported the same heading throughout the flight, which did not reflect what the copter was doing. The compasses (two onboard, one external) all noticed a change in the X and Y axes, which is consistent with a yaw rotation. Note that I was using external compass 3 only for this flight, but have observed identical behaviour using the two internal compasses.

I assume that the loiter controller needs to know the current heading in order to translate an error in North or East coordinates into corresponding roll and pitch commands. The reason for the spiral is (I think) because the roll/pitch command is adding to the error, rather than removing it, i.e. the correction is being applied in the original (non-rotated) direction.

I’ve been trying to get to the bottom of this problem for some months - with both 3.4.x and 3.5.x versions of arducopter. I’ve been sure to minimise the effects of electromagnetic interference, and have also tried an external compass on a pole above the frame. In this example, there appears to be no link between throttle and magnetic field.

To me, one of the following two things should be happening here, but aren’t:

  • If the copter yaw drifts (e.g. due to wind), then the attitude controller should reflect this drift, or
  • If the copter yaw drifts, the copter should correct this drift immediately to maintain the current heading

I’m going to spend some time working through the code, but I wondered if anyone else has experienced this, or could shed some light on why it might be happening? I’d be very grateful if someone with more knowledge in this area could have a look at the attached log to see if they can confirm what I’m seeing. I’m happy to do further experiments if necessary.

Apologies for the long post, and thanks in advance for any help or pointers!

Log: https://www.dropbox.com/s/0lone5rfk1d2byn/00000004.BIN?dl=0

Try setting COMPASS_ORIENT3 parameter to 8