2 * Copyright (C) 2014-2015 Intel Corporation.
5 #ifndef __CALIBRATION_H__
6 #define __CALIBRATION_H__
10 #define MAGN_DS_SIZE 32
14 /* hard iron offsets */
17 /* soft iron matrix */
18 double w_invert[3][3];
20 /* geomagnetic strength */
24 float sample[MAGN_DS_SIZE][3];
25 unsigned int sample_count;
32 float bias_x, bias_y, bias_z;
34 float min_x, min_y, min_z;
35 float max_x, max_y, max_z;
39 /* Accelerometer bias estimation and compensation */
41 #define BUCKET_COUNT 3
42 #define BUCKET_TOLERANCE 1 /* Maximum monitoring distance from value of interest, in m/s² */
43 #define SLICES 100 /* We currently have 3 buckets per axis, and 100 slices per bucket ; then we distribute incoming samples among slices */
50 float bucket_tolerance;
52 uint64_t bucket[3][BUCKET_COUNT][SLICES]; /* How many samples fell in each of the slices, per axis */
53 uint64_t bucket_usage[3][BUCKET_COUNT]; /* How many samples fell in each of the buckets (= sum of the slice counts) */
55 /* Estimated bias, according to accumulated data */
60 uint64_t last_estimation_ts;
65 typedef double mat_input_t[MAGN_DS_SIZE][3];
68 void calibrate_compass (int s, sensors_event_t* event);
69 void compass_read_data (int s);
70 void compass_store_data (int s);
72 void calibrate_gyro (int s, sensors_event_t* event);
73 void gyro_cal_init (int s);
74 void gyro_store_data (int s);
76 void calibrate_accel (int s, sensors_event_t* event);
77 void accel_cal_init (int s);
78 void accel_cal_store (int s);