Util_MagCalibration.h
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 PublicHeader:   OVR.h
00004 Filename    :   Util_MagCalibration.h
00005 Content     :   Procedures for calibrating the magnetometer
00006 Created     :   April 16, 2013
00007 Authors     :   Steve LaValle, Andrew Reisse
00008 
00009 Copyright   :   Copyright 2013 Oculus VR, Inc. All Rights reserved.
00010 
00011 Use of this software is subject to the terms of the Oculus license
00012 agreement provided at the time of installation or download, or which
00013 otherwise accompanies this software in either electronic or hard copy form.
00014 
00015 *************************************************************************************/
00016 
00017 #ifndef OVR_Util_MagCalibration_h
00018 #define OVR_Util_MagCalibration_h
00019 
00020 #include "../OVR_SensorFusion.h"
00021 #include "../Kernel/OVR_String.h"
00022 #include "../Kernel/OVR_Log.h"
00023 
00024 namespace OVR { namespace Util {
00025 
00026 class MagCalibration
00027 {
00028 public:
00029     enum MagStatus
00030     {
00031         Mag_Uninitialized = 0,
00032         Mag_AutoCalibrating = 1,
00033         Mag_ManuallyCalibrating = 2,
00034         Mag_Calibrated  = 3
00035     };
00036 
00037     MagCalibration() :
00038         Stat(Mag_Uninitialized),
00039         MinMagDistance(0.2f), MinQuatDistance(0.5f),
00040         SampleCount(0)
00041     {
00042         MinMagDistanceSq = MinMagDistance * MinMagDistance;
00043         MinQuatDistanceSq = MinQuatDistance * MinQuatDistance;
00044     }
00045 
00046     // Methods that are useful for either auto or manual calibration
00047     bool     IsUnitialized() const       { return Stat == Mag_Uninitialized; }
00048     bool     IsCalibrated() const        { return Stat == Mag_Calibrated; }
00049     int      NumberOfSamples() const     { return SampleCount; }
00050     int      RequiredSampleCount() const { return 4; }
00051         void     AbortCalibration()
00052         {
00053         Stat = Mag_Uninitialized;
00054         SampleCount = 0;
00055         }
00056 
00057     void     ClearCalibration(SensorFusion& sf) 
00058     {
00059         Stat = Mag_Uninitialized;
00060         SampleCount = 0;
00061         sf.ClearMagCalibration();
00062         };
00063   
00064     // Methods for automatic magnetometer calibration
00065     void     BeginAutoCalibration(SensorFusion& sf);
00066     unsigned UpdateAutoCalibration(SensorFusion& sf);
00067     bool     IsAutoCalibrating() const { return Stat == Mag_AutoCalibrating; }
00068 
00069     // Methods for building a manual (user-guided) calibraton procedure
00070     void     BeginManualCalibration(SensorFusion& sf);
00071     bool     IsAcceptableSample(const Quatf& q, const Vector3f& m);
00072     bool     InsertIfAcceptable(const Quatf& q, const Vector3f& m);
00073     // Returns true if successful, requiring that SampleCount = 4
00074     bool     SetCalibration(SensorFusion& sf);
00075     bool     IsManuallyCalibrating() const { return Stat == Mag_ManuallyCalibrating; }
00076 
00077     // This is the minimum acceptable distance (Euclidean) between raw
00078     // magnetometer values to be acceptable for usage in calibration.
00079     void SetMinMagDistance(float dist) 
00080     { 
00081         MinMagDistance = dist; 
00082         MinMagDistanceSq = MinMagDistance * MinMagDistance;
00083     }
00084 
00085     // The minimum acceptable distance (4D Euclidean) between orientations
00086     // to be acceptable for calibration usage.
00087     void SetMinQuatDistance(float dist) 
00088     { 
00089         MinQuatDistance = dist; 
00090         MinQuatDistanceSq = MinQuatDistance * MinQuatDistance;
00091     }
00092 
00093     // A result of the calibration, which is the center of a sphere that 
00094     // roughly approximates the magnetometer data.
00095     Vector3f GetMagCenter() const { return MagCenter; }
00096 
00097 private:
00098     // Determine the unique sphere through 4 non-coplanar points
00099     Vector3f CalculateSphereCenter(const Vector3f& p1, const Vector3f& p2,
00100                                    const Vector3f& p3, const Vector3f& p4);
00101 
00102     // Distance from p4 to the nearest point on a plane through p1, p2, p3
00103     float PointToPlaneDistance(const Vector3f& p1, const Vector3f& p2,
00104                                const Vector3f& p3, const Vector3f& p4);
00105 
00106     Vector3f MagCenter;
00107     unsigned Stat;
00108     float    MinMagDistance;
00109     float    MinQuatDistance;
00110     float    MinMagDistanceSq;
00111     float    MinQuatDistanceSq;
00112 
00113     unsigned SampleCount;
00114     Vector3f MagSamples[4];
00115     Quatf    QuatSamples[4];
00116 
00117 };
00118 
00119 }}
00120 
00121 #endif


oculus_sdk
Author(s):
autogenerated on Fri Aug 28 2015 11:53:11