iDevice态度:稳定四元数

时间:2014-12-26 18:36:00

标签: ios quaternions core-motion scenekit

我正在尝试使用iDevice的态度self.motionManager.deviceMotion.attitude.quaternion 设备搁在桌子上,但值不一样。如何在不造成不良旋转的情况下稳定这些值?我正在使用设备姿态来旋转相机节点。

 (x = -0.0055437298906573507, y = -0.0078092851375721247, z = -0.041180405121897398, w = 0.999105828407855)
 (x = -0.0061666945840810842, y = -0.0067849414785486747, z = -0.041464744435584115, w = 0.99909789881469635)
 (x = -0.0057767614213563457, y = -0.0075097232630314727, z = -0.041803806548186787, w = 0.99908091506248087)
 (x = -0.0054897030127900098, y = -0.0077124534854605253, z = -0.04219926058901851, w = 0.99906436410664467)
 (x = -0.0052714642886002782, y = -0.0078368692177714049, z = -0.042675299607953819, w = 0.99904435034111316)
 (x = -0.0050140321661910547, y = -0.0078121993123853265, z = -0.043041870709832147, w = 0.99903014288315972)
 (x = -0.0050055928591862253, y = -0.0077335374133680208, z = -0.043505056503552082, w = 0.99901073392523531)
 (x = -0.0049666831093899792, y = -0.007717140215596976, z = -0.043913562364765651, w = 0.99899318158145256)
 (x = -0.0047768022686966614, y = -0.0078160798819143576, z = -0.044274861496884942, w = 0.99897739098280313)
 (x = -0.0047310514463435671, y = -0.0078007790545880336, z = -0.044670164461142137, w = 0.9989601300379195)
 (x = -0.004618244779613233, y = -0.0078641769042355775, z = -0.045003270721875412, w = 0.99894520978936451)
 (x = -0.0049526705779270597, y = -0.0076127708990477733, z = -0.045411652395276572, w = 0.99892707371465494)
 (x = -0.0053219441444451315, y = -0.0074858231291817018, z = -0.045723089011719641, w = 0.99891192729581401)
 (x = -0.0056345717154138147, y = -0.0073613453524927486, z = -0.046005287981812061, w = 0.99889818083421522)
 (x = -0.0056064974434034201, y = -0.0074105820596984404, z = -0.046130222648849362, w = 0.99889221291304886)
 (x = -0.0053487406143112462, y = -0.0076910190187535112, z = -0.046331716108766401, w = 0.99888218088156866)


    self.motionManager = [[CMMotionManager alloc] init];
    self.motionManager.deviceMotionUpdateInterval = 1.0/20.0;
    [self.motionManager startDeviceMotionUpdates];

1 个答案:

答案 0 :(得分:2)

您正在寻找的是low pass filter - 一种将传感器输入(噪声,随机抖动)中的高频信号与低频信号(故意用户运动)分开的方法。

实时过滤器的典型公式如下:

newValue = (sampledValue * factor) + (lastValue * (1 - factor))

也就是说,从 sampledValue 的线性插值(来自传感器的原始输入)获得 newValue (您将要使用的滤波输入)和 lastValue (在前一个时间步计算的 newValue ;确保在第一次计算时将其初始化为合理的东西),并带有因子控制混合物的距离。您可以调整 factor 来控制通过过滤器的信号量。

您可以将此公式单独应用于 x y z w 中的每一个四元数的组成部分,并得到一个模糊的可通过的结果。但是a)四次编写相同的代码并不是那么有趣,而且b)四元数有一些特殊的数学运算会导致这种方法随着时间的推移而崩溃。

相反,您可以将CMQuaternion变为GLKQuaternion,然后通过一次调用GLKQuaternionSlerp进行混合。 (它会为你特别的数学思考。)

filteredAttitude = GLKQuaternionSlerp(lastAttitude, sampledAttitude, factor)

然后从SCNQuaternion制作GLKQuaternion,您可以设置节点的方向。