Sensor Fusion Library 0.6.1
Orientation sensing for Espressif (ESP32, ESP8266) processors
Loading...
Searching...
No Matches
Classes | Macros
magnetic.h File Reference

Lower level magnetic calibration interface. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MagBuffer
 
struct  MagCalibration
 Magnetic Calibration Structure. More...
 

Macros

#define F_USING_MAG   0x0002
 
Magnetic Calibration Constants
#define MAGBUFFSIZEX   14
 x dimension in magnetometer buffer (14x28 equals 392 elements)
 
#define MAGBUFFSIZEY   (2 * MAGBUFFSIZEX)
 y dimension in magnetometer buffer (14x28 equals 392 elements)
 
#define MINMEASUREMENTS4CAL   110
 minimum number of measurements for 4 element calibration
 
#define MINMEASUREMENTS7CAL   220
 minimum number of measurements for 7 element calibration
 
#define MINMEASUREMENTS10CAL   330
 minimum number of measurements for 10 element calibration
 
#define MAXMEASUREMENTS   360
 maximum number of measurements used for calibration
 
#define CAL_INTERVAL_SECS   300
 300s or 5min interval for regular calibration checks
 
#define MINBFITUT   10.0F
 minimum acceptable geomagnetic field B (uT) for valid calibration
 
#define MAXBFITUT   90.0F
 maximum acceptable geomagnetic field B (uT) for valid calibration
 
#define FITERRORAGINGSECS   86400.0F
 24 hours: time (s) for fit error to increase (age) by e=2.718
 
#define MESHDELTACOUNTS   50
 magnetic buffer mesh spacing in counts (here 5uT)
 
#define DEFAULTB   50.0F
 default geomagnetic field (uT)
 

Functions

Function prototypes for functions in magnetic.c

These functions comprise the core of the magnetic calibration features of the library. Parameter descriptions are not included here, as details are provided in sensor_fusion.h.

void fInitializeMagCalibration (struct MagCalibration *pthisMagCal, struct MagBuffer *pthisMagBuffer)
 
void iUpdateMagBuffer (struct MagBuffer *pthisMagBuffer, struct MagSensor *pthisMag, int32_t loopcounter)
 
void fInvertMagCal (struct MagSensor *pthisMag, struct MagCalibration *pthisMagCal)
 
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 each fusion cycle. Three versions of calibration exist, differing in complexity and referred to as 4, 7, and 10 element solvers.
 
