4

Android 3.1 デバイスのジャイロスコープ センサーからの方向の値を使用して、四角形を回転させる作業を行っています。

値 1.0 以上を取得するには、デバイスを非常に高速に回転させる必要があります。

ここにコードがあります

final float currentRotVector[] =  { 1, 0, 0, 0 };
if (timestamp != 0)
{
    final float dT = (event.timestamp - timestamp) * NS2S;
    // Axis of the rotation sample, not normalized yet.

    // Calculate the angular speed of the sample
    float omegaMagnitude = (float) Math.sqrt(X * X + Y * Y + Z * Z);

    // Normalize the rotation vector if it's big enough to get the axis
    if (omegaMagnitude > EPSILON)
    {
    X /= omegaMagnitude;
    Y /= omegaMagnitude;
    Z /= omegaMagnitude;
    }

    // Integrate around this axis with the angular speed by the timestep
    // in order to get a delta rotation from this sample over the timestep
    // We will convert this axis-angle representation of the delta rotation
    // into a quaternion before turning it into the rotation matrix.
    float thetaOverTwo = dT * omegaMagnitude / 2.0f;
    float sinThetaOverTwo = (float) Math.sin(thetaOverTwo);
    float cosThetaOverTwo = (float) Math.cos(thetaOverTwo);
    deltaRotationVector[0] = cosThetaOverTwo;
    deltaRotationVector[1] = sinThetaOverTwo * X;
    deltaRotationVector[2] = sinThetaOverTwo * Y;
    deltaRotationVector[3] = sinThetaOverTwo * Z;

    /* quaternion multiplication 
        Reference: http://www.cprogramming.com/tutorial/3d/quaternions.html
    */

    currentRotVector[0] = deltaRotationVector[0] * currentRotVector[0] - 
                          deltaRotationVector[1] * currentRotVector[1] - 
                          deltaRotationVector[2] * currentRotVector[2] - 
                          deltaRotationVector[3] * currentRotVector[3];

    currentRotVector[1] = deltaRotationVector[0] * currentRotVector[1] + 
                          deltaRotationVector[1] * currentRotVector[0] + 
                          deltaRotationVector[2] * currentRotVector[3] - 
                          deltaRotationVector[3] * currentRotVector[2];

    currentRotVector[2] = deltaRotationVector[0] * currentRotVector[2] - 
                          deltaRotationVector[1] * currentRotVector[3] + 
                          deltaRotationVector[2] * currentRotVector[0] + 
                          deltaRotationVector[3] * currentRotVector[1];

    currentRotVector[3] = deltaRotationVector[0] * currentRotVector[3] + 
                          deltaRotationVector[1] * currentRotVector[2] - 
                          deltaRotationVector[2] * currentRotVector[1] + 
                          deltaRotationVector[3] * currentRotVector[0];
    final float rad2deg = (float) (180.0f / Math.PI);
    RotAngle = currentRotVector[0] * rad2deg;
    axisX = currentRotVector[1];
    axisY = currentRotVector[2];
    axisZ = currentRotVector[3];

    Log.i("Sensor Orientation GyroScope", "axisX: " + axisX + //
        " axisY: " + axisY + //
                    " axisZ: " + axisZ + //
        " RotAngle: " + RotAngle);
}

タイムスタンプ = event.timestamp;

axisX: 0.69363713 axisY: 0.18359372 axisZ: 0.0228636 RotAngle: 36.7191 のような出力が得られます。また、軸の値のため、デバイスをテーブルに置いたときに出力長方形が微調整されたように見えます。

上記のコードに問題はありますか?

4

1 に答える 1

2

値は rad/s で測定されます。これは Android 2.3 から標準化されています。

約 1.0 の値を取得するには、ほぼ 60 度/秒の速度で回転する必要があります

以前のバージョンの Android を搭載した一部のデバイスでは、値が度/秒で返されますが、これらはほんの一部です。例として、Android 2.2 を搭載した LG Optimus Black (P970) は、これらのデバイスの 1 つで、度/秒を返しますが、これは一般的なケースではありません。

于 2011-12-16T09:16:46.090 に答える