JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGMassBalance Class Reference

Detailed Description

Models weight, balance and moment of inertia information.

Maintains a vector of point masses. Sums the contribution of all, and provides this to FGPropagate. Loads the <mass_balance> section of the aircraft configuration file. There can be any number of <pointmasses>. Each can also have a shape which - if present - causes an associated moment of inertia to be calculated based on the shape. Note that a cylinder is solid, a tube is hollow, a ball is solid and a sphere is hollow.

The inertia tensor must be specified in the structural frame (x axis positive aft, y axis positive out of the right wing and z axis upward). The sign of the inertia cross products are optional by JSBSim. if negated_crossproduct_inertia == "true", then define: ixy = -integral( x * y * dm ), ixz = -integral( x * z * dm ), iyz = -integral( y * z * dm ). else if negated_crossproduct_inertia == "false", then define: ixy = integral( x * y * dm ), ixz = integral( x * z * dm ), iyz = integral( y * z * dm ). default is negated_crossproduct_inertia = "true". We strongly recommend defining negated_crossproduct_inertia = "false", which is consistent with the specifications in the field of flight dynamics.

Configuration File Format for <mass_balance> Section:

<mass_balance negated_crossproduct_inertia="true|false">
<ixx unit="{SLUG*FT2 | KG*M2}"> {number} </ixx>
<iyy unit="{SLUG*FT2 | KG*M2}"> {number} </iyy>
<izz unit="{SLUG*FT2 | KG*M2}"> {number} </izz>
<ixy unit="{SLUG*FT2 | KG*M2}"> {number} </ixy>
<ixz unit="{SLUG*FT2 | KG*M2}"> {number} </ixz>
<iyz unit="{SLUG*FT2 | KG*M2}"> {number} </iyz>
<emptywt unit="{LBS | KG"> {number} </emptywt>
<location name="CG" unit="{IN | FT | M}">
<x> {number} </x>
<y> {number} </y>
<z> {number} </z>
</location>
[<pointmass name="{string}">
<form shape="{tube | cylinder | sphere | ball}">
<radius unit="{IN | FT | M}"> {number} </radius>
<length unit="{IN | FT | M}"> {number} </length>
</form>
<weight unit="{LBS | KG}"> {number} </weight>
<location name="{string}" unit="{IN | FT | M}">
<x> {number} </x>
<y> {number} </y>
<z> {number} </z>
</location>
</pointmass>
... other point masses ...]
</mass_balance>
@see Stevens and Lewis, "Flight Control & Simulation"
@see Bernard Etkin, " Dynamics Of Atmosferic Flight"
@see https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
@see https://www.mathworks.com/help/physmod/sm/ug/specify-custom-inertia.html

Definition at line 124 of file FGMassBalance.h.

#include <FGMassBalance.h>

+ Inheritance diagram for FGMassBalance:
+ Collaboration diagram for FGMassBalance:

Classes

struct  Inputs
 

Public Member Functions

 FGMassBalance (FGFDMExec *)
 
void AddPointMass (Element *el)
 
double GetDeltaXYZcg (int axis) const
 
const FGColumnVector3GetDeltaXYZcg (void) const
 
double GetEmptyWeight (void) const
 
const FGMatrix33GetJ (void) const
 Returns the inertia matrix expressed in the body frame.
 
const FGMatrix33GetJinv (void) const
 Returns the inverse of the inertia matrix expressed in the body frame.
 
double GetMass (void) const
 
void GetMassPropertiesReport (int i)
 
FGMatrix33 GetPointmassInertia (double mass_sl, const FGColumnVector3 &r) const
 Computes the inertia contribution of a pointmass.
 
const FGColumnVector3GetPointMassMoment (void)
 
double GetTotalPointMassWeight (void) const
 
double GetWeight (void) const
 
double GetXYZcg (int axis) const
 
const FGColumnVector3GetXYZcg (void) const
 Returns the coordinates of the center of gravity expressed in the structural frame.
 
bool InitModel (void) override
 
bool Load (Element *el) override
 
bool Run (bool Holding) override
 Runs the Mass Balance model; called by the Executive Can pass in a value indicating if the executive is directing the simulation to Hold.
 
void SetAircraftBaseInertias (const FGMatrix33 &BaseJ)
 
void SetBaseCG (const FGColumnVector3 &CG)
 
void SetEmptyWeight (double EW)
 
