• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - CMMotionManager deviceMotion 姿态值中的 "flickering"过多

[复制链接]
菜鸟教程小白 发表于 2022-12-12 10:16:52 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在记录从 CMMotionManager deviceMotion 获得的“态度”值在 CADisplayLink 回调中(我需要根据设备旋转执行动画)。

这些值似乎每隔几毫秒就会“抽搐”很大程度(高达 30%)。这似乎很不稳定,让我怀疑是我做错了什么还是设备有问题。

请在下面找到日志。打印的“Angle”是“attitude”的“roll”分量,换算成度数:

2013-04-10 00:07:12.683 MyApp[450:707] Angle: -92.91
2013-04-10 00:07:12.712 MyApp[450:707] Angle: -70.52
2013-04-10 00:07:12.714 MyApp[450:707] Angle: -92.25
2013-04-10 00:07:12.745 MyApp[450:707] Angle: -70.03
2013-04-10 00:07:12.747 MyApp[450:707] Angle: -91.74
2013-04-10 00:07:12.779 MyApp[450:707] Angle: -69.67
2013-04-10 00:07:12.784 MyApp[450:707] Angle: -91.23
2013-04-10 00:07:12.812 MyApp[450:707] Angle: -69.43
2013-04-10 00:07:12.815 MyApp[450:707] Angle: -91.19
2013-04-10 00:07:12.846 MyApp[450:707] Angle: -69.53
2013-04-10 00:07:12.849 MyApp[450:707] Angle: -91.33
2013-04-10 00:07:12.879 MyApp[450:707] Angle: -69.74
2013-04-10 00:07:12.881 MyApp[450:707] Angle: -91.57
2013-04-10 00:07:12.912 MyApp[450:707] Angle: -70.01
2013-04-10 00:07:12.915 MyApp[450:707] Angle: -91.85
2013-04-10 00:07:12.945 MyApp[450:707] Angle: -70.13
2013-04-10 00:07:12.949 MyApp[450:707] Angle: -91.99
2013-04-10 00:07:12.979 MyApp[450:707] Angle: -70.03
2013-04-10 00:07:12.983 MyApp[450:707] Angle: -91.93
2013-04-10 00:07:13.012 MyApp[450:707] Angle: -69.76
2013-04-10 00:07:13.016 MyApp[450:707] Angle: -91.71
2013-04-10 00:07:13.046 MyApp[450:707] Angle: -69.34
2013-04-10 00:07:13.051 MyApp[450:707] Angle: -91.19
2013-04-10 00:07:13.079 MyApp[450:707] Angle: -68.89
2013-04-10 00:07:13.082 MyApp[450:707] Angle: -90.94
2013-04-10 00:07:13.112 MyApp[450:707] Angle: -68.52
2013-04-10 00:07:13.114 MyApp[450:707] Angle: -90.66
2013-04-10 00:07:13.151 MyApp[450:707] Angle: -67.85
2013-04-10 00:07:13.156 MyApp[450:707] Angle: -89.47
2013-04-10 00:07:13.179 MyApp[450:707] Angle: -65.66
2013-04-10 00:07:13.181 MyApp[450:707] Angle: -88.10
2013-04-10 00:07:13.212 MyApp[450:707] Angle: -63.81
2013-04-10 00:07:13.216 MyApp[450:707] Angle: -86.33
2013-04-10 00:07:13.245 MyApp[450:707] Angle: -61.07
2013-04-10 00:07:13.248 MyApp[450:707] Angle: -83.63
2013-04-10 00:07:13.279 MyApp[450:707] Angle: -58.95
2013-04-10 00:07:13.282 MyApp[450:707] Angle: -81.46
2013-04-10 00:07:13.312 MyApp[450:707] Angle: -56.71
2013-04-10 00:07:13.314 MyApp[450:707] Angle: -79.06
2013-04-10 00:07:13.346 MyApp[450:707] Angle: -53.29
2013-04-10 00:07:13.350 MyApp[450:707] Angle: -75.23
2013-04-10 00:07:13.380 MyApp[450:707] Angle: -51.63
2013-04-10 00:07:13.383 MyApp[450:707] Angle: -73.37
2013-04-10 00:07:13.414 MyApp[450:707] Angle: -50.35
2013-04-10 00:07:13.418 MyApp[450:707] Angle: -72.11
2013-04-10 00:07:13.446 MyApp[450:707] Angle: -50.08
2013-04-10 00:07:13.450 MyApp[450:707] Angle: -72.01
2013-04-10 00:07:13.479 MyApp[450:707] Angle: -50.50
2013-04-10 00:07:13.488 MyApp[450:707] Angle: -73.51
2013-04-10 00:07:13.512 MyApp[450:707] Angle: -51.25
2013-04-10 00:07:13.514 MyApp[450:707] Angle: -74.14
2013-04-10 00:07:13.545 MyApp[450:707] Angle: -49.98
2013-04-10 00:07:13.547 MyApp[450:707] Angle: -72.96
2013-04-10 00:07:13.579 MyApp[450:707] Angle: -46.99
2013-04-10 00:07:13.582 MyApp[450:707] Angle: -68.58
2013-04-10 00:07:13.612 MyApp[450:707] Angle: -43.01
2013-04-10 00:07:13.616 MyApp[450:707] Angle: -65.32
2013-04-10 00:07:13.645 MyApp[450:707] Angle: -40.92
2013-04-10 00:07:13.647 MyApp[450:707] Angle: -62.80
2013-04-10 00:07:13.680 MyApp[450:707] Angle: -39.70
2013-04-10 00:07:13.683 MyApp[450:707] Angle: -61.30
2013-04-10 00:07:13.712 MyApp[450:707] Angle: -40.74
2013-04-10 00:07:13.714 MyApp[450:707] Angle: -63.06
2013-04-10 00:07:13.745 MyApp[450:707] Angle: -42.29
2013-04-10 00:07:13.747 MyApp[450:707] Angle: -65.68
2013-04-10 00:07:13.779 MyApp[450:707] Angle: -43.18
2013-04-10 00:07:13.780 MyApp[450:707] Angle: -67.58
2013-04-10 00:07:13.812 MyApp[450:707] Angle: -42.13
2013-04-10 00:07:13.815 MyApp[450:707] Angle: -66.35
2013-04-10 00:07:13.845 MyApp[450:707] Angle: -40.95
2013-04-10 00:07:13.848 MyApp[450:707] Angle: -64.67
2013-04-10 00:07:13.879 MyApp[450:707] Angle: -39.73
2013-04-10 00:07:13.881 MyApp[450:707] Angle: -62.90
2013-04-10 00:07:13.913 MyApp[450:707] Angle: -40.06
2013-04-10 00:07:13.916 MyApp[450:707] Angle: -63.12
2013-04-10 00:07:13.947 MyApp[450:707] Angle: -40.78
2013-04-10 00:07:13.949 MyApp[450:707] Angle: -63.39
2013-04-10 00:07:13.979 MyApp[450:707] Angle: -41.51
2013-04-10 00:07:13.981 MyApp[450:707] Angle: -62.78
2013-04-10 00:07:14.012 MyApp[450:707] Angle: -42.06
2013-04-10 00:07:14.014 MyApp[450:707] Angle: -61.77
2013-04-10 00:07:14.045 MyApp[450:707] Angle: -43.89
2013-04-10 00:07:14.047 MyApp[450:707] Angle: -61.02
2013-04-10 00:07:14.079 MyApp[450:707] Angle: -45.41
2013-04-10 00:07:14.080 MyApp[450:707] Angle: -61.20
2013-04-10 00:07:14.112 MyApp[450:707] Angle: -46.93
2013-04-10 00:07:14.114 MyApp[450:707] Angle: -61.53
2013-04-10 00:07:14.146 MyApp[450:707] Angle: -49.21
2013-04-10 00:07:14.147 MyApp[450:707] Angle: -62.76
2013-04-10 00:07:14.179 MyApp[450:707] Angle: -51.34
2013-04-10 00:07:14.182 MyApp[450:707] Angle: -64.51
2013-04-10 00:07:14.212 MyApp[450:707] Angle: -53.39
2013-04-10 00:07:14.214 MyApp[450:707] Angle: -66.41
2013-04-10 00:07:14.245 MyApp[450:707] Angle: -56.29
2013-04-10 00:07:14.248 MyApp[450:707] Angle: -69.30
2013-04-10 00:07:14.279 MyApp[450:707] Angle: -57.85
2013-04-10 00:07:14.280 MyApp[450:707] Angle: -70.88
2013-04-10 00:07:14.312 MyApp[450:707] Angle: -60.23

