我有一个非常简单的应用程序,我试图通过核心运动使用陀螺仪.
此时,出于测试目的,我只是抓住滚动,俯仰和偏航的值以及在屏幕上打印.根据下面的图片,据我所知,滚动,俯仰和偏航对应于红色,绿色和蓝色轴,对吗?
好.当我将iphone放在靠左侧的桌子(右侧的主页按钮)上时,完全相对于桌面平面成90度,这些是我读取的滚动,俯仰和偏航的值:-90,0, 0.然后我开始按照桌子的垂直轴以逆时针方式旋转iPhone,根据工作台垂直轴,它将在正方向上旋转.在iPhone上,这意味着一个音高旋转,但是当我旋转时,音高保持不变,而YAW则会改变!!!
如果iPhone放在桌子的左侧,则绿色轴(音高)是垂直的.如果我在X上逆时针(正向)旋转设备,我应该看到俯仰角增加,而不是偏航.
我对此的唯一解释是,旋转设备时陀螺仪轴不会旋转.因此,如果我使用默认态度参考,iPhone会认为面朝上静止位置是默认位置,蓝色轴(偏航)将始终是垂直位置.它是否正确?
这是我正在使用的代码......
在主要代码上
motionManager = [[CMMotionManager alloc] init];
motionManager.deviceMotionUpdateInterval = 1.0/60.0; //60 Hz
[motionManager startDeviceMotionUpdates];
timer = [[NSTimer scheduledTimerWithTimeInterval:(1.0/60.0)
target:self
selector:@selector( readIt )
userInfo:nil
repeats:YES]
retain];
Run Code Online (Sandbox Code Playgroud)
剩下的代码
#define degrees(x) (180.0 * x / M_PI)
- (void) readIt {
// CMAttitude *referenceAttitude;
CMAttitude *attitude;
CMDeviceMotion *motion = motionManager.deviceMotion;
if (!motion) {
return;
}
attitude = motion.attitude;
NSLog(@"roll = %f... pitch = %f ... yaw = %f", degrees(attitude.roll), degrees(attitude.pitch), degrees(attitude.yaw));
}
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
12648 次 |
| 最近记录: |