Servers by jDrones

How To: Successful Configuration and Calibration of Compass for Rover

There are many topics already posted around the topics of compass (magnetometer) guidance, heading, navigation, configuration and calibration – and I think I’ve read them all… – but none are complete in my view. This post presents what I believe is a simple, general, repeatable method to get a system configuration that’s useful for Ardupilot navigation. I am now using this as my base operating configuration for Rovers, and I recommend it at least as the baseline to start from for any system configuration – especially if you’re having configuration and calibration issues (examples: “bad compass health”, “bad GPS health”, the Current Heading won’t stabilize or align with GPS track, etc.). The ArduPilot system is extremely capable and useful (thanks developers!), but has so much potential complexity and conflicts as a wide variety of parts are added to and removed from your specific system that I recommend that you start with something that’s as simple as possible to meet your needs.
I will swallow my pride and reply to those who look at this and think “that’s obvious” that it wasn’t obvious to me despite plenty of previous experience with other systems, and I won’t whine (too much) about all the pain I experienced getting to this success. If you think my recommendations are controversial or counter-intuitive, let’s discuss. Please note these recommendations leave you without a backup compass, and your ArduPilot flyer will stop flying if it loses all compass input – but that’s a problem I’ve never experienced and so tend to de-emphasize, whereas problems with compass calibration have been abundant…

My equipment:

  • Chinese-clone Pixhawk PX4 controller
  • mRobotics mRo GPS u-Blox Neo-M8N Dual Compass (note: this is the best GPS I have and it has an authentic u-Blox Neo-M8N, although I’ve tried many others and that experience is factored into this post)
  • ArduPilot 3.4.1
  • Mission Planner 1.3.56
  • Multiple “rover” robots

My goals:

  • A reliable, accurate, repeatable compass reading (aka “Current Heading”) I can trust as the actual rover heading
  • Minimum compass drift, and consistent operation (e.g., it still shows the correct heading) after the rover is moved over multiple miles
  • Strong, consistent alignment between Current Heading and GPS Track
    (I believe all the above are common goals for all ArduPilot users)
  • Waypoint navigation accuracy of approximately 0.5 m (note: this is GPS-driven, and the ability to achieve this increased the dependency on GPS and reduced the dependency on compass described in my comments below)

Recommendations for System Hardware Configuration:

  • Strategy: get a good GPS (e.g., something with a real authentic u-Blox Neo-M8N) and de-emphasize the compass (these instructions explain how to do this)
  • Use only 1 compass (recommendation: the internal magnetometer in the PixHawk will most probably work just fine; even my inexpensive Chinese clone is very accurate and stable)
  • To ensure use of just one compass, don’t even connect the GPS/compass unit to the Pixhawk I2C port (the GPS component will still work if it’s connected to the Pixhawk GPS port)

Basic Recommendations for Compass Calibration:

  • Do initial hardware setup using “Initial Setup/Wizard” in Mission Planner
  • Do all follow-on compass calibrations using “Initial Setup/Mandatory Hardware/Compass” in Mission Planner (more details below; this is to account for any changes you’ve made to the system, and to re-check the calibration).

Procedure and Settings for Compass Calibration:

  • Connect to your Pixhawk using Mission Planner
  • Use the “Initial Setup/Mandatory Hardware/Compass” in Mission Planner
  • It’s OK to click on the Pixhawk/PX4 box, but not necessary
  • Select all these settings (no exceptions; “yes” means checkmark in the box, “no” means no checkmark in the box):
    Enable compasses (yes)
    Obtain declination automatically (yes)
    Automatically learn offsets (no)
    Compass #1
    Use this compass (yes)
    Externally mounted (no)
    Compass #2
    Use this compass (no)
    Compass #3
    Use this compass (no)
    Onboard Mag Calibration
    Fitness -> Default (note: do NOT select “Strict” here)
    (In a follow-up post I’ll show a screen capture of what your Mission Planner screen looks like with these correct settings)
  • To begin the calibration procedure, click on “Start” in the Onboard Mag Calibration box.
  • Fully rotate the Pixhawk through all 3 axes and other vectors, until you see the “MAG_CAL_SUCCESS” message pop up in the Onboard Mag Calibration box. This is the ONLY valid indicator – the green “progress” bar can be very misleading. (In a follow-up post I’ll show a screen capture of what your Mission Planner screen looks like with the success message.)
  • Reboot the Pixhawk and the new compass calibration offsets should be active. When you get a valid GPS heading on your Pixhawk (in my case, this means I need to run the rover around outside for a few seconds), the GPS Track and Current Heading should be closely aligned.

