7

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];

これらのデータを使用してモーションを検出するにはどうすればよいですか? これを行うために必要な計算は何ですか?

4

1 に答える 1

10

姿勢の値では、デバイスのモーションの更新を次のように開始する必要があります。

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];
}

また、ロール、ピッチ、ヨー (別名オイラー角) を使用しないことをお勧めします。精度を高めるには、Quaternion または Rotation 行列を使用します。オイラー角はジンバル ロックと呼ばれる状況になる傾向があり、データの信頼性が低下します。

クォータニオンの使用方法については、このリンクを確認し、その値をロール、ピッチ、ヨーの値に変換してください: SO リンク

于 2013-09-30T08:55:46.627 に答える