Python Jupyter Notebook and standalone Python version of https://github.com/hobbeshunter/Magnetometer_Calibration.git
Find a file
2026-04-30 09:56:37 -07:00
img Example of Jupyter results in two different location and among 7 units 2026-04-29 12:59:35 -07:00
src feat: Initial source commit 2019-11-16 17:32:27 +01:00
.gitignore feat: Initial source commit 2019-11-16 17:32:27 +01:00
comparison.html Added testing methodology 2026-04-30 09:56:37 -07:00
imu_readings.csv feat: Initial source commit 2019-11-16 17:32:27 +01:00
library.json feat: Initial source commit 2019-11-16 17:32:27 +01:00
LICENSE Initial commit 2019-10-31 09:46:21 +01:00
mag_calibration.ipynb Notebook works, standalone Python script works 2026-04-28 13:04:56 -07:00
mag_calibration.py Notebook works, standalone Python script works 2026-04-28 13:04:56 -07:00
Mag_Gyro_Calibration.ipynb Revised and runs on eos without errors 2026-04-28 13:49:51 -07:00
README.md Added Jupyter install steps 2026-04-29 12:57:30 -07:00

Magnetometer_Calibration

This repository contains a platformio library and an explanatory jupyter notebook for calculating the hard and soft iron offsets of an magnetometer as descriped in Calibrating an eCompass in the Presence of Hard- and Soft-Iron Interference by NXP.

Jupyter notebook

Simply run jupyter notebook int his folder to start jupyter. Then open the mag_calibration notebook. There you find all informations needed.

C++ implementation

This implementation depends on Eigen. For platform.io projects you can use Eigen_Platformio_Header.

Usage:

#define NO_CALIBRATION_MEASUREMENTS 5000
Eigen::Array<float, NO_CALIBRATION_MEASUREMENTS, 1> mxs;
Eigen::Array<float, NO_CALIBRATION_MEASUREMENTS, 1> mys;
Eigen::Array<float, NO_CALIBRATION_MEASUREMENTS, 1> mzs;
Eigen::Array<float, NO_CALIBRATION_MEASUREMENTS, 1> rolls;
Eigen::Array<float, NO_CALIBRATION_MEASUREMENTS, 1> pitchs;

// Fill measurement arrays

Magnetometer_Calibration mag_cal;
mag_cal.calibrate(mxs, mys, mzs, rolls, pitchs);
Winv = mag_cal.getWinv();
W = mag_cal.getW();
V = mag_cal.getV();
B = mag_cal.getB();
incl = mag_cal.getInclination();

Installing Jupyter

Setting up Jupyer

# upgrade packaging tools
python -m pip install --upgrade pip setuptools wheel

# install JupyterLab and classic notebook support
python -m pip install jupyterlab notebook ipykernel

# Register this environment as a Jupyter kernel
# you need to use your Python environment, e.g. "pioenv" or "rnsenv"
python -m ipykernel install \
  --user \
  --name pioenv \
  --display-name "Python ~/rnsenv"

Example:

(rnsenv) jlpoole@jp /usr/local/src/Magnetometer_Calibration $   python -m ipykernel install \
	  --user \
	  --name pioenv \
	  --display-name "Python ~/rnsenv"
Installed kernelspec pioenv in /home/jlpoole/.local/share/jupyter/kernels/pioenv
(rnsenv) jlpoole@jp /usr/local/src/Magnetometer_Calibration $ 

Modules:

pip install numpy pandas matplotlib pyserial cobs msgpack
pip install --upgrade ipywidgets jupyterlab_widgets widgetsnbextension ipympl

Restart Jupyter if already running

Start the Jupyter lab:

jupyter lab
# The above will open a tab in your current browser