diff options
author | Yuval Peress <peress@chromium.org> | 2019-10-24 14:29:06 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-08 01:42:46 +0000 |
commit | dc77f10578a33ef0d3450623bf5a648d42606d8b (patch) | |
tree | 739da5b3a151bafecb9e9f11f919d059428e873c /include/accel_cal.h | |
parent | 0fffe36e799cd7d0d0ecc7f28d01c332cdcebd57 (diff) | |
download | chrome-ec-dc77f10578a33ef0d3450623bf5a648d42606d8b.tar.gz |
common: Implement accelerometer calibration
This change implements the hybrid accelerometer calibration
algorithm described in
https://drive.google.com/corp/drive/u/0/folders/13k8AWvVkCg8KUr1HhD2qv6_ob1ixgCbE
1. Waits until the device is still
2. Adds a still sample to an orientation accumulator
- If the new sample is close to an existing one, they're
merged.
- If the new sample is unique, it is added to the list of
orientations in a FIFO manner (may be evicting an older
sample).
- Once enough orientations have been gathered, run the
kasa algorithm.
- The kasa algorithm should yield a radius that's near 1g,
since all the samples were added when still. If this isn't
the case, we fall back on newton's method (which takes
longer).
BUG=b:138303429,chromium:1023858
BRANCH=None
TEST=buildall with new unit tests
Change-Id: I98bb0d365017d8a916b008c7c0c263345a9cddac
Signed-off-by: Yuval Peress <peress@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1879716
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Diffstat (limited to 'include/accel_cal.h')
-rw-r--r-- | include/accel_cal.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/include/accel_cal.h b/include/accel_cal.h new file mode 100644 index 0000000000..cfba5b915d --- /dev/null +++ b/include/accel_cal.h @@ -0,0 +1,51 @@ +/* Copyright 2020 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 accelerometer calibration */ + +#ifndef __CROS_EC_ACCEL_CAL_H +#define __CROS_EC_ACCEL_CAL_H + +#include "kasa.h" +#include "newton_fit.h" +#include "stdbool.h" +#include "stillness_detector.h" + +struct accel_cal_algo { + struct kasa_fit kasa_fit; + struct newton_fit newton_fit; +}; + +struct accel_cal { + struct still_det still_det; + struct accel_cal_algo *algos; + uint8_t num_temp_windows; + fpv3_t bias; +}; + +/** + * Reset the accelerometer calibration object. This should only be called + * once. The struct will reset automatically in accel_cal_accumulate when + * a new calibration is computed. + * + * @param cal Pointer to the accel_cal struct to reset. + */ +void accel_cal_reset(struct accel_cal *cal); + +/** + * Add new reading to the accelerometer calibration. + * + * @param cal Pointer to the accel_cal struct to update. + * @param sample_time The timestamp when the sample was taken. + * @param x X component of the new reading. + * @param y Y component of the new reading. + * @param z Z component of the new reading. + * @param temp The sensor's internal temperature in degrees C. + * @return True if a new bias is available. + */ +bool accel_cal_accumulate(struct accel_cal *cal, uint32_t sample_time, fp_t x, + fp_t y, fp_t z, fp_t temp); + +#endif /* __CROS_EC_ACCEL_CAL_H */ |