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
가 도움이 기뻐 :) –