方位角值改变音调时,更改 [英] Azimuth values changing when changing pitch

查看:317
本文介绍了方位角值改变音调时,更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个增强现实应用程序,我的工作设备的方位和滚动值。使用加速度计和磁场 - 我得到的旋转矩阵 - 从 getRotationMatrix 。由于这是一个AR应用程序,我需要渲染(当通过摄像机看到的那样),当装置被移动,不会改变其在真实世界中的位置的物体。

I need the device's azimuth and roll values for an augmented reality app I'm working on. I'm getting the rotation matrix - from getRotationMatrix - using the accelerometer and the magnetic field. Since this is an AR app, I need to render objects that wouldn't change their positions in the real world (when seen through the camera) when the device is moved.

问题是,当使用物理滚动装置(在尝试观察在音调值变化),我可以观察变化方位角方向值,即使该应保持稳定。此外,方位角偏离关闭只有当节距是变化的,并返回到它的原始值时所述滚动停止。 因此,要澄清,因为我开始侧倾,方位角开始更改为好,而当滚动停止时,方位角慢慢返回到正确的值。我想不通,为什么方位角表现如此。

The problem is, when physically rolling the device (in attempts to observe the variations in the pitch values), I can observe changes in the azimuth orientation values, even though that should remain stable. Moreover, the azimuth strays off only when the pitch is changing, and returns back to its original value when the rolling is stopped. So to clarify, as I start the roll, the azimuth starts changing as well, and when the roll stops, the azimuth slowly returns back to the correct value. I can't figure out why the azimuth is behaving so.

下面是code表示获取传感器数据,并计算旋转矩阵。

Here is the code that gets the sensor data and calculates the rotation matrix.

@Override
public void onSensorChanged(SensorEvent sensorEvent) {
    switch (sensorEvent.sensor.getType()) {
    case Sensor.TYPE_ACCELEROMETER:
        accel = lowPass(sensorEvent.values.clone(), accel);
        break;

    case Sensor.TYPE_MAGNETIC_FIELD:
        magnet = lowPass(sensorEvent.values.clone(), magnet);
        break;
    }

    if (accel == null || magnet == null)
        return;

    if (!SensorManager.getRotationMatrix(rotationMatrix, null, accel, magnet))
        return;
    SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_Z,
            SensorManager.AXIS_MINUS_X, outRotationMatrix); // Remapping because the device is held in landscape.
    SensorManager.getOrientation(outRotationMatrix, orientationValues);

    currentOrientation = (float) (Math.toDegrees(orientationValues[0]) + this.getDeclination()); //Azimuth; (Degrees);
    eyeLevelInclination = (float) Math.toDegrees(orientationValues[1]); //Pitch; (Degrees); down is 90 , up is -90.
    deviceOrientation = (float) Math.toDegrees(orientationValues[2]);

    sendSensorBroadcast(); 
}

因此​​,在code以上, currentOrientation (负责横向稳定呈现AR对象)的变化过程中的设备轧辊,当仅 eyeLevelInclination 应万变(负责垂直稳定呈现AR对象)。
我还使用一个低通滤波器,以稳定的传感器数据。虽然我不相信这是负责的方位变化,我把它code在这里不管 -

So in the code above, currentOrientation (responsible for horizontally stabilizing the rendered AR objects) changes during device roll, when only eyeLevelInclination should be changing (responsible for vertically stabilizing the rendered AR object).
I'm also using a low pass filter to stabilize the sensor data. Although I dont believe this is responsible for the azimuth variations, I'm putting its code here regardless-

static final float ALPHA = 0.15f;

/**
 * @see Adapted from http://blog.thomnichols.org/2011/08/smoothing-sensor-data-with-a-low-pass-filter
 */
protected float[] lowPass( float[] input, float[] output ) {
    if ( output == null ) return input;

    for ( int i=0; i<input.length; i++ ) {
        output[i] = output[i] + ALPHA * (input[i] - output[i]);
    }
    return output;
}

如果问题不是很明确道歉。这是一个有点难以解释的问题。

Apologies if the question isn't very clear. It's a bit hard to explain the problem.

修改:我已经用原始值尝试,而不是通过一个低通滤波器和方位角仍然变化,。我注意到,渲染对象改变音高的时候,当它仅应垂直上升或下降随之而来的对角线。这对角移动的方位和俯仰两个正在发生变化,当我身体改变器件的间距,导致对角移动。也许有什么毛病我轴线?

Edit: I've tried using raw values, instead of going through a low pass filter and the azimuth still changes. I notice that the rendered object goes along a diagonal when changing the pitch, when it should only be going vertically up or down. It moves diagonally as the azimuth and the pitch both are changing when I physically change the device's pitch, causing the diagonal movement. Maybe there's something wrong with my axis?

推荐答案

看我如何能找到没有办法解决这个问题,我开始看的处理传感器的其它可能的方法。 我发现了一个更好的方法的处理的传感器数据,即消除不仅方位角摇曳,而且还需要有一个过滤器来平滑传感器值:
而不是使用 Sensor.TYPE_ACCELEROMETER Sensor.TYPE_MAGNETIC_FIELD 值来计算旋转矩阵,我使用了 Sensor.TYPE_ROTATION_VECTOR 传感器。然后,得到了该旋转矩阵,并作为做得比较早,得到了定向阵列从它。

Seeing how I was able to find no solution to this issue, I started to look at other possible ways of handling the sensors. I found out a much better way of handling the sensor data, that eliminated not only the azimuth swaying, but also the need to have a filter to smooth the sensor values:
Instead of using Sensor.TYPE_ACCELEROMETER and Sensor.TYPE_MAGNETIC_FIELD values to calculate the rotation matrix, I used the Sensor.TYPE_ROTATION_VECTOR sensor. Then, got the rotation matrix from this, and as done earlier, got the orientation array from it.

@Override
public void onSensorChanged(SensorEvent sensorEvent) {
    switch (sensorEvent.sensor.getType()) {

    case Sensor.TYPE_ROTATION_VECTOR:
        rotationMatrix=new float[16];
        SensorManager.getRotationMatrixFromVector(rotationMatrix, sensorEvent.values);
    }

    SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X,
            SensorManager.AXIS_Z, outRotationMatrix);   // Remap coordinate System to compensate for the landscape position of device
    SensorManager.getOrientation(outRotationMatrix, orientationValues);

    currentOrientation = (float) (Math.toDegrees(orientationValues[0]) + this.getDeclination()); //Azimuth; (Degrees);
    eyeLevelInclination = (float) Math.toDegrees(orientationValues[1]); //Pitch; (Degrees); down is 90 , up is -90.
    deviceOrientation = (float) Math.toDegrees(orientationValues[2]); // Roll;

    sendSensorBroadcast();  // Let other classes know of update to sensor data.

正如你可以在我的问题见上面,我是用一个低通滤波器来平滑方位角和俯仰值,但是这是没有必要了,因为值分别为pretty的没有经过任何过滤顺畅。此外,方位角摆动几乎消失殆尽了。我说差不多,因为你也许可以仍然可以看到一点它发生,但它几乎没有明显的,大概在半度。

As you can see in my question above, I was using a low pass filter to smooth the azimuth and pitch values, but this wasn't needed anymore, as the values were pretty smooth without any filtering. Plus, the azimuth swaying is almost gone now. I say almost because you can maybe still see a bit of it happening, but its barely noticeable, maybe about half a degree.

我被卡住这个问题相当长的一段时间,希望这将帮助别人了。

I was stuck with this problem for quite some time, hopefully this will help someone else too.

这篇关于方位角值改变音调时,更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