A Two-Step Calibration Framework for MEMS Magnetometer Error Compensation in Miniature Quadrotor Drones

The proliferation of micro-electromechanical systems (MEMS) technology has been a cornerstone in the miniaturization and cost reduction of navigation systems for unmanned aerial vehicles (UAVs). Among these, the miniature quadrotor drone represents a highly agile yet inherently unstable platform, demanding precise and reliable attitude information for stable autonomous flight. Attitude estimation typically fuses data from an inertial measurement unit (IMU)—comprising accelerometers and gyroscopes—with a magnetic heading reference provided by a three-axis magnetometer. For the quadrotor drone, an accurate yaw (heading) estimate is critical, as errors accumulate rapidly due to the platform’s underactuated nature. MEMS-based magnetometers are ubiquitous in this role due to their small size, low power consumption, and integration potential. However, their raw measurements are corrupted by various systematic errors, which, if uncorrected, severely degrade the accuracy of the computed attitude, particularly the heading angle. This degradation can lead to instability or navigational drift in the autonomous flight of a quadrotor drone.

We identify two primary layers of error that afflict the magnetic measurement system of a typical quadrotor drone. The first layer originates from the magnetometer sensor itself, arising from imperfections in the MEMS fabrication and assembly process. The second layer stems from the practical integration of the sensor chip onto the drone’s autopilot board. A comprehensive calibration strategy must address both to transform raw sensor readings into accurate vector measurements in the drone’s body frame. Traditional methods, such as the swing or multi-position calibration, often require precise reference orientations provided by expensive, high-grade turntables, making them impractical for widespread or field deployment. In this work, we present a robust, two-step calibration methodology that decouples these error sources. The first step employs an ellipsoid fitting algorithm to compensate for the intrinsic sensor errors without any external reference equipment. The second step utilizes a simple four-position procedure to determine and correct for the misalignment between the now-corrected sensor frame and the quadrotor drone‘s body coordinate system. This approach is pragmatic, requires minimal equipment, and is ideally suited for calibrating the navigation systems of commercial and research-grade quadrotor drones.

Error Modeling for the Tri-Axis Magnetometer System

To design an effective calibration algorithm, a precise mathematical model of all significant error sources is essential. We decompose the total error into a sensor model and an installation model.

Sensor Intrinsic Error Model

The raw output of a tri-axis MEMS magnetometer, denoted as $\mathbf{H}_m = [H_{mx}, H_{my}, H_{mz}]^T$, deviates from the true magnetic field vector in the sensor’s ideal orthogonal frame, $\mathbf{H}_e = [H_{ex}, H_{ey}, H_{ez}]^T$, due to three key imperfections: scale factor (sensitivity) errors, zero-offset (bias) errors, and non-orthogonality errors. These can be combined into a single linear model:
$$\mathbf{H}_m = \mathbf{K}_1 \mathbf{K}_2 \mathbf{H}_e + \mathbf{H}_0$$
where $\mathbf{H}_0 = [H_{0x}, H_{0y}, H_{0z}]^T$ is the vector of biases applied to each axis.

The matrix $\mathbf{K}_1$ is a diagonal matrix representing the scale factor errors:
$$\mathbf{K}_1 = \begin{bmatrix}
k_x & 0 & 0 \\
0 & k_y & 0 \\
0 & 0 & k_z
\end{bmatrix}$$
Here, $k_x, k_y, k_z$ are the actual sensitivities (output units per micro-Tesla) for each axis, which ideally should be identical.

The matrix $\mathbf{K}_2$ models the non-orthogonality of the sensor’s sensitive axes. We define the non-orthogonal measurement frame $(x_m, y_m, z_m)$ relative to the desired orthogonal frame $(x_e, y_e, z_e)$. Assuming the $z_m$ axis is aligned with $z_e$, the $x_m$ axis lies in the $x_e$-$z_e$ plane at an angle $\alpha$ from $x_e$. The $y_m$ axis has a projection in the $x_e$-$y_e$ plane at an angle $\beta$ from $y_e$, and is tilted out of that plane by an angle $\upsilon$. The corresponding transformation matrix is:
$$\mathbf{K}_2 = \begin{bmatrix}
\cos\alpha & 0 & \sin\alpha \\
\sin\beta \cos\upsilon & \cos\beta \cos\upsilon & \sin\upsilon \\
0 & 0 & 1
\end{bmatrix}$$

The inverse of this combined transformation is required for compensation: $\mathbf{H}_e = \mathbf{L}(\mathbf{H}_m – \mathbf{H}_0)$, where $\mathbf{L} = \mathbf{K}_2^{-1} \mathbf{K}_1^{-1}$.

Sensor-to-Body Installation Error Model

