|
@@ -15,7 +15,7 @@ namespace o0.Bow
|
|
|
public IMU.HardwareVariance AccHardwareVariance;
|
|
public IMU.HardwareVariance AccHardwareVariance;
|
|
|
public IMU.HardwareVariance MagHardwareVariance;
|
|
public IMU.HardwareVariance MagHardwareVariance;
|
|
|
|
|
|
|
|
- public static List<UnityEngine.Quaternion> QuaTest = new List<UnityEngine.Quaternion>();
|
|
|
|
|
|
|
+ // public static List<UnityEngine.Quaternion> QuaTest = new List<UnityEngine.Quaternion>();
|
|
|
public o09AxisAfterXiaMenFromDll(Vector<int> GyrByteIndex = default, Vector<int> AccByteIndex = default, Vector<int> MagByteIndex = default)
|
|
public o09AxisAfterXiaMenFromDll(Vector<int> GyrByteIndex = default, Vector<int> AccByteIndex = default, Vector<int> MagByteIndex = default)
|
|
|
{
|
|
{
|
|
|
Attitude = new IMU._9AxisPreProcessor(GyrByteIndex, AccByteIndex, MagByteIndex);
|
|
Attitude = new IMU._9AxisPreProcessor(GyrByteIndex, AccByteIndex, MagByteIndex);
|
|
@@ -23,8 +23,8 @@ namespace o0.Bow
|
|
|
AccHardwareVariance = new IMU.HardwareVariance();
|
|
AccHardwareVariance = new IMU.HardwareVariance();
|
|
|
MagHardwareVariance = new IMU.HardwareVariance();
|
|
MagHardwareVariance = new IMU.HardwareVariance();
|
|
|
|
|
|
|
|
- QuaTest.Add(UnityEngine.Quaternion.identity);
|
|
|
|
|
- QuaTest.Add(UnityEngine.Quaternion.identity);
|
|
|
|
|
|
|
+ // QuaTest.Add(UnityEngine.Quaternion.identity);
|
|
|
|
|
+ // QuaTest.Add(UnityEngine.Quaternion.identity);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static public Vector<double> AccIdentity = new Vector<double>(0, -1, 0);
|
|
static public Vector<double> AccIdentity = new Vector<double>(0, -1, 0);
|
|
@@ -64,6 +64,8 @@ namespace o0.Bow
|
|
|
var (Gyr, Acc, Mag, TimeGap) = Attitude.Update(gyrByte, accByte, magByte, min, sec, ms1, ms2);
|
|
var (Gyr, Acc, Mag, TimeGap) = Attitude.Update(gyrByte, accByte, magByte, min, sec, ms1, ms2);
|
|
|
if((Gyr, Acc, Mag, TimeGap) == default)
|
|
if((Gyr, Acc, Mag, TimeGap) == default)
|
|
|
return Geometry.Quaternion.Identity;
|
|
return Geometry.Quaternion.Identity;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
Vector<double> Buffer = default;
|
|
Vector<double> Buffer = default;
|
|
|
Buffer = GyrHardwareVariance.Update(Attitude.LastGyr);
|
|
Buffer = GyrHardwareVariance.Update(Attitude.LastGyr);
|
|
|
if (Buffer != default)
|
|
if (Buffer != default)
|
|
@@ -76,6 +78,9 @@ namespace o0.Bow
|
|
|
Debug.Log("MagHardwareVariance: " + Buffer.Length);
|
|
Debug.Log("MagHardwareVariance: " + Buffer.Length);
|
|
|
|
|
|
|
|
var GyrOperator = Geometry.Quaternion.Euler(Gyr * TimeGap);
|
|
var GyrOperator = Geometry.Quaternion.Euler(Gyr * TimeGap);
|
|
|
|
|
+ // TestVector.Update9AxisRotation(GyrOperator.ToUnityQuaternion(), 0);
|
|
|
|
|
+ // TestVector.SetAcc(Acc.ToUnityVector(), 0);
|
|
|
|
|
+ // TestVector.SetMag(Mag.ToUnityVector(), 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
var Last = States.LastOrDefault() ?? new State();
|
|
var Last = States.LastOrDefault() ?? new State();
|
|
@@ -139,7 +144,9 @@ namespace o0.Bow
|
|
|
//TestVector.SetAcc(Acc / 10, 1);
|
|
//TestVector.SetAcc(Acc / 10, 1);
|
|
|
//TestVector.SetMag(Mag, 1);
|
|
//TestVector.SetMag(Mag, 1);
|
|
|
var accTest = Geometry.Quaternion.FromToRotation(Last.Acc, Acc).Inversed;
|
|
var accTest = Geometry.Quaternion.FromToRotation(Last.Acc, Acc).Inversed;
|
|
|
|
|
+ // TestVector.Update9AxisRotation(accTest.ToUnityQuaternion(), 2);
|
|
|
var magTest = Geometry.Quaternion.FromToRotation(Last.Mag, Mag).Inversed;
|
|
var magTest = Geometry.Quaternion.FromToRotation(Last.Mag, Mag).Inversed;
|
|
|
|
|
+ // TestVector.Update9AxisRotation(magTest.ToUnityQuaternion(), 3);
|
|
|
//TestVector.Set9AxisRotation(Last.Qua, 3);
|
|
//TestVector.Set9AxisRotation(Last.Qua, 3);
|
|
|
|
|
|
|
|
double AccLengthToAngle = 5;//1倍引力差相当于多少度方差
|
|
double AccLengthToAngle = 5;//1倍引力差相当于多少度方差
|
|
@@ -189,7 +196,7 @@ namespace o0.Bow
|
|
|
var quaMinRate = GyrVariance / (GyrVariance + Math.Max(AccVariance, MagVariance));
|
|
var quaMinRate = GyrVariance / (GyrVariance + Math.Max(AccVariance, MagVariance));
|
|
|
var quaMaxRate = GyrVariance / (GyrVariance + Math.Min(AccVariance, MagVariance));
|
|
var quaMaxRate = GyrVariance / (GyrVariance + Math.Min(AccVariance, MagVariance));
|
|
|
Geometry.Quaternion quaFirst = Geometry.Quaternion.SLerp(quaGyr, quaAccMag, (float)quaMinRate);
|
|
Geometry.Quaternion quaFirst = Geometry.Quaternion.SLerp(quaGyr, quaAccMag, (float)quaMinRate);
|
|
|
- if (double.IsNaN(quaFirst.w))
|
|
|
|
|
|
|
+ if (double.IsNaN(quaFirst.x) || double.IsNaN(quaFirst.y) || double.IsNaN(quaFirst.z) || double.IsNaN(quaFirst.w))
|
|
|
quaFirst = Last.Qua;
|
|
quaFirst = Last.Qua;
|
|
|
|
|
|
|
|
var quaSecondRate = (quaMaxRate - quaMinRate) / (1 - quaMinRate);
|
|
var quaSecondRate = (quaMaxRate - quaMinRate) / (1 - quaMinRate);
|
|
@@ -201,7 +208,7 @@ namespace o0.Bow
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
- if (double.IsNaN(state.Qua.w))
|
|
|
|
|
|
|
+ if (double.IsNaN(state.Qua.x) || double.IsNaN(state.Qua.y) || double.IsNaN(state.Qua.z) || double.IsNaN(state.Qua.w))
|
|
|
state.Qua = Last.Qua;/**/
|
|
state.Qua = Last.Qua;/**/
|
|
|
state.QuaSmooth = Geometry.Quaternion.SLerp(Last.QuaSmooth, state.Qua, 0.3f);//Last.QuaSmooth - state.Qua 0 - 1
|
|
state.QuaSmooth = Geometry.Quaternion.SLerp(Last.QuaSmooth, state.Qua, 0.3f);//Last.QuaSmooth - state.Qua 0 - 1
|
|
|
|
|
|