2012-10-17 1 views
1

Je dois calculer en lacet Android, roulis, tangage de la sortie des smartphones gyroscope's et j'ai écrit ce code:Comment calculer le lacet, lancer le lancer d'une matrice de rotation?

if (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; 
      } 

Bonjour, je dois calculer rouleau de lacet, pas en utilisant la sortie d'un gyroscope et j'ai écrit ce code:

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

Je ne pas savoir où est le problème, mais le lacet, roulis, les valeurs de hauteur I obtenu en utilisant ce code sont faux, parce que j'ai obtenu la valeur totale différente même si le téléphone est dans la même orientation. Je les calcule à partir de la matrice de rotation dans les trois dernières lignes de code. Et aussi les valeurs de lacet, roulis écrits dans les formules, sont en radians?

+0

Il n'y a pas grand-chose à ajouter à la réponse de Kay, c'est la bonne chose à faire. Cependant j'espère que vous savez que [le lacet, le tangage et le roulis sont mauvais] (http://stackoverflow.com/a/5578867/341970) et [inapproprié pour l'interpolation] (http://stackoverflow.com/a/5580491/341970). – Ali

Répondre

2

J'ai une expérience limitée sur Android, mais selon le manuel de référence, vous pouvez obtenir ces valeurs de SensorManager.getOrientation (...) sans aucun calcul. Si cela est correct, je recommande d'utiliser ceci à la place de tout calcul effectué automatiquement, car les valeurs devraient être plus précises en raison des algorithmes de fusion de capteur travaillant sous le capot.

+0

Incroyable combien de fois cette question se pose. Avez-vous progressé avec votre article de revue/blog sur Motion Sensing? – Ali

+0

@Ali Honte sur moi, n'a pas encore commencé si loin, parce que j'ai trop de travail sur mon jeu. Mais le temps viendra - espérons-le ;-) – Kay

+0

S'il vous plaît laissez-moi savoir quand vous l'avez! – Ali

Questions connexes