gpt4 book ai didi

orientation - 如何从旋转矩阵计算偏航、俯仰?

转载 作者:行者123 更新时间:2023-12-04 05:28:20 27 4
gpt4 key购买 nike

我必须在 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]);

我不知道问题出在哪里,但是我使用此代码获得的偏航、滚转、俯仰值是错误的,因为即使手机处于相同的方向,我也获得了完全不同的值。我从最后三行代码中的旋转矩阵计算它们。还有公式中写的偏航、俯仰角的值是弧度吗?

最佳答案

我在 Android 上的经验有限,但根据引用手册,您可以从 SensorManager.getOrientation (...) 获得这些值。无需任何计算。如果这是正确的,我建议使用它而不是任何自制的计算,因为由于在引擎盖下工作的传感器融合算法,这些值应该更精确。

关于orientation - 如何从旋转矩阵计算偏航、俯仰?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12933962/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com