OSDN Git Service

GMIN-3044: Fix a few edge cases in filtering code
[android-x86/hardware-intel-libsensors.git] / calibration.h
1 /*
2  * Copyright (C) 2014 Intel Corporation.
3  */
4
5 #ifndef __CALIBRATION_H__
6 #define __CALIBRATION_H__
7
8 #include "common.h"
9
10 /* compass defines */
11 #define COMPASS_CALIBRATION_PATH "/data/compass.conf"
12 #define DS_SIZE 32
13 #define EPSILON 0.000000001
14 #define CAL_STEPS 4
15
16 /* We'll have multiple calibration levels
17 *  so that we can provide an estimation as fast as possible
18 */
19 static const float min_diffs[CAL_STEPS] =  { 0.2, 0.4, 0.6, 1.0 };
20 static const float max_sqr_errs[CAL_STEPS] = { 10.0, 8.0, 5.0, 3.5 };
21 static const unsigned int lookback_counts[CAL_STEPS] = { 3, 4, 5, 6 };
22
23
24 #ifdef DBG_RAW_DATA
25 #define RAW_DATA_FULL_PATH "/data/raw_compass_data_full_%d.txt"
26 #define RAW_DATA_SELECTED_PATH "/data/raw_compass_data_selected_%d.txt"
27 #endif
28
29 /* gyro defines */
30 #define GYRO_MAX_ERR 0.05f
31 #define GYRO_DS_SIZE 8
32
33 struct compass_cal {
34     /* hard iron offsets */
35     double offset[3][1];
36
37     /* soft iron matrix */
38     double w_invert[3][3];
39
40     /* geomagnetic strength */
41     double bfield;
42
43     /* selection data */
44     float sample[DS_SIZE][3];
45     unsigned int sample_count;
46 };
47
48 struct gyro_cal {
49     float bias[3];
50     int start;
51     int count;
52     float sample[GYRO_DS_SIZE][3];
53 };
54
55 typedef double mat_input_t[DS_SIZE][3];
56
57 void calibrate_compass (struct sensors_event_t* event, struct sensor_info_t* info, int64_t time);
58 void compass_read_data (struct sensor_info_t* info);
59 void compass_store_data (struct sensor_info_t* info);
60
61 void calibrate_gyro(struct sensors_event_t* event, struct sensor_info_t* info);
62 void gyro_cal_init(struct sensor_info_t* info);
63 #endif