Even after perfect intrinsic calibration, the sensor’s orthogonal $(x_e, y_e, z_e)$ frame is unlikely to be perfectly aligned with the body frame $(x_b, y_b, z_b)$ of the quadrotor drone (e.g., forward, right, down). This small mounting misalignment is modeled as a rotation from the body frame to the sensor frame, parameterized by three Euler angles $(\psi, \theta, \gamma)$. Using the common aerospace sequence (yaw, pitch, roll), the transformation is:
$$\mathbf{H}_e = \mathbf{C}_b^e \mathbf{H}_b = \mathbf{C}_3(\gamma) \mathbf{C}_2(\theta) \mathbf{C}_1(\psi) \mathbf{H}_b$$
where $\mathbf{H}_b$ is the true magnetic field in the quadrotor drone body frame, and the direction cosine matrices are:
$$ \mathbf{C}_1(\psi) = \begin{bmatrix} \cos\psi & \sin\psi & 0 \\ -\sin\psi & \cos\psi & 0 \\ 0 & 0 & 1 \end{bmatrix}, \quad
\mathbf{C}_2(\theta) = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos\theta & \sin\theta \\ 0 & -\sin\theta & \cos\theta \end{bmatrix}, \quad
\mathbf{C}_3(\gamma) = \begin{bmatrix} \cos\gamma & 0 & -\sin\gamma \\ 0 & 1 & 0 \\ \sin\gamma & 0 & \cos\gamma \end{bmatrix} $$
Thus, the complete measurement model, from body-frame field to raw sensor output, is: $\mathbf{H}_m = \mathbf{K}_1 \mathbf{K}_2 \mathbf{C}_b^e \mathbf{H}_b + \mathbf{H}_0$.

The Two-Step Calibration Methodology

Our proposed method strategically decouples the estimation of the intrinsic parameters $(\mathbf{K}_1, \mathbf{K}_2, \mathbf{H}_0)$ from the installation parameters $(\psi, \theta, \gamma)$.

Step 1: Intrinsic Calibration via Ellipsoid Fitting

The foundation of the first step is the principle that the magnitude of the local geomagnetic field vector, as measured in an ideal orthogonal sensor frame, is constant regardless of the sensor’s orientation: $||\mathbf{H}_e||^2 = \text{const}$. Substituting the intrinsic error model $\mathbf{H}_e = \mathbf{L}(\mathbf{H}_m – \mathbf{H}_0)$ yields:
$$(\mathbf{H}_m – \mathbf{H}_0)^T \mathbf{L}^T \mathbf{L} (\mathbf{H}_m – \mathbf{H}_0) = ||\mathbf{H}_e||^2$$
This is the equation of an ellipsoid in the space of raw measurements $\mathbf{H}_m$. The center of the ellipsoid is the bias $\mathbf{H}_0$, and its shape and orientation are encoded in the symmetric positive-definite matrix $\mathbf{M} = \mathbf{L}^T \mathbf{L}$.

By collecting $N$ raw magnetometer samples $\{\mathbf{H}_m^{(i)}\}$ while arbitrarily rotating the sensor (or the entire quadrotor drone) in a magnetically clean, homogeneous field, we can fit an ellipsoid to this cloud of points. The general quadratic surface equation is:
$$F(\boldsymbol{\xi}, \mathbf{z}) = \boldsymbol{\xi}^T \mathbf{z} = a x^2 + b y^2 + c z^2 + 2d xy + 2e xz + 2f yz + 2p x + 2q y + 2r z + g = 0$$
where $\mathbf{z} = [x^2, y^2, z^2, 2xy, 2xz, 2yz, 2x, 2y, 2z, 1]^T$ for a data point $(x, y, z) = (H_{mx}, H_{my}, H_{mz})$, and $\boldsymbol{\xi}$ contains the 10 ellipsoid parameters. We employ a constrained least-squares minimization to find $\boldsymbol{\xi}$ that best fits the data while ensuring the solution represents an ellipsoid (not a hyperboloid or paraboloid).

Once the ellipsoid parameters are found, they are converted to the canonical form:
$$(\mathbf{X} – \mathbf{X}_0)^T \mathbf{A} (\mathbf{X} – \mathbf{X}_0) = 1$$
Comparing this with the model-derived equation, we obtain the identities:
$$\mathbf{A} = \frac{\mathbf{L}^T\mathbf{L}}{||\mathbf{H}_e||^2}, \quad \mathbf{X}_0 = \mathbf{H}_0$$
Since $\mathbf{A}$ is a symmetric $3 \times 3$ matrix and $||\mathbf{H}_e||$ is the known local geomagnetic field strength (obtainable from a magnetic map or a reference magnetometer), we can perform a Cholesky decomposition or similar factorization on $\mathbf{A}$ to recover $\mathbf{L}$ up to an arbitrary orthogonal rotation (which is absorbed into the subsequent installation error). From $\mathbf{L}$, the individual parameters $k_x, k_y, k_z, \alpha, \beta, \upsilon$ can be extracted. Finally, any raw measurement can be corrected to the ideal orthogonal sensor frame: $\mathbf{H}_e = \mathbf{L}(\mathbf{H}_m – \mathbf{H}_0)$.

