]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/FGMassBalance.h
sync with JSB JSBSim CVS
[flightgear.git] / src / FDM / JSBSim / models / FGMassBalance.h
index 13f1aa9b370a003854e5efb120a29475c88e3010..9b11290b1da451607bcaa2a7b9e89774344eb8e4 100644 (file)
@@ -4,7 +4,7 @@
  Author:       Jon S. Berndt
  Date started: 09/12/2000
 
- ------------- Copyright (C) 2000  Jon S. Berndt (jsb@hal-pc.org) --------------
+ ------------- Copyright (C) 2000  Jon S. Berndt (jon@jsbsim.org) --------------
 
  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU Lesser General Public License as published by the Free Software
@@ -39,28 +39,68 @@ INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGModel.h"
-#include <math/FGColumnVector3.h>
-#include <math/FGMatrix33.h>
-#include <input_output/FGXMLElement.h>
+#include "math/FGColumnVector3.h"
+#include "math/FGMatrix33.h"
+#include "input_output/FGXMLElement.h"
 #include <vector>
+#include <string>
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 DEFINITIONS
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#define ID_MASSBALANCE "$Id$"
+#define ID_MASSBALANCE "$Id: FGMassBalance.h,v 1.27 2011/11/09 21:58:26 bcoconni Exp $"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 FORWARD DECLARATIONSS
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
+using std::string;
+
 namespace JSBSim {
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS DOCUMENTATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-/** Models weight and balance information.
+/** 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.
+
+    <h3>Configuration File Format:</h3>
+@code
+    <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>
+@endcode
   */
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -75,26 +115,36 @@ public:
   ~FGMassBalance();
 
   bool Load(Element* el);
-
-  bool Run(void);
-
-  inline double GetMass(void) const {return Mass;}
-  inline double GetWeight(void) const {return Weight;}
-  inline FGColumnVector3& GetXYZcg(void) {return vXYZcg;}
-  inline double GetXYZcg(int axis) const  {return vXYZcg(axis);}
+  bool InitModel(void);
+  /** Runs the Mass Balance model; called by the Executive
+      Can pass in a value indicating if the executive is directing the simulation to Hold.
+      @param Holding if 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.
+      @return false if no error */
+  bool Run(bool Holding);
+
+  double GetMass(void) const {return Mass;}
+  double GetWeight(void) const {return Weight;}
+  double GetEmptyWeight(void) const {return EmptyWeight;}
+  const FGColumnVector3& GetXYZcg(void) const {return vXYZcg;}
+  double GetXYZcg(int axis) const  {return vXYZcg(axis);}
+  const FGColumnVector3& GetDeltaXYZcg(void) const {return vDeltaXYZcg;}
+  double GetDeltaXYZcg(int axis) const  {return vDeltaXYZcg(axis);}
 
   /** 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.
-      @param slugs the mass of this single pointmass given in slugs
+      @param mass_sl the mass of this single pointmass given in slugs
       @param r the location of this single pointmass in the structural frame
    */
-  FGMatrix33 GetPointmassInertia(double slugs, const FGColumnVector3& r) const
+  FGMatrix33 GetPointmassInertia(double mass_sl, const FGColumnVector3& r) const
   {
     FGColumnVector3 v = StructuralToBody( r );
-    FGColumnVector3 sv = slugs*v;
+    FGColumnVector3 sv = mass_sl*v;
     double xx = sv(1)*v(1);
     double yy = sv(2)*v(2);
     double zz = sv(3)*v(3);
@@ -117,18 +167,26 @@ public:
    */
   FGColumnVector3 StructuralToBody(const FGColumnVector3& r) const;
 
-  inline void SetEmptyWeight(double EW) { EmptyWeight = EW;}
-  inline void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
+  void SetEmptyWeight(double EW) { EmptyWeight = EW;}
+  void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
 
   void AddPointMass(Element* el);
-  double GetPointMassWeight(void);
-  FGColumnVector3& GetPointMassMoment(void);
-  FGMatrix33& GetJ(void) {return mJ;}
-  FGMatrix33& GetJinv(void) {return mJinv;}
-  void SetAircraftBaseInertias(FGMatrix33 BaseJ) {baseJ = BaseJ;}
-
-  void bind(void);
-  void unbind(void);
+  double GetTotalPointMassWeight(void) const;
+
+  const FGColumnVector3& GetPointMassMoment(void);
+  const FGMatrix33& GetJ(void) const {return mJ;}
+  const FGMatrix33& GetJinv(void) const {return mJinv;}
+  void SetAircraftBaseInertias(const FGMatrix33& BaseJ) {baseJ = BaseJ;}
+  void GetMassPropertiesReport(void) const;
+  
+  struct Inputs {
+    double GasMass;
+    double TanksWeight;
+    FGColumnVector3 GasMoment;
+    FGMatrix33 GasInertia;
+    FGColumnVector3 TanksMoment;
+    FGMatrix33 TankInertia;
+  } in;
 
 private:
   double Weight;
@@ -139,23 +197,82 @@ private:
   FGMatrix33 pmJ;
   FGMatrix33 baseJ;
   FGColumnVector3 vXYZcg;
+  FGColumnVector3 vLastXYZcg;
+  FGColumnVector3 vDeltaXYZcg;
+  FGColumnVector3 vDeltaXYZcgBody;
   FGColumnVector3 vXYZtank;
   FGColumnVector3 vbaseXYZcg;
   FGColumnVector3 vPMxyz;
   FGColumnVector3 PointMassCG;
-  FGMatrix33& CalculatePMInertias(void);
+  const FGMatrix33& CalculatePMInertias(void);
 
+
+  /** The PointMass structure encapsulates a point mass object, moments of inertia
+     mass, location, etc. */
   struct PointMass {
     PointMass(double w, FGColumnVector3& vXYZ) {
       Weight = w;
       Location = vXYZ;
+      mPMInertia.InitMatrix();
+      Radius = 0.0;
+      Length = 0.0;
+    }
+
+    void CalculateShapeInertia(void) {
+      switch(eShapeType) {
+        case esTube:
+          mPMInertia(1,1) = (Weight/(slugtolb))*Radius*Radius; // mr^2
+          mPMInertia(2,2) = (Weight/(slugtolb*12))*(6*Radius*Radius + Length*Length);
+          mPMInertia(3,3) = mPMInertia(2,2);
+          break;
+        case esCylinder:
+          mPMInertia(1,1) = (Weight/(slugtolb*2))*Radius*Radius; // 0.5*mr^2
+          mPMInertia(2,2) = (Weight/(slugtolb*12))*(3*Radius*Radius + Length*Length);
+          mPMInertia(3,3) = mPMInertia(2,2);
+          break;
+        case esSphere:
+          mPMInertia(1,1) = (Weight/(slugtolb*3))*Radius*Radius*2; // (2mr^2)/3
+          mPMInertia(2,2) = mPMInertia(1,1);
+          mPMInertia(3,3) = mPMInertia(1,1);
+        case esBall:
+          mPMInertia(1,1) = (Weight/(slugtolb*5))*Radius*Radius*2; // (2mr^2)/5
+          mPMInertia(2,2) = mPMInertia(1,1);
+          mPMInertia(3,3) = mPMInertia(1,1);
+          break;
+        default:
+          break;
+      }
     }
+
+    enum esShape {esUnspecified, esTube, esCylinder, esSphere, esBall} eShapeType;
     FGColumnVector3 Location;
-    double Weight;
+    double Weight; /// Weight in pounds.
+    double Radius; /// Radius in feet.
+    double Length; /// Length in feet.
+    string Name;
+    FGMatrix33 mPMInertia;
+
+    double GetPointMassLocation(int axis) const {return Location(axis);}
+    double GetPointMassWeight(void) const {return Weight;}
+    esShape GetShapeType(void) {return eShapeType;}
+    const FGColumnVector3& GetLocation(void) {return Location;}
+    const FGMatrix33& GetPointMassInertia(void) {return mPMInertia;}
+    const string& GetName(void) {return Name;}
+
+    void SetPointMassLocation(int axis, double value) {Location(axis) = value;}
+    void SetPointMassWeight(double wt) {Weight = wt;}
+    void SetPointMassShapeType(esShape st) {eShapeType = st;}
+    void SetRadius(double r) {Radius = r;}
+    void SetLength(double l) {Length = l;}
+    void SetName(string name) {Name = name;}
+    double GetPointMassMoI(int r, int c) {return mPMInertia(r,c);}
+
+    void bind(FGPropertyManager* PropertyManager, int num);
   };
 
-  vector <struct PointMass> PointMasses;
+  std::vector <struct PointMass*> PointMasses;
 
+  void bind(void);
   void Debug(int from);
 };
 }