Detail Configuration to Improve Navigation Performance and Compass Stability:
(Notes: some explanation here. My experience is that with a good GPS rovers will navigate very well even if the compass and GPS headings disagree by as much as 15 degrees. But compass drift kills navigation, and too much use of ArduPilot EKF has increased compass drift in my experience. This is how I got this problem under control to achieve excellent accuracy and repeatability.)

  • Connect to your Pixhawk using Mission Planner
  • Perform the complete set of Compass Calibration procedure steps described above, and reboot your Pixhawk.
  • With your Pixhawk operational and on your rover, optimize the control tuning using this procedure (it’s good because it uses real metrics to determine the config settings): http://ardupilot.org/rover/docs/rover-tuning-steering-rate.html
  • Go into Mission Planner and open ConfigTuning/Full Parameter List, find these configuration parameters, and set them as follows (“yes” means checkmark; you’ll find many are already set the way shown here – they’re documented here just for completeness):
    AHRS_EKF_TYPE 3
    AHRS_ORIENTATION (make sure this is set correctly, based on how you’ve aligned the front of your Pixhawk to the front of your Rover; for me it’s 0)
    COMPASS_CAL_FIT 16
    COMPASS_EXTERN2 0
    COMPASS_EXTERN3 0
    COMPASS_EXTERNAL 0
    COMPASS_LEARN 0
    COMPASS_PRIMARY 0
    COMPASS_USE 1
    COMPASS_USE2 0
    COMPASS_USE3 0
    EK2_ENABLE 0
    EK3_ENABLE 1
    MAG_ENABLE 1
  • Click on “Write Params” on the right side of the screen and wait 10 seconds for the write to complete
  • Reboot the Pixhawk to activate all the new config settings. The rover should now be ready to run and test missions that you’ve planned.
  • Test the validity of the config settings for the actual orientation of your Pixhawk and compass. With the Pixhawk level, the Mag Z value should be positive in the northern hemisphere and negative in the southern. The Mag X value should increase significantly when you tilt your rover toward its front nose, and Mag Y should increase significantly when you tilt your rover toward its right side. If you don’t get these actions, repeat the complete calibration procedure using the correct AHRS_ORIENTATION.

Optimizing Compass Calibration:
This is an OPTIONAL procedure to improve the alignment of the compass (Current Heading) and GPS (GPS Track). I’ve found the ArduPilot onboard mag calibration can be off by as much as 10 degrees; this is one thing you can do to reduce this gap.

  • Perform the complete “Detail Configuration to Improve Navigation Performance and Compass Stability” procedure documented above
  • Get a valid GPS heading on your system (again, for me this requires running the rover around outside for a few seconds), and estimate the angular deviation between the compass (Current Heading) and GPS (GPS Track). If the Current Heading is clockwise from the GPS Track, the angular deviation is positive (if counterclockwise, the deviation is negative).
  • Note: if the angular deviation is greater than 30 degrees, you should do a full recalibration rather than the fine-tuning described here.
  • Go into Mission Planner and open ConfigTuning/Full Parameter List and find these configuration parameters:
    COMPASS_OFS_X
    COMPASS_OFS_Y
  • Write down the current values of those parameters in case things don’t work out… You can restore those values to get back to the original calibration.
  • Add the inverse of the angular deviation to the current value of the X and Y offsets, and set the value to the of the offsets to this new figure.
  • For example, if the angular deviation was 10 degrees, and the initial values of X was -121 and Y was 52, subtract 10 from each value to yield -131 for X and 42 for Y. Set the values as follows (again, this is an example):
    COMPASS_OFS_X -131
    COMPASS_OFS_Y 42
  • Click on “Write Params” on the right side of the screen and wait 10 seconds for the write to complete
  • Reboot the Pixhawk to activate all the new config settings.
  • Recheck the alignment between Current Heading and GPS Track and optimize further if needed, or go back to the original settings. Only make small changes this way – never more than 25 points.
3 Likes

Great information but I’d just like to point out that the compass offset parameters mentioned under “Optimizing Compass Calibration:” are measured in milligauss and not degrees. Without getting too far into the math required, I’d say your results from attempting to compensate in the manner you describe would vary considerably depending on where you are on the planet…

I agree. Thanks for the review and feedback!
They are meant to be an approximation. That’s why I don’t recommend attempting big corrections this way and caveat that it might not work for all people. But I have used this method successfully to achieve very close alignment (in my case the angular deviation has been less than 5 degrees). I’m hoping it helps a few other perfectionists out there…

1 Like

This help me , thanks

Thank you for such a detailed description of your procedure. I know this will help me when I get my mower back going soon.

1 Like

somehow my 12 dollars gps compass module’s compass always fail. stuck at 33 percent on calibration.

edit: issue solved(roll 180)

well if i knew. If i only KNEW! I would buy the Rmo Neo 8m unit! These all fake cheap gps’s can only find 8-9 sats max in open sky!

my huawei mate 9 finds 27 sats :frowning: same location

I think in the Wiki page the authors must emphasize people to not buy unbranded GPS/compass modules as they have lots of issues. clone pixhawks are ok imho but clone modules are not okay!.

Servers by jDrones