SDK Question ShiftCG and airfoils

kwan3217

Addon Developer
Addon Developer
Donator
Joined
Apr 29, 2008
Messages
115
Reaction score
0
Points
16
Location
Geosynchronous Orbit
I've been working on some code for a vessel to automatically manage the center of mass (CM). The idea is you build the vessel in "station coordinates", where you establish some origin not at the CM, then attach meshes, thrusters, airfoils, and masses to the vessel. The masses are my own contribution, and contains code like what is the CM of a cylinder, or what is the mass and CM of a solid-fueled propellant grain as it burns. From all of these masses, it calculates the CM in station coordinates, then shifts the CM accordingly. It remembers the last CM to calculate the amount of shift. You can detatch masses completely, like for a stage drop, and it does the right thing.

The code mostly works fine, the meshes and thrusters automatically move, but it doesn't seem like the airfoils do. Also touchdown points, but airfoils are more important. Is this a bug, or a missing feature in ShiftCG?

The concrete example I am working on is a sounding rocket. It has two stages and two sets of fins. I set the station origin to the tail end of the rocket, attach all the parts, then let my CM manager figure the actual CM and move it. With the station origin where it is, all the airfoils are forward of the station origin, but aft of the CM. When I calculate and shift to the center of mass, the airfoils remain forward of the CM and the rocket is unstable.

I need a way to do this. I have it mostly worked out with EditAirfoil and a bit of memory hacking to read the current airfoil attack point, but obviously that ties it to Orbiter 060929. I wonder if I missed the obvious way.
 
Last edited:

Xyon

Puts the Fun in Dysfunctional
Administrator
Moderator
Orbiter Contributor
Addon Developer
Webmaster
GFX Staff
Beta Tester
Joined
Aug 9, 2009
Messages
6,927
Reaction score
795
Points
203
Location
10.0.0.1
Website
www.orbiter-radio.co.uk
Preferred Pronouns
she/her
From the API reference, this is what ShiftCG() actually does;

• Calls ShiftMeshes (-shift) to re-align the vessel’s visual representation
with the shifted coordinate origin.
• Applies an equivalent shift to all thruster positions, docking ports,
attachment points and to the cockpit camera position.
• CallsShiftCentreOfMass (shift) to compensate for the mesh translation by
a translation of the vessel’s global position in the opposite direction.

The way I do similar things with Thunderchild (which is probably not most efficient) is by branching the SetClassCaps callback based on where it is in the staging process and defining things anew, so (provided you have handles to your airfoils)
Code:
switch (status) // branch on stage status
{
       case default: // launch config
- standard airfoil code
       break;
      case 1; // after staging once
       if (airfoil1) // conditional - because if we load from scenario this shouldn't be defined (provided you save "status")
       {
            DelAirfoil (airfoil1); // or you could redefine it, but I'm not so savvy with airfoil code to example it
        }
        airfoil1 = CreateAirfoil3( new params);
etc etc for each airfoil and stage label. Like I said, it's probably not the most efficient way of doing it, but it should work.
 
Last edited:
Top