What is the difference between TYPE_ACCELEROMETER and TYPE_LINEAR_ACCELERATION sensors?

谁说我不能喝 提交于 2020-05-13 07:14:45

问题


I think TYPE_ACCELEROMETER shows devices acceleration. However, I can't understand when I should use TYPE_LINEAR_ACCELERATION?
I need to calculate the speed of moving the device. Which sensor is proper for this application?

Also, I read that TYPE_LINEAR_ACCELERATION uses accelerometer and orientation to know where is directed the gravity and then subs.

How is this possible? How Android find out about orientation of device and subtract it?


回答1:


According to http://developer.android.com/reference/android/hardware/SensorEvent.html#values TYPE_LINEAR_ACCELERATION is the same as TYPE_ACCELEROMETER minus gravity: acceleration = gravity + linear-acceleration. So with TYPE_LINEAR_ACCELERATION you can't detect device orientation because it doesn't provide gravity data.

Acceleration is the second derivative from object location, speed (velocity) is the first derivative. It means that you can calculate relative change in velocity from acceleration, but you can't know from it what exact values of velocity the change is applied to, in general case. For example you can't say if the phone stands on a table in room or in a constantly moving car, in both cases the acceleration may be zero.

Games use accelerometer input to track user's feedback, since it doesn't matter for games if user sits in a moving car or home at a table, acceleration just fits that purpose perfectly (filtering out the speed data). If you really need speed then you should use other sensors, such as GPS.

It may be a safe assumption that the phone initially has the same speed as the user, so you can calculate speed of phone when user throws it away, relative to the user, but that's all.



来源:https://stackoverflow.com/questions/27461394/what-is-the-difference-between-type-accelerometer-and-type-linear-acceleration-s

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