| ISF 2.1 Intelligent Sensing Framework for Kinetis with Processor Expert

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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
33 struct MagneticBuffer
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
42 struct MagCalibration
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
MagneticBuffer
Definition: magnetic.h:33
MagneticBuffer::iBp
int16 iBp[3][MAGBUFFSIZEX][MAGBUFFSIZEY]
Definition: magnetic.h:35
MagCalibration::fvecA
float fvecA[10]
Definition: magnetic.h:57
MagCalibration::fV
float fV[3]
Definition: magnetic.h:44
MagneticBuffer::tanarray
int16 tanarray[MAGBUFFSIZEX-1]
Definition: magnetic.h:37
MagCalibration::ftrinvW
float ftrinvW[3][3]
Definition: magnetic.h:50
fUpdateCalibration7EIG
void fUpdateCalibration7EIG(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
Definition: magnetic.c:522
MagCalibration::fmatA
float fmatA[10][10]
Definition: magnetic.h:55
fUpdateCalibration10EIG
void fUpdateCalibration10EIG(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
Definition: magnetic.c:669
int8
signed char int8
Definition: basic_types.h:12
AccelSensor
Definition: sensor_data_types.h:28
MagCalibration::iValidMagCal
int8 iValidMagCal
Definition: magnetic.h:61
MagSensor
Definition: sensor_data_types.h:39
magnetic_config.h
MagCalibration::fA
float fA[3][3]
Definition: magnetic.h:53
MagneticBuffer::index
int32 index[MAGBUFFSIZEX][MAGBUFFSIZEY]
Definition: magnetic.h:36
MagCalibration::iCalInProgress
int8 iCalInProgress
Definition: magnetic.h:59
iUpdateMagnetometerBuffer
void iUpdateMagnetometerBuffer(struct MagneticBuffer *pthisMagBuffer, struct AccelSensor *pthisAccel, struct MagSensor *pthisMag, int32 loopcounter)
Definition: magnetic.c:79
MagCalibration::ftrV
float ftrV[3]
Definition: magnetic.h:49
MagCalibration::ftrFitErrorpc
float ftrFitErrorpc
Definition: magnetic.h:52
MAGBUFFSIZEX
#define MAGBUFFSIZEX
Definition: magnetic_config.h:26
MAGBUFFSIZEY
#define MAGBUFFSIZEY
Definition: magnetic_config.h:27
MagCalibration::fFitErrorpc
float fFitErrorpc
Definition: magnetic.h:48
MagCalibration::iMagCalHasRun
int8 iMagCalHasRun
Definition: magnetic.h:60
MagCalibration::fvecB
float fvecB[4]
Definition: magnetic.h:58
MagCalibration::finvA
float finvA[3][3]
Definition: magnetic.h:54
MagCalibration::fFourBsq
float fFourBsq
Definition: magnetic.h:47
MagCalibration::fB
float fB
Definition: magnetic.h:46
int32
long int32
This defines int32 as long.
Definition: isf_types.h:32
fUpdateCalibration4INV
void fUpdateCalibration4INV(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
Definition: magnetic.c:344
int16
short int16
This defines int16 as short.
Definition: isf_types.h:23
MagCalibration
Definition: magnetic.h:42
sensor_data_types.h
fInvertMagCal
void fInvertMagCal(struct MagSensor *pthisMag, struct MagCalibration *pthisMagCal)
Definition: magnetic.c:247
MagCalibration::fmatB
float fmatB[10][10]
Definition: magnetic.h:56
fRunMagCalibration
void fRunMagCalibration(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer, struct MagSensor *pthisMag)
Definition: magnetic.c:270
MagCalibration::ftrB
float ftrB
Definition: magnetic.h:51
MagneticBuffer::iMagBufferCount
int16 iMagBufferCount
Definition: magnetic.h:38
fInitMagCalibration
void fInitMagCalibration(struct MagCalibration *pthisMagCal, struct MagneticBuffer *pthisMagBuffer)
Definition: magnetic.c:42
MagCalibration::finvW
float finvW[3][3]
Definition: magnetic.h:45
- © Freescale Semiconductor, Inc. 2015. All Rights Reserved.