3

I want to compute rate of change of orientation of the iPhone along y axis. 1. Initially i need to define the reference as y axis, 2. Then measure the rate of change of orientation(angular measurement) from the defined reference.

Does CMAttitude provides a reliable angular measurements to implement this? Or Can i use rotational matrix or integrate gyroscope data(I implement this method, but it's not going to work due to the drift of the gyroscope). So please suggest me a reliable method to get this done?

Thank you in advance!

sam
  • 259
  • 1
  • 6
  • 22

1 Answers1

2

First, just to clarify: Rotation rates are not measured "from" any axis, they're measured "around" an axis. You don't need to provide an initial reference frame, since you're just worried about change over time.

Anyways, The best you'll get is CMDeviceMotion's rotationRate property, about which the docs say:

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.

It's saying that it integrates sensor data from multiple sources (Accelerometer) in an attempt to remove the gyro drift from the readings, as opposed to the CMGyroData class, about which the docs say:

This property yields a measurement of the device’s rate of rotation around three axes. Whereas this property gives the raw data from the gyroscope, the identically named property of CMDeviceMotion gives a CMRotationRate structure measuring gyroscope data whose bias has been removed by Core Motion algorithms.

The takeaway from those references is that, if you want the most accurate rotation rate data, you should use something like:

CMMotionManager* manager = [[CMMotionManager alloc] init];
[manager startDeviceMotionUpdates];

// Later, in some other scope...
double rotationAroundY = [[manager deviceMotion] rotationRate].y;
Matt Wilding
  • 20,115
  • 3
  • 67
  • 95
  • Thank you for ur valuable response. But consider this, I hold my iPhone vertically to the gravity axis, Then i move my iPhone in upward direction by 45 degrees and then turn back again(downward direction) by 60 degrees(So it passes my reference axis and goes negative, So if i plot it's change in angel with reference to vertical , It should show me, 45 degree movement in positive axis(if positive reading) and 15 degree in negative direction(Considering it passes reference) So this is what i want to achieve? How can i do it? – sam Sep 06 '12 at 18:28
  • 1
    @sam, The rotation rate will change its sign the instant you start rotating in the other direction, not when you pass the original reference frame. If you're trying to plot rotation offset from a reference frame over time, you don't want to use `rotationRate` at all. Better just sample the `attitude` property directly at some regular interval, and plot exactly what it gives you. – Matt Wilding Sep 06 '12 at 18:41
  • I plot the reading of attitude directly, But it shows me sudden drifts in the signal at points where rotation offset changes between different levels, But here i didn't use update from referenceattitude, Does it(update from referenceattitude) offer an advantage over normal updating? And Is there any other accurate way than using attitude property even at higher computation cost? Thanks! – sam Sep 06 '12 at 18:50
  • @sam Updating from a reference attitude has no effect on the accuracy of the readings. It's just a convenient way to change the way the exact same data is represented. `CMDeviceMotion` is the most computationally expensive and most accurate means of reading the data, because CoreMotion is massaging a collection of sensor data for you. `CMGyroData` is cheaper and less accurate, because it's just raw gyro data. Unfortunately, even the most accurate version still suffers noticeably from drift, and there's nothing we can do about it, aside from hoping Apple can improve the framework in the future. – Matt Wilding Sep 06 '12 at 18:56
  • Thank you for ur valuable time; For ur information, I integrate the gyroscope data(rotationRate) and calculated the rate of change of angle, But the plot shows a considerable drift, even though CMDeviceMotion provides a drift free signal(As they say rotationrate should not contain any dc offsets), But still it continues,,, Seems like, Some how, I need to find a way to come out of this deep black hole! :) – sam Sep 06 '12 at 19:09
  • @sam, you say you're calculating "rate of change of angle", when the rotation rate is given to point blank by the `rotationRate` property. What exactly do these "calculations" entail? – Matt Wilding Sep 06 '12 at 19:20
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/16387/discussion-between-sam-and-matt-wilding) – sam Sep 06 '12 at 19:39
  • @sam you may want to look at [this](http://stackoverflow.com/questions/1586658/combine-gyroscope-and-accelerometer-data/1590385#1590385) – Hammer Sep 06 '12 at 22:14
  • @Hammer, while that's useful info for combining accelerometer data with gyro data, the CoreMotion framework already does that for you if you're using "device motion" updates. – Matt Wilding Sep 06 '12 at 22:21
  • @Hammer; I implement this in my code once; But this is not accurate when the rate of change of angel varies. If it's at a constant rate, results are acceptable! I think only way to solve this to come up with a adaptive method(something like an adaptive filter) :) – sam Sep 07 '12 at 06:13