FGColumnVector3 StructuralToBody (const FGColumnVector3 &r) const
 Conversion from the structural frame to the body frame.
 
- Public Member Functions inherited from FGModel
 FGModel (FGFDMExec *)
 Constructor.
 
 ~FGModel () override
 Destructor.
 
virtual SGPath FindFullPathName (const SGPath &path) const
 
FGFDMExecGetExec (void) const
 
const std::string & GetName (void) const
 
unsigned int GetRate (void) const
 Get the output rate for the model in frames.
 
bool InitModel (void) override
 
void SetPropertyManager (std::shared_ptr< FGPropertyManager > fgpm)
 
void SetRate (unsigned int tt)
 Set the ouput rate for the model in frames.
 
- Public Member Functions inherited from FGModelFunctions
std::string GetFunctionStrings (const std::string &delimeter) const
 Gets the strings for the current set of functions.
 
std::string GetFunctionValues (const std::string &delimeter) const
 Gets the function values.
 
std::shared_ptr< FGFunctionGetPreFunction (const std::string &name)
 Get one of the "pre" function.
 
bool Load (Element *el, FGFDMExec *fdmex, std::string prefix="")
 
void PostLoad (Element *el, FGFDMExec *fdmex, std::string prefix="")
 
void PreLoad (Element *el, FGFDMExec *fdmex, std::string prefix="")
 
void RunPostFunctions (void)
 
void RunPreFunctions (void)
 
- Public Member Functions inherited from FGJSBBase
 FGJSBBase ()
 Constructor for FGJSBBase.
 
virtual ~FGJSBBase ()
 Destructor for FGJSBBase.
 
void disableHighLighting (void)
 Disables highlighting in the console output.
 

Public Attributes

struct JSBSim::FGMassBalance::Inputs in
 

Additional Inherited Members

- Public Types inherited from FGJSBBase
enum  { eL = 1 , eM , eN }
 Moments L, M, N. More...
 
enum  { eP = 1 , eQ , eR }
 Rates P, Q, R. More...
 
enum  { eU = 1 , eV , eW }
 Velocities U, V, W. More...
 
enum  { eX = 1 , eY , eZ }
 Positions X, Y, Z. More...
 
enum  { ePhi = 1 , eTht , ePsi }
 Euler angles Phi, Theta, Psi. More...
 
enum  { eDrag = 1 , eSide , eLift }
 Stability axis forces, Drag, Side force, Lift. More...
 
enum  { eRoll = 1 , ePitch , eYaw }
 Local frame orientation Roll, Pitch, Yaw. More...
 
enum  { eNorth = 1 , eEast , eDown }
 Local frame position North, East, Down. More...
 
enum  { eLat = 1 , eLong , eRad }
 Locations Radius, Latitude, Longitude. More...
 
enum  {
  inNone = 0 , inDegrees , inRadians , inMeters ,
  inFeet
}
 Conversion specifiers. More...
 
- Static Public Member Functions inherited from FGJSBBase
static const std::string & GetVersion (void)
 Returns the version number of JSBSim.
 
static constexpr double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit.
 
static constexpr double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine.
 
static constexpr double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius.
 
static constexpr double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine.
 
static constexpr double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin.
 
static constexpr double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius.
 
static constexpr double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit.
 
static constexpr double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin.
 
static constexpr double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius.
 
static constexpr double FeetToMeters (double measure)
 Converts from feet to meters.
 
static bool EqualToRoundoff (double a, double b)
 Finite precision comparison.
 
static bool EqualToRoundoff (float a, float b)
 Finite precision comparison.
 
static bool EqualToRoundoff (float a, double b)
 Finite precision comparison.
 
static bool EqualToRoundoff (double a, float b)
 Finite precision comparison.
 
static constexpr double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
static constexpr double sign (double num)
 
- Static Public Attributes inherited from FGJSBBase
static char highint [5] = {27, '[', '1', 'm', '\0' }
 highlights text
 
static char halfint [5] = {27, '[', '2', 'm', '\0' }
 low intensity text
 
static char normint [6] = {27, '[', '2', '2', 'm', '\0' }
 normal intensity text
 
static char reset [5] = {27, '[', '0', 'm', '\0' }
 resets text properties
 
static char underon [5] = {27, '[', '4', 'm', '\0' }
 underlines text
 
static char underoff [6] = {27, '[', '2', '4', 'm', '\0' }
 underline off
 
