ISF  2.1
Intelligent Sensing Framework for Kinetis with Processor Expert
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
magnetic.h
Go to the documentation of this file.
1 // Copyright (c) 2014, Freescale Semiconductor, Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of Freescale Semiconductor, Inc. nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL FREESCALE SEMICONDUCTOR, INC. BE LIABLE FOR ANY
19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 #ifndef MAGNETIC_H
27 #define MAGNETIC_H
28 
29 #include "sensor_data_types.h"
30 #include "magnetic_config.h"
31 
32 // magnetometer measurement buffer
34 {
35  int16 iBp[3][MAGBUFFSIZEX][MAGBUFFSIZEY]; // uncalibrated magnetometer readings
36  int32 index[MAGBUFFSIZEX][MAGBUFFSIZEY]; // array of time indices
37  int16 tanarray[MAGBUFFSIZEX - 1]; // array of tangents of (100 * angle)
38  int16 iMagBufferCount; // number of magnetometer readings
39 };
40 
41 // magnetic calibration structure
43 {
44  float fV[3]; // current hard iron offset x, y, z, (uT)
45  float finvW[3][3]; // current inverse soft iron matrix
46  float fB; // current geomagnetic field magnitude (uT)
47  float fFourBsq; // current 4*B*B (uT^2)
48  float fFitErrorpc; // current fit error %
49  float ftrV[3]; // trial value of hard iron offset z, y, z (uT)
50  float ftrinvW[3][3]; // trial inverse soft iron matrix size
51  float ftrB; // trial value of geomagnetic field magnitude in uT
52  float ftrFitErrorpc; // trial value of fit error %
53  float fA[3][3]; // ellipsoid matrix A
54  float finvA[3][3]; // inverse of ellipsoid matrix A
55  float fmatA[10][10]; // scratch 10x10 matrix used by calibration algorithms
56  float fmatB[10][10]; // scratch 10x10 matrix used by calibration algorithms
57  float fvecA[10]; // scratch 10x1 vector used by calibration algorithms
58  float fvecB[4]; // scratch 4x1 vector used by calibration algorithms
59  int8 iCalInProgress; // flag denoting that a calibration is in progress
60  int8 iMagCalHasRun; // flag denoting that at least one calibration has been launched
61  int8 iValidMagCal; // integer value 0, 4, 7, 10 denoting both valid calibration and solver used
62 };
63 
64 // function prototypes for functions in magnetic.c
65 void fInitMagCalibration(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer);
66 void iUpdateMagnetometerBuffer(struct MagneticBuffer *pthisMagBuffer, struct AccelSensor *pthisAccel,
67  struct MagSensor *pthisMag, int32 loopcounter);
68 
69 void fRunMagCalibration(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer, struct MagSensor *pthisMag);
70 void fInvertMagCal(struct MagSensor *pthisMag, struct MagCalibration *pthisMagCal);
71 void fUpdateCalibration4INV(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer, struct MagSensor *pthisMag);
72 void fUpdateCalibration7EIG(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer, struct MagSensor *pthisMag);
73 void fUpdateCalibration10EIG(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer, struct MagSensor *pthisMag);
74 
75 #endif // #ifndef MAGNETIC_H
int16 iBp[3][MAGBUFFSIZEX][MAGBUFFSIZEY]
Definition: magnetic.h:35
float fvecA[10]
Definition: magnetic.h:57
float fV[3]
Definition: magnetic.h:44
int16 tanarray[MAGBUFFSIZEX-1]
Definition: magnetic.h:37
float ftrinvW[3][3]
Definition: magnetic.h:50
void fUpdateCalibration7EIG(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
Definition: magnetic.c:522
float fmatA[10][10]
Definition: magnetic.h:55
void fUpdateCalibration10EIG(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
Definition: magnetic.c:669
signed char int8
Definition: basic_types.h:12
int8 iValidMagCal
Definition: magnetic.h:61
float fA[3][3]
Definition: magnetic.h:53
int32 index[MAGBUFFSIZEX][MAGBUFFSIZEY]
Definition: magnetic.h:36
int8 iCalInProgress
Definition: magnetic.h:59
void iUpdateMagnetometerBuffer(struct MagneticBuffer *pthisMagBuffer, struct AccelSensor *pthisAccel, struct MagSensor *pthisMag, int32 loopcounter)
Definition: magnetic.c:79
float ftrV[3]
Definition: magnetic.h:49
float ftrFitErrorpc
Definition: magnetic.h:52
#define MAGBUFFSIZEX
#define MAGBUFFSIZEY
float fFitErrorpc
Definition: magnetic.h:48
int8 iMagCalHasRun
Definition: magnetic.h:60
float fvecB[4]
Definition: magnetic.h:58
float finvA[3][3]
Definition: magnetic.h:54
float fFourBsq
Definition: magnetic.h:47
long int32
This defines int32 as long.
Definition: isf_types.h:32
void fUpdateCalibration4INV(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
Definition: magnetic.c:344
short int16
This defines int16 as short.
Definition: isf_types.h:23
void fInvertMagCal(struct MagSensor *pthisMag, struct MagCalibration *pthisMagCal)
Definition: magnetic.c:247
float fmatB[10][10]
Definition: magnetic.h:56
void fRunMagCalibration(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
Definition: magnetic.c:270
float ftrB
Definition: magnetic.h:51
int16 iMagBufferCount
Definition: magnetic.h:38
void fInitMagCalibration(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer)
Definition: magnetic.c:42
float finvW[3][3]
Definition: magnetic.h:45