Question

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

Was it helpful?

Solution

Looking into the core motion API it seems your best bet is to monitor the rotation rate. Specifically through the CMDeviceMotion interface which declares a rotationRate property with this discussion:

A CMRotationRate structure contains data specifying the device’s rate of rotation around three axes. The value of this property contains a measurement of gyroscope data whose bias has been removed by Core Motion algorithms. The identically name property of CMGyroData, on the other hand, gives the raw data from the gyroscope. The structure type is declared in CMGyroData.h.

You can monitor the events by declaring your interest through the CMMotionManager method:

- (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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top