iOS CoreMotion CMAttitude 相对于北极
我目前正在使用 CoreMotion 的 DeviceMotion 来获取 iPhone 的方向(滚动、俯仰、偏航)。现在我想要相对于地理北极的这些值;因此,我需要一个包含滚动、俯仰和偏航值的 CMAttitude 参考对象,如果 iPhone 背面面向北极(3D),则会报告这些值。 CLLocationManager 仅返回 Tesla 中的磁航向 (x, y, z)。
您知道如何将这些值转换为横滚、俯仰和偏航吗?
预先感谢,
亚历山大
I'm currently using CoreMotion's DeviceMotion to get the orientation (roll, pitch, yaw) of the iPhone. Now I would like to have these values relative to the geographic north pole; so I need a CMAttitude reference object containing the roll, pitch and yaw values, which would be reported, if the back of the iPhone would face to the north pole (3D). The CLLocationManager only returns the magnetic heading (x, y, z) in Tesla.
Do you have an idea of how to convert those values to roll, pitch and yaw?
Thanks in advance,
Alexander
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
iOS 5提供了指定方法。在开发人员文档中查找 CMAttitudeReferenceFrameXTrueNorthZVertical。
iOS 5 provides the designated method. Look for CMAttitudeReferenceFrameXTrueNorthZVertical in the developer documentation.
伪代码:
以下是代码:
Pseudo code:
Here is the code:
您需要时不时地将偏航值校准到磁航向,以确保您处于正确的轨道上。查看有关如何补偿指南针抖动的说明:补偿指南针iPhone 4 上的陀螺仪滞后
You would need to calibrate your yaw value to the magnetic heading now and then to make sure you are on the right track. Check out this explanation on how to compensate the shaky compass: Compensating compass lag with the gyroscope on iPhone 4
特斯拉值是磁场强度,是三个轴中每个轴感受到的磁“拉力”大小的度量。只有将这些信息与加速度计数据结合起来,并进行一系列奇特的数学运算,您才能获得实际的航向(设备相对于磁北“指向”的方向)。然后添加来自 GPS 的信息并进行更多数学计算,以获得真实航向(相对于地理北极)。
长话短说,您可能不想自己做数学计算。幸运的是,iOS 在其 CLHeading 对象中提供了MagneticHeading 和 trueHeading,可从 CLLocationManager 标题属性获取。
为了获得描述设备如何倾斜的俯仰和滚动,还需要对来自磁力计和加速度计的相同原始数据进行数学计算。抱歉,我不知道有任何用于俯仰和横滚的 iOS API。
The Tesla values are magnetic field strength, a measure of how much magnetic "pull" is felt in each of the three axes. Only by combining this information with accelerometer data, and doing a bunch of fancy math, can you get an actual heading (which way the device is "pointing" relative to magnetic north). Then add in information from the GPS and do more math, to get the true heading (relative to the geographic north pole).
Long story short, you probably don't want to do the math yourself. Luckily iOS provides both magneticHeading and trueHeading in its CLHeading object, available from the CLLocationManager heading property.
To get pitch and roll, which describe how the device is tilted, also involves doing math on these same raw data from the magnetometer and accelerometer. Sorry I don't know of any iOS API for pitch and roll.