26#define F_USING_MAG 0x0002
32#define MAGBUFFSIZEX 14
33#define MAGBUFFSIZEY (2 * MAGBUFFSIZEX)
34#define MINMEASUREMENTS4CAL 110
35#define MINMEASUREMENTS7CAL 220
36#define MINMEASUREMENTS10CAL 330
37#define MAXMEASUREMENTS 360
38#define CAL_INTERVAL_SECS 300
39#define MINBFITUT 10.0F
40#define MAXBFITUT 90.0F
41#define FITERRORAGINGSECS 86400.0F
42#define MESHDELTACOUNTS 50
103void iUpdateMagBuffer(
struct MagBuffer *pthisMagBuffer,
struct MagSensor *pthisMag, int32_t loopcounter);
void fRunMagCalibration(struct MagCalibration *pthisMagCal, struct MagBuffer *pthisMagBuffer, struct MagSensor *pthisMag, int32_t loopcounter)
Run the magnetic calibration. Calibration is done in time-slices, to avoid excessive CPU load during ...
#define MAGBUFFSIZEX
x dimension in magnetometer buffer (14x28 equals 392 elements)
#define MAGBUFFSIZEY
y dimension in magnetometer buffer (14x28 equals 392 elements)
int16_t tanarray[MAGBUFFSIZEX - 1]
array of tangents of (100 * angle)
int32_t index[MAGBUFFSIZEX][MAGBUFFSIZEY]
array of time indices
int16_t iMagBufferCount
number of magnetometer readings
int16_t iBs[3][MAGBUFFSIZEX][MAGBUFFSIZEY]
uncalibrated magnetometer readings
Magnetic Calibration Structure.
float finvA[3][3]
inverse of ellipsoid matrix A
float ftrFitErrorpc
trial value of fit error %
float fB
current geomagnetic field magnitude (uT)
int8_t iInitiateMagCal
flag to start a new magnetic calibration
float fFitErrorpc
current fit error %
float fA[3][3]
ellipsoid matrix A
int8_t i4ElementSolverTried
flag to denote at least one attempt made with 4 element calibration
int8_t i10ElementSolverTried
flag to denote at least one attempt made with 10 element calibration
float ftrV[3]
trial value of hard iron offset z, y, z (uT)
float ftrB
trial value of geomagnetic field magnitude in uT
float fV[3]
current hard iron offset x, y, z, (uT)
float fvecA[10]
scratch 10x1 vector used by calibration algorithms
float fmatB[10][10]
scratch 10x10 float matrix used by calibration algorithms
float finvW[3][3]
current inverse soft iron matrix
int32_t iSumBs[3]
sum of measurements in buffer (counts)
float ftrinvW[3][3]
trial inverse soft iron matrix size
int32_t iMeanBs[3]
average magnetic measurement (counts)
int8_t i7ElementSolverTried
flag to denote at least one attempt made with 7 element calibration
int8_t iNewCalibrationAvailable
flag denoting that a new calibration has been computed
float fBSq
square of fB (uT^2)
float fYTY
Y^T.Y for 4 element calibration = (iB^2)^2.
int8_t iCalInProgress
flag denoting that a calibration is in progress
int32_t itimeslice
counter for tine slicing magnetic calibration calculations
int32_t iValidMagCal
solver used: 0 (no calibration) or 4, 7, 10 element
int8_t iMagBufferReadOnly
flag to denote that the magnetic measurement buffer is temporarily read only
float fvecB[4]
scratch 4x1 vector used by calibration algorithms
float fmatA[10][10]
scratch 10x10 float matrix used by calibration algorithms
The MagSensor structure stores raw and processed measurements for a 3-axis magnetic sensor.