From 4e524d7125abc416ad4f0a652d802958e16d86e6 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 11 Jul 2013 12:10:15 -0700 Subject: [PATCH] Compass tweaks: better initial extents, scale extents to compensate for anisotropy, converge more quickly on compass heading. --- interface/src/SerialInterface.cpp | 4 ++-- interface/src/SerialInterface.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/SerialInterface.cpp b/interface/src/SerialInterface.cpp index 733ba0386f..aac1f8f1f2 100644 --- a/interface/src/SerialInterface.cpp +++ b/interface/src/SerialInterface.cpp @@ -31,7 +31,7 @@ const short NO_READ_MAXIMUM_MSECS = 3000; const int GRAVITY_SAMPLES = 60; // Use the first few samples to baseline values const int NORTH_SAMPLES = 30; const int ACCELERATION_SENSOR_FUSION_SAMPLES = 20; -const int COMPASS_SENSOR_FUSION_SAMPLES = 200; +const int COMPASS_SENSOR_FUSION_SAMPLES = 100; const int LONG_TERM_RATE_SAMPLES = 1000; const bool USING_INVENSENSE_MPU9150 = 1; @@ -383,7 +383,7 @@ void SerialInterface::resetSerial() { glm::vec3 SerialInterface::recenterCompass(const glm::vec3& compass) { // compensate for "hard iron" distortion by subtracting the midpoint on each axis; see // http://www.sensorsmag.com/sensors/motion-velocity-displacement/compensating-tilt-hard-iron-and-soft-iron-effects-6475 - return compass - (_compassMinima + _compassMaxima) * 0.5f; + return (compass - (_compassMinima + _compassMaxima) * 0.5f) / (_compassMaxima - _compassMinima); } diff --git a/interface/src/SerialInterface.h b/interface/src/SerialInterface.h index 555f2bac58..6398953456 100644 --- a/interface/src/SerialInterface.h +++ b/interface/src/SerialInterface.h @@ -33,8 +33,8 @@ public: _estimatedVelocity(0, 0, 0), _lastAcceleration(0, 0, 0), _lastRotationRates(0, 0, 0), - _compassMinima(-235, -132, -184), // experimentally derived initial values follow - _compassMaxima(83, 155, 120), + _compassMinima(-211, -132, -186), + _compassMaxima(89, 95, 98), _angularVelocityToLinearAccel( 0.003f, -0.001f, -0.006f, -0.005f, -0.001f, -0.006f,