我正在尝试使用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];

最佳答案

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

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

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


也就是说,您可以从sampledValue(传感器的原始输入)和lastValue(在上一个时间步长上计算得出的newValue)的线性插值中获得newValue(将要使用的过滤输入)。在第一次计算中比较明智),并控制混合沿多远的距离。您可以调整因子以控制有多少信号通过滤波器。

您可能可以将此公式分别应用于四元数的x,y,z和w分量,并获得可以通过的模糊结果。但是a)编写相同的代码四次并不那么有趣,并且b)四元数具有一些特殊的数学运算法则,随着时间的推移,这种方法会失效。

取而代之的是,您可以将CMQuaternion变成GLKQuaternion,然后一次调用GLKQuaternionSlerp进行混合。 (它为您介意特殊的数学运算。)

filteredAttitude = GLKQuaternionSlerp(lastAttitude, sampledAttitude, factor)


然后从SCNQuaternion中创建一个GLKQuaternion,然后可以设置节点的方向。

关于ios - iDevice态度:稳定四元数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27660653/

10-10 21:09