X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=calibration.h;h=2d17e7a113a2ad0c274f0fb688b46d80b03696af;hb=refs%2Ftags%2Fandroid-x86-8.1-r1;hp=052998cf528d64e0b0f3060be9a1c0829accdf8b;hpb=d9e2fa59dd45048bfee445cf5f5052bb35227d6a;p=android-x86%2Fhardware-intel-libsensors.git diff --git a/calibration.h b/calibration.h index 052998c..2d17e7a 100644 --- a/calibration.h +++ b/calibration.h @@ -1,39 +1,27 @@ /* - * Copyright (C) 2014 Intel Corporation. - */ +// Copyright (c) 2015 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +*/ #ifndef __CALIBRATION_H__ #define __CALIBRATION_H__ #include "common.h" -/* compass defines */ -#define COMPASS_CALIBRATION_PATH "/data/compass.conf" -#define DS_SIZE 48 -#define EPSILON 0.000000001 +#define MAGN_DS_SIZE 32 -/* If no cal data is present - first calibration will - use a more relaxed set of values to get an initial - calibration faster */ -#define FIRST_MIN_DIFF 0.5f -#define FIRST_MAX_SQR_ERR 5.0f -#define FIRST_LOOKBACK_COUNT 4 - -#define MIN_DIFF 1.0f -#define MAX_SQR_ERR 3.5f -#define LOOKBACK_COUNT 6 - - -#ifdef DBG_RAW_DATA -#define RAW_DATA_FULL_PATH "/data/raw_compass_data_full_%d.txt" -#define RAW_DATA_SELECTED_PATH "/data/raw_compass_data_selected_%d.txt" -#endif - -/* gyro defines */ -#define GYRO_MAX_ERR 0.05f -#define GYRO_DS_SIZE 8 - typedef struct { /* hard iron offsets */ double offset[3][1]; @@ -44,21 +32,61 @@ typedef struct { /* geomagnetic strength */ double bfield; -} calibration_data; + /* selection data */ + float sample[MAGN_DS_SIZE][3]; + unsigned int sample_count; + float average[3]; +} +compass_cal_t; + -struct gyro_cal { - float bias[3]; - int start; +typedef struct { + float bias_x, bias_y, bias_z; int count; - float sample[GYRO_DS_SIZE][3]; -}; + float min_x, min_y, min_z; + float max_x, max_y, max_z; +} +gyro_cal_t; + +/* Accelerometer bias estimation and compensation */ + +#define BUCKET_COUNT 3 +#define BUCKET_TOLERANCE 2.5 /* Maximum monitoring distance from value of interest, in m/s² */ +#define SLICES 100 /* We currently have 3 buckets per axis, and 100 slices per bucket ; then we distribute incoming samples among slices */ + +typedef struct +{ + int version; + int bucket_count; + int slices; + float bucket_tolerance; + + uint64_t bucket[3][BUCKET_COUNT][SLICES]; /* How many samples fell in each of the slices, per axis */ + uint64_t bucket_usage[3][BUCKET_COUNT]; /* How many samples fell in each of the buckets (= sum of the slice counts) */ + + /* Estimated bias, according to accumulated data */ + float accel_bias_x; + float accel_bias_y; + float accel_bias_z; + + uint64_t last_estimation_ts; +} +accel_cal_t; + + +typedef double mat_input_t[MAGN_DS_SIZE][3]; + + +void calibrate_compass (int s, sensors_event_t* event); +void compass_read_data (int s); +void compass_store_data (int s); -typedef double mat_input_t[DS_SIZE][3]; +void calibrate_gyro (int s, sensors_event_t* event); +void gyro_cal_init (int s); +void gyro_store_data (int s); -void calibrate_compass (struct sensors_event_t* event, int64_t time); -void compass_read_data (const char* config_path); -void compass_store_data (const char* config_path); +void calibrate_accel (int s, sensors_event_t* event); +void accel_cal_init (int s); +void accel_cal_store (int s); -void calibrate_gyro(struct sensors_event_t* event, struct sensor_info_t* info); -void gyro_cal_init(struct sensor_info_t* info); #endif