Fly without compass


I’m trying to fly copter in difficult conditions with great amount of metal constructions. It has a lot of troubles in Loiter and RTL because of strong magnetic interference. Making messages “Check Mag field”, “Magnetic anomaly” and some other errors.

Is there any alternative solution for today? Can optical flow help?

Auto mode is not needed. Only Loiter and RTL.

The GPS signal is good enought. The only trouble is with magnetometer.

Does anyone know what is “ekf2 imu ground mag anomaly” error and why copter is twitching pitch/roll because of it? Or making flip on autonomous take off?

Compass error shouldn’t lead to flip or twitch. It starts to make circle in case of compass error. Posting log would be helpful.

Ok, I found the log with this strange twitch.

I had two flights their with auto take off. The first flight is interesting. On the descending in Loiter I had a dangerous twitch after “ekf2 imu ground mag anomaly” error. It was about 3 meters height. Switched to Stabilaze and climbed a little. After this made landing again.

Swithing to Stabilize cleared all troubles in a moment.

The second flight was normal from the Take Off to Land.

Please, explain… how does Learn Offsets function work?

If I make compass calibration on the ground, set Compass_learn = 1 and than fly with it… Does calibration changes in flight? Or it makes changes after disarm and take effect next flight?

I have the same issue with roll/yaw twitch in diffictult mag conditions on Copter-3.6.9 on Pixhawk FMU2.
In log there were “ekf2 imu0 ground mag anomaly, ywa realigned” msgs and “EKF yaw reset” events.
interesting that there were several such events, but twitch happened only if dron actively moving, while it’s hovering the event went unnoticed.
I would also like to know how to reduce this effect of compass instability.

“I would also like to know how to reduce this effect of compass instability.”

Not much you can do to “fix” this other than flying at a different location.

The point is, something EXTERNAL to the aircraft is affecting the compass, and no amount of “tweaking” is going to fix it.

I ran into this a few years ago and it turned out the ground was laden with subsurface gravel that had a high iron concentration. I walked the ground carrying a hand held compass and it was all over the place… I won’t fly there at all…

it’s clear that i can’t fix compas instabillity, but EKFcode try somehow compensate it and as far as i understand in some conditions make some sort of reset and this may sometimes lead to twitching in roll and pitch axis, that’s dangerous especially in indoor limited space.
So i would like to understand, is it possible to reduce such influence on Roll and Pitch.
Drift on Yaw not that big problem for me.

You misunderstand what an EKF does. The EKF is not the problem. The compass is not the problem. Where you are flying is the problem. To fix the problem you need to fly in another location.

if so then the real world is problem ).
I try to understand why compass may affect Roll and Pitch axis whereas its purpose is to stabilize Yaw.

1 Like

It seems, that EKF switch to another IMU when compass tells bad data and because of some gyros incinsistency needs time to stabilize copter.Thats why it begins twitching. My opinion.

Not only that, ArduCopter for a multirotor aircraft does not have a “Heading Hold” flight mode.

If you want to test both compasses, connect the FC to Mission Planner. Go to Initial Setup > Compass. Verify that only 2 compasses are enabled (Use this compass is checked). Uncheck the box for Compass 2 (Pixhawk internal compass), and go fly the aircraft.

If you still get glitches, connect to Mission Planner, enable Compass 2, disable compass 1 and go fly. If you do not get glitches, then compass 1 is the cause. If you still get glitches, the cause is EXTERNAL to Pixhawk.

For EKF change AP log message “EKF primary changed:”.
In my case there was just “EKF Yaw reset” and “EKF2 IMU0 ground mag anomaly, yaw re-aligned”

I look in code and found out that this happening in Copter::check_ekf_reset() function and attitude corrected by call attitude_control->inertial_frame_reset();
the same action happening on EKF core change.
And we have open issue for it - Reset Attitude Controller after EKF change
Also i found out that such compass instability handling was changed in 2018.
Erlier version was attitude_control->shift_ef_yaw_target(ToDeg(yaw_angle_change_rad) * 100.0f);

I don’t know why it was changed in such manner, but it’s very interesting.