iphone - Gyro CMAttitude pitch, roll and yaw angle problems -
i have problem getting pitch, roll , yaw angles cmattitude class.
first, did normal gyro using 'cmmotionmanager' class , atributes x,y,z , worked fine. then, tried use cmattitude "absolute angles", doesn't work because seems not updating data. angles 0 (but isn't errors or warnings)
i have searched lot in stackoverflow, , used solutions find, have same problem. here's code:
- (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. motionmanager = [[cmmotionmanager alloc] init]; cmdevicemotion *devicemotion = motionmanager.devicemotion; cmattitude *attitude = devicemotion.attitude; referenceattitude = attitude; [motionmanager startgyroupdates]; timer = [nstimer scheduledtimerwithtimeinterval:1/30.0 target:self selector:@selector(dogyroupdate) userinfo:nil repeats:yes]; } -(void)dogyroupdate { //cambia el frame de referencia [motionmanager.devicemotion.attitude multiplybyinverseofattitude: referenceattitude]; double rrotation = motionmanager.devicemotion.attitude.roll*180/m_pi; double protation = motionmanager.devicemotion.attitude.pitch*180/m_pi; double yrotation = motionmanager.devicemotion.attitude.yaw*180/m_pi; nsstring *mystring = [nsstring stringwithformat:@"%f",rrotation]; self.angyaw.text = mystring; mystring = [nsstring stringwithformat:@"%f",protation]; self.angpitch.text = mystring; mystring = [nsstring stringwithformat:@"%f",yrotation]; self.angroll.text = mystring; }
thanks lot! :d
motionmanager has 4 modes: accelerometer, gyroscope, magnetometer , device motion.
depending on 1 need, need start appropriate mode: startaccelerometerupdates, startgyroupdates, startmagnetometerupdates or startdevicemotionupdates.
you starting startgyroupdates
reading devicemotion
property. in case gyrodata available.
do instead , getting devicemotion data:
[motionmanager startdevicemotionupdates];
Comments
Post a Comment