static char fgblue [6] = {27, '[', '3', '4', 'm', '\0' }
 blue text
 
static char fgcyan [6] = {27, '[', '3', '6', 'm', '\0' }
 cyan text
 
static char fgred [6] = {27, '[', '3', '1', 'm', '\0' }
 red text
 
static char fggreen [6] = {27, '[', '3', '2', 'm', '\0' }
 green text
 
static char fgdef [6] = {27, '[', '3', '9', 'm', '\0' }
 default text
 
static short debug_lvl = 1
 
- Protected Member Functions inherited from FGModel
bool Upload (Element *el, bool preLoad)
 Uploads this model in memory.
 
- Static Protected Member Functions inherited from FGJSBBase
static std::string CreateIndexedPropertyName (const std::string &Property, int index)
 
- Protected Attributes inherited from FGModel
unsigned int exe_ctr
 
FGFDMExecFDMExec
 
std::string Name
 
std::shared_ptr< FGPropertyManager > PropertyManager
 
unsigned int rate
 
- Protected Attributes inherited from FGModelFunctions
FGPropertyReader LocalProperties
 
std::vector< std::shared_ptr< FGFunction > > PostFunctions
 
std::vector< std::shared_ptr< FGFunction > > PreFunctions
 
- Static Protected Attributes inherited from FGJSBBase
static constexpr double radtodeg = 180. / M_PI
 
static constexpr double degtorad = M_PI / 180.
 
static constexpr double hptoftlbssec = 550.0
 
static constexpr double psftoinhg = 0.014138
 
static constexpr double psftopa = 47.88
 
static constexpr double fttom = 0.3048
 
static constexpr double ktstofps = 1852./(3600*fttom)
 
static constexpr double fpstokts = 1.0 / ktstofps
 
static constexpr double inchtoft = 1.0/12.0
 
static constexpr double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static constexpr double in3tom3 = inchtoft*inchtoft*inchtoft/m3toft3
 
static constexpr double inhgtopa = 3386.38
 
static constexpr double slugtolb = 32.174049
 Note that definition of lbtoslug by the inverse of slugtolb and not to a different constant you can also get from some tables will make lbtoslug*slugtolb == 1 up to the magnitude of roundoff.
 
static constexpr double lbtoslug = 1.0/slugtolb
 
static constexpr double kgtolb = 2.20462
 
static constexpr double kgtoslug = 0.06852168
 
static const std::string needed_cfg_version = "2.0"
 
static const std::string JSBSim_version = JSBSIM_VERSION " " __DATE__ " " __TIME__
 

Constructor & Destructor Documentation

◆ FGMassBalance()

FGMassBalance ( FGFDMExec fdmex)
explicit

Definition at line 57 of file FGMassBalance.cpp.

58 : FGModel(fdmex)
59{
60 Name = "FGMassBalance";
61 Weight = EmptyWeight = Mass = 0.0;
62
63 vbaseXYZcg.InitMatrix();
64 vXYZcg.InitMatrix();
65 vLastXYZcg.InitMatrix();
66 vDeltaXYZcg.InitMatrix();
67 baseJ.InitMatrix();
68 mJ.InitMatrix();
69 mJinv.InitMatrix();
70 pmJ.InitMatrix();
71 Propagate = fdmex->GetPropagate();
72
73 bind();
74
75 Debug(0);
76}
void InitMatrix(void)
Initialize the matrix.
FGModel(FGFDMExec *)
Constructor.
Definition FGModel.cpp:58

◆ ~FGMassBalance()

Definition at line 80 of file FGMassBalance.cpp.

81{
82 for(auto pm: PointMasses) delete pm;
83
84 Debug(1);
85}

Member Function Documentation

◆ AddPointMass()

void AddPointMass ( Element el)

Definition at line 267 of file FGMassBalance.cpp.

