CoreMotion 的罗盘航向值错误
我正在使用 CoreMotion 获取罗盘航向,我注意到罗盘航向存在一些问题。
首先我初始化了 CoreMotion。 我得到了一个 CMMotionManager 对象 locationManager,它是 CMMotionManager 的一个实例。
// initialize CoreMotion
motionManager = [CMMotionManager new];
[motionManager setDeviceMotionUpdateInterval:1.0/30.0];
[motionManager setShowsDeviceMovementDisplay:YES];
[self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical];
位置数据每 1/30.0 秒更新一次。
出于调试目的,我有一个 UILabel,它向我显示在每个更新间隔更新的当前罗盘标题。 当应用程序启动时,我总是必须执行神奇的 8 来校准指南针。
校准指南针后,南北航向在近 2-5 秒内都是正确的。
几秒钟后,罗盘变得疯狂,角度也在跳跃。 大多数情况下,它会从起始位置向两个方向浮动 10-20 度左右。足以产生奇怪的结果。 30-60 秒后,南边和北边时不时地互换或显示到东边和西边。
在 WWDC 2011 上,有一次会议讨论了他们如何使用另一个传感器计算每个传感器来弥补这个问题。 我在 CoreMotion 的配置中是否遗漏了什么,导致我在准确的航向结果方面遇到了巨大的问题?
我现在使用 3 台设备(2 个 iPhone 4s 和 iPhone 4)在建筑物内外测试了指南针。我去过田野、小城市和大城市。这种事经常发生。 在我的测试中,Apple 的示例指南针应用程序几乎准确,准确度为 90%。不幸的是它没有被苹果开源。
感谢您的阅读。
I'm using CoreMotion to get the ccompass heading and i noticed some problems with the compass heading.
At first my initialization of CoreMotion.
I got a CMMotionManager object, locationManager, which is an instance of the CMMotionManager.
// initialize CoreMotion
motionManager = [CMMotionManager new];
[motionManager setDeviceMotionUpdateInterval:1.0/30.0];
[motionManager setShowsDeviceMovementDisplay:YES];
[self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical];
The position data is updated every 1/30.0 seconds.
For debug purposes i have a UILabel which shows me the current compass heading updated on every update interval.
While the application is starting i always have to do the magical 8 for calibrating the compass.
After calibrating the compass, the heading for north and south is correct for almost 2-5 seconds.
Right after a couple of seconds the compass goes wild and the angles are jumping around.
Mostly its floating around 10-20 degrees from the starting position in both directions. Enought to have a wierd result.
After 30-60 seconds every now and again the south and north are interchanged or showing to east and west.
At the WWDC 2011, a session has been talked about how they calculate each sensor with another to compensate this problems.
Is there anything i missed at the configuration of CoreMotion that i have this massive problems of accurate heading results?
I tested the compass now with 3 devices (2 iPhone 4s and iPhone 4) in and outside buildings. I was at fields, small citys and big citys. It happens all the time.
The sample compass app from Apple is almost accurate with 90% accuracy in my tests. Unfortunately its not open sourced by Apple.
Thank you for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 CoreMotion通过 CoreLocation 将为您提供所需的信息。
默认情况下,手机将进行数字 8 校准,要禁用此功能,请覆盖
locationManagerShouldDisplayHeadingCalibration:
,如下所示:从问题中的代码中不清楚您是否正在调用
startUpdateHeading
。如果没有,请这样做:如果不打开标题过滤器,您可能会得到疯狂的结果,我建议您这样做。之后,当调用
didUpdateHeading
时,您只需在位置管理器委托中获取标题更改。另请注意,如果手机处于横向模式,您需要将航向调整适当的度数(+/- 90),因为航向始终位于纵向参考系中。
Using CoreMotion through CoreLocation will get you what you are looking for.
By default the handset will do the calibration figure 8, to disable this, override
locationManagerShouldDisplayHeadingCalibration:
as follows:It's not clear from the code in your question if you're calling
startUpdateHeading
. If not, do so:You can get crazy results if you don't turn on the heading filter, I'd recommend that you do so. After that, you just get the heading changes in your location manager delegate when
didUpdateHeading
is called.Also note that if the handset is in landscape mode, you'll need to adjust the heading by the appropriate number of degrees(+/- 90), since the heading is always in the Portrait frame of reference.