#MPU-9250-AHRS This Arduino repository was created to address significant shortcomings in other AHRS repositories for the MPU-9250 9DOF sensor. UPDATE October 2023: Python code for calibrating magnetometer and accelerometer added, which optionally replaces Magneto. The results are identical with the two methods. references : - https://teslabs.com/articles/magnetometer-calibration/ - https://github.com/nliaudat/magnetometer_calibration/blob/main/calibrate.py Clarification 12/17/2020: The standard sensor orientation for Tait-Bryan angles is X North Y West and Z Up (NWU system) The currently implemented AHRS algorithm is the standard Madgwick/Mahony scheme (two alternative solvers) found in other repositories. However, new features have been added, such as code to simplify accurate calibration of the accelerometer, magnetometer and gyro. The magnetometer and accelerometer axes are realigned so that the output orientation is meaningful, and to simplify overall operation. NEW filter code Mahony2.ino improves speed of convergence. Standard reference vectors are now Up (Accelerometer) and West (Accelerometer cross Magnetometer). SENSOR CALIBRATION The magnetometer and accelerometer calibration approaches are described in this excellent blog article: http://sailboatinstruments.blogspot.com/2011/08/improved-magnetometer-calibration.html I also strongly recommend this blog post as a general guide to magnetometer/accelerometer calibration https://thecavepearlproject.org/2015/05/22/calibrating-any-compass-or-accelerometer-for-arduino/ Magneto is a fair sized C program that runs on a PC or a Mac (suggest to use Code::Blocks IDE on Windows). For convenience, I’ve collected all of the basic parts of magneto, described in the sailboatinstruments link, into one file that can be compiled and run on a desktop. The magneto approach fits an ellipsoid to the data, avoiding statistical problems associated with the min/max approach, rotates the ellipsoid to align with the coordinate axes, scales the axial dimensions to a sphere, and rotates back. The result is a set of offsets and a nine element matrix correction that must be applied to the raw data. The magneto program was modified to add measurement rejection criteria and to publish data initialization statements that can be incorporated directly into the AHRS code. A detailed example of using the above procedures in a particularly difficult case, with severe "hard iron" distortion can be found at https://forum.pololu.com/t/correcting-the-balboa-magnetometer/14315 For compilation of MPU9250_Mahony.ino or MPU9250_tiltcomp.ino, copy the contents of the "lib" directory into a "lib" subfolder of the Arduino folders containing the respective .ino files.
K486D2/MPU-9250-AHRS
Arduino Mahony AHRS, includes magnetometer and accelerometer calibration code
C++