268{
269 Element* loc_element = el->FindElement("location");
270 string pointmass_name = el->GetAttributeValue("name");
271 if (!loc_element) {
272 XMLLogException err(el);
273 err << "Pointmass " << pointmass_name << " has no location." << endl;
274 throw err;
275 }
276
277 double w = el->FindElementValueAsNumberConvertTo("weight", "LBS");
278 FGColumnVector3 vXYZ = loc_element->FindElementTripletConvertTo("IN");
279
280 PointMass *pm = new PointMass(w, vXYZ);
281 pm->SetName(pointmass_name);
282
283 Element* form_element = el->FindElement("form");
284 if (form_element) {
285 double radius=0, length=0;
286 string shape = form_element->GetAttributeValue("shape");
287 Element* radius_element = form_element->FindElement("radius");
288 Element* length_element = form_element->FindElement("length");
289 if (radius_element) radius = form_element->FindElementValueAsNumberConvertTo("radius", "FT");
290 if (length_element) length = form_element->FindElementValueAsNumberConvertTo("length", "FT");
291 if (shape == "tube") {
292 pm->SetPointMassShapeType(PointMass::esTube);
293 pm->SetRadius(radius);
294 pm->SetLength(length);
295 pm->CalculateShapeInertia();
296 } else if (shape == "cylinder") {
297 pm->SetPointMassShapeType(PointMass::esCylinder);
298 pm->SetRadius(radius);
299 pm->SetLength(length);
300 pm->CalculateShapeInertia();
301 } else if (shape == "sphere") {
302 pm->SetPointMassShapeType(PointMass::esSphere);
303 pm->SetRadius(radius);
304 pm->CalculateShapeInertia();
305 } else if (shape == "ball") {
306 pm->SetPointMassShapeType(PointMass::esBall);
307 pm->SetRadius(radius);
308 pm->CalculateShapeInertia();
309 } else {
310 }
311 }
312 else {
313 pm->SetPointMassShapeType(PointMass::esUnspecified);
314 pm->SetPointMassMoI(ReadInertiaMatrix(el));
315 }
316
317 pm->bind(PropertyManager.get(), PointMasses.size());
318 PointMasses.push_back(pm);
319}

◆ GetDeltaXYZcg() [1/2]

double GetDeltaXYZcg ( int  axis) const
inline

Definition at line 151 of file FGMassBalance.h.

151{return vDeltaXYZcg(axis);}

◆ GetDeltaXYZcg() [2/2]

const FGColumnVector3 & GetDeltaXYZcg ( void  ) const
inline

Definition at line 150 of file FGMassBalance.h.

150{return vDeltaXYZcg;}

◆ GetEmptyWeight()

double GetEmptyWeight ( void  ) const
inline

Definition at line 145 of file FGMassBalance.h.

145{return EmptyWeight;}

◆ GetJ()

const FGMatrix33 & GetJ ( void  ) const
inline

Returns the inertia matrix expressed in the body frame.

Definition at line 195 of file FGMassBalance.h.

195{return mJ;}

◆ GetJinv()

const FGMatrix33 & GetJinv ( void  ) const
inline

Returns the inverse of the inertia matrix expressed in the body frame.

Definition at line 197 of file FGMassBalance.h.

197{return mJinv;}

◆ GetMass()

double GetMass ( void  ) const
inline

Definition at line 143 of file FGMassBalance.h.

143{return Mass;}

◆ GetMassPropertiesReport()

void GetMassPropertiesReport ( int  i)

Definition at line 437 of file FGMassBalance.cpp.

