Getting LOCAL Pitch, Yaw, Roll...

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Getting LOCAL Pitch, Yaw, Roll...

Postby misho » Mon Oct 18, 2010 5:57 pm

I've been testing NGD for use in a spacecraft orbital simulator. I need a robust functionality for Euclidian and Sperical conversion, especially with the spacecraft Pitch,Yaw,Roll functionality. So far, I put together a PYR controller that lets me set torques on object's LOCAL axis. This works well aside from small torques that show up on the axis that are supposed to be "still" (I'm guessing this is the system's imprecision coming into play). This controller lets me control PYR on a local axis, just as a spacecraft in orbit would using small thrusters.

My problem is getting Pitch,Yaw,Roll angles that are LOCAL to the object. I'm probably missing something here and my head is wrapped too tightly around this... I'm using this line in my SetTransformCallback:

Code: Select all
   NewtonBodyGetRotation(body, &rotation.m_q0);
   EulerXYZ = rotation.GetXYZ_EulerAngles();


However, EulerXYZ are in world coordinates. I need them converted to local object ("body" in this case) coordinates. When I look at the EulerXYZ values, a change in roll should be shown in EulerXYZ.m_z value only, but I am getting changes in m_x and m_y values, as they are obviously pertaining to the world coordinates. How do I transform these values into LOCAL Euler angles?

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby Julio Jerez » Mon Oct 18, 2010 6:42 pm

the pitch Yaw and Roll angle for a matrix he take you from one space to the its parent frame.
the is not such locat/global comsept when talking about angles. Angle are parametric quantitites.
Using angle it a very bad idea for controlling and vehicle.
iy is better to use axis angle rotation.

basically you can rotate a body arond any arbitrry axis by any angle. and by pacing the axis in the local space of the body you can achive what you want.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby misho » Mon Oct 18, 2010 10:14 pm

Hi Julio, and thanks! Actually, I am not rotating the body using angles - I use torques and apply them to body's local axes:

(This is all in ApplyForceAndTorqueCallback)

Code: Select all
   dVector Torques(0.0f,0.0f,0.0f); // Torque vector
   if(YawKey)
   {
      Torques.m_z = 0.5f; //set a torque value on that vector's z (yaw) axis

   }

   dQuaternion rotation;
   NewtonBodyGetRotation(body, &rotation.m_q0);
   
   Torques = rotation.RotateVector (Torques); // use body's rotation quaternion to rotate the vector and align it with body

   NewtonBodySetTorque(body, &Torques[0]); // Finally, apply the aligned torques

   NewtonBodyGetOmega(body, &mOmega[0]);      
   mOmega = rotation.UnrotateVector (mOmega);


I also obtain the "aligned" values of Omega (last two lines of code) and they DO display correctly, local to body's axis (except for small values that I mentioned that seem to be the result of imprecision)

But to display the LOCAL Pitch, Yaw, Roll values (just like the local Omega values) - I am stumped.

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby misho » Fri Oct 22, 2010 10:23 am

More on this... I tried to take a different approach: I took the rotational velocities (Omegas) on local axes and used those values to calculate the per-frame angle on each local axis. I used the " g_physicTime " for a time interval. I got the proper behavior going - I get the values of rotations on the local axes... but, calculating angles using:

Code: Select all
      LocalEuler.m_x += mOmega.m_x*physicTimeSeconds;
      LocalEuler.m_y += mOmega.m_y*physicTimeSeconds;
      LocalEuler.m_z += mOmega.m_z*physicTimeSeconds;


gives me wrong angle values on the order of magnitude of a 100. I use

Code: Select all
      physicTimeSeconds = g_physicTime / 10000.0f;


to convert to time in seconds, but I should be dividing by 1000000 (as physicTime is in microseconds). Also, the values ( in degrees ) I get this way are not 100% accurate, they are off by about 1 degree. Can anyone tell me what I'm doing wrong?

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby misho » Tue Nov 02, 2010 4:23 pm

Julio Jerez wrote:the pitch Yaw and Roll angle for a matrix he take you from one space to the its parent frame.
the is not such locat/global comsept when talking about angles. Angle are parametric quantitites.
Using angle it a very bad idea for controlling and vehicle.
iy is better to use axis angle rotation.

basically you can rotate a body arond any arbitrry axis by any angle. and by pacing the axis in the local space of the body you can achive what you want.


Hi Julio, anyone? - I am still struggling with this. Can you suggest the order of operation with this? The closest that I can gather, I need to "un-rotate" the object around 2 other axis to get the readout for the local axis, correct? What is the concept for doing this here? I'm on the right path because I am properly applying torques on the body's LOCAL axis, however, I just can't get the readout of those resulting angles on the local axis...

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby Julio Jerez » Tue Nov 02, 2010 4:53 pm

can you make a sketch of what you want to do? I am having a difficult time figure out what the problem is.
I may be able to give you some solution.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby Julio Jerez » Tue Nov 02, 2010 5:15 pm

Berserkguard wrote:Couldn't you just save the global yaw, pitch, and roll values on one update, then on the following update subtract those values from the global yaw, pitch, and roll values to get the "local" values? That would give you the delta values... Not sure if that's what you were needing though.

this is what is wrong, you can not play with angle if fi they are linear quantities.

basically when you have a rotaion made out of tree rotaion

R0 = Picth0 * Yaw0 * Roll0
R1 = Picth1 * Yaw1 * Rol10

if

R1 = Rx * R0
the relation between the angle is no linera

Pitchx is not equal to Picth1 - Pitch0, and so on,

I am sure there are ways to do what you wnat, but I need to undernat the problem.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby misho » Tue Nov 02, 2010 5:37 pm

Julio Jerez wrote:can you make a sketch of what you want to do? I am having a difficult time figure out what the problem is.
I may be able to give you some solution.


Indeed - I can send you a small test app that will illustrate everything - here is a link to it (public dropbox loc) http://dl.dropbox.com/u/10506379/Tutorial_102_5_TestingEuler.exe You should place it into "..\NewtonTutorials\bin\x32", as it needs "frowny.dat" and "dumb.dat" objects.

What you will see is two "dumbell" objects, and one "Frowny" which is designating space origin (0,0,0). The top "dumbell" can be rotated around its local axis:

x axis: X/ShiftX
y axis: Y/ShiftY
z axis: Z/ShiftZ

immediately stop rotation: "C" key
add/subtract thrust along z axis: Space/ShiftSpace

Initially, the top dumbell is correctly rotated at 30,40,10 degrees (which is visible in the readout). Basically, when I rotate only around Y axis (pressing Y/ShiftY key), I want the Y rotation value (that reads 40) to show increase/decrease. Same with Z. Right now, if I rotate around Y or Z, other values change, and that's because the angles displayed are PYR angles around global axis. I need angles around local axis. X works as it should - I am not sure why, but I am guessing its because it is first in line for rotation so the values are still correct. I am getting those rotation values by calling

Code: Select all
EulerXYZ = rotation.GetXYZ_EulerAngles();


and displaying EulerXYZ.m_x, m_y, m_z values. (EulerXYZ.m_x behaves correctly)

The omega readouts behave correctly - they display the omegas on the LOCAL axis only. That is, when I apply torques on individual axis, other omegas are "still". I need the same thing, but for angles. I hope this clears it up... I am sure there is an elegant way of using this - some combination of rotating quaternions to get to local axis...

Thanks a bunch!!
Misho

PS: Incidentally, this is a very common thing in flight simulation - the roll, pitch and yaw are always displayed from the aircraft's internal frame of reference...
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby Julio Jerez » Wed Nov 03, 2010 10:52 am

Ok.
The Yaw Pitch And Roll are displayed in the read oput, but these angle are not use for any king of calculation.
Basicall the display get an input and decompose it three angles just fo display.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby misho » Wed Nov 03, 2010 11:55 am

Hi Julio, yes, that is correct, the display purposes only. I won't be using these values in any Newton calculations, BUT, my graphics engine (Microsoft Flight Simulator X) needs a position/attitude info in Lat/Lon/Alt (no problem, I have that going) and Pitch,Yaw,Roll in the Earth frame reference, so I'll be using these values to convert. Earth frame reference is basically a spherical coordinate system where "up" is always radially outward, and "level" is always tangential plane on the sphere.

I'm ok with that math as long as I get the local PYR worked out...any ideas?

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby Julio Jerez » Wed Nov 03, 2010 2:31 pm

I download the demo, and running, I could not see what id does but I did not run enoght to figure out. I run out of time before go to work

I will try again tonight. I am sure tehr is a solution fo that.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby misho » Wed Nov 03, 2010 3:10 pm

Ok great! The demo basically lets you rotate a dumbell using X,Y and Z keys - that's all.

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby misho » Mon Nov 15, 2010 12:50 pm

Hi Julio - I was wondering if you had a chance to think about this again...?

If it helps, here is a link to a forum post on Epic games, that deals with the same problem:

http://forums.epicgames.com/showthread.php?t=743407

I looked at it but I still can't get it to work on my end. Any help would be greatly appreciated...

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby Julio Jerez » Mon Nov 15, 2010 2:49 pm

Oh not I forget about this.
I will check it out tonight

what I am going, sicne I still can no figure out what the problems is,
is that I will make tow sketchve of two rotaion.
one relative to axis in world space, and one relative to axis fixed to the body, and you tell me which one is the you want.
The I post ta funtion to do jsut that,

quite frankly the function is very eassy to write, and it is teh same for both case, just teh impot data changes.
I can be done with matrices or quaternion, by using the concept of similar tranformations.

note:
Please make a post after this so that I remember tonight to do that for you.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Getting LOCAL Pitch, Yaw, Roll...

Postby misho » Mon Nov 15, 2010 3:32 pm

Ok thanks!!

Julio, it is VERY easy to figure out what I need:

Can you see the Omega readouts on the screen? "Omega: X = " and so on?

Ok - press and hold "X" key for a second or two. You will see the Omega X value increase as the dumbell starts to rotate around X axis. Now Press "C". The rotation will stop. (note that Omega Y and Omega Z values are zero, or very very small)

Now press and hold "Y" key for a second or two. You will see the Omega Y value increase as the dumbell starts to rotate around Y axis. Now Press "C". The rotation will stop. (note that Omega X and Omega Z values are zero, or very very small)

Now press and hold "Z" key for a second or two. You will see the Omega Z value increase as the dumbell starts to rotate around Z axis. Now Press "C". The rotation will stop. (note that Omega X and Omega Y values are zero, or very very small)

Those Omegas are values on LOCAL axis, not the world axis.

OK - I'd Like to see the SAME thing, but for the ANGLES on local axis, just like those omegas are on local axis.

I actually tried to get the angles FROM the omegas and it worked, but I wasn't sure how to reliably get the PHYSICS TIME to calculate a valid time step to get the accurate angle. That was described in one of the posts above. I would prefer it in Quaternions - Although I can't crack this nut, as I'm working on this I got to learn and use quaternions and I can see how powerful they are. I just wish there were more functions (like this one, something like "GetLocalEuler") that came with Quaternion class.

thanks,
Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests