2

I am relatively new to iPhone development and I am playing with the gyroscope, using Core Motion. After a few tests, this is my question.

What information is exactly the gyroscope measuring? absolute angles? I mean, suppose I hold my phone in portrait, at exactly 90 degrees and start sampling. These may be not the correct values, but suppose that at this position, the gyroscope gives me 0, 0 and 0 degrees for yaw, pitch and roll.

Now I throw my iphone in the air and as it goes up it rolls at random a high number of full turns in all axis and returns to my hand at the same position as before. Will the gyroscope read 0,0,0 (meaning that it has the same position as before = absolute angle) or not?

If not, there's a way to measure absolute degrees in all axis? As absolute degrees I mean assuming 0,0,0 as the position it was when the sampling started.

thanks

Roger
  • 243
  • 2
  • 4
  • 14

2 Answers2

4

The gyroscope measures many things for you, and yes, one of these is "absolute angles". Take a look at the docs on CMDeviceMotion. It can give you a rotation rate, which is how fast the device is spinning, and it can give you a CMAttitude. The CMAttitude is what you're calling "absolute angles". It is technically defined as:

the orientation of a body relative to a given frame of reference

The really nice thing is that normal gyroscopes, as noted in the other answer, are prone to drift. The Core Motion framework does a lot of processing behind the scened for you in an effort to compensate for the drift before the measurements are reported. Practically, I've found that the framework does a remarkable (though not perfect) job at this task. Unless you need long term precision to a magnetic pole or something, the attitude reported by the framework can be considered as a perfect relative attitude measurement, for all intents and purposes.

Matt Wilding
  • 20,115
  • 3
  • 67
  • 95
  • thanks! I have tested it a little bit and I see a drift after turning the device a few times. Every 4 to 5 full rotations the device drifts from 3 to 10 degrees! I am not sure how I can compensate that. I will keep searching. thanks. – Roger Feb 25 '11 at 10:27
  • @Matt - I was looking for a post something similar, thanks god, i found you, Can you help me? Actually i want to compute the rate of change of orientation along y axis of my iphone, How can i use CMAttitude with reference as vertical axis? Please help me sir! If possible any coding! Thanks in advance! – sam Sep 06 '12 at 16:36
  • @sam, look at the [CMDeviceMotion docs](http://developer.apple.com/library/ios/#documentation/CoreMotion/Reference/CMDeviceMotion_Class/Reference/Reference.html#//apple_ref/doc/c_ref/CMDeviceMotion). It has exactly that information in the `rotationRate` property. For future reference, since this is basically a separate question, it would be better form to post a question, rather than a comment on an answer. – Matt Wilding Sep 06 '12 at 16:52
  • @MattWilding - [link](http://stackoverflow.com/questions/12305041/compute-rate-of-change-of-orientationangular-measurement-along-y-axis) Here is my question. Can you please provide me a comprehensive answer with a reference code, if possible. Thank you! :) – sam Sep 06 '12 at 17:09
2

The iPhone uses accelerometers for its internal angle measurements, which means they are relative to the Earth's gravity. That's about as absolute as you're going to get, unless you need this program to work in space, too.

gpcz
  • 806
  • 6
  • 8
  • I am talking about the gyroscope, not the accelerometer. – Roger Feb 25 '11 at 01:36
  • 3
    In that case, gyroscopes measure angular speed, which can then be integrated with respect to time to produce angles. However, this method is prone to drift. This means throwing the iPhone in the air and putting it in the same orientation would likely not give you the same orientation as before. The cheap and less-accurate way to remedy this is to occasionally use the accelerometer data as a sanity check against the gyro. The more difficult and accurate way (how nuclear missiles can go down chimneys) is to plug the gyro and accelerometer data into a Kalman filter. – gpcz Feb 25 '11 at 01:40