测量的角度每几毫秒“闪烁”近 20 度。根据我到目前为止所读到的有关 CoreMotion 的内容,我预计会出现错误,但不在此范围内。

我可能做错了什么 - 我没有衡量正确的事情吗?

编辑:下面的代码 - 抱歉格式化。 “代码”和“ block 引用”似乎都不能正常工作。


//I'm letting the user laze around a bit before starting the motion updates.
//At the moment this is in the form of a naive idle timer which is fired after
//the first 9 seconds of launching the app (just cause)


- (void)didFireIdleTimerid)theTimer {

[mReferenceAttitude release];
mReferenceAttitude = [[[sSharedMotionManager deviceMotion] attitude] retain];

[self stopIdleTimer];
}

//sSharedMotionManager is an instance of CMMotionManager

//Then, I'm setting up a display link callback wherein the "current" deviceMotion
//is retrieved every time and the difference between the current "attitude"
//and reference "attitude" calculated. It is this difference that is
//converted to degrees and printed

//This is the display link callback, lazily named.
- (void)didRefreshScreenid)sender {

CMAttitude *thisAttitude = [[sSharedMotionManager deviceMotion] attitude];
[thisAttitude multiplyByInverseOfAttitude:mReferenceAttitude];

NSLog(@"Angle: %0.2f", thisAttitude.roll * 180 / 3.14159);

//Rest of the code
//....
}



Best Answer-推荐答案


几个小时的测试证实问题是由 deviceMotionUpdateInterval 引起的未在 CMMotionManager 上设置实例。将其设置为 1.0/60.0 (或任何其他有效值)修复此“闪烁”并导致值平滑变化。

关于ios - CMMotionManager deviceMotion 姿态值中的 "flickering"过多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15910402/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap