【问题标题】:How to use deviceMotion attitude values (roll,pitch and yaw) to detect a motion如何使用 deviceMotion 姿态值(滚动、俯仰和偏航)来检测运动
【发布时间】:2013-05-17 06:30:17
【问题描述】:

我在我的应用程序中使用 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];

如何使用这些数据来检测运动?为此我需要进行哪些计算?

【问题讨论】:

  • 先生,您想用这些值做什么?如果您试图在设备移动时监控这些值,则可以将它们显示为标签。

标签: ios core-motion


【解决方案1】:

姿态值需要设备运动更新启动为:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-28
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    • 2012-08-02
    相关资源
    最近更新 更多