438{
439 FGLogging out(LogLevel::STDOUT);
440 out << endl << LogFormat::BLUE << LogFormat::BOLD
441 << " Mass Properties Report (English units: lbf, in, slug-ft^2)"
442 << LogFormat::RESET << endl;
443 out << " " << LogFormat::UNDERLINE_ON << " Weight CG-X CG-Y"
444 << " CG-Z Ixx Iyy Izz"
445 << " Ixy Ixz Iyz" << LogFormat::UNDERLINE_OFF << endl;
446 out << fixed << setprecision(1);
447 out << LogFormat::BOLD << setw(34) << left << " Base Vehicle " << LogFormat::NORMAL
448 << right << setw(12) << EmptyWeight
449 << setw(8) << vbaseXYZcg(eX) << setw(8) << vbaseXYZcg(eY) << setw(8) << vbaseXYZcg(eZ)
450 << setw(12) << baseJ(1,1) << setw(12) << baseJ(2,2) << setw(12) << baseJ(3,3)
451 << setw(12) << baseJ(1,2) << setw(12) << baseJ(1,3) << setw(12) << baseJ(2,3) << endl;
452
453 for (unsigned int i=0;i<PointMasses.size();i++) {
454 PointMass* pm = PointMasses[i];
455 double pmweight = pm->GetPointMassWeight();
456 out << LogFormat::BOLD << left << setw(4) << i << setw(30) << pm->GetName() << LogFormat::NORMAL
457 << right << setw(12) << pmweight << setw(8) << pm->GetLocation()(eX)
458 << setw(8) << pm->GetLocation()(eY) << setw(8) << pm->GetLocation()(eZ)
459 << setw(12) << pm->GetPointMassMoI(1,1) << setw(12) << pm->GetPointMassMoI(2,2) << setw(12) << pm->GetPointMassMoI(3,3)
460 << setw(12) << pm->GetPointMassMoI(1,2) << setw(12) << pm->GetPointMassMoI(1,3) << setw(12) << pm->GetPointMassMoI(2,3) << endl;
461 }
462
463 out << FDMExec->GetPropulsionTankReport();
464
465 out << " " << LogFormat::UNDERLINE_ON << setw(136) << " " << LogFormat::UNDERLINE_OFF << endl;
466 out << LogFormat::BOLD << left << setw(30) << " Total: " << right << setw(14) << Weight
467 << setw(8) << vXYZcg(eX)
468 << setw(8) << vXYZcg(eY)
469 << setw(8) << vXYZcg(eZ)
470 << setw(12) << mJ(1,1)
471 << setw(12) << mJ(2,2)
472 << setw(12) << mJ(3,3)
473 << setw(12) << mJ(1,2)
474 << setw(12) << mJ(1,3)
475 << setw(12) << mJ(2,3)
476 << LogFormat::NORMAL << endl;
477}

◆ GetPointmassInertia()

FGMatrix33 GetPointmassInertia ( double  mass_sl,
const FGColumnVector3 r 
) const
inline

Computes the inertia contribution of a pointmass.

Computes and returns the inertia matrix of a pointmass of mass slugs at the given vector r in the structural frame. The units should be for the mass in slug and the vector in the structural frame as usual in inches.

Parameters
mass_slthe mass of this single pointmass given in slugs
rthe location of this single pointmass in the structural frame

Definition at line 161 of file FGMassBalance.h.

162 {
163 FGColumnVector3 v = StructuralToBody( r );
164 FGColumnVector3 sv = mass_sl*v;
165 double xx = sv(1)*v(1);
166 double yy = sv(2)*v(2);
167 double zz = sv(3)*v(3);
168 double xy = -sv(1)*v(2);
169 double xz = -sv(1)*v(3);
170 double yz = -sv(2)*v(3);
171 return FGMatrix33( yy+zz, xy, xz,
172 xy, xx+zz, yz,
173 xz, yz, xx+yy );
174 }
FGColumnVector3 StructuralToBody(const FGColumnVector3 &r) const
Conversion from the structural frame to the body frame.

◆ GetPointMassMoment()

const FGColumnVector3 & GetPointMassMoment ( void  )

Definition at line 335 of file FGMassBalance.cpp.

336{
337 PointMassCG.InitMatrix();
338
339 for (auto pm: PointMasses)
340 PointMassCG += pm->Weight * pm->Location;
341
342 return PointMassCG;
343}

◆ GetTotalPointMassWeight()

double GetTotalPointMassWeight ( void  ) const

Definition at line 323 of file FGMassBalance.cpp.

324{
325 double PM_total_weight = 0.0;
326
327 for(auto pm: PointMasses)
328 PM_total_weight += pm->Weight;
329
330 return PM_total_weight;
331}

◆ GetWeight()

double GetWeight ( void  ) const
inline

Definition at line 144 of file FGMassBalance.h.

144{return Weight;}

◆ GetXYZcg() [1/2]

double GetXYZcg ( int  axis) const
inline

Definition at line 149 of file FGMassBalance.h.

149{return vXYZcg(axis);}

◆ GetXYZcg() [2/2]

const FGColumnVector3 & GetXYZcg ( void  ) const
inline

Returns the coordinates of the center of gravity expressed in the structural frame.

Definition at line 148 of file FGMassBalance.h.

148{return vXYZcg;}

◆ InitModel()

bool InitModel ( void  )
overridevirtual

Reimplemented from FGModelFunctions.

Definition at line 89 of file FGMassBalance.cpp.

90{
91 if (!FGModel::InitModel()) return false;
92
93 vLastXYZcg.InitMatrix();
94 vDeltaXYZcg.InitMatrix();
95
96 return true;
97}

◆ Load()

bool Load ( Element el)
overridevirtual

Reimplemented from FGModel.

