Hello,
i am trying to calibrate magnetometer inside MPU9250. Using BolderFlight library to get magnetometer data.
First of all i toke about 11k raw samples. Then i ploted the points in 3D to ensure i covered most of the points.
Then build and run Magneto 1.2 program for calibration (default hm = 56.024670) - returned me following biases ( x: 18.70 y: -18.35 z: 7.05 )
and corection matrix:
+1.25872. +0.00608 -0.01511
+0.00608 +1.04680 +0.02554
-0.01511 +0.02554 +1.21148
then applying corection matrix together with biases on raw data - graph looks good to me.
Now i want to ensure that its working as expected.
Moving flat with sensor around z axis and applying corection matrix and bias.
Is magnetometer correctly calibrated?
I have doubts coz when using AHRS filter i am getting wrong yaw values while rotating sensor. For ex. when rotating around z-axis 90 degrees, yaw changes only by 60 degrees.
The goal is to get 3-axis absolute orientation but thats imposible without properly calibrated magnetometer.
Thank you
#include "MPU9250.h"
#include <ESP8266WiFi.h>
int imuu2MemoryStartAddr = 12;
long long counter = 0;
MPU9250 imuu2(SPI, 4, imuu2MemoryStartAddr);
int status;
void initSensor(MPU9250 &imu, int i) {
status = imu.begin();
if (status < 0) {
Serial.println((String) "IMU initialization unsuccessful, num " + i);
Serial.println((String) "Status: " + status);
while (1) {}
}
Serial.println("Sensor initialized");
}
void readSensor(MPU9250 & imu, int i) {
float mx, my, mz, mbx, mby, mbz;
float tm[3][3] = {
{ +1.25872, +0.00608, -0.01511 },
{ +0.00608, +1.04680, +0.02554 },
{ -0.01511, +0.02554, +1.21148 }
};
mbx = 18.70, mby = -18.35, mbz = 7.05;
imu.readSensor();
mx = imu.getMagX_uT(), my = imu.getMagY_uT(), mz = imu.getMagZ_uT();
mx = mx - mbx, my = my - mby, mz = mz - mbz;
float smx = (mx * tm[0][0]) + (my * tm[0][1]) + (mz * tm[0][2]);
float smy = (mx * tm[1][0]) + (my * tm[1][1]) + (mz * tm[1][2]);
float smz = (mx * tm[2][0]) + (my * tm[2][1]) + (mz * tm[2][2]);
if (counter % 200 == 0) {
Serial.println((String) smx + "," + smy + "," + smz);
}
}
void setup() {
Serial.begin(115200);
initSensor(imuu2, 1);
}
void loop() {
counter++;
readSensor(imuu2, 1);
}