【问题标题】:Android: Does getOrientation() require successive remaps?Android:getOrientation() 是否需要连续重新映射?
【发布时间】:2013-10-15 17:57:53
【问题描述】:

我一直在尝试使用 getOrientation() 方法获取航向值。

boolean success = SensorManager.getRotationMatrix(rot, incl, accel, magnet);
if (success) {
    // Compute orientation
    float orientation[] = new float[3];
    SensorManager.getOrientation(rot, orientation);

}

即使我保持手机稳定并以稳定的位置行走,这些值也会有很大差异。

然后我尝试将加速度值的参考从手机更改为世界轴:

        // Compute world acceleration
        float wAccel[] = new float[4];
        float newAccel[] = new float[]{accel[0],accel[1],accel[2], 0};
        android.opengl.Matrix.multiplyMV(wAccel, 0, rot, 0, newAccel, 0);
        magnetLine += "W" + LOGSEPARATOR +
                tsString + LOGSEPARATOR +
                wAccel[0] + LOGSEPARATOR +
                wAccel[1] + LOGSEPARATOR +
                wAccel[2] + "\n";
    }

然后我在 atan2 函数上使用 X 和 Y 轴的值来确定向量的角度。即使以不同的方式变化,这些值仍然会表现出奇怪的行为(有时值是恒定的,有时会表现出周期性的行为,就像跟随脚步一样)。

我见过一些人调用 remapCoordinate system 来解决与此类似的情况。这是我想念的吗?

【问题讨论】:

    标签: android orientation sensors


    【解决方案1】:

    以下是您可以做的几件事:

    1. 首先,除非您使用的是旧版本的 Android API,否则请使用 Sensor.TYPE_GRAVITY 而不是 Sensor.TYPE_ACCELEROMETERSensor.TYPE_GRAVITY 旨在尝试过滤掉运动,只留下重力矢量。
    2. 使用SensorEventListener 接口的onAccuracyChanged(Sensor sensor, int accuracy) 方法监控传感器的精度。我也遇到过同样的问题,就我而言,它发生在 Sensor.TYPE_MAGNETIC_FIELD 变成 SensorManager.SENSOR_STATUS_UNRELIABLE 时。
    remapCoordinateSystem() 用于在坐标系中进行 90 度旋转,例如将 x 与 z 轴等交换。如果你是例如制作一个显示真北方向的指南针,然后您需要考虑您的设备是处于纵向还是横向模式等。但是,传感器的测量值不依赖于纵向/横向,所以如果它们变化很大,那么您的问题就出在其他地方。

    另请注意android compass seems unreliable,有些人发现Android设备中的指南针不是很好。不过,那篇文章是大约 2 年前的事了,所以希望现在情况会好一些:-)。

    【讨论】:

    • 感谢使用重力传感器的提示,它可以显着平滑信号。我不认为我在图表中丢失了磁力计值,因为每当我获得读数时都会绘制所有这些点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-25
    • 1970-01-01
    • 2014-04-12
    相关资源
    最近更新 更多