oculus1

diff libovr/Src/Util/Util_MagCalibration.h @ 1:e2f9e4603129

added LibOVR and started a simple vr wrapper.
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Sep 2013 16:14:59 +0300
parents
children b069a5c27388
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libovr/Src/Util/Util_MagCalibration.h	Sat Sep 14 16:14:59 2013 +0300
     1.3 @@ -0,0 +1,1 @@
     1.4 +/************************************************************************************
     1.5 
     1.6 PublicHeader:   OVR.h
     1.7 Filename    :   Util_MagCalibration.h
     1.8 Content     :   Procedures for calibrating the magnetometer
     1.9 Created     :   April 16, 2013
    1.10 Authors     :   Steve LaValle, Andrew Reisse
    1.11 
    1.12 Copyright   :   Copyright 2013 Oculus VR, Inc. All Rights reserved.
    1.13 
    1.14 Use of this software is subject to the terms of the Oculus license
    1.15 agreement provided at the time of installation or download, or which
    1.16 otherwise accompanies this software in either electronic or hard copy form.
    1.17 
    1.18 *************************************************************************************/
    1.19 
    1.20 #ifndef OVR_Util_MagCalibration_h
    1.21 #define OVR_Util_MagCalibration_h
    1.22 
    1.23 #include "../OVR_SensorFusion.h"
    1.24 #include "../Kernel/OVR_String.h"
    1.25 #include "../Kernel/OVR_Log.h"
    1.26 
    1.27 namespace OVR { namespace Util {
    1.28 
    1.29 class MagCalibration
    1.30 {
    1.31 public:
    1.32     enum MagStatus
    1.33     {
    1.34         Mag_Uninitialized = 0,
    1.35         Mag_AutoCalibrating = 1,
    1.36         Mag_ManuallyCalibrating = 2,
    1.37         Mag_Calibrated  = 3
    1.38     };
    1.39 
    1.40     MagCalibration() :
    1.41         Stat(Mag_Uninitialized),
    1.42         MinMagDistance(0.2f), MinQuatDistance(0.5f),
    1.43         SampleCount(0)
    1.44     {
    1.45         MinMagDistanceSq = MinMagDistance * MinMagDistance;
    1.46         MinQuatDistanceSq = MinQuatDistance * MinQuatDistance;
    1.47         MinMagValues = Vector3f(10000.0f,10000.0f,10000.0f);
    1.48         MaxMagValues = Vector3f(-10000.0f,-10000.0f,-10000.0f);
    1.49 		MinQuatValues = Quatf(1.0f,1.0f,1.0f,1.0f);
    1.50 		MaxQuatValues = Quatf(0.0f,0.0f,0.0f,0.0f);
    1.51 		}
    1.52 
    1.53     // Methods that are useful for either auto or manual calibration
    1.54     bool     IsUnitialized() const       { return Stat == Mag_Uninitialized; }
    1.55     bool     IsCalibrated() const        { return Stat == Mag_Calibrated; }
    1.56     int      NumberOfSamples() const     { return SampleCount; }
    1.57     int      RequiredSampleCount() const { return 4; }
    1.58 	void     AbortCalibration()
    1.59 	{
    1.60         Stat = Mag_Uninitialized;
    1.61         SampleCount = 0;
    1.62 	}
    1.63 
    1.64     void     ClearCalibration(SensorFusion& sf) 
    1.65     {
    1.66         Stat = Mag_Uninitialized;
    1.67         SampleCount = 0;
    1.68         sf.ClearMagCalibration();
    1.69 	};
    1.70   
    1.71     // Methods for automatic magnetometer calibration
    1.72     void     BeginAutoCalibration(SensorFusion& sf);
    1.73     unsigned UpdateAutoCalibration(SensorFusion& sf);
    1.74     bool     IsAutoCalibrating() const { return Stat == Mag_AutoCalibrating; }
    1.75 
    1.76     // Methods for building a manual (user-guided) calibraton procedure
    1.77     void     BeginManualCalibration(SensorFusion& sf);
    1.78     bool     IsAcceptableSample(const Quatf& q, const Vector3f& m);
    1.79     bool     InsertIfAcceptable(const Quatf& q, const Vector3f& m);
    1.80     // Returns true if successful, requiring that SampleCount = 4
    1.81     bool     SetCalibration(SensorFusion& sf);
    1.82     bool     IsManuallyCalibrating() const { return Stat == Mag_ManuallyCalibrating; }
    1.83 
    1.84     // This is the minimum acceptable distance (Euclidean) between raw
    1.85     // magnetometer values to be acceptable for usage in calibration.
    1.86     void SetMinMagDistance(float dist) 
    1.87     { 
    1.88         MinMagDistance = dist; 
    1.89         MinMagDistanceSq = MinMagDistance * MinMagDistance;
    1.90     }
    1.91 
    1.92     // The minimum acceptable distance (4D Euclidean) between orientations
    1.93     // to be acceptable for calibration usage.
    1.94     void SetMinQuatDistance(float dist) 
    1.95     { 
    1.96         MinQuatDistance = dist; 
    1.97         MinQuatDistanceSq = MinQuatDistance * MinQuatDistance;
    1.98     }
    1.99 
   1.100     // A result of the calibration, which is the center of a sphere that 
   1.101     // roughly approximates the magnetometer data.
   1.102     Vector3f GetMagCenter() const { return MagCenter; }
   1.103     // Retrieves the full magnetometer calibration matrix
   1.104     Matrix4f GetMagCalibration() const;
   1.105     // Retrieves the range of each quaternion term during calibration
   1.106     Quatf GetCalibrationQuatSpread() const { return QuatSpread; }
   1.107     // Retrieves the range of each magnetometer term during calibration
   1.108     Vector3f GetCalibrationMagSpread() const { return MagSpread; }
   1.109 
   1.110 private:
   1.111     // Determine the unique sphere through 4 non-coplanar points
   1.112     Vector3f CalculateSphereCenter(const Vector3f& p1, const Vector3f& p2,
   1.113                                    const Vector3f& p3, const Vector3f& p4);
   1.114 
   1.115     // Distance from p4 to the nearest point on a plane through p1, p2, p3
   1.116     float PointToPlaneDistance(const Vector3f& p1, const Vector3f& p2,
   1.117                                const Vector3f& p3, const Vector3f& p4);
   1.118 
   1.119     Vector3f MagCenter;
   1.120     unsigned Stat;
   1.121     float    MinMagDistance;
   1.122     float    MinQuatDistance;
   1.123     float    MinMagDistanceSq;
   1.124     float    MinQuatDistanceSq;
   1.125 	// For gathering statistics during calibration
   1.126 	Vector3f    MinMagValues;
   1.127 	Vector3f    MaxMagValues;
   1.128 	Vector3f    MagSpread;
   1.129 	Quatf		MinQuatValues;
   1.130 	Quatf		MaxQuatValues;
   1.131 	Quatf       QuatSpread;
   1.132 
   1.133     unsigned SampleCount;
   1.134     Vector3f MagSamples[4];
   1.135     Quatf    QuatSamples[4];
   1.136 
   1.137 };
   1.138 
   1.139 }}
   1.140 
   1.141 #endif
   1.142 \ No newline at end of file