Как вычислить рыскание, крен по тангажу из матрицы вращения?

Мне нужно вычислить в Android рыскание, вращение, тангаж с выходных данных смартфонов гироскопа, и я написал этот код:

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

Привет, мне нужно вычислить рыскание и тангаж, используя выходные данные гироскопа, и я написал этот код:

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

Я не знаю, в чем проблема, но значения рыскания, крена и тангажа, которые я получил с помощью этого кода, неверны, потому что я получил совершенно разные значения, даже если телефон находится в одной ориентации. Я вычисляю их из матрицы вращения в последних трех строках кода. А также значения рыскания, крена тангажа, записанные в формулах, в радианах?


person user1753037    schedule 17.10.2012    source источник
comment
К ответу Кея добавить особо нечего, это правильно. Однако я надеюсь, вы знаете, что рыскание, тангаж и крен - зло и не подходит для интерполяции.   -  person Ali    schedule 17.10.2012


Ответы (1)


У меня ограниченный опыт работы с Android, но, согласно справочному руководству, вы можете получить эти значения из SensorManager.getOrientation(...) без каких-либо вычислений. Если это верно, я рекомендую использовать это вместо любого самостоятельного расчета, потому что значения должны быть более точными из-за алгоритмов слияния датчиков, работающих под капотом.

person Kay    schedule 17.10.2012
comment
Удивительно, сколько раз возникает этот вопрос. Был ли достигнут какой-либо прогресс в вашей обзорной статье/сообщении в блоге о распознавании движения? - person Ali; 17.10.2012
comment
@Ali Позор мне, я еще не начал, потому что сейчас у меня слишком много работы над своей игрой. Но время придет - надеюсь на это ;-) - person Kay; 18.10.2012
comment
Пожалуйста, дайте мне знать, когда он у вас есть! - person Ali; 18.10.2012