CoreMotion错误的指南针标题值(Wrong compass heading values with CoreMotion)

编程入门 行业动态 更新时间:2024-10-09 23:15:34
CoreMotion错误的指南针标题值(Wrong compass heading values with CoreMotion)

我正在使用CoreMotion来获取ccompass标题,并发现指南针标题存在一些问题。

起初,我对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)测试了指南针。 我在田野,小城市和大城市。 它总是发生。 苹果公司的示例罗盘应用程序在我的测试中准确度达到了90%。 不幸的是,它不是由Apple开源的。

谢谢你的阅读。

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.

最满意答案

通过 CoreLocation使用CoreMotion将为您提供所需的内容。

默认情况下,手机将执行校准图8,要禁用此功能,请覆盖locationManagerShouldDisplayHeadingCalibration:如下所示:

- (BOOL)locationManagerShouldDisplayHeadingCalibration: (CLLocationManager *)manager { return NO; }

从你问题中的代码中不清楚你是否调用了startUpdateHeading 。 如果没有,那就这样做:

if( [CLLocationManager locationServicesEnabled] && [CLLocationManager headingAvailable]) { [myLocationManager startUpdatingLocation]; [myLocationManager startUpdatingHeading]; }

如果你不打开标题过滤器,你会得到疯狂的结果,我建议你这样做。 之后,当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:

- (BOOL)locationManagerShouldDisplayHeadingCalibration: (CLLocationManager *)manager { return NO; }

It's not clear from the code in your question if you're calling startUpdateHeading. If not, do so:

if( [CLLocationManager locationServicesEnabled] && [CLLocationManager headingAvailable]) { [myLocationManager startUpdatingLocation]; [myLocationManager startUpdatingHeading]; }

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.

更多推荐

本文发布于:2023-04-29 03:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1334432.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指南针   错误   标题   CoreMotion   values

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!