Pixhawk 2.1 Loiter Drift Problem

We are building a quadcopter using the SpektreWorks carrier board for PixHawk 2.1 Cube and currently facing the problem of drifting away in loiter mode as described below:

  1. The quad is installed with firmware version 3.5.0-rc11.
  2. In our test flight, it can take off fine and we could control it in stabilize and altitude hold modes.
  3. But after switching to loiter, the quad started drifting away slowly but steadily for 15’-20’ and we had to switch back to stabilize mode to control its horizontal movement.
  4. The GPS was solidly fixed
  5. The accelerometer and compass are calibrated well.
  6. EFK checked and performed well within limit.
  7. Vibration was well within limit.
  8. The flight log shows that the velocity X and Y don’t track the desired velocity (when not only in loiter mode) so I suspect the problem might be that the default PixHawk PID parameters that we used might not perform up to the task.

So could you please take a look at the log file and give us your expert advice?

  1. Did the problem come from the PixHawk PID parameters?
  2. Would an autotune help getting the Loiter parameters (and other controller’s parameters) right?
  3. If we want to manual tune those parameters, how can we change them to have a better result?

This is the log file: https://www.mediafire.com/file/ch4nufkbez99i79/2017-08-04%2016-17-30.log

Thank you for your time and I appreciate any ideas and support from you guys!


That springs out at me.

I’m no log guru - but looking at your RCIN channels - they’re all slightly offset - Have you done a radio calibration (both in MP and TX) recently - and made sure you’ve got no trims on? otherwise you’ll find it will drift in loiter/pos hold (as it thinks you’re putting stick inputs in).
A averages around 1545

Thank you @stik79 for your reply. I did trim the TX a little in Stabilize mode before switching to Loiter. But in loiter mode, when the quad started drifting I could not pull it back at all even when the sticks at max/min position, so I think it wasn’t because of the radio trim.

Can you elaborate on that point? Are the numbers suspiciously too high or varies too much between each other? Before the flight I calibrated compass and EKF looked fine during the flight.

These numbers refer to the orientation of the compass versus the AHRS alignment of the flight controller.In otherwords which way the compass is pointing relative to the FC and frame.The numbers you have in your paramters actually mean this.

COMPASS_ORIENT, 28 rotation pitch 180 - yaw 90

COMPASS_ORIENT2,18 rotation roll 90 - yaw 90

COMPASS_ORIENT3, 0 rotation none

Which say either your compasses have strange mounting angles or they are set wrong.

I suspect compass 1 (or 0 ) is an external one in the GPS housing and the other two are those on the flight controller board.Those would be unusual mounts.The GPS compass will need to be worked out (probably 0) and the two FC compass also 0.In other words all pointing the same way as the flight controller and frame.The range of different numbers is to allow mounting at any angle to the frame.

For instance - the copter I have powered up in front of me now is a Pixhawk 2.4.8 and uses 1,0,0 so (unusually ) that’s Yaw 45,None and None.

Number 8 is often used ( Roll_180 ) for compasses mounted upside down on the GPS board.

Thank you @Jagger. I originally configured the compass in Mission Planner / Initial Setup / Compass with compass 1 (external) - orientation as roll90pitch 90 (because that was the way my compass mounted), compass 2 (internal) enabled and compass 3 disabled. I did not check the parameters under Config / Tuning so I don’t really know why the COMPASS_ORIENT params had those values. Why do the COMPASS_ORIENT in params list differ from the settings in Compass Setup tab?

Anyway, the problem is solved. Today I reset all params, correct all the COMPASS_ORIENT params, re-calibrate everything and finally I had a good loiter flight. I also removed all the trim on TX. Maybe it was the combination of both that caused the problem, I’m not sure.

If I had my COMPASS_ORIENT params all wrong, why didn’t error EKF COMPASS VARIANCE pop up?

Excellent. :grinning:

No idea about the EKF compass variance.I guess they agreed within limits.It’s really easy to change a parameter without noticing in full parameters list.I try to not use a touch pad when I’m in there.