Definition at line 133 of file FGMassBalance.cpp.

134{
135 string element_name = "";
136
137 Name = "Mass Properties Model: " + document->GetAttributeValue("name");
138
139 // Perform base class Pre-Load
140 if (!FGModel::Upload(document, true))
141 return false;
142
143 SetAircraftBaseInertias(ReadInertiaMatrix(document));
144 if (document->FindElement("emptywt")) {
145 EmptyWeight = document->FindElementValueAsNumberConvertTo("emptywt", "LBS");
146 }
147
148 Element *element = document->FindElement("location");
149 while (element) {
150 element_name = element->GetAttributeValue("name");
151 if (element_name == "CG") vbaseXYZcg = element->FindElementTripletConvertTo("IN");
152 element = document->FindNextElement("location");
153 }
154
155// Find all POINTMASS elements that descend from this METRICS branch of the
156// config file.
157
158 element = document->FindElement("pointmass");
159 while (element) {
160 AddPointMass(element);
161 element = document->FindNextElement("pointmass");
162 }
163
164 double ChildFDMWeight = 0.0;
165 for (size_t fdm=0; fdm<FDMExec->GetFDMCount(); fdm++) {
166 if (FDMExec->GetChildFDM(fdm)->mated) ChildFDMWeight += FDMExec->GetChildFDM(fdm)->exec->GetMassBalance()->GetWeight();
167 }
168
169 Weight = EmptyWeight + in.TanksWeight + GetTotalPointMassWeight()
170 + in.GasMass*slugtolb + ChildFDMWeight;
171
172 Mass = lbtoslug*Weight;
173
174 PostLoad(document, FDMExec);
175
176 Debug(2);
177 return true;
178}
size_t GetFDMCount(void) const
Gets the number of child FDMs.
Definition FGFDMExec.h:426
auto GetChildFDM(int i) const
Gets a particular child FDM.
Definition FGFDMExec.h:428
static constexpr double slugtolb
Note that definition of lbtoslug by the inverse of slugtolb and not to a different constant you can a...
Definition FGJSBBase.h:314
bool Upload(Element *el, bool preLoad)
Uploads this model in memory.
Definition FGModel.cpp:111

◆ Run()

bool Run ( bool  Holding)
overridevirtual

Runs the Mass Balance model; called by the Executive Can pass in a value indicating if the executive is directing the simulation to Hold.

Parameters
Holdingif true, the executive has been directed to hold the sim from advancing time. Some models may ignore this flag, such as the Input model, which may need to be active to listen on a socket for the "Resume" command to be given.
Returns
false if no error

Reimplemented from FGModel.

Definition at line 182 of file FGMassBalance.cpp.

