Advanced Question Changing COG

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
10,538
Reaction score
4,369
Points
203
Location
Dallas, TX
I have a vessel that had has 3 pods but the pods are at about 45 degees off the center line. They are docked. So that affects the Center of Gravity.

I did this and it fixed it on main thrust.
Code:
        th_main[0] = CreateThruster (_V(0,0,-79.3), _V(0,0,1), 4500000, ph_main, 890000);


Code:
GetSuperstructureCG(shipcg);
SetThrusterRef  (th_main[0], _V(0,((shipcg.y)-0),(-79.3-(shipcg.z)))) ;
But now we noticed then you apply this when in translation.
Up Pitch Up
Down Pitch Down
Left Yaw Left and Pitch Down
Right Yaw Right and Pitch Up

By removing the pod no issues so it seems it is the pods are affecting the COG. So how do I adjust the rcs?
 
yes.
I can't even find this in the doc.
Code:
GetSuperstructureCG(shipcg);

But for the main thrust since I had a pod on either side before I adjusted the cg I had issues. If along the z axis then no issues.

But it seems the translation rcs location may need to change

bool VESSEL::GetSuperstructureCG ( VECTOR3 & cg ) const
Returns the centre of gravity of the superstructure to which the vessel belongs, if applicable.

Parameters:
cg superstructure centre of gravity [m] Returns: true if the vessel is part of a superstructure, false otherwise. Note: The returned vector is the position of the superstructure centre of gravity, in coordinates of the local vessel frame. If the vessel is not part of a superstructure, cg returns (0,0,0).


I ran it in the debugger:
I get for the
shipcg.x .0000000000000000 double
shipcg.y -0.45195982579326277 double
shipcg.z 12.384019198293483 double




So do I need to adjust the positions of the rcs?
attleft
Code:
	th_rcs[4]=CreateThruster(_V(6,0,10),_V(-1,0,0),MAXRCSTH,ph_main,ISP_QUI);
	th_rcs[19]=CreateThruster(_V(-6,0,-10),_V(1,0,0),MAXRCSTH,ph_main,ISP_QUI);
attright
Code:
	th_rcs[9]=CreateThruster(_V(-6,0,10),_V(1,0,0),MAXRCSTH,ph_main,ISP_QUI);
	th_rcs[14]=CreateThruster(_V(6,0,-10),_V(-1,0,0),MAXRCSTH,ph_main,ISP_QUI);
 
Last edited:
So is this a bug or fixable? If fixable how?

I would think like the main thrust position changes due to the shift of COG. So would the RCS needs to adjust also
 
Simplest solution...

Code:
// --------------------------------------------------------------
// Return current center of mass
// --------------------------------------------------------------
inline VECTOR3 DiscoveryII::CoG (void)
{
	VECTOR3 output = NULL_VECTOR;
	GetMeshOffset (0, output);
	return output;
} // End "CoG ()"


// --------------------------------------------------------------
// Calculate center of mass
// --------------------------------------------------------------
bool DiscoveryII::UpdateCoG ()
{
	// Starting values, CoG centered on mesh and vice versa. 
	VECTOR3 datum = NULL_VECTOR;
	VECTOR3 moment = NULL_VECTOR;

	// Calculate Hab module's balance moment (position * mass) and add it to our datum
	moment = _V( 0, 0.4, 80.9) * DISC_HABMASS; 
	datum += moment; 

	// add reactor's balance moment
	moment = _V( 0, 0,-140.0) * DISC_REACTORMASS;
	datum += moment; 

	// add propellant tanks' balance moment
	moment = _V( 0, 0, 102.1) * (DISC_CRYOTANKMASS + GetPropellantMass (ph_prop)); 
	datum += moment; 

	// Calculate datum's offset from current CoG 
	datum = datum / GetMass ();		// Divide datum by vessel's mass...
	VECTOR3 ofs = CoG () - datum;	// ...and subtract the result from current CoG to get offset.

	// if offset is greater than 1 m update vessel's CoG
	if (length (ofs) > 1.0)
	{
		// Shift center of gravity
		ShiftCG (ofs);

		// Shift antenna pos
		for (int i = 0; i < 2; i++) Dish[i]->SetOffset (CoG () + DISC_ANTENNA_POS[i]);

		// the ShiftCG() function doesn't update BEACONSPEC positions so we must do this manually...
		for (int i = 0; i < 12; i++) poslight_ofs[i] -= (ofs); 		// Position Lights
		for (int i = 0; i < 4; i++) strobelight_ofs[i] -= (ofs);	// Strobe lights		
		for (int i = 0; i < 2; i++) docklight_ofs[i] -= (ofs);		// Docking lights

		// NOTE: We only need to update the hab light's positions if the spin section is stationary. Otherwise their positions are updated as part of the animation sequence.   
		if (hab_rpm == 0) for (int i = 0; i < 3; i++) hablight_ofs[i] -= (ofs);	

		// Update vessel's clip radius to prevent visual artifacts 
		double cliprad = length (ofs) + length (DISC_DOCK_POS); // "DISC_DOCK_POS" is analogous to the bow of the vessel, getting the distance of the bow from our CoG gives us a nominal radius for visualization.
		SetClipRadius (cliprad);

		// Return true;
		return true;
	}
	else return false;

} // End "UpdateCoG ()"

from here gimbaling thrusters and RCS to match is pretty simple.
 
Last edited:
Back
Top