My project structure is similar to the original one.
The code collects 300 samples, or some other value.
I use raw data, not converted to microTesla.
Usually I used the MAGNETO method and got the bias and scale, and then applied them according to this formula.
But here the bias values ββare somehow huge, which made me doubt the correctness of my adaptation of the source code.
In this code I expected something similar, but I didnβt get any scale or matrices right away.
After calibration, I get both uncalibrated and calibrated values, and the calibrated values ββmagically calibrateβnot perfectly, but still.
I became curious about how the code works and whether it correctly fits the ellipsoid using the least-squares method.
I wrote another test code, for which I collected three sets of samples: 20, 100, and 300 points along each axis of the magnetometer.
Here I have already collected samples in microTesla.
#define _USE_MATH_DEFINES
#include <Arduino.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
extern "C" {
#include "mag_calib_new/geometry.h"
}
#define SERIAL_BAUD 115200
#define MIN_DATA_LEN 15
// Select mode: 1 - 20 samples, 2 - 100 samples, 3 - 300 samples
#define DATA_MODE 3
// DEMO OF MAGNETOMETER CALIBRATION USING REAL DATA
// This demo:
// 1. Takes real magnetometer data points
// 2. Calculates calibration data (offset vector and transformation matrix)
// 3. Checks if calibration was successful
// 4. Calibrates the data points
typedef struct {
Vector vx;
Vector vy;
Vector vz;
} mag_data_t;
#if DATA_MODE == 1
// Variance of distances before calibration: 74.736556
// Variance of distances after calibration: 0.013583
#define MAX_DATA_LEN 20
double x[20] = {
0.312500, 6.500000, 18.437500, 30.000000, 34.000000, 35.812500, 32.937500, 30.000000, 19.875000, 9.750000,
-1.437500, -10.125000, -16.625000, -23.875000, -28.937500, -28.562500, -26.375000, -19.875000, -14.812500, -6.875000
};
double y[20] = {
12.250000, 22.062500, 32.187500, 35.812500, 38.687500, 36.875000, 32.187500, 22.437500, 9.000000, -4.312500,
-15.875000, -22.750000, -25.312500, -17.687500, -5.062500, 8.687500, 26.750000, 33.250000, 40.187500, 48.875000
};
double z[20] = {
-44.750000, -41.937500, -35.937500, -37.562500, -39.187500, -42.437500, -44.062500, -46.875000, -47.250000, -46.062500,
-41.625000, -36.375000, -32.312500, -28.312500, -28.312500, -24.250000, -23.062500, -20.625000, -22.250000, -26.687500
};
#elif DATA_MODE == 2
// Variance of distances before calibration: 99.927141
// Variance of distances after calibration: 0.063912
#define MAX_DATA_LEN 100
double x[100] = {
-11.562500, -17.687500, -22.062500, -24.937500, -25.312500, -23.500000, -19.187500, -14.437500, -10.812500, -4.687500,
0.312500, 3.250000, 6.500000, 14.062500, 18.437500, 24.250000, 30.000000, 32.937500, 34.000000, 35.062500,
35.812500, 34.750000, 32.937500, 31.500000, 30.000000, 24.250000, 19.875000, 13.750000, 9.750000, 3.250000,
-1.437500, -4.687500, -10.125000, -14.812500, -16.625000, -21.000000, -23.875000, -26.750000, -28.937500, -28.937500,
-28.562500, -27.875000, -26.375000, -22.812500, -19.875000, -15.875000, -14.812500, -10.812500, -6.875000, -1.750000,
3.250000, 8.687500, 14.437500, 19.187500, 24.562500, 27.875000, 31.812500, 34.750000, 35.812500, 35.437500,
35.437500, 35.437500, 34.375000, 33.625000, 32.562500, 30.375000, 30.375000, 28.187500, 22.062500, 20.625000,
12.250000, 11.937500, 5.750000, 0.687500, -3.250000, -8.687500, -14.062500, -16.625000, -20.625000, -25.687500,
-28.187500, -31.812500, -35.125000, -38.375000, -36.187500, -38.687500, -39.062500, -41.625000, -41.250000, -41.625000
};
double y[100] = {
12.250000, 17.000000, 22.062500, 27.125000, 32.187500, 35.437500, 35.812500, 38.000000, 38.687500, 40.125000,
36.875000, 34.375000, 32.187500, 25.312500, 22.437500, 14.437500, 9.000000, 2.125000, -4.312500, -10.125000,
-15.875000, -18.437500, -22.750000, -24.250000, -25.312500, -23.500000, -17.687500, -13.000000, -5.062500, 1.062500,
8.687500, 18.437500, 26.750000, 30.375000, 33.250000, 36.875000, 40.187500, 45.250000, 48.875000, 49.562500,
50.312500, 47.375000, 45.937500, 42.687500, 39.062500, 34.750000, 30.750000, 27.125000, 26.750000, 23.500000,
18.062500, 14.437500, 14.437500, 3.250000, -0.312500, -4.312500, -9.375000, -14.812500, -19.875000, -23.125000,
-26.750000, -28.937500, -27.875000, -26.062500, -23.500000, -20.250000, -13.375000, -7.562500, -1.062500, 6.500000,
11.937500, 18.812500, 25.687500, 30.375000, 34.000000, 36.187500, 38.687500, 41.625000, 42.312500, 43.062500,
44.125000, 44.500000, 43.062500, 39.062500, 34.000000, 28.937500, 27.500000, 23.125000, 17.687500, 13.750000,
9.750000, 9.750000, 12.250000, 13.750000, 17.375000, 17.000000, 14.062500, 12.625000, 9.375000, 7.187500,
};
double z[100] = {
-44.750000, -43.562500, -41.937500, -37.125000, -35.937500, -33.875000, -37.562500, -37.937500, -39.187500, -40.375000,
-42.437500, -44.437500, -44.062500, -46.062500, -46.875000, -45.687500, -47.250000, -46.062500, -46.062500, -44.437500,
-41.625000, -38.812500, -36.375000, -33.937500, -32.312500, -30.312500, -28.312500, -29.125000, -28.312500, -27.875000,
-24.250000, -25.875000, -23.062500, -20.625000, -20.625000, -21.000000, -22.250000, -24.625000, -25.500000, -26.687500,
-30.312500, -31.562500, -35.562500, -38.000000, -40.062500, -42.875000, -45.687500, -45.312500, -46.937500, -45.312500,
-44.875000, -47.312500, -46.562500, -46.125000, -44.500000, -46.125000, -44.125000, -41.250000, -40.062500, -37.250000,
-35.187500, -29.937500, -31.125000, -29.937500, -30.750000, -28.687500, -29.500000, -29.125000, -27.500000, -27.125000,
-25.500000, -23.875000, -21.437500, -20.187500, -20.187500, -20.187500, -20.625000, -21.812500, -23.437500, -27.937500,
-27.937500, -34.000000, -40.875000, -43.312500, -46.937500, -48.187500, -50.187500, -49.375000, -49.812500, -48.562500,
-48.562500, -46.937500, -43.312500, -42.875000, -42.062500, -42.500000, -41.250000, -39.250000, -40.062500, -40.437500
};
#elif DATA_MODE == 3
// Variance of distances before calibration: 49.279169
// Variance of distances after calibration: 0.000708
#define MAX_DATA_LEN 300
double x[MAX_DATA_LEN] = {
9.375000, 11.937500, 13.750000, 14.812500, 17.312500, 16.625000, 19.500000, 18.812500, 19.500000, 18.812500,
18.437500, 16.625000, 14.812500, 12.625000, 9.750000, 7.937500, 6.125000, 2.500000, 0.000000, -2.875000,
-4.312500, -8.687500, -11.562500, -14.812500, -17.687500, -20.625000, -22.062500, -23.125000, -24.937500, -24.250000,
-25.312500, -24.937500, -23.500000, -21.312500, -19.187500, -17.000000, -14.437500, -13.375000, -10.812500, -8.312500,
-4.687500, -3.250000, 0.312500, 1.062500, 3.250000, 4.312500, 6.500000, 8.687500, 14.062500, 14.812500,
18.437500, 21.000000, 24.250000, 26.750000, 30.000000, 31.125000, 32.937500, 32.937500, 34.000000, 35.812500,
35.062500, 35.062500, 35.812500, 34.750000, 34.750000, 33.625000, 32.937500, 32.562500, 31.500000, 30.750000,
30.000000, 25.687500, 24.250000, 21.687500, 19.875000, 18.062500, 13.750000, 11.562500, 9.750000, 5.750000,
3.250000, 1.062500, -1.437500, -3.562500, -4.687500, -7.562500, -10.125000, -12.625000, -14.812500, -16.625000,
-16.625000, -19.500000, -21.000000, -23.125000, -23.875000, -25.687500, -26.750000, -27.500000, -28.937500, -28.937500,
-28.937500, -28.937500, -28.562500, -28.937500, -27.875000, -27.875000, -26.375000, -24.562500, -22.812500, -22.062500,
-19.875000, -18.062500, -15.875000, -15.875000, -14.812500, -12.250000, -10.812500, -8.312500, -6.875000, -4.312500,
-1.750000, 1.062500, 3.250000, 6.500000, 8.687500, 11.187500, 14.437500, 17.000000, 19.187500, 22.062500,
24.562500, 27.125000, 27.875000, 30.375000, 31.812500, 32.937500, 34.750000, 35.812500, 35.812500, 35.437500,
35.437500, 35.437500, 37.250000, 35.437500, 34.375000, 34.000000, 33.625000, 32.187500, 32.562500, 30.375000,
30.375000, 26.750000, 28.187500, 26.062500, 22.062500, 18.437500, 20.625000, 14.812500, 12.250000, 11.937500,
11.937500, 7.187500, 5.750000, 3.250000, 0.687500, 1.062500, -3.250000, -5.750000, -8.687500, -10.500000,
-14.062500, -14.437500, -16.625000, -17.375000, -20.625000, -22.437500, -25.687500, -26.750000, -28.187500, -30.750000,
-31.812500, -33.312500, -35.125000, -36.562500, -38.375000, -38.375000, -36.187500, -38.000000, -38.687500, -38.687500,
-39.062500, -39.812500, -41.625000, -42.687500, -41.250000, -41.625000, -41.625000, -40.187500, -38.687500, -35.125000,
-31.500000, -28.562500, -24.937500, -23.125000, -21.000000, -18.437500, -16.250000, -14.437500, -12.625000, -10.812500,
-10.125000, -9.000000, -8.687500, -7.187500, -5.750000, -5.750000, -5.750000, -5.750000, -5.750000, -5.750000,
6.500000, 8.687500, 11.187500, 11.937500, 13.000000, 14.812500, 15.187500, 14.812500, 13.000000, 12.625000,
11.562500, 8.687500, 5.062500, 2.500000, -1.062500, -5.375000, -9.375000, -12.625000, -17.687500, -21.312500,
-26.062500, -29.312500, -32.562500, -33.312500, -33.625000, -31.812500, -32.562500, -33.312500, -29.312500, -26.062500,
-25.687500, -20.250000, -17.687500, -15.562500, -14.062500, -13.750000, -12.312500, -10.500000, -7.187500, -6.500000,
-4.312500, -2.500000, -1.437500, -1.750000, -0.687500, -1.062500, -1.437500, -1.750000, -2.875000, -5.750000,
-7.562500, -8.687500, -13.750000, -13.375000, -12.312500, -13.000000, -15.187500, -16.625000, -15.562500, -13.750000,
-15.562500, -14.812500, -11.937500, -11.187500, -9.375000, -9.375000, -9.750000, -9.750000, -7.187500, -8.312500,
-7.562500, -6.125000, -2.125000, -1.750000, 0.000000, 1.750000, 3.250000, 4.687500, 6.500000, 5.062500
};
double y[MAX_DATA_LEN] = {
12.250000, 14.437500, 17.000000, 19.500000, 22.062500, 25.312500, 27.125000, 29.625000, 32.187500, 32.937500,
35.437500, 35.437500, 35.812500, 37.250000, 38.000000, 38.375000, 38.687500, 40.875000, 40.125000, 38.375000,
36.875000, 34.750000, 34.375000, 32.187500, 27.500000, 25.312500, 22.437500, 18.812500, 14.437500, 11.187500,
9.000000, 6.500000, 2.125000, -0.312500, -4.312500, -7.187500, -10.125000, -13.000000, -15.875000, -17.687500,
-18.437500, -20.625000, -22.750000, -24.937500, -24.250000, -24.937500, -25.312500, -24.937500, -23.500000, -20.625000,
-17.687500, -15.187500, -13.000000, -8.687500, -5.062500, -1.437500, 1.062500, 4.312500, 8.687500, 12.625000,
18.437500, 22.750000, 26.750000, 28.187500, 30.375000, 31.500000, 33.250000, 35.062500, 36.875000, 39.062500,
40.187500, 43.062500, 45.250000, 46.312500, 48.875000, 48.875000, 49.562500, 51.375000, 50.312500, 50.312500,
47.375000, 47.750000, 45.937500, 44.500000, 42.687500, 40.500000, 39.062500, 36.875000, 34.750000, 33.312500,
30.750000, 29.312500, 27.125000, 26.062500, 26.750000, 25.687500, 23.500000, 21.312500, 18.062500, 14.437500,
14.437500, 14.437500, 5.750000, 3.250000, -0.312500, -2.875000, -4.312500, -7.562500, -9.375000, -11.562500,
-14.812500, -19.187500, -19.875000, -22.437500, -23.125000, -25.687500, -26.750000, -26.750000, -27.125000, -27.875000,
-28.937500, -28.187500, -27.875000, -26.375000, -26.062500, -24.937500, -23.500000, -22.437500, -20.250000, -14.812500,
-13.375000, -9.750000, -7.562500, -5.375000, -1.062500, 2.125000, 6.500000, 9.375000, 11.937500, 15.875000,
18.812500, 22.437500, 25.687500, 28.187500, 30.375000, 32.187500, 34.000000, 35.125000, 36.187500, 38.687500,
40.500000, 41.625000, 42.312500, 43.437500, 43.062500, 44.125000, 44.500000, 44.125000, 43.062500, 39.062500,
36.875000, 34.000000, 31.812500, 28.937500, 27.500000, 26.062500, 23.125000, 20.625000, 17.687500, 16.625000,
13.750000, 12.625000, 9.750000, 9.750000, 10.125000, 11.562500, 12.250000, 13.750000, 13.750000, 14.062500,
17.375000, 17.375000, 17.000000, 14.812500, 14.062500, 11.187500, 12.625000, 10.812500, 9.375000, 10.500000,
7.187500, 6.875000, 6.875000, 6.125000, 7.187500, 7.937500, 7.187500, 8.687500, 7.187500, 7.937500,
6.125000, 5.375000, 3.250000, 1.062500, -2.125000, -5.375000, -10.125000, -13.000000, -16.625000, -20.625000,
-24.562500, -24.562500, -26.375000, -28.562500, -32.937500, -32.937500, -32.937500, -32.937500, -32.937500, -32.937500,
-34.750000, -32.937500, -31.500000, -29.312500, -27.125000, -23.125000, -20.250000, -17.375000, -13.750000, -10.812500,
-5.750000, 0.312500, 4.312500, 7.937500, 10.812500, 12.625000, 15.875000, 18.437500, 21.000000, 23.500000,
27.125000, 30.000000, 34.000000, 35.125000, 39.437500, 40.875000, 43.062500, 43.437500, 43.437500, 45.250000,
44.500000, 45.625000, 45.250000, 44.875000, 43.437500, 42.687500, 40.500000, 38.000000, 35.812500, 33.312500,
29.687500, 25.312500, 20.625000, 15.562500, 10.500000, 9.375000, 6.500000, 5.750000, 2.125000, -1.750000,
-3.250000, -4.687500, -7.187500, -10.500000, -15.562500, -18.062500, -21.687500, -23.875000, -26.062500, -27.500000,
-28.562500, -29.687500, -29.687500, -31.500000, -33.312500, -33.312500, -33.312000, -34.375000, -34.000000, -33.625000,
-33.625000, -30.375000, -28.937500, -27.500000, -25.312500, -25.312500, -24.625000, -22.812500, -19.500000, -15.562500
};
double z[MAX_DATA_LEN] = {
-44.750000, -44.375000, -43.562500, -41.937500, -41.937500, -39.125000, -37.125000, -36.312500, -35.937500, -36.312500,
-33.875000, -35.937500, -37.562500, -37.562500, -37.937500, -40.000000, -39.187500, -40.812500, -40.375000, -42.000000,
-42.437500, -44.437500, -44.437500, -44.062500, -46.062500, -45.625000, -46.875000, -46.875000, -45.687500, -45.687500,
-47.250000, -45.687500, -46.062500, -45.250000, -46.062500, -44.875000, -44.437500, -43.250000, -41.625000, -39.625000,
-38.812500, -38.375000, -36.375000, -34.750000, -33.937500, -32.312500, -32.312500, -30.312500, -28.312500, -29.500000,
-29.125000, -29.937500, -28.312500, -28.687500, -27.875000, -26.687500, -24.250000, -26.312500, -25.875000, -25.062500,
-23.062500, -21.000000, -20.625000, -21.000000, -20.625000, -21.437500, -21.000000, -20.625000, -22.250000, -21.812500,
-24.625000, -24.687500, -25.500000, -27.062500, -26.687500, -25.062500, -30.312500, -29.937500, -31.562500, -33.562500,
-35.562500, -36.000000, -38.000000, -40.062500, -40.062500, -41.250000, -42.875000, -43.687500, -45.687500, -45.687500,
-45.312500, -46.500000, -46.937500, -45.312500, -46.500000, -46.125000, -44.875000, -43.687500, -47.312500, -46.562500,
-46.562500, -46.562500, -46.125000, -44.500000, -44.500000, -46.125000, -44.500000, -44.937500, -44.125000, -42.875000,
-41.250000, -40.062500, -40.062500, -38.437500, -37.250000, -36.375000, -35.187500, -34.000000, -29.937500, -31.937500,
-31.125000, -30.312500, -29.937500, -29.937500, -30.750000, -29.125000, -28.687500, -27.937500, -29.500000, -29.937500,
-29.125000, -29.500000, -27.500000, -27.500000, -27.125000, -26.687500, -25.500000, -24.687500, -23.875000, -23.437500,
-21.437500, -21.000000, -20.187500, -18.187500, -20.187500, -17.812500, -20.187500, -20.625000, -20.187500, -21.812500,
-21.812500, -23.062500, -23.437500, -24.687500, -27.937500, -29.125000, -27.937500, -32.375000, -34.000000, -37.250000,
-40.875000, -41.687500, -43.312500, -45.312500, -46.937500, -45.312500, -48.187500, -49.375000, -50.187500, -50.187500,
-49.375000, -49.000000, -49.812500, -49.000000, -48.562500, -49.000000, -48.562500, -46.562500, -46.562500, -45.750000,
-46.937500, -43.312500, -43.312500, -42.875000, -41.687500, -42.062500, -42.125000, -42.500000, -42.500000, -41.312500,
-41.250000, -40.437500, -39.250000, -38.875000, -40.062500, -39.250000, -40.437500, -41.250000, -41.312500, -42.500000,
-44.125000, -44.937500, -46.562500, -46.562500, -45.750000, -44.500000, -44.500000, -41.687500, -39.250000, -36.812500,
-35.187500, -33.562500, -31.187500, -29.125000, -23.875000, -23.875000, -23.875000, -23.875000, -23.875000, -23.875000,
-16.187500, -17.812500, -19.812500, -21.812500, -25.062500, -28.312500, -31.187500, -34.375000, -38.062500, -40.437500,
-42.062500, -44.937500, -46.125000, -48.187500, -48.562500, -46.937500, -49.000000, -49.375000, -49.000000, -46.937500,
-45.312500, -41.687500, -40.062500, -39.687500, -37.625000, -36.437500, -34.375000, -35.187500, -36.437500, -34.812500,
-36.437500, -37.250000, -38.437500, -39.250000, -40.062500, -40.500000, -41.312500, -43.312500, -43.312500, -44.937500,
-45.312500, -44.937500, -44.500000, -47.375000, -46.125000, -47.375000, -46.937500, -46.937500, -45.750000, -44.937500,
-44.937500, -45.312500, -42.937500, -42.500000, -40.062500, -38.437500, -35.187500, -32.750000, -32.000000, -27.937500,
-29.125000, -28.312500, -27.500000, -25.062500, -22.250000, -22.687500, -21.875000, -22.687500, -23.062500, -24.687500,
-27.125000, -28.750000, -30.750000, -32.375000, -33.187500, -32.375000, -33.187500, -34.812500, -37.625000, -40.062500
};
#else
#error "DATA_MODE must be 1, 2, or 3!"
#endif
void setup() {
Serial.begin(115200);
delay(100);
Serial.println("=== Magnetometer Calibration Demo ===");
Serial.println("Starting calibration process...");
// Create vectors based on data arrays
// We allocate memory on the heap, since the library will try to free() the passed pointer when calling vec_free()
// and static arrays cannot be freed.
double* x_dyn = (double*)malloc(MAX_DATA_LEN * sizeof(double));
double* y_dyn = (double*)malloc(MAX_DATA_LEN * sizeof(double));
double* z_dyn = (double*)malloc(MAX_DATA_LEN * sizeof(double));
if (x_dyn == NULL || y_dyn == NULL || z_dyn == NULL) {
Serial.println("ERROR: Failed to allocate memory for arrays");
free(x_dyn); free(y_dyn); free(z_dyn);
return;
}
memcpy(x_dyn, x, MAX_DATA_LEN * sizeof(double));
memcpy(y_dyn, y, MAX_DATA_LEN * sizeof(double));
memcpy(z_dyn, z, MAX_DATA_LEN * sizeof(double));
Vector vx = vec_from_array(x_dyn, MAX_DATA_LEN);
Vector vy = vec_from_array(y_dyn, MAX_DATA_LEN);
Vector vz = vec_from_array(z_dyn, MAX_DATA_LEN);
if (vx == NULL || vy == NULL || vz == NULL) {
Serial.println("ERROR: Failed to create vectors");
if (vx != NULL) vec_free(vx);
if (vy != NULL) vec_free(vy);
if (vz != NULL) vec_free(vz);
// Clearing temporary buffers in case of vector creation error
free(x_dyn); free(y_dyn); free(z_dyn);
return;
}
// Calculate calibration data (offset vector and transformation matrix)
Callibration_t calib = calib_calibrate_sensor(vx, vy, vz);
// Check if calibration was successful
Serial.print("Calculating calibration data of data points was ");
if (calib_calibration_success(calib)) {
Serial.println("SUCCESSFUL");
} else {
Serial.println("UNSUCCESSFUL");
calib_free(calib);
vec_free(vx);
vec_free(vy);
vec_free(vz);
return;
}
// Print variance before calibration
Serial.print("Variance of distances before calibration: ");
Serial.println(square_distance_variance(vx, vy, vz), 6);
// Calibrate single point
Vector dataPoint = vec_new(3);
if (dataPoint != NULL) {
VEC_X(dataPoint) = VEC_ELEM(vx, 0);
VEC_Y(dataPoint) = VEC_ELEM(vy, 0);
VEC_Z(dataPoint) = VEC_ELEM(vz, 0);
calib_calibrate_point(calib, dataPoint);
Vector gravity = vec_new(3);
if (gravity != NULL) {
VEC_X(gravity) = 0;
VEC_Y(gravity) = 0;
VEC_Z(gravity) = 1;
wmm_compensate(dataPoint, gravity, 5.9, 68.2);
vec_free(gravity);
}
vec_free(dataPoint);
}
// Calibrate all data points
calib_calibrate_multiple_points(calib, vx, vy, vz);
// Print variance after calibration
Serial.print("Variance of distances after calibration: ");
Serial.println(square_distance_variance(vx, vy, vz), 6);
// Print the result
vec_print(calib.offset);
mat_print(calib.transform);
// Free allocated memory
calib_free(calib);
vec_free(vx);
vec_free(vy);
vec_free(vz);
Serial.println("=== Calibration completed ===");
}
void loop() {
vTaskDelay(pdMS_TO_TICKS(1000));
}
Basically, I'm confused about whether I've adapted the code correctly, whether I'm collecting the data correctly, whether the algorithm is working correctly, and whether the underlying logic is even correct.
All these questions remain unanswered for me.
I hope you could help me figure this out and perhaps even provide additional details on how to use the library and clear applications for achieving practical results.
Thank you.
Hello @michal34512 π
I wrote code based on the library.
The code runs on an
ESP32-S3and reads data from theBNO085sensor.My project structure is similar to the original one.
The code collects 300 samples, or some other value.
I use raw data, not converted to microTesla.
Usually I used the MAGNETO method and got the bias and scale, and then applied them according to this formula.
But here the bias values ββare somehow huge, which made me doubt the correctness of my adaptation of the source code.
In this code I expected something similar, but I didnβt get any scale or matrices right away.
But if I comment out the line in the code,
After calibration, I get both uncalibrated and calibrated values, and the calibrated values ββmagically calibrateβnot perfectly, but still.
I became curious about how the code works and whether it correctly fits the ellipsoid using the least-squares method.
I wrote another test code, for which I collected three sets of samples:
20, 100, and 300 pointsalong each axis of the magnetometer.Here I have already collected samples in
microTesla.I also read the description
And added the output to the code:
The results are ambiguous and depend on the number of samples:
Here is the data for 300 samples
I still agree with the
bias, but the matrices, which, as I understand it, aresoft iron(scale), are for some reason very small, while they are usually about 1 in diagonal.Like this:
Basically, I'm confused about whether I've adapted the code correctly, whether I'm collecting the data correctly, whether the algorithm is working correctly, and whether the underlying logic is even correct.
All these questions remain unanswered for me.
I hope you could help me figure this out and perhaps even provide additional details on how to use the library and clear applications for achieving practical results.
Thank you.