2013-04-05 12 views
1

CMAttitude 클래스에서 피치, 롤 및 요우 각도를 가져 오는 데 문제가 있습니다.자이로 CMA 태도, 롤 및 요각 문제

먼저 'CMMotionManager'클래스를 사용하여 정상적인 자이로를 수행하고 x, y, z를 조정하고 잘 작동했습니다. 그런 다음 CMAttitude를 "절대 각도"로 사용하려고했지만 데이터를 업데이트하지 않는 것 같아서 작동하지 않습니다. 각도는 항상 0입니다 (그러나 오류 또는 경고가 아닙니다).

나는 stackoverflow에서 많은 부분을 검색하고 찾은 해결책을 사용했지만 동일한 문제가 있습니다. 여기 내 코드 :

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a 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; 

} 

고마워! : D

답변

3

motionManager에는 가속도계, 자이로 스코프, 자력계 및 장치 동작의 4 가지 모드가 있습니다.

필요한 항목에 따라 startAccelerometerUpdates, startGyroUpdates, startMagnetometerUpdates 또는 startDeviceMotionUpdates와 같은 적절한 모드를 시작해야합니다.

startGyroUpdates을 시작하지만 deviceMotion 속성을 읽는 중입니다. 귀하의 경우에는 gyroData 만 사용할 수 있습니다.

대신 이렇게 당신은 deviceMotion의 데이터를 가져 오는됩니다

[motionManager startDeviceMotionUpdates]; 
+0

가 도움이 기뻐 :) –