CMMotionManager 在 iOS 7 启动后返回偏航的大幅跳跃
Posted
技术标签:
【中文标题】CMMotionManager 在 iOS 7 启动后返回偏航的大幅跳跃【英文标题】:CMMotionManager returns big jump in yaw just after starting in iOS 7 【发布时间】:2013-09-20 02:37:25 【问题描述】:这是一个我不相信我在 ios 6 中遇到问题的功能,但现在在 iOS 7 中似乎遇到了问题。每次我启动我的运动管理器(使用 startDeviceMotionUpdatesUsingReferenceFrame)时,我的运动处理程序总是报告一个大约半秒后,大的,不存在的偏航跳跃。这似乎只在您使用 CMAttitudeReferenceFrameXMagneticNorthZVertical 或 CMAttitudeReferenceFrameXTrueNorthZVertical 的参考框架时发生。有没有办法以任何方式更新 CMDeviceMotionHandler 来弥补它?
为了说明,下面是启动我的运动管理器后每个输出姿态的详细输出。请注意大约 0.5 秒后偏航是如何自发跳跃的。
2013-08-28 21:22:41.325 Déjà Vu[5675:60b] CMAttitude Pitch: 49.628127, Roll: 3.061527, Yaw: -1.420758
2013-08-28 21:22:41.366 Déjà Vu[5675:60b] CMAttitude Pitch: 49.567161, Roll: 2.539731, Yaw: -1.035483
2013-08-28 21:22:41.368 Déjà Vu[5675:60b] CMAttitude Pitch: 49.542753, Roll: 2.248727, Yaw: -0.822929
2013-08-28 21:22:41.370 Déjà Vu[5675:60b] CMAttitude Pitch: 49.475405, Roll: 2.006880, Yaw: -0.646478
2013-08-28 21:22:41.373 Déjà Vu[5675:60b] CMAttitude Pitch: 49.405571, Roll: 1.796121, Yaw: -0.490888
2013-08-28 21:22:41.375 Déjà Vu[5675:60b] CMAttitude Pitch: 49.331390, Roll: 1.644289, Yaw: -0.385082
2013-08-28 21:22:41.385 Déjà Vu[5675:60b] CMAttitude Pitch: 49.247448, Roll: 1.499398, Yaw: -0.293233
2013-08-28 21:22:41.400 Déjà Vu[5675:60b] CMAttitude Pitch: 49.169564, Roll: 1.375473, Yaw: -0.217664
2013-08-28 21:22:41.403 Déjà Vu[5675:60b] CMAttitude Pitch: 49.087577, Roll: 1.298058, Yaw: -0.170136
2013-08-28 21:22:41.416 Déjà Vu[5675:60b] CMAttitude Pitch: 49.016980, Roll: 1.253348, Yaw: -0.143872
2013-08-28 21:22:41.431 Déjà Vu[5675:60b] CMAttitude Pitch: 48.976531, Roll: 1.196151, Yaw: -0.101682
2013-08-28 21:22:41.434 Déjà Vu[5675:60b] CMAttitude Pitch: 48.958237, Roll: 1.156605, Yaw: -0.071089
2013-08-28 21:22:41.447 Déjà Vu[5675:60b] CMAttitude Pitch: 48.939612, Roll: 1.071295, Yaw: 0.002808
2013-08-28 21:22:41.462 Déjà Vu[5675:60b] CMAttitude Pitch: 48.903235, Roll: 1.020576, Yaw: 0.050194
2013-08-28 21:22:41.465 Déjà Vu[5675:60b] CMAttitude Pitch: 48.866325, Roll: 0.977751, Yaw: 0.089039
2013-08-28 21:22:41.477 Déjà Vu[5675:60b] CMAttitude Pitch: 48.835792, Roll: 0.952468, Yaw: 0.106070
2013-08-28 21:22:41.493 Déjà Vu[5675:60b] CMAttitude Pitch: 48.831971, Roll: 0.934805, Yaw: 0.116239
2013-08-28 21:22:41.496 Déjà Vu[5675:60b] CMAttitude Pitch: 48.843288, Roll: 0.920311, Yaw: 0.121559
2013-08-28 21:22:41.509 Déjà Vu[5675:60b] CMAttitude Pitch: 48.857048, Roll: 0.912051, Yaw: 0.118162
2013-08-28 21:22:41.526 Déjà Vu[5675:60b] CMAttitude Pitch: 48.863274, Roll: 0.898121, Yaw: 0.116690
2013-08-28 21:22:41.530 Déjà Vu[5675:60b] CMAttitude Pitch: 48.866083, Roll: 0.874281, Yaw: 0.123867
2013-08-28 21:22:41.541 Déjà Vu[5675:60b] CMAttitude Pitch: 48.863881, Roll: 0.835707, Yaw: 0.147356
2013-08-28 21:22:41.555 Déjà Vu[5675:60b] CMAttitude Pitch: 48.862856, Roll: 0.800074, Yaw: 0.168110
2013-08-28 21:22:41.559 Déjà Vu[5675:60b] CMAttitude Pitch: 48.872933, Roll: 0.765896, Yaw: 0.188365
2013-08-28 21:22:41.570 Déjà Vu[5675:60b] CMAttitude Pitch: 48.881562, Roll: 0.749693, Yaw: 0.200020
2013-08-28 21:22:41.586 Déjà Vu[5675:60b] CMAttitude Pitch: 48.876250, Roll: 0.728082, Yaw: 0.212002
2013-08-28 21:22:41.590 Déjà Vu[5675:60b] CMAttitude Pitch: 48.856920, Roll: 0.707687, Yaw: 0.219435
2013-08-28 21:22:41.601 Déjà Vu[5675:60b] CMAttitude Pitch: 48.840266, Roll: 0.678230, Yaw: 0.231034
2013-08-28 21:22:41.617 Déjà Vu[5675:60b] CMAttitude Pitch: 48.838389, Roll: 0.646075, Yaw: 0.248422
2013-08-28 21:22:41.621 Déjà Vu[5675:60b] CMAttitude Pitch: 48.846803, Roll: 0.606845, Yaw: 0.269967
2013-08-28 21:22:41.632 Déjà Vu[5675:60b] CMAttitude Pitch: 48.850193, Roll: 0.563535, Yaw: 0.290147
2013-08-28 21:22:41.648 Déjà Vu[5675:60b] CMAttitude Pitch: 48.854796, Roll: 0.521405, Yaw: 0.310114
2013-08-28 21:22:41.651 Déjà Vu[5675:60b] CMAttitude Pitch: 48.848840, Roll: 0.495401, Yaw: 0.320581
2013-08-28 21:22:41.663 Déjà Vu[5675:60b] CMAttitude Pitch: 48.847574, Roll: 0.476676, Yaw: 0.329254
2013-08-28 21:22:41.679 Déjà Vu[5675:60b] CMAttitude Pitch: 48.846378, Roll: 0.465281, Yaw: 0.323528
2013-08-28 21:22:41.682 Déjà Vu[5675:60b] CMAttitude Pitch: 48.871945, Roll: 0.459737, Yaw: 0.315833
2013-08-28 21:22:41.696 Déjà Vu[5675:60b] CMAttitude Pitch: 48.872580, Roll: 0.453971, Yaw: 0.314404
2013-08-28 21:22:41.710 Déjà Vu[5675:60b] CMAttitude Pitch: 48.860497, Roll: 0.439179, Yaw: 0.321968
2013-08-28 21:22:41.714 Déjà Vu[5675:60b] CMAttitude Pitch: 48.838540, Roll: 0.413087, Yaw: 0.342403
2013-08-28 21:22:41.726 Déjà Vu[5675:60b] CMAttitude Pitch: 48.828212, Roll: 0.394198, Yaw: 0.354884
2013-08-28 21:22:41.741 Déjà Vu[5675:60b] CMAttitude Pitch: 48.836743, Roll: 0.370267, Yaw: 0.366601
2013-08-28 21:22:41.744 Déjà Vu[5675:60b] CMAttitude Pitch: 48.839021, Roll: 0.342199, Yaw: 0.380237
2013-08-28 21:22:41.758 Déjà Vu[5675:60b] CMAttitude Pitch: 48.842708, Roll: 0.338735, Yaw: 0.370630
2013-08-28 21:22:41.772 Déjà Vu[5675:60b] CMAttitude Pitch: 48.837031, Roll: 0.350693, Yaw: 0.347981
2013-08-28 21:22:41.777 Déjà Vu[5675:60b] CMAttitude Pitch: 48.830125, Roll: 0.372368, Yaw: 0.326675
2013-08-28 21:22:41.787 Déjà Vu[5675:60b] CMAttitude Pitch: 48.828191, Roll: 0.375706, Yaw: 0.320968
2013-08-28 21:22:41.803 Déjà Vu[5675:60b] CMAttitude Pitch: 48.811894, Roll: 0.367849, Yaw: 38.517324
2013-08-28 21:22:41.807 Déjà Vu[5675:60b] CMAttitude Pitch: 48.804581, Roll: 0.339469, Yaw: 38.530965
2013-08-28 21:22:41.818 Déjà Vu[5675:60b] CMAttitude Pitch: 48.804247, Roll: 0.308285, Yaw: 38.546571
【问题讨论】:
打印CMAttitude.CMQuaternion的内容时能看到同样的突变吗? 是的,我愿意。我已将该输出添加为上面的编辑。 好的,绝对是报告的旋转变化,而不仅仅是转换问题。如果演示项目运动图也可重现地显示该峰值,则应提交错误。我在初始化阶段启动了一次运动管理器,之后它似乎运行稳定 我真的没有看到 MotionGraphs 演示项目(在上面添加)的输出中的峰值。像偏航这样的维度有一些逐渐放松,但这似乎并不太不寻常。有什么方法可以让我错误地初始化我的运动管理器? 其实我已经意识到它是专门由使用CMAttitudeReferenceFrameXTrueNorthZVertical或CMAttitudeReferenceFrameXMagneticNorthZVertical的参考框架引起的。没有参考框架,输出是平滑和正常的。使用参考框架,它引入了跳转,这似乎是在 iOS 7 中引入的。如果我将 MotionGraphs 演示更改为使用参考框架,我会看到完全相同的跳转。 【参考方案1】:这种跳跃总是在传感器长时间不活动后发生。
只需将此值添加到您的日志中:
[[motionManager deviceMotion] magneticField].accuracy
【讨论】:
以上是关于CMMotionManager 在 iOS 7 启动后返回偏航的大幅跳跃的主要内容,如果未能解决你的问题,请参考以下文章
iOS 阿里百川SDK 报错 "_OBJC_CLASS_$_CMMotionManager", referenced from: objc-class-"_res_9_g
iOS 阿里百川SDK 报错 "_OBJC_CLASS_$_CMMotionManager", referenced from: objc-class-"_res_9_g