Mag Interference
The Compass Problem
ArduPilot relies on a Magnetometer (Compass) to know which way is North.
- Outdoors: The Earth's magnetic field is clean.
- Indoors: Steel beams, rebar, and high-current electrical wiring warp the magnetic field.
- Result: The "North" vector spins as you fly past a pillar. The EKF becomes confused, rotates the velocity vector, and causes the drone to fly sideways ("Toilet Bowling").
Solution 1: Gaussian Sum Filter (GSF)
You can fly completely without a compass by letting the EKF "learn" heading from movement.
Configuration
- Disable Compass:
COMPASS_ENABLE = 0(orCOMPASS_USE = 0for all instances). - Enable GSF:
EK3_SRC1_YAW = 8(GSF).
The Flight Procedure
The GSF cannot determine heading while sitting on the ground. It needs Velocity to calculate Course.
- Arm & Takeoff: You must take off in AltHold (non-GPS mode). Do not try Loiter yet.
- Align: Fly forward briskly for 5-10 meters.
- Lock: The EKF will observe that the GPS velocity vector aligns with the IMU accelerometer vector. It "snaps" the heading to the correct value.
- Loiter: Once the "EKF Yaw Alignment" message appears (or you see the heading snap on the GCS), you can switch to Loiter.
Solution 2: External Yaw (GPS Yaw)
If MAVLink GPS provides a valid heading (e.g., from Visual Odometry or a Dual-Antenna setup):
- Config:
EK3_SRC1_YAW = 2(GPS). - Benefit: The heading is valid instantly on the ground. No "alignment flight" needed.
Source Code Reference
- Yaw Sources:
libraries/AP_NavEKF/AP_NavEKF_Source.h- SeeSourceYawenum. - GSF Logic:
libraries/AP_NavEKF/EKFGSF_yaw.cpp- Implementation of the emergency yaw reset.