Accelerometer

The accelerometer is a sensor for accelerations, but maybe it's easier to think about it as a "force sensor": The sensor registers all forces that pull or push at the device. One force, that is always there even when the phone is lying still on the table is the gravity force, which points to the center of Mother Earth (or "down" as people also say).

Now the force/accel sensor registers forces on three axes that are called x, y and z.

It uses a right-hand coordinate system for this, that you can visualize easily with your own right hand: Just point out your first three fingers: thumb, index and middle so they are rectangular to each other to make a three axis coordinate system. Then you have these axis-to-finger mapping:

 thumb: x-axis
 index: y-axis
 middle: z-axis
       y = index finger
       ^
       |
       |
       |
       |
       +----------> x = thumb
      /
     /
    /
   /
  z = middle finger

This coordinate system is *glued* to your phone. So e.g. z is always pointing straight through the screen, and x is always where your thumb is when holding the phone in your right hand even if you turn around your hand or perform a headstand.

If the phone is lying flat on the table, that would be equivalent to your hand lying palm up on the table, middle finger pointing up. The only force that is acting then is the gravity, which is registered by the phone as a value of -1g (values are in units of "g" = gravity constant) on the z-axis (i.e. one g-step in the opposite direction, that the middle finger is pointing.)

In RjDj this would be a vector of three numbers: (0, 0, -1). Now if you shake the phone left-right in the direction of your thumb, you would still have the -1 on the z-axis, but additionally some changes in x-directions. If you turn the phone from it's rest position:

     _________
    | iPhone  |
-------------------- <- table  
        | gravity
        |
        v

upwards:

        _
       | |
       | | iPhone
       | |
       | |
       |_|
-------------------- <- table
        | gravity
        |
        v

then your vector will change to be something like (-1, 0, 0) depending on which side is up now. For example if your right thumb is up, then it would be (-1, 0, 0) because now gravity will try to pull the thumb downwards. (Btw. that's the trick Apple is using to rotate the screen in Safari if you turn around your phone.)

Quite often you're not really interested in which side is up, but only if the phone is shaken or not. Then you can calculate a grand total of all forces on all axis by adding up the absolute values on all axes. The [accelerate] object in RjDj does this for you. There are other analysis methods for the force data, which is something we're working on for the RjDj library. ;)