3

私が取り組んでいるプロジェクトのコンパス アプリを作ろうとしています。標準TYPE_ACCELEROMETERTYPE_MAGNETIC_FIELDセンサーを使用しましたが、かなり正確な測定値が得られるようです。ただし、電話を y 軸と z 軸の周りに傾けると、電話が同じ方向 (一定の z 軸) を指していても、Heading の読み取り値が変わります。

これを補う方法を知っている人はいますか?サンプルコードをいただければ幸いです。

現在使用しているコードは次のとおりです。

private void updateDirection() {
  float[] R = new float[16];
      float[] orientationValues = new float[3];

      if(SensorManager.getRotationMatrix (R, null, accelerometerValues, magneticValues)){

        SensorManager.getOrientation (R, orientationValues);

        orientationValues[0] = (float)Math.toDegrees (orientationValues[0]);
        orientationValues[1] = (float)Math.toDegrees (orientationValues[1]);
        orientationValues[2] = (float)Math.toDegrees (orientationValues[2]);

        if(orientationValues[0] < 0){
          orientationValues[0] = 360 + orientationValues[0];
        }

        final int trueNorthHeading = NavigationUtils.getTrueNorthBearing(currentLocation, orientationValues[0]);
        if(trueNorthHeading == currentHeading) {
      return;
    }

        int accuracy = 3;
        if(NavigationUtils.isSignificantHeadingChange(currentHeading, trueNorthHeading, accuracy, SIGNIFICANT_CHANGE_LIMIT)){

          int headingChangeDegrees = NavigationUtils.getStearageDegree(currentHeading, trueNorthHeading);
      currentHeading = trueNorthHeading;    

      navigationManager.headingUpdate(trueNorthHeading, Math.round(orientationValues[0]), headingChangeDegrees);

          Log.d("COMPASS", "North: values[0]: " + (int)orientationValues[0]);
        }
      }
}

ご協力いただきありがとうございます、

アダム

4

2 に答える 2

2

代わりに TYPE_GRAVITY を使用するか、使用できない場合は、ローパス フィルターまたはカルマン フィルターを使用して加速度センサーをフィルター処理します。TYPE_GRAVITY は、最大 10 度のローパス フィルターで精度を向上させます。

于 2013-04-30T20:06:12.613 に答える
0

このAndroid の getOrientation() メソッドを試してみると、悪い結果が返されましたが、動作しているように見えました。

提案されている方向の結果と生の加速度計配列の両方にフィルターを適用しました。

于 2013-04-30T21:36:45.637 に答える