After seeing some odd behavior while rotating the accelerometer, I eventually noticed that in the formula I used, an assumption is made that rotation is ideal around the y axis. So as long as you have x rotation but not y, it works, or y rotation, but not x, it works. But if you have a combination of both, it did not give you correct values.
Time for a new equation. The good news was, the same data sheet that showed me the "ideal" equation had an example of the equation I wanted.
This equation required longs, and a few other adjustments. It seems to be pretty accurate, though I have not come up with an easy way to test it.
I have included TRIGL.INC, which has a minor edit to run with pbpl.
Here is the meat of the code:
Code:
solveangle:
'**********Solve for x angle ********************************************
if xresult < yresult + zresult then
dummy = 5000 'when x is smaller the following equation works best
xlong = (dummy * xresult) /(sqr((yresult*yresult) + (zresult*zresult)))
else 'keeps results accurate at near 0 and near 90 degree values
dummy =30 'when x is larger the following equation works best
xlong = (dummy * xresult*xresult) / ((yresult*yresult)+(zresult*zresult))
endif
y = xlong
x = dummy 'Assign x and y values for atan2 function
call atan2
xangle = 9000 - y
if yresult < xresult + zresult then
dummy = 5000 'when y is smaller the following eqauation works best
ylong = (dummy * yresult) / (sqr((xresult*xresult) + (zresult*zresult)))
else
dummy =30 'when y is larger the following equation works best
ylong = (dummy * yresult*yresult) / ((xresult*xresult)+(zresult*zresult))
endif
y = ylong
x = dummy '
call atan2
yangle = 9000 - y
Last edited by ScaleRobotics; - 9th October 2010 at 17:36.
Bookmarks