我在我的应用程序中使用coreMotion来检测iOS设备的运动。我知道如何从coreMotion获取不同传感器的数据。我正在获得滚动、俯仰和偏航数据,如deviceMotion所示
float pitch = (180/M_PI)*self.manager.deviceMotion.attitude.pitch];
float roll = (180/M_PI)*self.manager.deviceMotion.attitude.roll];
float yaw = (180/M_PI)*self.manager.deviceMotion.attitude.yaw];如何使用这些数据来检测运动?我需要做些什么计算?
发布于 2013-09-30 08:55:46
姿态值需要以下列方式启动设备运动更新:
startDevicemotionUpdates若要监视设备移动时的姿态值,请使用要在标签中显示的姿态值:
[self.cmMotionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMDeviceMotion *devMotion, NSError *error) {
float pitch = (180/M_PI)*self.manager.devMotion.attitude.pitch];
float roll = (180/M_PI)*self.manager.devMotion.attitude.roll];
float yaw = (180/M_PI)*self.manager.devMotion.attitude.yaw];
self.rollLabel.text = [NSString stringWithFormat:@"%f", roll];
self.pitchLabel.text = [NSString stringWithFormat:@"%f",pitch];
self.yawLabel.text = [NSString stringWithFormat:@"%f",yaw];
}另外,最好不要使用滚动,俯仰和偏航(也就是欧拉角)。使用四元数或旋转矩阵以获得更高的精度。欧拉角往往处于一种叫做万向节锁的情况下,这会导致不可靠的数据。
请检查此链接以了解如何使用四元数,并将该值转换为滚动、俯仰和偏航值:SO link。
https://stackoverflow.com/questions/16602840
复制相似问题