183{
184 double denom, k1, k2, k3, k4, k5, k6;
185 double Ixx, Iyy, Izz, Ixy, Ixz, Iyz;
186
187 if (FGModel::Run(Holding)) return true;
188 if (Holding) return false;
189
190 RunPreFunctions();
191
192 double ChildFDMWeight = 0.0;
193 for (size_t fdm=0; fdm<FDMExec->GetFDMCount(); fdm++) {
194 if (FDMExec->GetChildFDM(fdm)->mated) ChildFDMWeight += FDMExec->GetChildFDM(fdm)->exec->GetMassBalance()->GetWeight();
195 }
196
197 Weight = EmptyWeight + in.TanksWeight + GetTotalPointMassWeight()
198 + in.GasMass*slugtolb + ChildFDMWeight;
199
200 Mass = lbtoslug*Weight;
201
202// Calculate new CG
203
204 vXYZcg = (EmptyWeight*vbaseXYZcg
205 + GetPointMassMoment()
206 + in.TanksMoment
207 + in.GasMoment) / Weight;
208
209 // Track frame-by-frame delta CG, and move the EOM-tracked location
210 // by this amount.
211 if (vLastXYZcg.Magnitude() == 0.0) vLastXYZcg = vXYZcg;
212 vDeltaXYZcg = vXYZcg - vLastXYZcg;
213 vDeltaXYZcgBody = StructuralToBody(vLastXYZcg) - StructuralToBody(vXYZcg);
214 vLastXYZcg = vXYZcg;
215
216 // Compensate displacements of the structural frame when the mass distribution
217 // is modified while the aircraft is in contact with the ground.
218 if (FDMExec->GetHoldDown() || in.WOW)
219 Propagate->NudgeBodyLocation(vDeltaXYZcgBody);
220
221// Calculate new total moments of inertia
222
223 // At first it is the base configuration inertia matrix ...
224 mJ = baseJ;
225 // ... with the additional term originating from the parallel axis theorem.
226 mJ += GetPointmassInertia( lbtoslug * EmptyWeight, vbaseXYZcg );
227 // Then add the contributions from the additional pointmasses.
228 mJ += CalculatePMInertias();
229 mJ += in.TankInertia;
230 mJ += in.GasInertia;
231
232 Ixx = mJ(1,1);
233 Iyy = mJ(2,2);
234 Izz = mJ(3,3);
235 Ixy = -mJ(1,2);
236 Ixz = -mJ(1,3);
237 Iyz = -mJ(2,3);
238
239// Calculate inertia matrix inverse (ref. Stevens and Lewis, "Flight Control &
240// Simulation")
241
242 k1 = (Iyy*Izz - Iyz*Iyz);
243 k2 = (Iyz*Ixz + Ixy*Izz);
244 k3 = (Ixy*Iyz + Iyy*Ixz);
245
246 denom = 1.0/(Ixx*k1 - Ixy*k2 - Ixz*k3 );
247 k1 = k1*denom;
248 k2 = k2*denom;
249 k3 = k3*denom;
250 k4 = (Izz*Ixx - Ixz*Ixz)*denom;
251 k5 = (Ixy*Ixz + Iyz*Ixx)*denom;
252 k6 = (Ixx*Iyy - Ixy*Ixy)*denom;
253
254 mJinv = { k1, k2, k3,
255 k2, k4, k5,
256 k3, k5, k6 };
257
258 RunPostFunctions();
259
260 Debug(0);
261
262 return false;
263}
double Magnitude(void) const
Length of the vector.
bool GetHoldDown(void) const
Gets the value of the property forces/hold-down.
Definition FGFDMExec.h:617
FGMatrix33 GetPointmassInertia(double mass_sl, const FGColumnVector3 &r) const
Computes the inertia contribution of a pointmass.
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition FGModel.cpp:90
+ Here is the call graph for this function:

◆ SetAircraftBaseInertias()

void SetAircraftBaseInertias ( const FGMatrix33 BaseJ)
inline

Definition at line 198 of file FGMassBalance.h.

198{baseJ = BaseJ;}

◆ SetBaseCG()

void SetBaseCG ( const FGColumnVector3 CG)
inline

Definition at line 188 of file FGMassBalance.h.

188{vbaseXYZcg = vXYZcg = CG;}

◆ SetEmptyWeight()

void SetEmptyWeight ( double  EW)
inline

Definition at line 187 of file FGMassBalance.h.

187{ EmptyWeight = EW;}

◆ StructuralToBody()

FGColumnVector3 StructuralToBody ( const FGColumnVector3 r) const

Conversion from the structural frame to the body frame.

Converts the location given in the structural frame coordinate system to the body frame. The units of the structural frame are assumed to be in inches. The unit of the result is in ft.

Parameters
rvector coordinate in the structural reference frame (X positive aft, measurements in inches).
Returns
vector coordinate in the body frame, in feet.

Definition at line 363 of file FGMassBalance.cpp.

364{
365 // Under the assumption that in the structural frame the:
366 //
367 // - X-axis is directed afterwards,
368 // - Y-axis is directed towards the right,
369 // - Z-axis is directed upwards,
370 //
371 // (as documented in http://jsbsim.sourceforge.net/JSBSimCoordinates.pdf)
372 // we have to subtract first the center of gravity of the plane which
373 // is also defined in the structural frame:
374 //
375 // FGColumnVector3 cgOff = r - vXYZcg;
376 //
377 // Next, we do a change of units:
378 //
379 // cgOff *= inchtoft;
380 //
381 // And then a 180 degree rotation is done about the Y axis so that the:
382 //
383 // - X-axis is directed forward,
384 // - Y-axis is directed towards the right,
385 // - Z-axis is directed downward.
386 //
387 // This is needed because the structural and body frames are 180 degrees apart.
388
389 return FGColumnVector3(inchtoft*(vXYZcg(1)-r(1)),
390 inchtoft*(r(2)-vXYZcg(2)),
391 inchtoft*(vXYZcg(3)-r(3)));
392}

The documentation for this class was generated from the following files: