|
Sensor Fusion Library 0.6.1
Orientation sensing for Espressif (ESP32, ESP8266) processors
|
Lower level magnetic calibration interface. More...
#include <math.h>#include <stdbool.h>#include <stdint.h>#include "sensor_fusion.h"#include "calibration_storage.h"#include "magnetic.h"
Go to the source code of this file.
Macros | |
| #define | MATRIX_7_SIZE 7 |
| #define | MATRIX_10_SIZE 10 |
Functions | |
| 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 | 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) |
| void | fComputeMagCalibration4 (struct MagCalibration *pthisMagCal, struct MagBuffer *pthisMagBuffer, struct MagSensor *pthisMag) |
| void | fComputeMagCalibration7 (struct MagCalibration *pthisMagCal, struct MagBuffer *pthisMagBuffer, struct MagSensor *pthisMag) |
| void | fComputeMagCalibration10 (struct MagCalibration *pthisMagCal, struct MagBuffer *pthisMagBuffer, struct MagSensor *pthisMag) |
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.c.
| void fComputeMagCalibration10 | ( | struct MagCalibration * | pthisMagCal, |
| struct MagBuffer * | pthisMagBuffer, | ||
| struct MagSensor * | pthisMag | ||
| ) |
Definition at line 1791 of file magnetic.c.
| void fComputeMagCalibration4 | ( | struct MagCalibration * | pthisMagCal, |
| struct MagBuffer * | pthisMagBuffer, | ||
| struct MagSensor * | pthisMag | ||
| ) |
Definition at line 1433 of file magnetic.c.
| void fComputeMagCalibration7 | ( | struct MagCalibration * | pthisMagCal, |
| struct MagBuffer * | pthisMagBuffer, | ||
| struct MagSensor * | pthisMag | ||
| ) |
Definition at line 1628 of file magnetic.c.
| void fInitializeMagCalibration | ( | struct MagCalibration * | pthisMagCal, |
| struct MagBuffer * | pthisMagBuffer | ||
| ) |
Definition at line 27 of file magnetic.c.
| void fInvertMagCal | ( | struct MagSensor * | pthisMag, |
| struct MagCalibration * | pthisMagCal | ||
| ) |
Definition at line 286 of file magnetic.c.
| 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.
| pthisMagCal | struct containing details of the current calibration. |
| pthisMagBuffer | buffer of readings to be used for new calibration. |
| pthisMag | current magnetic reading. |
| loopcounter | counts iterations of fusion algorithm. Used in timeslicing. |
Definition at line 352 of file magnetic.c.
| void fUpdateMagCalibration10Slice | ( | struct MagCalibration * | pthisMagCal, |
| struct MagBuffer * | pthisMagBuffer, | ||
| struct MagSensor * | pthisMag | ||
| ) |
Definition at line 1000 of file magnetic.c.
| void fUpdateMagCalibration4Slice | ( | struct MagCalibration * | pthisMagCal, |
| struct MagBuffer * | pthisMagBuffer, | ||
| struct MagSensor * | pthisMag | ||
| ) |
Definition at line 482 of file magnetic.c.
| void fUpdateMagCalibration7Slice | ( | struct MagCalibration * | pthisMagCal, |
| struct MagBuffer * | pthisMagBuffer, | ||
| struct MagSensor * | pthisMag | ||
| ) |
Definition at line 713 of file magnetic.c.
| void iUpdateMagBuffer | ( | struct MagBuffer * | pthisMagBuffer, |
| struct MagSensor * | pthisMag, | ||
| int32_t | loopcounter | ||
| ) |
Definition at line 92 of file magnetic.c.