3

I'm building an application that detects if the phone has rotated 360 degrees. This rotation will most likely be done in 35 seconds. How do I detect this accurately? I've read some articles about 'integration' and using the gyroscope for the short term and the accelerometer to compensate the gyroscope. What is the best way to achieve this, and, to start, how do I get the rotation values from the gyroscope?

I don't really understand the RotationMatrix from the multiplied by inverse'd CMAttitude. CMAttitude.yaw gives me different values even when I'm not using the phone. I have also seen the teapot example. My code goes about the same, except that I need to process the data from the RotationMatrix myself, since I'm not using OpenGL to do this for me.

Thanks in advance, Hidde

4

1 回答 1

1

查看核心运动 API,您最好的选择似乎是监控旋转速率。特别是通过CMDeviceMotion接口,该接口声明了一个 rotationRate 属性,讨论如下:

CMRotationRate 结构包含指定设备围绕三个轴的旋转速率的数据。此属性的值包含陀螺仪数据的测量值,其偏差已被核心运动算法消除。另一方面,CMGyroData 的同名属性提供来自陀螺仪的原始数据。结构类型在 CMGyroData.h 中声明。

您可以通过CMMotionManager 方法声明您的兴趣来监控事件:

- (void)startDeviceMotionUpdatesUsingReferenceFrame:(CMAttitudeReferenceFrame)referenceFrame toQueue:(NSOperationQueue *)queue withHandler:(CMDeviceMotionHandler)handler

然后,您需要做一些数学运算来计算出以给定速率发生旋转以构成完整的 360 度旋转的时间量。

于 2011-11-26T10:25:57.680 回答