Thread: 3 axis accelerometer calculations

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001

    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?

  2. #2
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Kent, UK
    What have you defined lowercase x,y and z to be? I couldn't see it in your post

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help making a dot bounce up and down y axis in this prog
    By redwing26 in forum Game Programming
    Replies: 10
    Last Post: 08-05-2006, 12:48 PM
  2. AXIS and C++
    By bman1176 in forum C++ Programming
    Replies: 0
    Last Post: 03-29-2006, 11:00 AM
  3. Axis based on 2 Vectors
    By durban in forum Game Programming
    Replies: 1
    Last Post: 11-10-2005, 04:38 PM
  4. Graph axis
    By fkheng in forum C Programming
    Replies: 2
    Last Post: 07-25-2003, 07:03 AM
  5. How do I get these calculations correct?
    By nadeni0119 in forum C++ Programming
    Replies: 10
    Last Post: 04-07-2003, 11:09 AM