Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android compass accuracy - when to calibrate?

I develop an application which provides some augmented reality features using compass. I found out that sometimes I need to calibrate my compass to make it work well.

How do I know (programatically) that calibration is needed?

I mean I know how to calibrate compass using the 8-pattern figure, but I want to detect that calibration is needed and display some alert to user ("Your compass is not accurate enough, please calibrate your compass sensor.").

Is this possible, please? Thanks!

like image 656
Berťák Avatar asked Jan 27 '15 16:01

Berťák


People also ask

When should you calibrate a compass?

At a minimum, it is recommended to calibrate the compass at first use, when the batteries are replaced, and after traveling long distances. However, to ensure the compass is always working properly, you may want to calibrate right before using the device.

Why do you need to calibrate a compass?

An output of any magnetometer will be a combination of earth's magnetic field and any other magnetic fields present around. Before a digital magnetic compass is put to the actual use, it is very important to calibrate it so as to compensate for the factors which affect its output from the correct value.

How do I know if my compass is accurate?

Tap on the location icon to bring up more information about your location. At the bottom, tap the “Calibrate Compass” button. This will bring up the compass calibration screen. Your current compass accuracy should be displayed at the bottom as either low, medium, or high.


1 Answers

My solution would be to use the onAccuracyChanged() method of the SensorEventListener interface.

This is how I would do :

//In SensorEventListener interface implementation    
@Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
        switch(sensor.getType()){
            case Sensor.TYPE_MAGNETIC_FIELD :
                switch(accuracy) {
                    case SensorManager.SENSOR_STATUS_ACCURACY_LOW :
                        doSomething();
                        break;
                    case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM :
                        doSomethingElse();
                        break;
                    case SensorManager.SENSOR_STATUS_ACCURACY_HIGH :
                        doNothing();
                        break;
                }
                break;
            default:
                break;
        }
    }

You should also look at this answer here : https://stackoverflow.com/a/7877688/7501326

"Typically, if a device is not calibrated, you will see great variations in the azimuth value for small rotations. That is what I would be worried about."

like image 128
Kerat Avatar answered Sep 29 '22 17:09

Kerat