我可以使用此代码依赖此“默认”更新间隔(加速度计)吗?
Posted
技术标签:
【中文标题】我可以使用此代码依赖此“默认”更新间隔(加速度计)吗?【英文标题】:Can I rely on this "default" update interval (accelerometer) with this code? 【发布时间】:2012-08-03 12:25:24 【问题描述】:-(void)play
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
[motionManager startDeviceMotionUpdates];
while(!self.stopButtonPressed)
NSLog(@"Y-Axis acceleration is %f", motionManager.deviceMotion.userAcceleration.y);
控制台:
2012-08-03 13:06:10.798 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.803 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.805 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.807 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.808 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.810 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.812 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.814 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.817 MyProject[8896:3a03] Y-Axis acceleration is 0.013498
2012-08-03 13:06:10.820 MyProject[8896:3a03] Y-Axis acceleration is 0.013498
2012-08-03 13:06:10.822 MyProject[8896:3a03] Y-Axis acceleration is 0.013498
2012-08-03 13:06:10.824 MyProject[8896:3a03] Y-Axis acceleration is 0.013498
2012-08-03 13:06:10.826 MyProject[8896:3a03] Y-Axis acceleration is 0.013498
2012-08-03 13:06:10.828 MyProject[8896:3a03] Y-Axis acceleration is 0.013498
2012-08-03 13:06:10.831 MyProject[8896:3a03] Y-Axis acceleration is -0.082339
2012-08-03 13:06:10.833 MyProject[8896:3a03] Y-Axis acceleration is -0.082339
2012-08-03 13:06:10.835 MyProject[8896:3a03] Y-Axis acceleration is -0.082339
2012-08-03 13:06:10.837 MyProject[8896:3a03] Y-Axis acceleration is -0.082339
2012-08-03 13:06:10.840 MyProject[8896:3a03] Y-Axis acceleration is -0.082339
2012-08-03 13:06:10.842 MyProject[8896:3a03] Y-Axis acceleration is -0.082339
2012-08-03 13:06:10.846 MyProject[8896:3a03] Y-Axis acceleration is -0.099570
2012-08-03 13:06:10.848 MyProject[8896:3a03] Y-Axis acceleration is -0.099570
2012-08-03 13:06:10.850 MyProject[8896:3a03] Y-Axis acceleration is -0.099570
2012-08-03 13:06:10.852 MyProject[8896:3a03] Y-Axis acceleration is -0.099570
2012-08-03 13:06:10.855 MyProject[8896:3a03] Y-Axis acceleration is -0.099570
2012-08-03 13:06:10.857 MyProject[8896:3a03] Y-Axis acceleration is -0.099570
2012-08-03 13:06:10.859 MyProject[8896:3a03] Y-Axis acceleration is -0.120698
2012-08-03 13:06:10.862 MyProject[8896:3a03] Y-Axis acceleration is -0.120698
2012-08-03 13:06:10.864 MyProject[8896:3a03] Y-Axis acceleration is -0.120698
2012-08-03 13:06:10.866 MyProject[8896:3a03] Y-Axis acceleration is -0.120698
2012-08-03 13:06:10.868 MyProject[8896:3a03] Y-Axis acceleration is -0.120698
2012-08-03 13:06:10.870 MyProject[8896:3a03] Y-Axis acceleration is -0.120698
2012-08-03 13:06:10.873 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.875 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.877 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.879 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.881 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.882 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.884 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.888 MyProject[8896:3a03] Y-Axis acceleration is -0.083223
....etc.
根据控制台,加速度值平均每 14 微秒更新一次
我没有明确使用具有更新间隔的队列,所以我是否应该假设默认更新间隔约为 14 微秒(当我在这段代码中专门从 while 循环中请求新值时)?
或者这是“意外”,我不应该依赖它?我的意思是我已经测试了几次,更新间隔总是在 13-14 毫秒之间,但是如果处理器在以后的一些测试中更新间隔有可能(如果我没有明确设置更新间隔)会发生显着变化当时出于某种原因碰巧“更忙”(比平时..)..?
感谢您的帮助
【问题讨论】:
【参考方案1】:你不应该依赖这个间隔,因为来自UIAccelerometer 类参考 - 最大更新间隔基于可用的硬件,所以当苹果在未来的设备中更新加速度计芯片时,频率可能会改变(它也可以不同当前的 iPad 和 iPhone)
【讨论】:
所以我应该使用队列并明确设置更新间隔对吗? 嗯,对,但如果您只需要获取加速度计数据,我会使用 UIAcceleremeter 及其方便的委托系统。 hmm...我不太了解委托,而且文档听起来很复杂,谈论运行循环模式等。我会尝试使用类似[motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) //although I'm not sure what goes in here given the code I provided in my original post.. ];
的东西。跨度>
看看我现在要做什么:***.com/questions/11797857/… 谢谢! :)以上是关于我可以使用此代码依赖此“默认”更新间隔(加速度计)吗?的主要内容,如果未能解决你的问题,请参考以下文章