iDevice 态度:稳定四元数 [英] iDevice attitude: stabilising quaternion

查看:83
本文介绍了iDevice 态度:稳定四元数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 iDevice 的态度 self.motionManager.deviceMotion.attitude.quaternion设备放在桌子上,但数值不一样.如何稳定这些值而不会导致不良旋转?我正在使用设备姿态来旋转相机节点.

I'm trying to use iDevice's attitude self.motionManager.deviceMotion.attitude.quaternion the device is resting on the table, but the values are not the same. how to stabilise these values without causing bad rotation? I'm using the device attitude to rotate the camera node.

 (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];

推荐答案

您正在寻找的是 低通滤波器 — 一种将传感器输入中的高频信号(噪声、随机抖动)与低频信号(故意的用户运动)分离的方法.

What you're looking for is a low pass filter — a way to separate the high frequency signals in a sensor input (noise, random jiggling) from the low frequency ones (deliberate user motion).

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

The typical formula for a real-time filter goes like this:

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

也就是说,您从 sampledValue(来自传感器的原始输入)和 sampledValue 的线性插值中获得 newValue(您将要使用的过滤输入)em>lastValue(在上一个时间步计算的 newValue;确保在第一次计算时将其初始化为合理的值),带有控制的 factor混合有多远.您可以调整 factor 来控制通过过滤器的信号量.

That is, you get newValue (the filtered input you're going to use) from the linear interpolation of sampledValue (the raw input from the sensor) and lastValue (the newValue computed on the previous time step; be sure to initialize it to something sensible on the first computation), with a factor that controls how far along the blend is. You can tweak factor to control how much signal gets through your filter.

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

You could probably apply this formula separately to each of the x, y, z, and w components of a quaternion and get a vaguely passable result. But a) writing the same code four times isn't so fun, and b) quaternions have some special math that'll cause this method to break down over time.

相反,您可以将 CMQuaternion 变成 GLKQuaternion 并在一次调用 GLKQuaternionSlerp.(它会为你考虑特殊的数学.)

Instead, you can make your CMQuaternion into a GLKQuaternion and do the blending in one call to GLKQuaternionSlerp. (And it minds the special math for you.)

filteredAttitude = GLKQuaternionSlerp(lastAttitude, sampledAttitude, factor)

然后从您的 GLKQuaternion 制作一个 SCNQuaternion 并且您可以设置节点的方向.

Then make an SCNQuaternion from your GLKQuaternion and you can set the orientation of your node.

这篇关于iDevice 态度:稳定四元数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