Loiter does not work F450 + APM 2.8 + UBLOX 7M

Hi.
I have F450 frame with APM 2.8 flight controller on vibro platfom, and also GPS+external compass module (UBLOX 7M)
Stabilize mode works well, but when I switch to Loiter mode (or RTL), copter going to fly away. It seems sometimes (at some yaw) loiter works, but when I turn yaw for some degrese it start to fly away.

I do hot have experience with ArduCopter, so do not understand what to do. I have searched for this problem and found that this could be related with compass calibration. I recalibrated compass several times, but it does not help. Before I start to fly I checked that yaw seems ok.

Can someone help me? Logs attached.

2017-10-31 09-19-37.log.param (5.0 KB)
2017-10-31 09-19-37.bin (382.6 KB)

What is your compass offsets after calibration?
You could check your compass as that: connect to MissionPlanner, then rotate your copter by 45 degrees steps and verify that heading direction line in mission planner also rotates by the same angle.
Also ensure compass provides right headings (i.e. in MissionPlanner heading to North when copter is really heading North and so on for S, E, W).

I have attached parameters list, so you can see all my parameters including compass offsets.
So my compass-related parameters are:
COMPASS_AUTODEC 1
COMPASS_DEC 0.1561242
COMPASS_EXTERNAL 1
COMPASS_LEARN 0
COMPASS_MOT_X 0
COMPASS_MOT_Y 0
COMPASS_MOT_Z 0
COMPASS_MOTCT 0
COMPASS_OFS_X 36
COMPASS_OFS_Y -64
COMPASS_OFS_Z 20
COMPASS_ORIENT 0

And at every calibration compass offsets are about the same.

I already done all this manipulations with rotation and coparing result with iphone compass. Values seems correct before flight at place where I fly. I do not have redio-telemetry, so do not know about values at flight. just according with logs, but they seems also OK. I think I miss something, but do not know what exactly.

Your offsets looks good to me.
I didn’t see in your log where is the case with fly away. I see you switched to Loiter sometimes, but there was no significant location changes (GPS) at these times.
I found your GPS HDOP is not very good all the time (It should be < 1). So may be it is not a fly away but a drift due to bad GPS?

Thanks for your replies.

I found the problem.
I connected external mag to i2c port and do not change jumper on APM. Thats why I think I was using internal mag data (despite I set external mag in configuration). Now it Loiters well.

So to fix this problem I made changes:

  • connect external mag into port under GPS instead of connection it to i2C
  • set mag jumper from 1 to 3 position.
  • recalibrate magnetometer