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?
Accelerometer detects acceleration in space. The reason why it will always detect an acceleration of 9.8m/s^2 downwards is because gravity is equivalent to acceleration in space. Orientation detects if your device's axis are rotated from the real-world; it detects tilts and and degrees from the magnetic North.
An accelerometer works using an electromechanical sensor that is designed to measure either static or dynamic acceleration. Static acceleration is the constant force acting on a body, like gravity or friction. These forces are predictable and uniform to a large extend.
Due to this, the accelerometer measures both the linear acceleration due to motion as well as the pseudo-acceleration caused by gravity. The acceleration caused by gravity is referred to as a pseudo-acceleration as it does not actually result in a change in velocity or position.
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.
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