2 * Copyright (C) 2014 Intel Corporation.
5 #ifndef __CALIBRATION_H__
6 #define __CALIBRATION_H__
11 #define COMPASS_CALIBRATION_PATH "/data/compass.conf"
13 #define EPSILON 0.000000001
16 #define MAGNETIC_LOW 960 /* 31 micro tesla squared */
17 #define MAGNETIC_HIGH 3600 /* 60 micro tesla squared */
19 /* We'll have multiple calibration levels
20 * so that we can provide an estimation as fast as possible
22 static const float min_diffs[CAL_STEPS] = { 0.2, 0.4, 0.6, 1.0 };
23 static const float max_sqr_errs[CAL_STEPS] = { 10.0, 8.0, 5.0, 3.5 };
24 static const unsigned int lookback_counts[CAL_STEPS] = { 3, 4, 5, 6 };
28 #define RAW_DATA_FULL_PATH "/data/raw_compass_data_full_%d.txt"
29 #define RAW_DATA_SELECTED_PATH "/data/raw_compass_data_selected_%d.txt"
33 #define GYRO_MAX_ERR 0.05f
34 #define GYRO_DS_SIZE 100
37 /* hard iron offsets */
40 /* soft iron matrix */
41 double w_invert[3][3];
43 /* geomagnetic strength */
47 float sample[DS_SIZE][3];
48 unsigned int sample_count;
52 float bias_x, bias_y, bias_z;
54 float min_x, min_y, min_z;
55 float max_x, max_y, max_z;
58 typedef double mat_input_t[DS_SIZE][3];
60 void calibrate_compass (struct sensors_event_t* event, struct sensor_info_t* info, int64_t time);
61 void compass_read_data (struct sensor_info_t* info);
62 void compass_store_data (struct sensor_info_t* info);
64 void calibrate_gyro(struct sensors_event_t* event, struct sensor_info_t* info);
65 void gyro_cal_init(struct sensor_info_t* info);