ISSDK  1.8
IoT Sensing Software Development Kit
precisionAccelerometer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /*! \file precisionAccelerometer.h
10  \brief Implements accelerometer calibration routines
11 */
12 
13 #ifndef PRECISIONACCELEROMETER_H
14 #define PRECISIONACCELEROMETER_H
15 
16 /// calibration constants
17 #define ACCEL_CAL_AVERAGING_SECS 2 ///< calibration measurement averaging period (s)
18 #define MAX_ACCEL_CAL_ORIENTATIONS 12 ///< number of stored precision accelerometer measurements
19 
20 /// accelerometer measurement buffer
21 typedef struct AccelBuffer
22 {
23  float fGsStored[MAX_ACCEL_CAL_ORIENTATIONS][3]; ///< uncalibrated accelerometer measurements (g)
24  float fSumGs[3]; ///< averaging sum for current storage location
25  int16_t iStoreCounter; ///< number of remaining iterations at FUSION_HZ to average measurement
26  int16_t iStoreLocation; ///< -1 for none, 0 to 11 for the 12 storage locations
27  int16_t iStoreFlags; ///< denotes which measurements are present
28 } AccelBuffer;
29 
30 /// precision accelerometer calibration structure
31 typedef struct AccelCalibration
32 {
33  // start of elements stored in flash memory
34  float fV[3]; ///< offset vector (g)
35  float finvW[3][3]; ///< inverse gain matrix
36  float fR0[3][3]; ///< forward rotation matrix for measurement 0
37  // end of elements stored in flash memory
38  float fmatA[10][10]; ///< scratch 10x10 matrix used by calibration algorithms
39  float fmatB[10][10]; ///< scratch 10x10 matrix used by calibration algorithms
40  float fvecA[10]; ///< scratch 10x1 vector used by calibration algorithms
41  float fvecB[4]; ///< scratch 4x1 vector used by calibration algorithms
42  float fA[3][3]; ///< ellipsoid matrix A
43  float finvA[3][3]; ///< inverse of the ellipsoid matrix A
45 
46 struct AccelSensor; // actual typedef is located in sensor_fusion_types.h
47 
48 // function prototypes for functions in precisionAcclerometer.c
49 /// Initialize the accelerometer calibration functions
51  struct AccelCalibration *pthisAccelCal, ///< Accelerometer calibration parameter structure
52  struct AccelBuffer *pthisAccelBuffer, ///< Buffer of measurements used as input to the accel calibration functions
53  volatile int8_t *AccelCalPacketOn ///< Used to coordinate calibration sample storage and communications
54 );
55 /// Update the buffer used to store samples used for accelerometer calibration.
57  struct AccelCalibration *pthisAccelCal, ///< Accelerometer calibration parameter structure
58  struct AccelBuffer *pthisAccelBuffer, ///< Buffer of measurements used as input to the accel calibration functions
59  struct AccelSensor* pthisAccel, ///< Pointer to the accelerometer input/state structure
60  volatile int8_t *AccelCalPacketOn ///< Used to coordinate calibration sample storage and communications
61 );
62 /// function maps the accelerometer data fGs (g) onto precision calibrated and de-rotated data fGc (g), iGc (counts)
63 void fInvertAccelCal(
64  struct AccelSensor *pthisAccel, ///< Pointer to the accelerometer input/state structure
65  struct AccelCalibration *pthisAccelCal ///< Accelerometer calibration parameter structure
66 );
67 /// function runs the precision accelerometer calibration
69  struct AccelCalibration *pthisAccelCal, ///< Accelerometer calibration parameter structure
70  struct AccelBuffer *pthisAccelBuffer, ///< Buffer of measurements used as input to the accel calibration functions
71  struct AccelSensor* pthisAccel ///< Pointer to the accelerometer input/state structure
72 );
73 /// calculate the 4 element calibration from the available measurements
75  struct AccelBuffer *pthisAccelBuffer, ///< Buffer of measurements used as input to the accel calibration functions
76  struct AccelCalibration *pthisAccelCal, ///< Accelerometer calibration parameter structure
77  struct AccelSensor* pthisAccel ///< Pointer to the accelerometer input/state structure
78 );
79 /// calculate the 7 element calibration from the available measurements
81  struct AccelBuffer *pthisAccelBuffer, ///< Buffer of measurements used as input to the accel calibration functions
82  struct AccelCalibration *pthisAccelCal, ///< Accelerometer calibration parameter structure
83  struct AccelSensor* pthisAccel ///< Pointer to the accelerometer input/state structure
84 );
85 /// calculate the 10 element calibration from the available measurements
87  struct AccelBuffer *pthisAccelBuffer, ///< Buffer of measurements used as input to the accel calibration functions
88  struct AccelCalibration *pthisAccelCal, ///< Accelerometer calibration parameter structure
89  struct AccelSensor* pthisAccel ///< Pointer to the accelerometer input/state structure
90 );
91 
92 #endif // PRECISIONACCELEROMETER_H
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.
void fComputeAccelCalibration10(struct AccelBuffer *pthisAccelBuffer, struct AccelCalibration *pthisAccelCal, struct AccelSensor *pthisAccel)
calculate the 10 element calibration from the available measurements
int16_t iStoreCounter
number of remaining iterations at FUSION_HZ to average measurement
struct AccelBuffer AccelBuffer
accelerometer measurement buffer
void fRunAccelCalibration(struct AccelCalibration *pthisAccelCal, struct AccelBuffer *pthisAccelBuffer, struct AccelSensor *pthisAccel)
function runs the precision accelerometer calibration
The AccelSensor structure stores raw and processed measurements for a 3-axis accelerometer.
void fInitializeAccelCalibration(struct AccelCalibration *pthisAccelCal, struct AccelBuffer *pthisAccelBuffer, volatile int8_t *AccelCalPacketOn)
Initialize the accelerometer calibration functions.
precision accelerometer calibration structure
int16_t iStoreFlags
denotes which measurements are present
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
void fComputeAccelCalibration7(struct AccelBuffer *pthisAccelBuffer, struct AccelCalibration *pthisAccelCal, struct AccelSensor *pthisAccel)
calculate the 7 element calibration from the available measurements
float fGsStored[MAX_ACCEL_CAL_ORIENTATIONS][3]
uncalibrated accelerometer measurements (g)
float fSumGs[3]
averaging sum for current storage location
void fComputeAccelCalibration4(struct AccelBuffer *pthisAccelBuffer, struct AccelCalibration *pthisAccelCal, struct AccelSensor *pthisAccel)
calculate the 4 element calibration from the available measurements
int16_t iStoreLocation
-1 for none, 0 to 11 for the 12 storage locations
#define MAX_ACCEL_CAL_ORIENTATIONS
number of stored precision accelerometer measurements