From 828b55a7358ad5ec8bc27552bfb280eb173dd453 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Fri, 11 Sep 2015 12:02:26 -0700 Subject: common: Add magnetometer online calibration. 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 Reviewed-on: https://chromium-review.googlesource.com/299583 Reviewed-by: Anton Staaf --- common/vec3.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 common/vec3.c (limited to 'common/vec3.c') diff --git a/common/vec3.c b/common/vec3.c new file mode 100644 index 0000000000..12c33179c2 --- /dev/null +++ b/common/vec3.c @@ -0,0 +1,33 @@ +/* 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. + */ + +#include "common.h" +#include "math.h" +#include "math_util.h" +#include "vec3.h" +#include "util.h" + +void vec3_scalar_mul(vec3_t v, float c) +{ + v[X] *= c; + v[Y] *= c; + v[Z] *= c; +} + +float vec3_dot(const vec3_t v, const vec3_t w) +{ + return v[X] * w[X] + v[Y] * w[Y] + v[Z] * w[Z]; +} + +float vec3_norm_squared(const vec3_t v) +{ + return vec3_dot(v, v); +} + +float vec3_norm(const vec3_t v) +{ + return sqrtf(vec3_norm_squared(v)); +} + -- cgit v1.2.1