C Board  

Go Back   C Board > Community Boards > Tech Board

Reply
 
LinkBack Thread Tools Display Modes
Old 09-04-2008, 12:55 AM   #1
& the hat of GPL slaying
 
Thantos's Avatar
 
Join Date: Sep 2001
Posts: 5,732
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?
Attached Images
 
Thantos is offline   Reply With Quote
Old 09-05-2008, 04:26 AM   #2
.com
 
Stonehambey's Avatar
 
Join Date: Jan 2008
Location: Kent, UK
Posts: 116
What have you defined lowercase x,y and z to be? I couldn't see it in your post
Stonehambey is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 01:57 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22