3

I see that I can retrieve CMAttitude from a device and from it I can read 3 values which I need (pitch, roll and yaw). As I understand, this CMAttitude object is managed by CoreMotion which is a Sensor Fusion manager for calculating correct results from compass, gyro and accelerometer together (on Android it is SensorManager Class).

So my questions are:

  1. Are those values (pitch, roll and yaw) relative to the magnetic north and gravity?

  2. If above is correct, how can I modify it to give me results relative to the geographic north?

  3. If a device (such as iPhone 3GS) doesn't have an gyroscope, do I have to tell it to Manager or can I just tell it to give me the device's attitude based on the sensors it has (acc + gyro + compas OR acc + compas)

Cœur
  • 37,241
  • 25
  • 195
  • 267
vale4674
  • 4,161
  • 13
  • 47
  • 72

1 Answers1

6
  1. and 2:

iOS 5.0 simplifies this task. CMMotion manager has new method:


- (void)startDeviceMotionUpdatesUsingReferenceFrame:(CMAttitudeReferenceFrame)referenceFrame

As reference frame you can use this values:

  • CMAttitudeReferenceFrameXMagneticNorthZVertical for magnetic north,
  • CMAttitudeReferenceFrameXTrueNorthZVertical for true north.

If you want to do this with older iOS im afraid you have to calibrate this by yourself using current user location.

Try checkout this resources:

3. If device has no gyro, the deviceMotionAvailable property of CMMotionManger will be "NO" (it is equivalent to gyroAvailable property) and you cannot get attitude using device motion. The only thing you can do is to read accelerometer and magnetometer data directly.

Artur Ozierański
  • 1,177
  • 7
  • 18
  • Tnx for reply. So this means if I set ReferenceFrame CMAttitudeReferenceFrameXTrueNorthZVertical I have to have GPS enabled because iOS would use my current location also? 1. and 2. I would like to support 4.0 OS also so I'll have to figure that. 3. It is OK for me to not support 3GS then or to calculate for that device orientation with only accelerometer and compas. So you see I would have 3 checks in my code 1. isOS5 - use CMAttitudeReferenceFrameXTrueNorthZVertical 2. isOS4 - calibrate 3. is 3GS - I can't get attitude so I must calculate with accelerometer and compas only. – vale4674 Feb 16 '12 at 19:08
  • I just finished watching both videos and it clarifies a lot, tnx. – vale4674 Feb 16 '12 at 23:49
  • I've been researching for a while now but I can't find what I want. That thing with iOS4. Can you tell me some tips or guidelines on how to get those values on iOS4? – vale4674 Feb 17 '12 at 15:14