Advanced Question oapiGetGlobalVel() and superstructures

smarly

New member
Joined
Jul 27, 2008
Messages
40
Reaction score
0
Points
0
Hi everyone,

during my latest project I ran into a problem which I don't quite understand...

I have two vessels, say ISS (tgtVessel) and Deltaglider (myVessel). The vessels are docked, forming a superstructure.

I have written a small piece of code that should calculate the relative velocity between the CoG of the two vessels. ( I know there is a Orbiter function which does exactly that, but that's beside the point).

Code:
VECTOR3 issVel; 
oapiGetGlobalVel(tgtVessel->GetHandle(),&issVel);

VECTOR3 dgVel;
oapiGetGlobalVel(myVessel->GetHandle(), &dgVel);

 sprintf(oapiDebugString(), "Relative velocity: %f %f %f ",(dgVel-issVel).x,(dgVel-issVel).y,(dgVel-issVel).z);

The output is always "0.000 0.000 0.000".

If the superstructure has no angular velocity, the result is as expected.

If I add a rotation rate to the superstructure (via the scenario editor / angular velocity menu) , I would expect that there would be a difference between the global velocity vectors of the two different CoGs, due to the superposition of the rotation and the translation of the superstructure. However, the output still remains "0.000 0.000 0.000".

Maybe someone out there can enlighten me as to where I am mistaken? I have been on this problem for quite some time now, and I am beginning to doubt my entire understanding of kinematics ... or maybe it's just the lack of sleep. :rofl:

Anyway, any help at all would be greatly appreciated.

Thanks!
 

SolarLiner

It's necessary, TARS.
Addon Developer
Joined
Jun 14, 2010
Messages
1,847
Reaction score
2
Points
0
Location
404 ROAD NOT FOUND
What I will do in this case, instead of reading physics books, is write a longer debug string to include the raw vessel's velocity vectors. Then if the numbers are always the same, the subtraction will return 0; as very basic maths tells us.

So if that happens, the most likely mistake is that tgtVessel returns current vessel's vel vec. Can we see how you get the ISS handle?
 

smarly

New member
Joined
Jul 27, 2008
Messages
40
Reaction score
0
Points
0
So if that happens, the most likely mistake is that tgtVessel returns current vessel's vel vec. Can we see how you get the ISS handle?

Hi, thanks for the suggestion. :thumbup:

That was my first thought as well. Unfortunatly, that's not the case. Posting the code for the vessels is a bit more complicated, since they are passed from another function.
However, I did verify that vessels are correct by adding myVessel->GetName() and tgtVessel->GetName() to the debug string. Vessel names are correct, and since there are only two vessels in the scenario I think it is a safe assumption that this is not the source of the problem. Would you agree?

Any other ideas? :tiphat:
 

SolarLiner

It's necessary, TARS.
Addon Developer
Joined
Jun 14, 2010
Messages
1,847
Reaction score
2
Points
0
Location
404 ROAD NOT FOUND
Well, try to output the "raw" velocity vectors into the debug string and see what it returns. I'll go and search for an alternative way to get velocity vectors...
 

smarly

New member
Joined
Jul 27, 2008
Messages
40
Reaction score
0
Points
0
Well, try to output the "raw" velocity vectors into the debug string and see what it returns.


Done. As expected, the values are exactly the same ... I am starting to believe that Orbiter just returns the global velocity of the superstructure CoG for every vessel that is part of the superstructure???
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
IIRC, super-structures are treated as a single combined vessel for the purposes of calculating orbital elements.
 

smarly

New member
Joined
Jul 27, 2008
Messages
40
Reaction score
0
Points
0
IIRC, super-structures are treated as a single combined vessel for the purposes of calculating orbital elements.

Hm, according to the API reference this should only by the case for total mass, center of mass, inertia tensor and effects of forces.

So, it's either missing in the documentation or I am just not able to find it.

Anyway, working under the assumption that a call to getGlobalVel() always returns the velocity of the superstructure CoG instead of the velocity of the vessel CoG, I wrote a small function that should return the global velocity for any given offset point of a vessel. It should work with both superstructures and "normal" vessels, with and without angular rate.

If someone else is having the same problem, maybe this helps.

Code:
//Returns the global velocity of any given offset point of the specified vessel (offset point in local vessel coordinates)
VECTOR3 oapi2GetGlobalOffsetVel(VESSEL *vessel, VECTOR3 offsetLocal) {

    // Get vessel angular velocity
    VECTOR3 vesselRot;
    vessel->GetAngularVel(vesselRot);

    // Add superstructure CG offset
    VECTOR3 superStructCG;
    vessel->GetSuperstructureCG(superStructCG);            // Returns (0,0,0) if vessel is not part of superstructure
    offsetLocal = offsetLocal - superStructCG;

    // Calculate offset point velocity induced by vessel rotation (in local vessel coordinate system, Center of turn in superstructure CG)
    // NOTE: Left-hand-side coordinate system!!!!
    VECTOR3 offsetLocalVel;
    offsetLocalVel.x =  - offsetLocal.y * vesselRot.z + offsetLocal.z * vesselRot.y;
    offsetLocalVel.y =  - offsetLocal.z * vesselRot.x + offsetLocal.x * vesselRot.z;
    offsetLocalVel.z =  - offsetLocal.x * vesselRot.y + offsetLocal.y * vesselRot.x;
    
    // Transform offset point velocity induced from vessel rotation to global coordinate system
    MATRIX3 m;
    vessel->GetRotationMatrix(m);
    VECTOR3 offsetGlobalVel = mul(m,offsetLocalVel);    
    
    // Get global translation velocity of superstructure CoG / vessel CoG 
    // NOTE: If vessel is not part of superstructure, vessel CoG equals superstructure CoG)
    // Assumption: If vessel is part of a superstructure, oapiGetGlobalVel() returns the velocity of the superstructure CoG instead of the velocity of the vessel CoG
    VECTOR3 vesselGlobalVel;
    oapiGetGlobalVel(vessel->GetHandle(), &vesselGlobalVel);

    // Add vessel translation velocity and rotation velocity of offset point to get offset point total global velocity
    return vesselGlobalVel + offsetGlobalVel;

}

It seems to work for the moment, but I am still debugging it...

Thanks for all your help and suggestions! :thumbup:
 
Last edited:

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
Hm, according to the API reference this should only by the case for total mass, center of mass, inertia tensor and effects of forces.

the bolded bit, that's your problem right there ^
 

Hielor

Defender of Truth
Donator
Beta Tester
Joined
May 30, 2008
Messages
5,580
Reaction score
2
Points
0
Center of mass and center of gravity are the same :)
 

