Question

I found two example in these two source code, but sensorEvent.java said "When the device lies flat on a table and is pushed on its left side toward the right, the x acceleration value is positive." and sensorListener.java said "When the device is pushed on its left side toward the right, the x acceleration value is negative (the device applies a reaction force to the push toward the left)". You can scroll up to see what Definition of the coordinate system is and you can find they are same. So I'm confused.

Of cause I do an experiment that just push my phone left side toward the right, I see x-axis is rising.

So,is there a wrong in example or I miss something?

Here is sensorEvent.java and sensorListener.java

Was it helpful?

Solution

As far as I know, the statement in SensorEvent is correct - illustrated by your own experiment. SensorListener has been deprecated for quite some time already (at least two years - it has been replaced by SensorEventListener), so you should assume the non-deprecated statement to be correct.

My guess is that in the earlier days of Android, the acceleration values used to be mirrored, as the difference between one of the other examples mentioned in both of these classes is similar to what you're getting confused by:

Current (in SensorEvent):

When the device lies flat on a table, the acceleration value is +9.81, which correspond to the acceleration of the device (0 m/s^2) minus the force of gravity (-9.81 m/s^2).

Deprecated (in SensorListener):

When the device lies flat on a table, the acceleration value is -STANDARD_GRAVITY, which correspond to the force the device applies on the table in reaction to gravity.

-STANDARD_GRAVITY resolves to -(9.80665) = -9.80665, exactly the opposite of the positive value stated in SensorEvent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top