2 // Copyright (c) 2015 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __CALIBRATION_H__
18 #define __CALIBRATION_H__
22 #define MAGN_DS_SIZE 32
26 /* hard iron offsets */
29 /* soft iron matrix */
30 double w_invert[3][3];
32 /* geomagnetic strength */
36 float sample[MAGN_DS_SIZE][3];
37 unsigned int sample_count;
44 float bias_x, bias_y, bias_z;
46 float min_x, min_y, min_z;
47 float max_x, max_y, max_z;
51 /* Accelerometer bias estimation and compensation */
53 #define BUCKET_COUNT 3
54 #define BUCKET_TOLERANCE 2.5 /* Maximum monitoring distance from value of interest, in m/s² */
55 #define SLICES 100 /* We currently have 3 buckets per axis, and 100 slices per bucket ; then we distribute incoming samples among slices */
62 float bucket_tolerance;
64 uint64_t bucket[3][BUCKET_COUNT][SLICES]; /* How many samples fell in each of the slices, per axis */
65 uint64_t bucket_usage[3][BUCKET_COUNT]; /* How many samples fell in each of the buckets (= sum of the slice counts) */
67 /* Estimated bias, according to accumulated data */
72 uint64_t last_estimation_ts;
77 typedef double mat_input_t[MAGN_DS_SIZE][3];
80 void calibrate_compass (int s, sensors_event_t* event);
81 void compass_read_data (int s);
82 void compass_store_data (int s);
84 void calibrate_gyro (int s, sensors_event_t* event);
85 void gyro_cal_init (int s);
86 void gyro_store_data (int s);
88 void calibrate_accel (int s, sensors_event_t* event);
89 void accel_cal_init (int s);
90 void accel_cal_store (int s);