One of the APM features the dev teams have been working hardest on is improved compass calibration. Magnetometers are a tricky thing to get right because there are at least three kinds of variation: 1) each sensor is different, 2) the Earth's magnetic field varies around the planet (Declination), 3) The "hard iron" magnetic interference of each aircraft is different, and even that varies in flight when the motors are going.
Right now we have three different kinds of calibration you can use:
- Auto calibration. You do nothing, and the code figures out all the offsets and declination by comparing the compass readings with the GPS and IMU readings over time in flight. Pro: no user effort. Con: it takes a few minutes of flying to get right, so the compass is inaccurate at first launch.
- Manual calibration in the Mission Planner. This is the screen on the Configuration screen, where you can enter your Declination and then press the "Calibration" button and move and rotate your aircraft around for 30 seconds while it records the data and does some math to calibrate the sensor. Pro: works. Con: it's a little awkward, especially for big aircraft. Also doesn't reflect the magnetic interference that can occur when the motors are going in flight.
- Replay a flight log. This is a very cool option, shown above, where you can just replay a flight log (.tlog) and the code will compare the GPS and IMU readings with the compass reading and make the necessary corrections. Pro: works great. Con: must have already flown, will be messed up if you load a .tlog file where you didn't actually fly.
It's interesting to see how others do this. In the video below, from the radio program Marketplace, you can see (at 1:20) how Foxconn calibrates the magnetometer in an iPad. It's basically the same as our Method 2, but highly automated: