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의 값은 라디안 단위입니까?
Kay의 대답에 추가 할 내용이 많지 않습니다. 바로해야 할 일입니다. 그러나 [yaw, pitch and roll은 악합니다.] (http://stackoverflow.com/a/5578867/341970) 및 [보간을 위해 부적합하다] (http://stackoverflow.com/a/5580491/341970)). – Ali