1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* 18 * This module contains a data structure and corresponding helper functions for 19 * a three-axis sensor calibration. The calibration consists of a bias vector, 20 * bias, and a lower-diagonal scaling and skew matrix, scale_skew_mat. 21 * 22 * The calibration is applied to impaired sensor data as follows: 23 * 24 * corrected_data = scale_skew_mat * (impaired_data - bias). 25 */ 26 27 #ifndef LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_SPHERE_FIT_CALIBRATION_DATA_H_ 28 #define LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_SPHERE_FIT_CALIBRATION_DATA_H_ 29 30 #include <stdint.h> 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #define THREE_AXIS_DIM (3) 37 38 // Calibration data structure. 39 struct ThreeAxisCalData { 40 // Scale factor and skew terms. Used to construct the following lower 41 // diagonal scale_skew_mat: 42 // scale_skew_mat = [scale_factor_x 0 0 43 // skew_yx scale_factor_y 0 44 // skew_zx skew_zy scale_factor_z]. 45 float scale_factor_x; 46 float scale_factor_y; 47 float scale_factor_z; 48 float skew_yx; 49 float skew_zx; 50 float skew_zy; 51 52 // Sensor bias offset. 53 float bias[THREE_AXIS_DIM]; 54 55 // Calibration time. 56 uint64_t calibration_time_nanos; 57 }; 58 59 // Set calibration data to identity scale factors, zero skew and 60 // zero bias. 61 void calDataReset(struct ThreeAxisCalData* calstruct); 62 63 // Apply a stored calibration to correct a single sample of impaired sensor 64 // data. 65 void calDataCorrectData(const struct ThreeAxisCalData* calstruct, 66 const float x_impaired[THREE_AXIS_DIM], 67 float* x_corrected); 68 69 #ifdef __cplusplus 70 } 71 #endif 72 73 #endif // LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_SPHERE_FIT_CALIBRATION_DATA_H_ 74