Quaternions vs atan2

Here is the place for all your dsPic or autopilot questions.

Moderator: lukasz

Re: Quaternions vs atan2

Postby Tom » Thu Mar 18, 2010 6:07 pm

Well the word "combine" might be to general to answer this question...
But yes, they kind of need eachother: centripetal force is also measured by the accelerometer, and the gyroscope's turning rates are a way to calculate this centripetal forces.
Also, the non-drifting nature of your accelerometers allow you to use it to compensate the drift from your gyroscopes.
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Re: Quaternions vs atan2

Postby Goldfinch » Fri Mar 19, 2010 7:29 pm

Tom wrote:the gyroscope's turning rates are a way to calculate this centripetal forces
I think that it is not exact. Gyro rates are needed to get angles by integration. So quaternions or Euler angle are different representation of attitude. If there is no gyro bias only 3 gyros can be used for attitude calculation. But zero bias and drift-free gyros are fantastic. My experience showed that it is sufficient for only 5 minutes flight with MEMS IMU. So next step is to combine integrated angles with direct measuremens from accelerometers via Kalman or complementary filter.
But transition formulas from gyro rates to body angle rates consist of deviding by cosine(theta) which maybe equal to zero when pitch=90, so quaternion would be better.
Tom, could You tell me what coordinate system (body) do You use in algorithms? X - forward, Y-right wing, Z - down? (Russian standarts are different from European)
Goldfinch
 
Posts: 12
Joined: Mon Mar 15, 2010 11:22 am
Location: Russia

Re: Quaternions vs atan2

Postby Tom » Sat Mar 20, 2010 10:00 am

Goldfinch wrote:
Tom wrote:the gyroscope's turning rates are a way to calculate this centripetal forces
I think that it is not exact.


Formulas to calculate centripetal acceleration (when there is no speed along the y-axis; v = 0):
Along x = q * w
Along y = r * u - p * w
Along z = q * u

I use a right-handed reference frame: x-axis pointing out of the noise, y-axis pointing out of the right wing, z-axis pointing down
p, q, r are the rotation rates along the respective axis,
u, v, w are the speeds along the respective axis.
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Re: Quaternions vs atan2

Postby Goldfinch » Sat Mar 20, 2010 10:36 am

Tom, You're right. I was not attentive reading post. But these formulas are true for small Euler's angles. Don't You think that p-q-r must be changed to pitch_dot, roll_dot and yaw_dot? It is about coordinated turn with non-zero roll and centripetal acceleration is projected to y- and z-axis. But conversion to Euler angle rates requires estimated angles that is not good. Do You use centripetal accelerations with posted formulas when measuring angles from accelerometer? Are there any limitations?
We use another frame so I have some dificulties to transfer from one system to another in english docs. And Analog Devices uses same as yours frame but rotated by 180 degrees around X-axis.
Goldfinch
 
Posts: 12
Joined: Mon Mar 15, 2010 11:22 am
Location: Russia

Re: Quaternions vs atan2

Postby Alejos » Mon Apr 05, 2010 5:58 pm

Hi all,

I am new in this forum. I was looking for an information for my project and found this blog that is helping me. Thanks Tom for all your job. I have a question, i think is a silly question. I was looking for a solution around and didn't find the good one:

I am developing an IMU and following this http://www.freescale.com/files/sensors/ ... AN3461.pdf application note to calculate de pitch and roll angle (cos I am using the same accelerometer). My question is about the formulas in page 4 with "arctan". I know that is better to use atan2, but i don't know how to use this function. I am developing my application in C# and atan2 is defined as atan2(y,x).How should I replace the x and y to follow the formulas in the application note? This is my proposal but I am not sure of it...

atan2(y,x) = atan2(sqrt(Ay^2+Az^2),Ax) // I found in Google that atan2=arctan(y/x)

Is my proposal good? Can you tell me how should i do it? Thank you very much for your help..

Greetings
Alejos
Alejos
 
Posts: 1
Joined: Mon Apr 05, 2010 5:41 pm

