Total Acceleration from Axes – How to Calculate Total Acceleration from 3 Axes?

accelerationgravity

For a project I'm working on I'm using an accelerometer which measures acceleration in 3 directions, x, y and z.

My question is: How can I calculate the total acceleration in a certain direction from these 3 values?

Considering this simple graph layout: enter image description here

My initial idea is:

  • Take the sqrt of (x^2 + z^2) to calculate the resulting value in the zx plane.
  • Take this value, square it and add y^2, take the square root of that
  • Final equation: Sqrt(y^2 + Sqrt(x^2 + z^2))

Is this correct? On some sites I see x^2 + y^2 + z^2 being used, but I don't know if that's right and why it's right.

EDIT: I just figured that taking the Sqrt of (x^2 + z^2) and squaring it just results back in x^2 + z^2, so that's why I can use x^2 + y^2 + z^2.

Another thing: Do I have to normalize for gravity? I think I do, but how would I go about this? Do I need to know the exact position and tilt of my device as it will be in the end?

Best Answer

Your procedure gives:

$$ a_{xz} = \sqrt{a_x^2 + a_z^2} $$

then:

$$ a_{total} = \sqrt{a_y^2 + a_{xz}^2} $$

but if you substitute for $a_{xz}$ in the second equation you get:

$$ a_{total} = \sqrt{a_y^2 + (\sqrt{a_x^2 + a_z^2})^2} = \sqrt{a_y^2 + a_x^2 + a_z^2}$$

so you don't need to split the calculation into two steps.

Your accelerometer may already exclude the acceleration due to gravity. If it doesn't then yes you need to use the inclination to work out the three components of gravity then subtract them from $a_x$, $a_y$ and $a_z$. It's hard to say exactly how to do this without knowing how your phone reports it's inclination.

response to comment:

Suppose you have your device held flat so $a_z$ = -1. Now move the device downwards at and angle of $\theta$ as shown below:

Forces

Assuming it's moving in the $xz$ plane the value of $a_z$ will be decreased a bit and the value of $a_x$ will increase from zero. Suppose you're applying an acceleration to the phone of $2g\space cos(\theta)$ - you'll see why i've chosen this value in a moment. Now the values of $a_x$ and $a_z$ are:

$$ a_x = 2g\space cos\theta \space sin\theta $$

$$ a_z = g - 2g \space cos^2 \theta $$

You now calculate $a_{total}$ by just squaring and adding as we discussed above to get:

$$a_{total}^2 = 4g^2 \space sin^2\theta \space cos^2\theta + g^2 + 4g^2 \space cos^4\theta - 4g^2 \space cos^2\theta $$

and a bit of rearrangement gives:

$$a_{total}^2 = g^2 + 4g^2 \space cos^2\theta \left( sin^2\theta + cos^2\theta - 1\right) $$

and because $sin^2\theta + cos^2\theta = 1$ the quantity in the brackets is zero so you end up with:

$$a_{total}^2 = g^2 $$

that is:

$$a_{total} = g $$

which is the same as when the phone is stationary. So it's possible to be accelerating the phone and still have the total acceleration come out as $g$ ($g$ = -1 in the phone's units). That's why just subtracting one isn't a reliable way to tell if the phone is accelerating.