7

I'm using coreMotion in my app to detect a motion of iOS device. I know how to get the different sensor's data from coreMotion. I am getting roll, pitch, and yaw data as follows from the deviceMotion:

 float pitch =  (180/M_PI)*self.manager.deviceMotion.attitude.pitch];
 float roll = (180/M_PI)*self.manager.deviceMotion.attitude.roll];
 float yaw = (180/M_PI)*self.manager.deviceMotion.attitude.yaw];

How can I use these data to detect a motion? What are the calculations that I need to do for this?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Madhu
  • 994
  • 1
  • 12
  • 33
  • Sir, What are you trying to do with these values? If you are trying to monitor these values when the device moves then, you could display these as labels. – iSeeker Sep 30 '13 at 08:55

1 Answers1

10

The attitude values need the device motion updates to be started as:

startDevicemotionUpdates

To monitor attitude values when device moves, use the attitude values to be displayed in labels:

[self.cmMotionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMDeviceMotion *devMotion, NSError *error) {

float pitch =  (180/M_PI)*self.manager.devMotion.attitude.pitch];
float roll = (180/M_PI)*self.manager.devMotion.attitude.roll];
float yaw = (180/M_PI)*self.manager.devMotion.attitude.yaw];

self.rollLabel.text = [NSString stringWithFormat:@"%f", roll];
self.pitchLabel.text = [NSString stringWithFormat:@"%f",pitch];
self.yawLabel.text = [NSString stringWithFormat:@"%f",yaw];
}

Also it is better not to use roll, pitch and yaw(aka Euler Angles). Use Quaternion or Rotation matrices for better accuracy. Euler angles have the tendency to be in a situation called gimbal lock which results in unreliable data.

Please check this link for how to use quaternion, and convert that value to the roll, pitch and yaw values: SO link

Community
  • 1
  • 1
iSeeker
  • 776
  • 1
  • 8
  • 24