问题
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