ISSDK  1.7
IoT Sensing Software Development Kit
precisionAccelerometer.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /*! \file precisionAccelerometer.h
36  \brief Implements accelerometer calibration routines
37 */
38 
39 #ifndef PRECISIONACCELEROMETER_H
40 #define PRECISIONACCELEROMETER_H
41 
42 /// calibration constants
43 #define ACCEL_CAL_AVERAGING_SECS 2 ///< calibration measurement averaging period (s)
44 #define MAX_ACCEL_CAL_ORIENTATIONS 12 ///< number of stored precision accelerometer measurements
45 
46 /// accelerometer measurement buffer
47 typedef struct AccelBuffer
48 {
49  float fGsStored[MAX_ACCEL_CAL_ORIENTATIONS][3]; ///< uncalibrated accelerometer measurements (g)
50  float fSumGs[3]; ///< averaging sum for current storage location
51  int16_t iStoreCounter; ///< number of remaining iterations at FUSION_HZ to average measurement
52  int16_t iStoreLocation; ///< -1 for none, 0 to 11 for the 12 storage locations
53  int16_t iStoreFlags; ///< denotes which measurements are present
54 } AccelBuffer;
55 
56 /// precision accelerometer calibration structure
57 typedef struct AccelCalibration
58 {
59  // start of elements stored in flash memory
60  float fV[3]; ///< offset vector (g)
61  float finvW[3][3]; ///< inverse gain matrix
62  float fR0[3][3]; ///< forward rotation matrix for measurement 0
63  // end of elements stored in flash memory
64  float fmatA[10][10]; ///< scratch 10x10 matrix used by calibration algorithms
65  float fmatB[10][10]; ///< scratch 10x10 matrix used by calibration algorithms
66  float fvecA[10]; ///< scratch 10x1 vector used by calibration algorithms
67  float fvecB[4]; ///< scratch 4x1 vector used by calibration algorithms
68  float fA[3][3]; ///< ellipsoid matrix A
69  float finvA[3][3]; ///< inverse of the ellipsoid matrix A
71 
72 struct AccelSensor; // actual typedef is located in sensor_fusion_types.h
73 
74 // function prototypes for functions in precisionAcclerometer.c
75 /// Initialize the accelerometer calibration functions
77  struct AccelCalibration *pthisAccelCal, ///< Accelerometer calibration parameter structure
78  struct AccelBuffer *pthisAccelBuffer, ///< Buffer of measurements used as input to the accel calibration functions
79  volatile int8_t *AccelCalPacketOn ///< Used to coordinate calibration sample storage and communications
80 );
81 /// Update the buffer used to store samples used for accelerometer calibration.
83  struct AccelCalibration *pthisAccelCal, ///< Accelerometer calibration parameter structure
84  struct AccelBuffer *pthisAccelBuffer, ///< Buffer of measurements used as input to the accel calibration functions
85  struct AccelSensor* pthisAccel, ///< Pointer to the accelerometer input/state structure
86  volatile int8_t *AccelCalPacketOn ///< Used to coordinate calibration sample storage and communications
87 );
88 /// function maps the accelerometer data fGs (g) onto precision calibrated and de-rotated data fGc (g), iGc (counts)
89 void fInvertAccelCal(
90  struct AccelSensor *pthisAccel, ///< Pointer to the accelerometer input/state structure
91  struct AccelCalibration *pthisAccelCal ///< Accelerometer calibration parameter structure
92 );
93 /// function runs the precision accelerometer calibration
95  struct AccelCalibration *pthisAccelCal, ///< Accelerometer calibration parameter structure
96  struct AccelBuffer *pthisAccelBuffer, ///< Buffer of measurements used as input to the accel calibration functions
97  struct AccelSensor* pthisAccel ///< Pointer to the accelerometer input/state structure
98 );
99 /// calculate the 4 element calibration from the available measurements
101  struct AccelBuffer *pthisAccelBuffer, ///< Buffer of measurements used as input to the accel calibration functions
102  struct AccelCalibration *pthisAccelCal, ///< Accelerometer calibration parameter structure
103  struct AccelSensor* pthisAccel ///< Pointer to the accelerometer input/state structure
104 );
105 /// calculate the 7 element calibration from the available measurements
107  struct AccelBuffer *pthisAccelBuffer, ///< Buffer of measurements used as input to the accel calibration functions
108  struct AccelCalibration *pthisAccelCal, ///< Accelerometer calibration parameter structure
109  struct AccelSensor* pthisAccel ///< Pointer to the accelerometer input/state structure
110 );
111 /// calculate the 10 element calibration from the available measurements
113  struct AccelBuffer *pthisAccelBuffer, ///< Buffer of measurements used as input to the accel calibration functions
114  struct AccelCalibration *pthisAccelCal, ///< Accelerometer calibration parameter structure
115  struct AccelSensor* pthisAccel ///< Pointer to the accelerometer input/state structure
116 );
117 
118 #endif // PRECISIONACCELEROMETER_H
int16_t iStoreLocation
-1 for none, 0 to 11 for the 12 storage locations
void fRunAccelCalibration(struct AccelCalibration *pthisAccelCal, struct AccelBuffer *pthisAccelBuffer, struct AccelSensor *pthisAccel)
function runs the precision accelerometer calibration
void fComputeAccelCalibration4(struct AccelBuffer *pthisAccelBuffer, struct AccelCalibration *pthisAccelCal, struct AccelSensor *pthisAccel)
calculate the 4 element calibration from the available measurements
struct AccelCalibration AccelCalibration
precision accelerometer calibration structure
void fUpdateAccelBuffer(struct AccelCalibration *pthisAccelCal, struct AccelBuffer *pthisAccelBuffer, struct AccelSensor *pthisAccel, volatile int8_t *AccelCalPacketOn)
Update the buffer used to store samples used for accelerometer calibration.
The AccelSensor structure stores raw and processed measurements for a 3-axis accelerometer.
float fSumGs[3]
averaging sum for current storage location
void fInitializeAccelCalibration(struct AccelCalibration *pthisAccelCal, struct AccelBuffer *pthisAccelBuffer, volatile int8_t *AccelCalPacketOn)
Initialize the accelerometer calibration functions.
void fInvertAccelCal(struct AccelSensor *pthisAccel, struct AccelCalibration *pthisAccelCal)
function maps the accelerometer data fGs (g) onto precision calibrated and de-rotated data fGc (g)...
accelerometer measurement buffer
int16_t iStoreFlags
denotes which measurements are present
int16_t iStoreCounter
number of remaining iterations at FUSION_HZ to average measurement
precision accelerometer calibration structure
void fComputeAccelCalibration7(struct AccelBuffer *pthisAccelBuffer, struct AccelCalibration *pthisAccelCal, struct AccelSensor *pthisAccel)
calculate the 7 element calibration from the available measurements
#define MAX_ACCEL_CAL_ORIENTATIONS
number of stored precision accelerometer measurements
float fGsStored[MAX_ACCEL_CAL_ORIENTATIONS][3]
uncalibrated accelerometer measurements (g)
struct AccelBuffer AccelBuffer
accelerometer measurement buffer
void fComputeAccelCalibration10(struct AccelBuffer *pthisAccelBuffer, struct AccelCalibration *pthisAccelCal, struct AccelSensor *pthisAccel)
calculate the 10 element calibration from the available measurements