如何提高加速度计和罗盘传感器的准确度?加速度计、准确度、传感器

2023-09-04 10:40:10 作者:烟雨风飘渺

我创建一个增强现实应用程序,只需visualices一个TextView当手机正面临着利息(至极GPS位置存储在手机上)的点。 TextView是被涂在感兴趣位置的在屏幕上的点。

i am creating an augmented reality app that simply visualices a textview when the phone is facing a Point of Interest (wich gps position is stored on the phone). The textview is painted on the point of interest location in the screen.

它工作正常,问题是,指南针和加速计是非常变种,而TextView的是不断移​​动的上下左右,因为传感器的innacuracy。

It works ok, the problem is that compass and accelerometer are very "variant", and the textview is constantly moving up and down left and right because the innacuracy of the sensors.

有一种方法可以解决呢?

there is a way to solve it?

推荐答案

我们的问题是一样的。我也有同样的问题,当我创建简单的增强现实项目。该解决方案是使用指数平滑或移动平均功能。我推荐指数平滑法,因为它仅需要存储一个previous值。示例实现可用如下:

Our problem is same. I also had same problem when I create simple augmented reality project. The solution is to use exponential smoothing or moving average function. I recommend exponential smoothing because it only need to store one previous values. Sample implementation is available below :

private float[] exponentialSmoothing( float[] input, float[] output, float alpha ) {
        if ( output == null ) 
            return input;
        for ( int i=0; i<input.length; i++ ) {
             output[i] = output[i] + alpha * (input[i] - output[i]);
        }
        return output;
}

阿尔法平滑因子(0℃=阿尔法&其中; = 1)。如果设置的α= 1时,输出将是相同的输入(无平滑的话)。如果设置阿尔法= 0,则输出永远不会改变。去除噪声,你可以简单地平滑的加速度计和磁力计值。

Alpha is smoothing factor (0<= alpha <=1). If you set alpha = 1, the output will be same as the input (no smoothing at all). If you set alpha = 0, the output will never change. To remove noise, you can simply smoothening accelerometer and magnetometer values.

在我的情况,我用加速度计Alpha值= 0.2和磁强计alpha值= 0.5。对象将更加稳定和运行是相当不错的。

In my case, I use accelerometer alpha value = 0.2 and magnetometer alpha value = 0.5. The object will be more stable and the movement is quite nice.