我必须得到当前的设备态度。 ipad在ipad支架上正好是风景,然后以某种方式向后倾斜。第一次运行的self.motionManager.deviceMotion.attitude
无法提供。当ipad在桌子上休息时,第一个值是相等的吗?我错过了什么吗?如何获得目前正确的态度?
self.motionManager = [[CMMotionManager alloc] init];
self.motionManager.deviceMotionUpdateInterval = 1.0/60.0;
[self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXMagneticNorthZVertical toQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) {
if (error == nil)
{
startattitude = self.motionManager.deviceMotion.attitude;
CMQuaternion quat = self.motionManager.deviceMotion.attitude.quaternion;
double myRoll = RADIANS_TO_DEGREES(atan2(2*(quat.y*quat.w - quat.x*quat.z), 1 - 2*quat.y*quat.y - 2*quat.z*quat.z)) ;
double myPitch = RADIANS_TO_DEGREES(atan2(2*(quat.x*quat.w + quat.y*quat.z), 1 - 2*quat.x*quat.x - 2*quat.z*quat.z));
double myYaw = RADIANS_TO_DEGREES(asin(2*quat.x*quat.y + 2*quat.w*quat.z));
}
}];
我需要得到正确的态度,以便稍后我可以找出开始和新态度之间的区别。
在处理程序块中更新34后,它具有正确的方向值。如何找出达到正确的值。偏航辊间距的调试输出:
2014-12-29 12:57:40.383 testApp myRoll: -68.0961
2014-12-29 12:57:40.383 testApp myPitch: 1.7463
2014-12-29 12:57:40.383 testApp myYaw: 2.2242
2014-12-29 12:57:40.386 testApp myRoll: -68.1005
2014-12-29 12:57:40.386 testApp myPitch: 1.7079
2014-12-29 12:57:40.386 testApp myYaw: 2.2592
2014-12-29 12:57:40.386 testApp myRoll: -68.1005
2014-12-29 12:57:40.387 testApp myPitch: 1.7079
2014-12-29 12:57:40.387 testApp myYaw: 2.2592
2014-12-29 12:57:40.387 testApp myRoll: -68.1005
2014-12-29 12:57:40.387 testApp myPitch: 1.7079
2014-12-29 12:57:40.388 testApp myYaw: 2.2592
2014-12-29 12:57:40.388 testApp myRoll: -68.1005
2014-12-29 12:57:40.388 testApp myPitch: 1.7079
2014-12-29 12:57:40.389 testApp myYaw: 2.2592
2014-12-29 12:57:40.389 testApp myRoll: -68.1005
2014-12-29 12:57:40.389 testApp myPitch: 1.7079
2014-12-29 12:57:40.389 testApp myYaw: 2.2592
2014-12-29 12:57:40.389 testApp myRoll: -68.1005
2014-12-29 12:57:40.389 testApp myPitch: 1.7079
2014-12-29 12:57:40.389 testApp myYaw: 2.2592
2014-12-29 12:57:40.390 testApp myRoll: -68.1005
2014-12-29 12:57:40.390 testApp myPitch: 1.7079
2014-12-29 12:57:40.390 testApp myYaw: 2.2592
2014-12-29 12:57:40.390 testApp myRoll: -68.1005
2014-12-29 12:57:40.390 testApp myPitch: 1.7079
2014-12-29 12:57:40.391 testApp myYaw: 2.2592
2014-12-29 12:57:40.391 testApp myRoll: -68.1005
2014-12-29 12:57:40.391 testApp myPitch: 1.7079
2014-12-29 12:57:40.391 testApp myYaw: 2.2592
2014-12-29 12:57:40.391 testApp myRoll: -68.1005
2014-12-29 12:57:40.392 testApp myPitch: 1.7079
2014-12-29 12:57:40.392 testApp myYaw: 2.2592
2014-12-29 12:57:40.392 testApp myRoll: -68.1005
2014-12-29 12:57:40.393 testApp myPitch: 1.7079
2014-12-29 12:57:40.393 testApp myYaw: 2.2592
2014-12-29 12:57:40.393 testApp myRoll: -68.1005
2014-12-29 12:57:40.393 testApp myPitch: 1.7079
2014-12-29 12:57:40.393 testApp myYaw: 2.2592
2014-12-29 12:57:40.394 testApp myRoll: -68.1005
2014-12-29 12:57:40.394 testApp myPitch: 1.7079
2014-12-29 12:57:40.394 testApp myYaw: 2.2592
2014-12-29 12:57:40.413 testApp myRoll: -68.1002
2014-12-29 12:57:40.418 testApp myPitch: 1.6904
2014-12-29 12:57:40.418 testApp myYaw: 2.2757
2014-12-29 12:57:40.419 testApp myRoll: -68.1011
2014-12-29 12:57:40.419 testApp myPitch: 1.6541
2014-12-29 12:57:40.419 testApp myYaw: 2.3094
2014-12-29 12:57:40.420 testApp myRoll: -68.1011
2014-12-29 12:57:40.420 testApp myPitch: 1.6541
2014-12-29 12:57:40.421 testApp myYaw: 2.3094
2014-12-29 12:57:40.429 testApp myRoll: -68.1038
2014-12-29 12:57:40.429 testApp myPitch: 1.6240
2014-12-29 12:57:40.431 testApp myYaw: 2.3363
2014-12-29 12:57:40.436 testApp myRoll: -68.1038
2014-12-29 12:57:40.440 testApp myPitch: 1.6240
2014-12-29 12:57:40.442 testApp myYaw: 2.3363
2014-12-29 12:57:40.444 testApp myRoll: -68.1038
2014-12-29 12:57:40.445 testApp myPitch: 1.6240
2014-12-29 12:57:40.457 testApp myYaw: 2.3363
2014-12-29 12:57:40.459 testApp myRoll: -68.1055
2014-12-29 12:57:40.460 testApp myPitch: 1.6077
2014-12-29 12:57:40.462 testApp myYaw: 2.3511
2014-12-29 12:57:40.463 testApp myRoll: -68.1061
2014-12-29 12:57:40.465 testApp myPitch: 1.5822
2014-12-29 12:57:40.467 testApp myYaw: 2.3747
2014-12-29 12:57:40.472 testApp myRoll: -68.1061
2014-12-29 12:57:40.474 testApp myPitch: 1.5822
2014-12-29 12:57:40.476 testApp myYaw: 2.3747
2014-12-29 12:57:40.478 testApp myRoll: -68.1061
2014-12-29 12:57:40.478 testApp myPitch: 1.5822
2014-12-29 12:57:40.479 testApp myYaw: 2.3747
2014-12-29 12:57:40.480 testApp myRoll: -68.1061
2014-12-29 12:57:40.481 testApp myPitch: 1.5822
2014-12-29 12:57:40.483 testApp myYaw: 2.3747
2014-12-29 12:57:40.486 testApp myRoll: -68.1061
2014-12-29 12:57:40.487 testApp myPitch: 1.5668
2014-12-29 12:57:40.488 testApp myYaw: 2.3893
2014-12-29 12:57:40.489 testApp myRoll: -68.1061
2014-12-29 12:57:40.491 testApp myPitch: 1.5668
2014-12-29 12:57:40.492 testApp myYaw: 2.3893
2014-12-29 12:57:40.494 testApp myRoll: -68.1085
2014-12-29 12:57:40.495 testApp myPitch: 1.5357
2014-12-29 12:57:40.496 testApp myYaw: 2.4182
2014-12-29 12:57:40.497 testApp myRoll: -68.1085
2014-12-29 12:57:40.498 testApp myPitch: 1.5357
2014-12-29 12:57:40.499 testApp myYaw: 2.4182
2014-12-29 12:57:40.500 testApp myRoll: -68.1085
2014-12-29 12:57:40.501 testApp myPitch: 1.5357
2014-12-29 12:57:40.502 testApp myYaw: 2.4182
2014-12-29 12:57:40.515 testApp myRoll: -68.1125
2014-12-29 12:57:40.517 testApp myPitch: 1.5137
2014-12-29 12:57:40.518 testApp myYaw: 2.4381
2014-12-29 12:57:40.526 testApp myRoll: -68.1155
2014-12-29 12:57:40.526 testApp myPitch: 1.5031
2014-12-29 12:57:40.527 testApp myYaw: 2.4485
2014-12-29 12:57:40.547 testApp myRoll: -68.1160
2014-12-29 12:57:40.549 testApp myPitch: 1.4823
2014-12-29 12:57:40.550 testApp myYaw: 2.4678
2014-12-29 12:57:40.558 testApp myRoll: -111.3225
2014-12-29 12:57:40.558 testApp myPitch: 178.5306
2014-12-29 12:57:40.559 testApp myYaw: 5.6269
2014-12-29 12:57:40.579 testApp myRoll: -111.3233
2014-12-29 12:57:40.580 testApp myPitch: 178.5440
2014-12-29 12:57:40.580 testApp myYaw: 5.6146
2014-12-29 12:57:40.591 testApp myRoll: -111.3260
2014-12-29 12:57:40.591 testApp myPitch: 178.5605
2014-12-29 12:57:40.591 testApp myYaw: 5.5995
2014-12-29 12:57:40.612 testApp myRoll: -111.3311
2014-12-29 12:57:40.612 testApp myPitch: 178.5775
2014-12-29 12:57:40.613 testApp myYaw: 5.5849
2014-12-29 12:57:40.623 testApp myRoll: -111.3352
2014-12-29 12:57:40.623 testApp myPitch: 178.5856
2014-12-29 12:57:40.623 testApp myYaw: 5.5785
2014-12-29 12:57:40.644 testApp myRoll: -111.3378
2014-12-29 12:57:40.645 testApp myPitch: 178.6032
2014-12-29 12:57:40.645 testApp myYaw: 5.5633
2014-12-29 12:57:40.655 testApp myRoll: -111.3330
2014-12-29 12:57:40.655 testApp myPitch: 178.6188
2014-12-29 12:57:40.656 testApp myYaw: 5.5477
2014-12-29 12:57:40.676 testApp myRoll: -111.3342
2014-12-29 12:57:40.677 testApp myPitch: 178.6249
2014-12-29 12:57:40.677 testApp myYaw: 5.5421
2014-12-29 12:57:40.687 testApp myRoll: -111.3386
2014-12-29 12:57:40.688 testApp myPitch: 178.6378
2014-12-29 12:57:40.688 testApp myYaw: 5.5316
2014-12-29 12:57:40.709 testApp myRoll: -111.3422
2014-12-29 12:57:40.709 testApp myPitch: 178.6439
2014-12-29 12:57:40.709 testApp myYaw: 5.5273
编辑:没有参考它仍然是相同的。我需要进一步调查。
答案 0 :(得分:0)
事实证明,如果不提供参考,它会提供几乎正确的值。这些值包含我用±2度过滤的噪音。
self.motionManager = [[CMMotionManager alloc] init];
self.motionManager.deviceMotionUpdateInterval = 1.0/60.0;
[self.motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) {
if (error == nil)
{
startattitude = self.motionManager.deviceMotion.attitude;
}
}];