2012-10-17 3 views
1

I는 gyroscope's 스마트 출력 안드로이드, 요, 롤, 피치 계산해야하고이 코드 썼다회전 행렬에서 yaw, pitch roll을 계산하는 방법은 무엇입니까?

경우 (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) {

 float xgyr=event.values[0];    //rotation around x-axis [rad/sec] 
     float ygyr=event.values[1];    // rotation around y-axis 
     float zgyr=event.values[2];    // rotation around z-axis 


     // This timestep's delta rotation to be multiplied by the current rotation 
     // after computing it from the gyro sample data. 

     double EPSILON = 0.0;   //EPSILON value to be defined 
     if (timestamp != 0) { 
      final float dT = (event.timestamp - timestamp) * NS2S; 
      // Axis of the rotation sample, not normalized yet. 
      float axisX = event.values[0]; 
      float axisY = event.values[1]; 
      float axisZ = event.values[2]; 

      // Calculate the angular speed of the sample, teta is the vector length 
      float omegaMagnitude = (float) Math.sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ); 

      // Normalize the rotation vector if it's big enough to get the axis 
      if (omegaMagnitude > EPSILON) {     //EPSILON TO BE DEFINED 
       axisX /= omegaMagnitude; 
       axisY /= omegaMagnitude; 
       axisZ /= omegaMagnitude; 
      } 

안녕하세요, 나는 자이로 스코프의 출력을 사용하여 요 롤, 피치를 계산해야하고이 코드 작성 : 나는 문제가 어디 있는지하지는

   float thetaOverTwo = omegaMagnitude * dT/2.0f;  //Insert initial value for orientation omegaMagnitude 
      float sinThetaOverTwo = (float) Math.sin(thetaOverTwo); 
      float cosThetaOverTwo = (float) Math.cos(thetaOverTwo); 

      /*rotation vector, a non-normalized three-dimensional vector the direction of which specifies the rotation axis, 
      and the length of which is teta, Combining two consecutive quaternion rotations is therefore just as simple as using the rotation matrix. 
      Remember that two successive rotation matrices, A1 , A2 are combined A3 = A2*A1*/ 

      //Quaternions 
      deltaRotationVector[0] = sinThetaOverTwo * axisX; 
      deltaRotationVector[1] = sinThetaOverTwo * axisY; 
      deltaRotationVector[2] = sinThetaOverTwo * axisZ; 
      deltaRotationVector[3] = cosThetaOverTwo; 
     } 
     timestamp = event.timestamp; 
     float[] deltaRotationMatrix = new float[9]; 
     SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRotationVector); 
     // User code should concatenate the delta rotation we computed with the current rotation 
     // in order to get the updated rotation. 
     // rotationCurrent = rotationCurrent * deltaRotationMatrix; The initial rotation has to be computedand then at each step updated 
     /*Rotation current is a vector with rotation on pitch, roll, yaw (3x1) multiplied by 3x3 rotation matrix i have the new orientation*/ 

     /*In the "xyz (pitch-roll-yaw) convention," theta is pitch, psi is roll, and phi is yaw. */ 




     double pitch = Math.atan2(deltaRotationMatrix[6], deltaRotationMatrix[7]); 
     double roll = Math.acos(deltaRotationMatrix[8]); 
     double yaw = - Math.atan2(deltaRotationMatrix[2], deltaRotationMatrix[5]); 

을하지만, 요, 롤, 피치 값은 내가 획득 이 코드를 사용하는 것은 잘못된 것입니다. 왜냐하면 제가 총 다른 값을 얻었 기 때문입니다. 전화기가 같은 방향으로 있어도 마찬가지입니다. 마지막 세 줄의 코드에서 회전 행렬을 사용하여이를 계산합니다. 또한 공식에 쓰여있는 yaw, pitch roll의 값은 라디안 단위입니까?

+0

Kay의 대답에 추가 할 내용이 많지 않습니다. 바로해야 할 일입니다. 그러나 [yaw, pitch and roll은 악합니다.] (http://stackoverflow.com/a/5578867/341970) 및 [보간을 위해 부적합하다] (http://stackoverflow.com/a/5580491/341970)). – Ali

답변

2

Android에서의 사용 경험이 제한되어 있지만 참조 설명서에 따르면 계산없이 SensorManager.getOrientation (...)에서이 값을 얻을 수 있습니다. 이것이 정확하다면 후드에서 작동하는 센서 융합 알고리즘으로 인해 값이 더 정확해야하기 때문에 자체 계산 대신이 값을 사용하는 것이 좋습니다.

+0

놀랍게도 몇 번이나이 질문이 떠오른다. 모션 감지에 대한 리뷰 기사/블로그 게시물로 어떤 진전을 보였습니까? – Ali

+0

@Ali Shame on me, 아직도 내 게임에 너무 많은 작업을했기 때문에 지금까지 시작하지 못했습니다. 그러나 시간이 올 것입니다 - 희망 그렇게 ;-) – Kay

+0

당신이 그것을 가지고있을 때 알려주십시오! – Ali

관련 문제