Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
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
00065 void BeginAutoCalibration(SensorFusion& sf);
00066 unsigned UpdateAutoCalibration(SensorFusion& sf);
00067 bool IsAutoCalibrating() const { return Stat == Mag_AutoCalibrating; }
00068
00069
00070 void BeginManualCalibration(SensorFusion& sf);
00071 bool IsAcceptableSample(const Quatf& q, const Vector3f& m);
00072 bool InsertIfAcceptable(const Quatf& q, const Vector3f& m);
00073
00074 bool SetCalibration(SensorFusion& sf);
00075 bool IsManuallyCalibrating() const { return Stat == Mag_ManuallyCalibrating; }
00076
00077
00078
00079 void SetMinMagDistance(float dist)
00080 {
00081 MinMagDistance = dist;
00082 MinMagDistanceSq = MinMagDistance * MinMagDistance;
00083 }
00084
00085
00086
00087 void SetMinQuatDistance(float dist)
00088 {
00089 MinQuatDistance = dist;
00090 MinQuatDistanceSq = MinQuatDistance * MinQuatDistance;
00091 }
00092
00093
00094
00095 Vector3f GetMagCenter() const { return MagCenter; }
00096
00097 private:
00098
00099 Vector3f CalculateSphereCenter(const Vector3f& p1, const Vector3f& p2,
00100 const Vector3f& p3, const Vector3f& p4);
00101
00102
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