JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGMassBalance Class Reference

Models weight, balance and moment of inertia information. More...

#include <FGMassBalance.h>

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

Classes

struct  Inputs
 

Public Member Functions

 FGMassBalance (FGFDMExec *)
 
void AddPointMass (Element *el)
 
const FGColumnVector3GetDeltaXYZcg (void) const
 
double GetDeltaXYZcg (int axis) const
 
double GetEmptyWeight (void) const
 
const FGMatrix33GetJ (void) const
 
const FGMatrix33GetJinv (void) const
 
double GetMass (void) const
 
void GetMassPropertiesReport (int i)
 
FGMatrix33 GetPointmassInertia (double mass_sl, const FGColumnVector3 &r) const
 Computes the inertia contribution of a pointmass. More...
 
const FGColumnVector3GetPointMassMoment (void)
 
double GetTotalPointMassWeight (void) const
 
double GetWeight (void) const
 
const FGColumnVector3GetXYZcg (void) const
 
double GetXYZcg (int axis) const
 
bool InitModel (void)
 
bool Load (Element *el)
 Loads this model. More...
 
bool Run (bool Holding)
 Runs the Mass Balance model; called by the Executive Can pass in a value indicating if the executive is directing the simulation to Hold. More...
 
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. More...
 
- Public Member Functions inherited from FGModel
 FGModel (FGFDMExec *)
 Constructor.
 
virtual ~FGModel ()
 Destructor.
 
virtual SGPath FindFullPathName (const SGPath &path) const
 
FGFDMExecGetExec (void)
 
unsigned int GetRate (void)
 Get the output rate for the model in frames.
 
