How to improve accuracy of accelerometer and compass sensors?

后端 未结 4 1221
北荒
北荒 2021-02-01 11:07

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

4条回答
  •  生来不讨喜
    2021-02-01 11:39

    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

    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.

    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.

提交回复
热议问题