mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-29 18:11:05 +00:00
Code for hard iron calibration: Every seconds (or faster if enough samples), find a sphere that fit the compass data. Based on Android code. BRANCH=smaug BUG=chrome-os-partner:39900 TEST=Check hard-iron bias is removed. Works better outside. Change-Id: Iab479d5113b6560b4f01b0fd87373d2eecdb9b54 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/299583 Reviewed-by: Anton Staaf <robotboy@chromium.org>
47 lines
1.0 KiB
C
47 lines
1.0 KiB
C
/* Copyright 2015 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
/* Online magnetometer calibration */
|
|
|
|
#ifndef __CROS_EC_MAG_CAL_H
|
|
#define __CROS_EC_MAG_CAL_H
|
|
|
|
#include "math_util.h"
|
|
#include "mat44.h"
|
|
#include "vec4.h"
|
|
|
|
#define MAG_CAL_MAX_SAMPLES 0xffff
|
|
#define MAG_CAL_MIN_BATCH_WINDOW_US SECOND
|
|
#define MAG_CAL_MIN_BATCH_SIZE 25 /* samples */
|
|
|
|
struct mag_cal_t {
|
|
/*
|
|
* Matric for sphere fitting:
|
|
* +----+----+----+----+
|
|
* | xx | xy | xz | x |
|
|
* +----+----+----+----+
|
|
* | xy | yy | yz | y |
|
|
* +----+----+----+----+
|
|
* | xz | yz | zz | z |
|
|
* +----+----+----+----+
|
|
* | x | y | z | 1 |
|
|
* +----+----+----+----+
|
|
*/
|
|
mat44_t acc;
|
|
vec4_t acc_w;
|
|
float radius;
|
|
|
|
vector_3_t bias;
|
|
|
|
/* number of samples needed to calibrate */
|
|
uint16_t batch_size;
|
|
uint16_t nsamples;
|
|
};
|
|
|
|
void init_mag_cal(struct mag_cal_t *moc);
|
|
|
|
int mag_cal_update(struct mag_cal_t *moc, const vector_3_t v);
|
|
#endif /* __CROS_EC_MAG_CAL_H */
|