Skip to content
Create Magnetometer Calibration Guide authored by Georgia Zachou's avatar Georgia Zachou
[[_TOC_]]
## Magnetometer Errors
Magnetometers can detect the orientation with respect to the Earth's magnetic field. Basically, they are 3D compasses. We are using FXOS8700 3-Axis accelerometer and magnetometer (by [Adafruit](https://www.adafruit.com/product/3463)). Since magnetometers have to measure quite small magnetic fields, it is easy to be affected from other sources.
Some magnetometer errors, can be:
1. Hard iron distortions caused by external magnetic fields (high current wires, magnets)
2. Soft iron distortions that come from paramagnetic materials or the Earth's magnetic field.
3. Temperature & acceleration dependence
## Method
In this way, magnetometer calibration is essential. Following a simple matrix multiplication calculation, using the raw data, the hard-iron correction data and the matrix with the soft iron, scale factor & misalingment corrections, we can estimate the calibrated values.
If we plot the uncalibrated values we have an ellipsoid, while the calibrated values give us a circle. Thus, the method we described above is called ellipsoid fitting.
**Calibrated vs Uncalibrated figures:**
<img src="/uploads/e028c232a926675e361140404e68d969/image.png" width="200" />
Sources used for magnetometer calibration:
- [Magneto](https://sites.google.com/view/sailboatinstruments1/a-download-magneto-v1-2) calibration software
- Magnetic field [calculator](https://www.ngdc.noaa.gov/geomag/calculators/magcalc.shtml#igrfwmm)
- Python [code & example](https://github.com/michaelwro/mag-cal-example)
Before starting:
- Don't forget to adjust python code to `port` and `baudrate`.
- Install `pyserial` and not serial unless the code won't run
- Don't forget to install `Adafruit AHRS` library for Arduino
## Measurements & Results
**Matrix construction using [Magneto](https://sites.google.com/view/sailboatinstruments1/a-download-magneto-v1-2)**
<img src="/uploads/fc85ded299d54e208dbf14fe2c8b0ece/Screenshot_13.png" width="200" />
We replaced the above corrections at the python code that we used.
**Calibrated & Uncalibrated data figures**
<p float="left">
<img src="/uploads/a6358f2caeabbf19358363631a744d1c/Figure_1.png" width="200" />
<img src="/uploads/2987a12e500bbd87cb7695ce64f5a21d/Figure_2.png" width="200" />
<img src="/uploads/7dcf9753bf55290ea002c8127e167947/Figure_3.png" width="200" />
<img src="/uploads/b03c5d90e384b68e816f5bfe9fd9e3be/Figure_4.png" width="200" />
</p>
## Comments
XY,YZ & XZ-graph: Calibrated data shape a better-centered circle, while raw data shape an ellipsoid that is shifted. With the ellipsoid fitting method, we corrected the data to fit in a perfect sphere.