Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use deviceMotion attitude values (roll,pitch and yaw) to detect a motion

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?

like image 827
Madhu Avatar asked May 17 '13 06:05

Madhu


1 Answers

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

like image 126
iSeeker Avatar answered Oct 20 '22 06:10

iSeeker