smarly

New member
Joined
Jul 27, 2008
Messages
40
Reaction score
0
Points
0
Center of mass and center of gravity are the same :)

That I know. What I meant to say is:The API reference mentions that for a superstructure, all vessels are treated as one when it comes to calculating the center of mass / gravity, inertia tensor, etc. However, it doesn't say anything about the velocity being the same for all vessels.

The code I posted above solves the issue with rotating vessels and superstructures, but now I am stuck with relative velocities in rotating reference coordinate systems ... jeiks. This thing is getting really out of hand. :facepalm:

Does anyone know a simpler way to get the relative velocities of the docking ports of two rotating vessels?
 
Last edited:

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
all vessels are treated as one when it comes to calculating the center of mass

...exactly, and if two vessels are following the same trajectory and sharing a single CoM thier relative velocity is obviously 0.

Does anyone know a simpler way to get the relative velocities of the docking ports of two rotating vessels?

The relative velocities between the docking ports of two docked vessels will always be 0 if they are docked to each other.
 

smarly

New member
Joined
Jul 27, 2008
Messages
40
Reaction score
0
Points
0
...exactly, and if two vessels are following the same trajectory and sharing a single CoM thier relative velocity is obviously 0.

Ok, if you look at it from this perspective, that makes sense. Still, just from the documentation I would never have guessed that behaviour. If I make a call to oapiGetGlobalVel for a specific vessel, I would expect the function to return the actual gloabl velocity of that vessels CoG, which I would expect to be the total global velocity of the superstructure CoG + rotational velocity of the vessels CoG around the superstructure CoG.... Thanks for the clarification!

The relative velocities between the docking ports of two docked vessels will always be 0 if they are docked to each other.

Ok, that is obvious ;) Sorry, I probably didn't express myself clear enough. Of course I am not so much interested in the situation when the vessels are docked, but more in what happens during the approach. The case where both vessels are docked is more like a reference / debug situation.

So, again: if two vessels are not docked, but floating freely and rotating around their own axis, is there a simple way to calculate the relative speed of the docking ports of both vessels?
The relative velocity should be calculated both in global coordinates and in a reference coordinate system that has its origin in the target vessels docking port and rotates with the target vessel (around the target ships CoG.)
 
Last edited:

Hielor

Defender of Truth
Donator
Beta Tester
Joined
May 30, 2008
Messages
5,580
Reaction score
2
Points
0
If I make a call to oapiGetGlobalVel for a specific vessel, I would expect the function to return the actual gloabl velocity of that vessels CoG, which I would expect to be the total global velocity of the superstructure CoG + rotational velocity of the vessels CoG around the superstructure CoG.... Thanks for the clarification!
There is no "vessel's CoG" while the vessel is docked. There is only the superstructure CoG.

So, again: if two vessels are not docked, but floating freely and rotating around their own axis, is there a simple way to calculate the relative speed of the docking ports of both vessels?
The relative velocity should be calculated both in global coordinates and in a reference coordinate system that has its origin in the target vessels docking port and rotates with the target vessel (around the target ships CoG.)
Now you've gone and changed the question, and in this case you can use GetGlobalVel as a starting point and your rotational calculations to get the rest of the way.
 
Top