Blog


Sign up for updates on our latest news and blog posts


When to Use a Magnetometer (And When You Shouldn’t)

Adding more axes isn’t always the right approach. So how do you determine when to use a 6-axis IMU and when you should be using a 9-axis IMU with a magnetometer? Read on to find out.

Friday, March 29, 2019

When you’re incorporating motion into an application, you’ll need to determine exactly what you need to measure and how to best gather the data. Multi-axis MEMS IMUs (inertial measurement units) for motion sensing typically include at least a 3-axis accelerometer as well as a 3-axis gyroscope, for a total of 6 axes of measurement.

However, 9-axis IMUs also exist, which layer on a 3-axis magnetometer (abbrev: mag). Mags are used to measure the strength and direction of a magnetic field. In IMUs, they can provide a point of reference. And you might say to yourself, “well, the more axes the better, right?” As we outlined in a recent post, just adding more axes is not always the right solution. When it comes to mags, you need to really understand your application before you can decide whether it will help or hurt your user experience.

Absolute Versus Relative Heading

The first decision you’ll need to make is whether you need a drift-free or absolute heading output, which requires a constant reference point to measure against, or if your application can work with relative heading, which will result in some heading drift. Let’s take a look at these options in relation to one real-world application: robotic vacuum cleaners.

A 6-axis configuration will deliver highly accurate relative heading. With relative heading, your robot will be able to understand a change in heading as compared to its previous heading, so it can stay on course and clean efficiently.

But with relative heading, the output can drift over time, which reduces accuracy. Having an absolute heading can help to solve for that. You might think that adding a magnetometer to this 6-axis configuration will provide a global reference point of the Earth’s magnetic field, therefore solving the problem. But that’s not the best choice in this scenario.

This is because magnetometers can be adversely affected by all of the other magnetic fields present in the average household, workplace or city, including other devices or even a building’s structure, which interferes with the mag’s ability to find Earth’s magnetic North. This interference can be further exacerbated by changing locations of magnetic objects present in the area (for example, moving a tablet or phone around a room), which only serves to confuse the mag.

So, what’s a solution in this use case? By developing sensor fusion algorithms to minimize drift over time and using additional sensors as a reference (such as IR sensors to follow walls, or a camera for VSLAM), a 6-axis configuration delivers more consistent performance than a 9-axis with a mag. This configuration is also our recommendation if you are designing for 6DoF (Degrees of Freedom) AR/VR applications.

However, there are use cases when an IMU with a mag is the right choice. For example, if you are developing an application that needs to support global positioning, such as a UAV (unmanned aerial vehicle) or even a smartphone that can support a navigation application, then a mag can help you find true North.

Considerations When Designing with a Magnetometer

So, you’ve decided that your application can’t tolerate drift over time, and/or you need absolute heading. What do you need to bear in mind as you move through adding a magnetometer to the design process?

First, make sure that your use case will encounter lower mag interference (for example, in a 3D audio application, the headset is staying in the same general area, granting a consistent magnetic field). To do this, you’ll need to measure and understand the typical magnetic environment that your device will need to operate within.

Then, consider the different magnetic properties of your device, noting the following:

  • Device calibration determines mag sphere. The magnetometer and body frame will point in different directions, describing:
    • The sphere of magnetic field strength at each point; and
    • Inclination: the angle between gravity and the mag vector in the same frame (user or body).
  • Hard and soft iron effects from nearby magnetic objects (including the device itself) will warp the measured field:
    • Soft iron: causes skew, scaling the magnetic sphere and effectively turning it into a rugby ball; and
    • Hard iron: causes offset, moving your magnetometer readings so that they no longer come from in the center of the sphere, resulting in changes in magnitude.
  • Constant or inconstant magnetic field
    • Magnetic fields can be constant (unchanging), which are easier to calibrate against, or inconstant with mutability that needs to be accounted for, like a room with a lot of moving electronics and things powering on and off.

Any changes that can’t be calibrated for will adversely affect performance. If, after calibration, you can determine when the mag field isn’t constant or where anomalies are occurring, you can then determine whether or not to rely on the mag data.

You’ll also need to consider interference detection. If the mag field is mostly constant but occasionally inconstant, then you can ignore the mag when it seems off, choosing to rely on your 6-axis data when needed and come back to 9-axis when the field has returned to a constant. Interference, by definition, must be temporary. However, some interference isn’t detectable by the mag. For example, if a large magnetic field in the corner of a room has the same strength as the general mag field, warping won’t be detected as a change in magnetic field or in our inclination angle with gravity (planar change in the magnetic field). For example, warping East-West along the magnetic sphere is undetectable by mags. These types of magnetic interferences will confuse your mag and impact your results.

Considerations When Designing without a Magnetometer

Perhaps you’re considering going without a mag. First, ask yourself the typical length of time that your application is used for your specific use case. Will relative heading be sufficient? You’ll need to determine if your application can tolerate the amount of heading drift that you’re likely to accumulate. Note that certain applications, such as hand-held motion controllers, are more drift-tolerable than others.

You could also account for drift by determining truth periodically, using an external truth source and correcting accordingly. If these considerations sound like they can work for your application, then you can likely move forward with a 6-axis configuration.

Two Birds, One IMU?

If you’re still unsure about what you need to do for your application, no worries! There is a way to test which fits best. If you prototype with a 9-axis IMU, you can always choose to turn the magnetometer on or off as needed in order to determine which configuration gives you the best results. This ensures maximum flexibility when configuring for your application, which will likely continue to evolve over time and generations.

Still have questions about using mags? Our engineers are happy to help talk through the implications of your application. Contact us today.