How to improve accuracy of accelerometer and compa

2019-03-09 14:46发布

问题:

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.

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?

回答1:

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 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.



回答2:

You should take a look at low-pass filters for you orientation data or sensor fusion if you want to a step further.

Good Luck with your app.

JQCorreia



回答3:

I solved it with a simple trick. This will delay your results a bit but they surly avoid the inaccuracy of the compass and accelerometer.

Create a history of the last N values (so save the value to an array, increment index, when you reach N start with zero again). Then you simply use the arithmetic average of the stored values.



回答4:

Integration of gyroscope sensor readings can give a huge improvement in the stability of the final estimation of the orientation. Have a look at the steady compass application if your device has a gyroscope, or just have a look at the video if you do not have a gyroscope.

The integration of gyroscope can be done in a rather simple way using a complementary filter.