1 Attachment(s)

3 axis accelerometer calculations

For fun I'm going to be building a bicycle computer that does a bit more then my current one. One of the things I'd like to know is my speed and angle (uphill/downhill). I ran through the math and was wondering if someone could double check it. For the purposes of this work I am considering G to be 1.

For the angles I'll be using a 3 axis accelerometer that is setup so that when it is flat the Y axis value is equal to the force of gravity, X would be along the front of it, and Z would be along the length of it. The arrows in the attached picture indicate the direction of positive values for the force.

There are only two useful rotations to consider: Rotation in the XY plane and YZ plane. I have labeled this as Θr and Θp (roll and pitch). Rotation in the XZ plane is meaningless in terms of the application and would not be measurable by the device.

First considering counter-clockwise rotation in the XY plane. I came up with:

x = sin Θr

y = cos Θr

which makes sense as the value of Θr approaches pi/2 sin increases and cos decreases.

Considering rotation in the YZ plane such that the the positive Z "drops down". I came up with

z = sin Θp

y = cos Θp

Now through the use of just looking at a model (made of knitting needles :)) I looked at the case were there is rotation in both the XY and YZ planes. It seems in that all three will get smaller as the oppose angle increases. So I got:

x = sin(Θr)*cos(Θp)

y = cos(Θr)*cos(Θp)

z = cos(Θr)*sin(Θp)

Now in reality I'll have x,y,z and need to get Θr and Θp. So by doing a bit of elimination and setting equations equal I get:

Θr = arctan(x/y)

Θp = arctan(z/y)

Does this seem right or did I make a mistake somewhere?