ROBOTICS 101Concept explainer

Magnetometers and Calibration

A magnetometer measures the Earth's magnetic field, which gives a compass heading. On a robot, motors, batteries, and steel frames distort that field. Spinning the robot in a full circle shows the distortion, and calibration removes it.

Two kinds of distortion

Hard iron distortion comes from magnetized parts, such as motor magnets. It adds a fixed offset \(\mathbf{b}\), which shifts the circle of readings away from the center. Soft iron distortion comes from steel that bends the field, which stretches the circle into an ellipse with matrix \(A\):

$$\mathbf{m}_{\text{raw}} = A\,\mathbf{m}_{\text{true}} + \mathbf{b} \qquad \Longrightarrow \qquad \hat{\mathbf{m}} = A^{-1}\left(\mathbf{m}_{\text{raw}} - \mathbf{b}\right)$$

Calibration fits an ellipse to readings taken while turning in a full circle. Its center gives \(\mathbf{b}\), and its shape gives \(A\).

What to notice

Without calibration, the heading from the raw readings can be off by tens of degrees, and the error changes with direction, as the error plot shows. After calibration the points land on a centered circle and the error nearly vanishes. Calibration only holds for the setup it was done in, so moving a battery or adding a motor means calibrating again.