如何提高加速度计和罗盘传感器的精度? [英] How to improve accuracy of accelerometer and compass sensors?

查看:23
本文介绍了如何提高加速度计和罗盘传感器的精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个增强现实应用程序,当手机面向兴趣点(手机上存储了 GPS 位置)时,它可以简单地将文本视图可视化.文本视图绘制在屏幕上的兴趣点位置.

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 不断地左右上下移动.

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.

有办法解决吗?

推荐答案

我们的问题是一样的.我在创建简单的增强现实项目时也遇到了同样的问题.解决方案是使用指数平滑或移动平均函数.我推荐指数平滑,因为它只需要存储一个以前的值.示例实现如下:

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;
}

Alpha 是平滑因子(0<= alpha <=1).如果您设置 alpha = 1,则输出将与输入相同(根本没有平滑).如果您设置 alpha = 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.

这篇关于如何提高加速度计和罗盘传感器的精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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