void fUpdateMagCalibration4 (struct MagCalibration *pthisMagCal, struct MagBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
 
void fUpdateMagCalibration7 (struct MagCalibration *pthisMagCal, struct MagBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
 
void fUpdateMagCalibration10 (struct MagCalibration *pthisMagCal, struct MagBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
 
void fUpdateMagCalibration4Slice (struct MagCalibration *pthisMagCal, struct MagBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
 
void fUpdateMagCalibration7Slice (struct MagCalibration *pthisMagCal, struct MagBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
 
void fUpdateMagCalibration10Slice (struct MagCalibration *pthisMagCal, struct MagBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
 

Detailed Description

Lower level magnetic calibration interface.

Many developers can utilize the NXP Sensor Fusion Library without ever making any adjustment to the lower level magnetic calibration functions defined in this file.

Definition in file magnetic.h.

Macro Definition Documentation

◆ CAL_INTERVAL_SECS

#define CAL_INTERVAL_SECS   300

300s or 5min interval for regular calibration checks

Definition at line 38 of file magnetic.h.

◆ DEFAULTB

#define DEFAULTB   50.0F

default geomagnetic field (uT)

Definition at line 43 of file magnetic.h.

◆ F_USING_MAG

#define F_USING_MAG   0x0002

Definition at line 26 of file magnetic.h.

◆ FITERRORAGINGSECS

#define FITERRORAGINGSECS   86400.0F

24 hours: time (s) for fit error to increase (age) by e=2.718

Definition at line 41 of file magnetic.h.

◆ MAGBUFFSIZEX

#define MAGBUFFSIZEX   14

x dimension in magnetometer buffer (14x28 equals 392 elements)

Definition at line 32 of file magnetic.h.

◆ MAGBUFFSIZEY

#define MAGBUFFSIZEY   (2 * MAGBUFFSIZEX)

y dimension in magnetometer buffer (14x28 equals 392 elements)

Definition at line 33 of file magnetic.h.

◆ MAXBFITUT

#define MAXBFITUT   90.0F

maximum acceptable geomagnetic field B (uT) for valid calibration

Definition at line 40 of file magnetic.h.

◆ MAXMEASUREMENTS

#define MAXMEASUREMENTS   360

maximum number of measurements used for calibration

Definition at line 37 of file magnetic.h.

◆ MESHDELTACOUNTS

#define MESHDELTACOUNTS   50

magnetic buffer mesh spacing in counts (here 5uT)

Definition at line 42 of file magnetic.h.

◆ MINBFITUT

#define MINBFITUT   10.0F

minimum acceptable geomagnetic field B (uT) for valid calibration

Definition at line 39 of file magnetic.h.

◆ MINMEASUREMENTS10CAL

#define MINMEASUREMENTS10CAL   330

minimum number of measurements for 10 element calibration

Definition at line 36 of file magnetic.h.

◆ MINMEASUREMENTS4CAL

#define MINMEASUREMENTS4CAL   110

minimum number of measurements for 4 element calibration

Definition at line 34 of file magnetic.h.

◆ MINMEASUREMENTS7CAL

#define MINMEASUREMENTS7CAL   220

minimum number of measurements for 7 element calibration

Definition at line 35 of file magnetic.h.

Function Documentation

◆ fInitializeMagCalibration()

void fInitializeMagCalibration ( struct MagCalibration pthisMagCal,
struct MagBuffer pthisMagBuffer 
)

Definition at line 27 of file magnetic.c.

◆ fInvertMagCal()

void fInvertMagCal ( struct MagSensor pthisMag,
struct MagCalibration pthisMagCal 
)

Definition at line 286 of file magnetic.c.

◆ fRunMagCalibration()

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 each fusion cycle. Three versions of calibration exist, differing in complexity and referred to as 4, 7, and 10 element solvers.

If a calibration is in progress, indicated by the flag iCalInProgress, then it continues to completion using the same solver. If a calibration is not in progress and has not been done previously, then one is started using the most complex solver suited to the number of measurements available in the buffer. If a calibration is not in progress but has been done previously, then at CAL_INTERVAL_SECS one is started using the most complex solver suited to the number of measurements available in the buffer.

When a solver completes, it indicates this via iNewCalibrationAvailable.

A new calibration is accepted if: mag field strength is within reasonable limits; AND the fit error ftrFitErrorpc is less than 15%; AND the fit error is better than existing cal OR (be from higher-order solver AND fit error less than 3.5%). If (the mag field strength is outside reasonable limits OR the fit error ftrFitErrorpc is greater than 15%) AND the 10-order solver was used, then it is assumed some readings were corrupted so the buffer is cleared and the cal process restarts from the top.

The fit error of the existing calibration is 'aged' slowly, increasing by 1% every 24 hours. This causes a new calibration to be favoured over the old one after sufficient time elapses. I am unsure whether this is desirable in a nautical application where it is conceivable for the vessel to be on a consistent heading for long periods.

Parameters
pthisMagCalstruct containing details of the current calibration.
pthisMagBufferbuffer of readings to be used for new calibration.
pthisMagcurrent magnetic reading.
loopcountercounts iterations of fusion algorithm. Used in timeslicing.

Definition at line 352 of file magnetic.c.

◆ fUpdateMagCalibration10Slice()

void fUpdateMagCalibration10Slice ( struct MagCalibration pthisMagCal,
struct MagBuffer pthisMagBuffer,
struct MagSensor pthisMag 
)

Definition at line 1000 of file magnetic.c.

◆ fUpdateMagCalibration4Slice()

void fUpdateMagCalibration4Slice ( struct MagCalibration pthisMagCal,
struct MagBuffer pthisMagBuffer,
struct MagSensor pthisMag 
)

Definition at line 482 of file magnetic.c.

◆ fUpdateMagCalibration7Slice()

void fUpdateMagCalibration7Slice ( struct MagCalibration pthisMagCal,
struct MagBuffer pthisMagBuffer,
struct MagSensor pthisMag 
)

Definition at line 713 of file magnetic.c.

◆ iUpdateMagBuffer()

void iUpdateMagBuffer ( struct MagBuffer pthisMagBuffer,
struct MagSensor pthisMag,
int32_t  loopcounter 
)

Definition at line 92 of file magnetic.c.