Android linear acceleration accuracy

倾然丶 夕夏残阳落幕 提交于 2019-12-12 04:07:16

问题


I have an app where I poll the sensors for acceleration data and save the XYZ values to a SQL DB. Codewise it is pretty simple:

public void onSensorChanged(SensorEvent event) {
        sensor = event.sensor;

        int i = sensor.getType();
        if (i == MainActivity.TYPE_ACCELEROMETER) {
            accelerometerMatrix = event.values;
        } else if (i == MainActivity.TYPE_GYROSCOPE) {
            gyroscopeMatrix = event.values;
        } else if (i == MainActivity.TYPE_GRAVITY) {
            gravityMatrix = event.values;
        } else if (i == MainActivity.TYPE_MAGNETIC) {
            magneticMatrix = event.values;
        }

        //insert into database

    }

MainActivity.TYPE_ACCELEROMETER is just a field I set in my MainActivity class.

If I set this to Sensor.TYPE_LINEAR_ACCELERATION I notice that the values that get stored to my DB are fairly low in accuracy (only 2 decimal places). But if I use the hardware accelerometer Sensor.TYPE_ACCELERATION then the accuracy is much higher (6dp)

My question is, am I retrieving the linear acceleration values incorrectly to cause me to only get 2dp of accuracy? Or is this just a limitation of how the sensors are fused together in Android? If its the latter, how do I get higher accuracy in my accelerometer values, after filtering out gravity, when working with fused sensors?


回答1:


As far as I know, you cannot change accuracy of the hardware sensors on Android. You can only adjust sampling period with registerListener() method from SensorManager class or monitor accuracy change with onAccuracyChanged() callback from SensorEventListener interface.

It looks that you are retrieving sensor readings correctly in your code snippet.

I would suggest doing the following things:

  • try to perform the same measurement with just one sensor and check if application behavior has changed - maybe multiple readings are causing measurement inaccuracy?
  • try to run this application on a different device if you have one and verify if behavior and accuracy is different - maybe accuracy of the sensors is different on different devices?
  • check accuracy and datatypes in your database and verify if it handles more accurate data correctly

If you don't notice any difference after applying mentioned suggestions, I think we cannot do anything about increasing sensor readings accuracy.

Moreover, I performed some experiments with sensors on Android some time ago using Nexus 5 and Nexus 6 and I see that different sensors has different accuracy as you also noticed. According to my knowledge, we cannot control that from the Android SDK API level.



来源:https://stackoverflow.com/questions/36247535/android-linear-acceleration-accuracy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!