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!
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.
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.
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.
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."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With