Step 2: Installation Error Calibration via Four-Position Method

After Step 1, we have measurements $\mathbf{H}_e$ in a perfectly orthogonal frame fixed to the sensor chip. We now need to find the rotation matrix $\mathbf{C}_b^e$ that relates this frame to the quadrotor drone‘s body frame. We exploit a geometric property: when the body is rotated 180° about one of its principal axes, the component of the Earth’s magnetic field along that axis remains unchanged, while the components in the perpendicular plane invert sign.

The procedure requires the quadrotor drone (or its flight controller board) to be placed on a level surface. We define the body frame: $x_b$ forward, $y_b$ right, $z_b$ down. The method involves four specific orientations:

  1. Position A: Board in its default, level orientation.
  2. Position B: Board rotated 180° about its $z_b$ axis (yaw).
  3. Position C: Board rotated 180° about its $y_b$ axis (pitch).
  4. Position D: Board rotated 180° about its $x_b$ axis (roll). This final position is often used as a consistency check or to improve estimate robustness.

For each position $i$, we record the intrinsically calibrated vector $\mathbf{H}_e^{(i)}$. Let $\mathbf{H}_b = [H_{bx}, H_{by}, H_{bz}]^T$ be the unknown but constant magnetic field in the body frame during the experiment. The relationship is $\mathbf{H}_e^{(i)} = \mathbf{C}_b^e \mathbf{R}^{(i)} \mathbf{H}_b$, where $\mathbf{R}^{(i)}$ is the known 180° rotation matrix for position $i$ relative to Position A.

Analyzing the equations for rotations about $z_b$ (Positions A and B) allows us to solve for two of the three installation angles, $\gamma$ and $\theta$:
$$\gamma = \arctan\left( -\frac{H_{ex}^{(A)} + H_{ex}^{(B)}}{H_{ez}^{(A)} + H_{ez}^{(B)}} \right)$$
$$\theta = \arctan\left( \frac{H_{ey}^{(A)} + H_{ey}^{(B)}}{\cos\gamma (H_{ez}^{(A)}+H_{ez}^{(B)}) – \sin\gamma (H_{ex}^{(A)}+H_{ex}^{(B)})} \right)$$
Subsequently, using the data from the rotation about $y_b$ (Positions A and C), we can solve for the remaining angle $\psi$:
$$\psi = \arctan\left( -\frac{\cos\gamma(H_{ex}^{(A)}+H_{ex}^{(C)}) + \sin\gamma(H_{ez}^{(A)}+H_{ez}^{(C)})}{\cos\theta(H_{ey}^{(A)}+H_{ey}^{(C)}) – \cos\gamma\sin\theta(H_{ez}^{(A)}+H_{ez}^{(C)}) + \sin\gamma\sin\theta(H_{ex}^{(A)}+H_{ex}^{(C)}) } \right)$$
With $(\psi, \theta, \gamma)$ estimated, we construct the full rotation matrix $\mathbf{C}_b^e$. The final, fully calibrated body-frame magnetic measurement is then:
$$\mathbf{H}_b = (\mathbf{C}_b^e)^T \mathbf{H}_e = (\mathbf{C}_b^e)^T \mathbf{L} (\mathbf{H}_m – \mathbf{H}_0)$$
This $\mathbf{H}_b$ is the accurate vector input required by the attitude estimation filter of the quadrotor drone.

Experimental Validation and Results

To validate the two-step method, we conducted experiments using a commercially available MEMS magnetometer integrated on a quadrotor drone autopilot board. The local geomagnetic field strength was measured using a high-precision, calibrated fluxgate magnetometer. The board was manually rotated through hundreds of arbitrary orientations in a magnetically clean outdoor environment to collect data for the ellipsoid fit.

The results of the ellipsoid fitting step yielded the following intrinsic error parameters:

Parameter Value Parameter Value (nT)
$k_x$ 1.1235 $H_{0x}$ -2704
$k_y$ 1.1121 $H_{0y}$ -529
$k_z$ 1.0274 $H_{0z}$ 1096
$\alpha$ -1.3726°
$\beta$ -1.8288°
$\upsilon$ 0.3551°

