Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #2684

Re: Android Sensor Coordinates

Date 2011-03-31 18:20 -0700
From Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com>
Newsgroups comp.lang.java.programmer
Subject Re: Android Sensor Coordinates
References <in34ov$2ts$1@lust.ihug.co.nz>
Message-ID <fsCdnQCv4rXYtQjQnZ2dnUVZ_vOdnZ2d@posted.palinacquisition> (permalink)

Show all headers | View raw


On 3/31/11 5:03 PM, Lawrence D'Oliveiro wrote:
> The diagram of the linear sensor coordinate system here
> <http://developer.android.com/reference/android/hardware/SensorEvent.html>
> seems to be wrong.
>
> I have a test program running on my HTC Desire (Android 2.2), showing me
> values from the accelerometer. As it lies horizontally, face-up on my desk,
> the Z value is positive (around 9.8, as you would expect). But that diagram
> says that positive Z is up, not down.
>
> I tilt the phone to the left, and the X value increases. Tilt to the right,
> it decreases. But the diagram says positive X is to the right, not the left.
>
> Tilt it up, the Y value increases. Hold it vertical, with the display upside
> down, and the Y value shows negative. Again, completely the opposite to the
> diagram.

The accelerometer is something that measures acceleration, not tilt. 
You want an inclinometer if you want to measure tilt.

Incredibly enough, the behavior you are seeing is documented on the same 
page you referred us to:

     In particular, the force of gravity is always influencing
     the measured acceleration:

         Ad = -g - ∑F / mass

     For this reason, when the device is sitting on a table
     (and obviously not accelerating), the accelerometer
     reads a magnitude of g = 9.81 m/s^2

     Similarly, when the device is in free-fall and therefore
     dangerously accelerating towards to ground at 9.81 m/s^2,
     its accelerometer reads a magnitude of 0 m/s^2.

But, if you would like a more elaborate explanation…

As Patricia says, if the phone is flat, parallel to the surface of the 
planet, then it is being accelerated 9.81 m/s^2 upward (see above) 
relative to the planet (I suppose technically it's net acceleration 
relative to all gravity sources, but I doubt anything except Earth is 
significant).  That's the acceleration it takes to exactly counteract 
the downward acceleration the planet causes.  It is typical for 0 
acceleration in all directions to be registered during freefall of an 
accelerometer.

To see why this makes sense, consider the phone floating in an orbiting 
spacecraft (or even better, away from any measurable gravity sources). 
Now, quickly move the device in the positive direction of the documented 
Z axis.  What value do you want the phone to report?  A positive 
acceleration, of course.  And note that if you were a very tiny person 
sitting inside the phone, and the phone were moved in that direction, 
you would perceive a force relative to your frame of reference that felt 
just like gravity pulling you in the other direction (i.e. you would be 
pressed against the back side of the phone).

That force that your very tiny self mistakes for gravity is exactly the 
same as the gravity that the accelerometer _does_ feel when the phone is 
sitting still on a table.

Basically, in a self-contained system, whether a phone or your own body, 
forces acting on elements in that system can be perceived only by those 
elements relative to the self-contained system.  In free-fall, no force 
can be perceived, as all forces are acting on every part of the system 
equally.  But when sitting still, the system's frame of reference is 
stationary, while gravity is still pulling on the piece that senses 
acceleration.  That piece perceives the force as acceleration in the 
opposite direction of the pull.


As far as tilting goes, when the phone is flat, I'd expect the X and Y 
axes to register as 0.  When you tilt the phone, then those will start 
to experience a force because they are not completely perpendicular to 
the planet's gravity, and thus will start registering that force as well.

Note that for the X and Y axes, the change in value is consistent with 
the Z axis.  With the phone tilted to the left, the X axis is pointing 
in a direction that has a vertical component, away from gravity, and 
registers a positive force in that direction, balancing the force in the 
other direction that gravity is causing.  Again, drop the phone in that 
orientation or any other, and the registered force will be 0.

Finally note that this really is the only sensible approach for a 3-axis 
accelerometer.  You can't get rid of the force pulling on the 
accelerometer, so either you just report it, or you include an offset so 
that the device reads 0 when it's flat.  But the offset is only valid in 
a particular orientation; so you'd actually need an inclinometer so that 
you could calculate the offset required.

It's much simpler and practical to just report the real force 
experienced by the accelerometer.  Let the software figure out how best 
to interpret that (see the same doc page for a code example showing just 
that).

Pete

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Android Sensor Coordinates Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-04-01 13:03 +1300
  Re: Android Sensor Coordinates Patricia Shanahan <pats@acm.org> - 2011-03-31 17:53 -0700
    Re: Android Sensor Coordinates Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-04-01 15:44 +1300
  Re: Android Sensor Coordinates Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-03-31 18:20 -0700
    Re: Android Sensor Coordinates BGB <cr88192@hotmail.com> - 2011-04-01 11:02 -0700
      Re: Android Sensor Coordinates Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-04-01 17:51 -0700
        Re: Android Sensor Coordinates Lew <noone@lewscanon.com> - 2011-04-01 21:23 -0400

csiph-web