void SetPropertyManager (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. More...
 
std::string GetFunctionValues (const std::string &delimeter) const
 Gets the function values. More...
 
FGFunctionGetPreFunction (const std::string &name)
 Get one of the "pre" function. More...
 
bool Load (Element *el, FGPropertyManager *PropertyManager, std::string prefix="")
 
void PostLoad (Element *el, FGPropertyManager *PropertyManager, std::string prefix="")
 
void PreLoad (Element *el, FGPropertyManager *PropertyManager, 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.
 
std::string GetVersion (void)
 Returns the version number of JSBSim. More...
 
void PutMessage (const Message &msg)
 Places a Message structure on the Message queue. More...
 
void PutMessage (const std::string &text)
 Creates a message with the given text and places it on the queue. More...
 
void PutMessage (const std::string &text, bool bVal)
 Creates a message with the given text and boolean value and places it on the queue. More...
 
void PutMessage (const std::string &text, int iVal)
 Creates a message with the given text and integer value and places it on the queue. More...
 
void PutMessage (const std::string &text, double dVal)
 Creates a message with the given text and double value and places it on the queue. More...
 
int SomeMessages (void)
 Reads the message on the queue (but does not delete it). More...
 
void ProcessMessage (void)
 Reads the message on the queue and removes it from the queue. More...
 
MessageProcessNextMessage (void)
 Reads the next message on the queue and removes it from the queue. More...
 

Public Attributes

struct JSBSim::FGMassBalance::Inputs in
 
- Public Attributes inherited from FGModel
std::string Name
 

Additional Inherited Members

- Public Types inherited from FGJSBBase
enum  { eL = 1, eM, eN }
 Moments L, M, N.
 
enum  { eP = 1, eQ, eR }
 Rates P, Q, R.
 
enum  { eU = 1, eV, eW }
 Velocities U, V, W.
 
enum  { eX = 1, eY, eZ }
 Positions X, Y, Z.
 
enum  { ePhi = 1, eTht, ePsi }
 Euler angles Phi, Theta, Psi.
 
enum  { eDrag = 1, eSide, eLift }
 Stability axis forces, Drag, Side force, Lift.
 
enum  { eRoll = 1, ePitch, eYaw }
 Local frame orientation Roll, Pitch, Yaw.
 
enum  { eNorth = 1, eEast, eDown }
 Local frame position North, East, Down.
 
enum  { eLat = 1, eLong, eRad }
 Locations Radius, Latitude, Longitude.
 
enum  {
  inNone = 0, inDegrees, inRadians, inMeters,
  inFeet
}
 Conversion specifiers.
 
- Static Public Member Functions inherited from FGJSBBase
static double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit. More...
 
static double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin. More...
 
static double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine. More...
 
static double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
static bool EqualToRoundoff (double a, double b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (float a, float b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (float a, double b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (double a, float b)
 Finite precision comparison. More...
 
static double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius. More...
 
static double FeetToMeters (double measure)
 Converts from feet to meters. More...
 
static double GaussianRandomNumber (void)
 
static double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius. More...
 
static double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit. More...
 
static double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine. More...
 
static double MachFromVcalibrated (double vcas, double p, double psl, double rhosl)
 Calculate the Mach number from the calibrated airspeed. More...
 
static double PitotTotalPressure (double mach, double p)
 Compute the total pressure in front of the Pitot tube. More...
 
static double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius. More...
 
static double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin. More...
 
static double sign (double num)
 
static double VcalibratedFromMach (double mach, double p, double psl, double rhosl)
 Calculate the calibrated airspeed from the Mach number. More...
 
- Static Public Attributes inherited from FGJSBBase
static short debug_lvl = 1
 
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
 
- Protected Member Functions inherited from FGJSBBase
void Debug (int)
 
- 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
 
FGPropertyManagerPropertyManager
 
unsigned int rate
 
- Protected Attributes inherited from FGModelFunctions
FGPropertyReader LocalProperties
 
std::vector< FGFunction * > PostFunctions
 
std::vector< FGFunction * > PreFunctions
 
- Static Protected Attributes inherited from FGJSBBase
static const double degtorad = 0.017453292519943295769236907684886
 
static const double fpstokts = 1.0/ktstofps
 
static const double fttom = 0.3048
 
static int gaussian_random_number_phase = 0
 
static const double hptoftlbssec = 550.0
 
static const double in3tom3 = 1.638706E-5
 
static const double inchtoft = 0.08333333
 
static const double inhgtopa = 3386.38
 
static const std::string JSBSim_version = "1.0 " __DATE__ " " __TIME__
 
static const double kgtolb = 2.20462
 
static const double kgtoslug = 0.06852168
 
static const double ktstofps = 1.68781
 
static const double lbtoslug = 1.0/slugtolb
 
static Message localMsg
 
static const double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static double Mair = 28.9645
 
static unsigned int messageId = 0
 
static std::queue< MessageMessages
 
static const std::string needed_cfg_version = "2.0"
 
static const double psftoinhg = 0.014138
 
static const double psftopa = 47.88
 
static const double radtodeg = 57.295779513082320876798154814105
 
static double Reng = 1716.56
 
static double Rstar = 1545.348
 
static const double SHRatio = 1.40
 
static const double slugtolb = 32.174049
 

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.

Configuration File Format:

<mass_balance>
<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>

Definition at line 107 of file FGMassBalance.h.

Member Function Documentation

◆ 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 141 of file FGMassBalance.h.

142  {
143  FGColumnVector3 v = StructuralToBody( r );
144  FGColumnVector3 sv = mass_sl*v;
145  double xx = sv(1)*v(1);
146  double yy = sv(2)*v(2);
147  double zz = sv(3)*v(3);
148  double xy = -sv(1)*v(2);
149  double xz = -sv(1)*v(3);
150  double yz = -sv(2)*v(3);
151  return FGMatrix33( yy+zz, xy, xz,
152  xy, xx+zz, yz,
153  xz, yz, xx+yy );
154  }
FGColumnVector3 StructuralToBody(const FGColumnVector3 &r) const
Conversion from the structural frame to the body frame.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Load()

bool Load ( Element el)
virtual

Loads this model.

Parameters
ela pointer to the element
Returns
true if model is successfully loaded

Reimplemented from FGModel.

Definition at line 130 of file FGMassBalance.cpp.

131 {
132  string element_name = "";
133 
134  Name = "Mass Properties Model: " + document->GetAttributeValue("name");
135 
136  // Perform base class Pre-Load
137  if (!FGModel::Load(document))
138  return false;
139 
140  SetAircraftBaseInertias(ReadInertiaMatrix(document));
141  if (document->FindElement("emptywt")) {
142  EmptyWeight = document->FindElementValueAsNumberConvertTo("emptywt", "LBS");
143  }
144 
145  Element *element = document->FindElement("location");
146  while (element) {
147  element_name = element->GetAttributeValue("name");
148  if (element_name == "CG") vbaseXYZcg = element->FindElementTripletConvertTo("IN");
149  element = document->FindNextElement("location");
150  }
151 
152 // Find all POINTMASS elements that descend from this METRICS branch of the
153 // config file.
154 
155  element = document->FindElement("pointmass");
156  while (element) {
157  AddPointMass(element);
158  element = document->FindNextElement("pointmass");
159  }
160 
161  double ChildFDMWeight = 0.0;
162  for (int fdm=0; fdm<FDMExec->GetFDMCount(); fdm++) {
163  if (FDMExec->GetChildFDM(fdm)->mated) ChildFDMWeight += FDMExec->GetChildFDM(fdm)->exec->GetMassBalance()->GetWeight();
164  }
165 
166  Weight = EmptyWeight + in.TanksWeight + GetTotalPointMassWeight()
167  + in.GasMass*slugtolb + ChildFDMWeight;
168 
169  Mass = lbtoslug*Weight;
170 
171  PostLoad(document, PropertyManager);
172 
173  Debug(2);
174  return true;
175 }
childData * GetChildFDM(int i) const
Gets a particular child FDM.
Definition: FGFDMExec.h:422
int GetFDMCount(void) const
Gets the number of child FDMs.
Definition: FGFDMExec.h:420
virtual bool Load(Element *el)
Loads this model.
Definition: FGModel.cpp:113
+ Here is the call graph for this function:

◆ Run()

bool Run ( bool  Holding)
virtual

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 179 of file FGMassBalance.cpp.

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

◆ 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 357 of file FGMassBalance.cpp.

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

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