当我调用 startDeviceMotionUpdatesUsingReferenceFrame,然后缓存对我的第一个参考帧的引用并在之后对我的所有运动更新调用 multiplyByInverseOfAttitude 时,我没有从我期望的参考帧中得到变化。这是我不理解的一个非常简单的演示。
self.motionQueue = [[NSOperationQueue alloc] init];
self.motionManager = [[CMMotionManager alloc] init];
self.motionManager.deviceMotionUpdateInterval = 1.0/20.0;
[self.motionManager startDeviceMotionUpdatesUsingReferenceFrame: CMAttitudeReferenceFrameXArbitraryZVertical toQueue:self.motionQueue withHandler:^(CMDeviceMotion *motion, NSError *error){
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
CMAttitude *att = motion.attitude;
if(self.motionManagerAttitudeRef == nil){
self.motionManagerAttitudeRef = att;
return;
}
[att multiplyByInverseOfAttitude:self.motionManagerAttitudeRef];
NSLog(@"yaw:%+0.1f, pitch:%+0.1f, roll:%+0.1f, att.yaw, att.pitch, att.roll);
}];
}];
首先,在我的应用程序中,我只关心俯仰和滚动。但是偏航也在那里表明我的困惑。
如果我将手机放在我的平板桌面上,启动应用程序并查看日志,一切都会按预期进行。所有的偏航、俯仰滚转值为 0.0,然后如果我将手机旋转 90 度而不将其从表面抬起,则只有偏航发生变化。所以那里一切都很好。
为了证明我认为是问题所在......现在将手机放在(例如)一个空咖啡杯中,这样所有角度都略微倾斜,并且重力方向在所有轴上都有一些分数值。现在启动应用程序,使用上面的代码,您会认为一切正常,因为偏航、俯仰和滚动的值再次为 0.0。但现在将咖啡杯旋转 90 度,但不要将其从桌面抬起。 为什么我看到所有偏航、俯仰和滚动的姿态发生显着变化? 由于我缓存了我的初始姿态(现在是我的新参考姿态),并调用了 muptiplyByInverseOfAttitude 我不应该只是改变偏航吗?