Re: Quaternions vs atan2

Postby Tom » Tue Apr 06, 2010 7:23 pm

Welcome to the forum :-)

Wikipedia describes how you should calculate atan2 : http://en.wikipedia.org/wiki/Atan2

As you can see in my code, I made my own version to make sure it conforms with the quaternion to pitch and roll: http://code.google.com/p/gluonpilot/sou ... aternion.c

Tom
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Re: Quaternions vs atan2

Postby echarry » Wed Aug 04, 2010 10:41 am

Hi Tom,
I'm also new to this forum, and although I'm not using IMU's for UAV or airplanes, my application also involves 3D orientation.
My hardware is a simple 3-axis accelerometer and 1-axis gyro sitting parallel to the z-axis (parallel to gravity either) and perpendicular to the xy plane. The Euler angles with respect to the global frame are computed using the accelerometers/gyro integration, however I'm thinking in using the Quaternions (due to the singularities of the R. Matrices).

With your great experience maybe you can shed some light on my project:
1) To compute pitch and roll, do I ALWAYS need to use atan2 or asin and subsequently transform to Quaternions to "unrotate" the accelerations? At the moment I am doing something like:

a. gamma= integ(w(t).dt)

b. RZ(t) = [cos(gamma) -sin(gamma) 0
sin(gamma) cos(gamma) 0
0 0 1]

c. Acc_Untwisted = RZ(t)*Acc_Raw

d. beta = atan2(Acc_Untwisted_x,Acc_Untwisted_z)

e.RY = [cos(beta ) 0 sin(beta )
0 1 0
-sin(beta ) 0 cos(beta )]

e. Acc_Unlateral = RZ(t)*Acc_Untwisted

f. alfa = atan2(Acc_UnLateral_y,Acc_Unlateral_z)

So my angles are alfa,beta,gamma, as you can see are wrt body frame of reference. Any suggestions on how to do this but with Quaternions? Don't know if you noticed, but it doesn't make sense to me, that I didn't use RX, and therefore I'm having inaccuracies. Any ideas?

2) Knowing that the gyro integration drifts (and that I don't have any redundancy such as a magnetometer), a Kalman Filter is still worthwhile to implement?

My message is very big already, so any ideas are welcomed.
Many thanks,
Edgar
echarry
 
Posts: 3
Joined: Wed Aug 04, 2010 6:55 am

Re: Quaternions vs atan2

Postby Tom » Wed Aug 04, 2010 12:05 pm

Hi Edgar,

When deciding which sensors to you, one should always look at the application. What will your board be used for?

Quaternions are usually used when rotations are involved. With only 1 gyroscope, this won't be possible.

I guess your module will need to sense the attitude, but the angles will remain smaller than something like 45°?
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Re: Quaternions vs atan2

Postby echarry » Wed Aug 04, 2010 12:44 pm

Hi Tom,

Thanks for the quick reply.
The application is back monitoring (which pretty much translates to measuring 3D orientation of back using inertial sensors). Unfortunately the HW at this stage for several reasons can't be changed.

"Quaternions are usually used when rotations are involved. With only 1 gyroscope, this won't be possible."
I thought Quaternions represent a vector rotation given a particular axis. If I'm able to get the pitch and roll angles from the accelerometer and the yaw from the gyro (assuming is perfect), I would've thought I could transform these Euler angles to Quaternions. Do I need to go further down to the basics here?
echarry
 
Posts: 3
Joined: Wed Aug 04, 2010 6:55 am

Re: Quaternions vs atan2

Postby Tom » Wed Aug 04, 2010 12:53 pm

Hi Edgar,

No you are right, but here you won't have any of the advantage of quaternions, except easier integration of the yaw angular rate.

You would need asin/atan to convert your accelerometers to a quaternion, which is what we want to avoid (gimbal lock, accuracy issues when near 90°) when using gyroscopes instead.
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

PreviousNext

Return to Firmware

Who is online

Users browsing this forum: No registered users and 18 guests

cron