Android: the range of z-value in the accelerometer sensor are different on different devices

自闭症网瘾萝莉.ら 提交于 2019-12-06 03:55:10

Apparently the device is poorly calibrated. A well-calibrated device should return 9.81m/s^2, the gravitational acceleration.

What you could do instead: Compare the z value to the x and y values. If the z value dominates than the device is facing up. For example:

if (z/sqrt(x^2+y^2+z^2+1.0e-6) > 0.9) { // Facing up

I added the term 1.0e-6 so that you won't accidentally divide by zero.

This heuristic requires testing and tweaking but I guess you get the idea. Good luck!

The general idea about this kind of sensors is to avoid them or to not abuse them in a way that your application relies on a really precise measure.

The problem with this sensors is basically that they have really different range of values and they are really noisy, so they need to be normalized by you, the coder, and they can't be so reliable in terms of accuracy.

I forgot the exact name of this public speech, but even Google and the Android team suggest to not rely so much on this in terms of decimals or to not expect great accuracy; also remember that every little part of this smartphones and tablets is really really cheap, we are talking about sensors that usually do not cost more than 1$.

Try to code in a way that your code only requires the general direction or axis, if you want a value be sure that it's an integer and always do rough calc and do not expect precision or decimals.

Also remember that Android doesn't offers a normalized approach to this values, so you have to deal with that in your code.

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