The four-position calibration was then performed on a leveled surface, yielding the installation error angles: $\psi = -1.1211^\circ$, $\theta = -0.3303^\circ$, $\gamma = 2.0537^\circ$. These non-zero angles confirm the presence of a small but significant mounting misalignment on the quadrotor drone‘s PCB.

The effectiveness of each calibration step is quantitatively assessed by examining the error in the total field magnitude and in a single axis. The total field magnitude should be constant; its variation indicates residual uncompensated errors. The Z-axis body component was chosen for single-axis analysis because the four-position method provides a direct reference for it. The following table summarizes the statistical errors (mean and standard deviation) before calibration, after Step 1 (Ellipsoid Fit), and after Step 2 (Full Calibration).

Calibration Stage Field Magnitude Error (nT) Z-axis Body Component Error (nT)
Uncalibrated 2900 ± 170 2736 ± 145
After Step 1 (Ellipsoid) 900 ± 120 221 ± 124
After Step 2 (Full) 900 ± 120 49 ± 122

The data reveals several key findings. The ellipsoid fitting (Step 1) dramatically reduces the total field error from 2900 nT to 900 nT, demonstrating excellent compensation of scale, bias, and non-orthogonality errors. This step also reduces the Z-axis error significantly. However, the final step is crucial: applying the four-position installation correction reduces the mean Z-axis error from 221 nT to just 49 nT. This ~77% reduction in the mean error for a specific body axis validates the necessity and effectiveness of the second calibration step for the quadrotor drone application. The residual standard deviation is attributed to sensor noise and minor environmental magnetic disturbances during data collection.

Discussion and Comparative Analysis

The proposed two-step method offers distinct advantages over traditional calibration techniques for quadrotor drone applications. The widely used “swing” or “figure-8” method requires the drone to be moved through a specific set of motions, often relying on the assumption that the measured field vector uniformly samples a sphere. Our method’s first step uses an arbitrary rotation pattern, which is simpler to execute reliably. More importantly, the traditional methods typically solve for a combined $3 \times 3$ soft-iron and $3 \times 1$ hard-iron matrix that implicitly mixes intrinsic sensor errors and installation errors. This can lead to suboptimal performance if the sensor itself has significant non-orthogonality, as is common with low-cost MEMS devices.

By explicitly modeling and decoupling the non-orthogonality ($\mathbf{K}_2$) and the frame rotation ($\mathbf{C}_b^e$), our method provides a more physically accurate representation of the error chain. This decoupling is particularly beneficial during system integration or sensor replacement on a quadrotor drone. The intrinsic parameters need only be calibrated once for a specific sensor chip, potentially in a factory setting. The installation parameters are specific to each drone’s assembly and can be re-calibrated quickly in the field using the simple four-position procedure without needing the full rotation dataset.

The mathematical foundation is also robust. The ellipsoid fitting via constrained least squares is a well-established and numerically stable approach. The four-position method provides a closed-form, non-iterative solution for the installation angles, making it computationally trivial to implement even on the resource-constrained microcontroller of a quadrotor drone flight controller.

Conclusion

Accurate magnetic heading is a non-negotiable requirement for stable autonomous navigation in miniature quadrotor drones. The MEMS magnetometers that enable this functionality introduce complex errors that extend beyond simple scale and offset. We have presented a comprehensive, two-step calibration framework that systematically addresses both the intrinsic errors of the sensor (bias, scale factor, and axis non-orthogonality) and the extrinsic error caused by misalignment between the sensor die and the drone’s body frame. The first step employs an ellipsoid fitting algorithm that requires no external reference equipment, only a series of arbitrary rotations in a clean magnetic environment. The second step utilizes a simple four-position static procedure to resolve the installation misalignment.

Experimental results confirm the efficacy of this decoupled approach. The ellipsoid fit corrects the vast majority of the total field error, while the subsequent four-position alignment brings the error of individual body-axis components down to levels consistent with the sensor’s intrinsic noise floor. This method is superior to traditional combined calibration techniques in its physical clarity, ease of execution, and lack of dependence on high-precision instrumentation. It is therefore exceptionally well-suited for the calibration of attitude and heading reference systems (AHRS) in commercial, research, and hobbyist quadrotor drone platforms, ultimately contributing to more reliable and precise autonomous flight.

The integration of this calibrated magnetometer data with complementary sensors (gyroscopes, accelerometers) via sensor fusion algorithms like the extended Kalman filter or complementary filter will yield a dramatic improvement in the attitude estimate’s yaw accuracy, directly enhancing the navigation performance and flight stability of the quadrotor drone. Future work may involve automating the data collection process and integrating the calibration routine directly into the drone’s ground control software for seamless end-user operation.

Scroll to Top