Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52e2cbdd authored by Khalid Zubair's avatar Khalid Zubair Committed by Rashed Abdel-Tawab
Browse files

sensorservice: customize sensor fusion mag filter via prop

When large magnetic fields values get filtered out by the Sensor
Fusion algorithm the fused sensors (rotation vector, gravity, linear
acceleration etc) do not produce any output. As a result the CTS tests
fail if the compass is uncalibrated on some devices.

This change allows the magnetic field filter to be tweaked on a
per-device basis to allow the fused sensors to operate even when the
compass in uncalibrated.

Change-Id: I608b307e8b7712e806315a6181c19130ec17c847
parent c205bfa9
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include <stdio.h>

#include <cutils/properties.h>
#include <utils/Log.h>

#include "Fusion.h"
@@ -78,9 +79,8 @@ static const float FREE_FALL_THRESHOLD = 0.1f * (NOMINAL_GRAVITY);
 * Fields strengths greater than this likely indicate a local magnetic
 * disturbance which we do not want to update into the fused frame.
 */
static const float MAX_VALID_MAGNETIC_FIELD = 100; // uT
static const float MAX_VALID_MAGNETIC_FIELD_SQ =
        MAX_VALID_MAGNETIC_FIELD*MAX_VALID_MAGNETIC_FIELD;
static const int MAX_VALID_MAGNETIC_FIELD = 100; // uT
#define MAX_VALID_MAGNETIC_FIELD_PROP "ro.fusion.magfield.max"

/*
 * Values of the field smaller than this should be ignored in fusion to avoid
@@ -187,6 +187,10 @@ Fusion::Fusion() {
    x0 = 0;
    x1 = 0;

    maxValidMagFieldSq = property_get_int32(
        MAX_VALID_MAGNETIC_FIELD_PROP, MAX_VALID_MAGNETIC_FIELD);
    maxValidMagFieldSq = maxValidMagFieldSq * maxValidMagFieldSq;

    init();
}

@@ -357,7 +361,7 @@ status_t Fusion::handleMag(const vec3_t& m) {
    // the geomagnetic-field should be between 30uT and 60uT
    // reject if too large to avoid spurious magnetic sources
    const float magFieldSq = length_squared(m);
    if (magFieldSq > MAX_VALID_MAGNETIC_FIELD_SQ) {
    if (magFieldSq > maxValidMagFieldSq) {
        return BAD_VALUE;
    } else if (magFieldSq < MIN_VALID_MAGNETIC_FIELD_SQ) {
        // Also reject if too small since we will get ill-defined (zero mag)
+5 −0
Original line number Diff line number Diff line
@@ -60,6 +60,11 @@ class Fusion {
     */
    mat<mat33_t, 2, 2> GQGt;

    /**
     * the maximum acceptable geomagnetic-field (square)
     */
    float maxValidMagFieldSq;

public:
    Fusion();
    void init(int mode = FUSION_9AXIS);