简体   繁体   English

使用iphone的传感器检测旋转

[英]Detect rotation using iphone's sensors

I'm building an application that detects if the phone has rotated 360 degrees. 我正在构建一个应用程序来检测手机是否已旋转360度。 This rotation will most likely be done in 35 seconds. 这种旋转很可能在35秒内完成。 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. 我不太了解RotationMatrix乘以逆CMAttitude。 CMAttitude.yaw gives me different values even when I'm not using the phone. 即使我不使用手机,CMAttitude.yaw也会给我不同的价值。 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. 我的代码大致相同,只是我需要自己处理RotationMatrix的数据,因为我没有使用OpenGL为我做这个。

Thanks in advance, Hidde 谢谢,希德

Looking into the core motion API it seems your best bet is to monitor the rotation rate. 查看核心动作API,似乎最好的办法是监控旋转速度。 Specifically through the CMDeviceMotion interface which declares a rotationRate property with this discussion: 特别是通过CMDeviceMotion接口,它通过以下讨论声明了一个rotationRate属性:

A CMRotationRate structure contains data specifying the device's rate of rotation around three axes. CMRotationRate结构包含指定设备围绕三个轴的旋转速率的数据。 The value of this property contains a measurement of gyroscope data whose bias has been removed by Core Motion algorithms. 此属性的值包含陀螺仪数据的测量值,其偏差已被Core Motion算法删除。 The identically name property of CMGyroData, on the other hand, gives the raw data from the gyroscope. 另一方面,CMGyroData的相同名称属性给出了陀螺仪的原始数据。 The structure type is declared in CMGyroData.h. 结构类型在CMGyroData.h中声明。

You can monitor the events by declaring your interest through the CMMotionManager method: 您可以通过CMMotionManager方法声明您的兴趣来监视事件

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

Then you'd need to do a bit of maths to work out the amount of time a rotation should occur at a given rate to constitute a full 360 degree rotation. 然后你需要做一些数学计算一个旋转应该以给定的速率发生的时间,以构成一个完整的360度旋转。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM