]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGMassBalance.h
Frederic Bouvier:
[flightgear.git] / src / FDM / JSBSim / FGMassBalance.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGMassBalance.h
4  Author:       Jon S. Berndt
5  Date started: 09/12/2000
6
7  ------------- Copyright (C) 2000  Jon S. Berndt (jsb@hal-pc.org) --------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  details.
18
19  You should have received a copy of the GNU General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 09/12/2000  JSB  Created
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGMASSBALANCE_H
35 #define FGMASSBALANCE_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include "FGModel.h"
42 #include "FGColumnVector3.h"
43 #include "FGMatrix33.h"
44 #include <vector>
45
46 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 DEFINITIONS
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49
50 #define ID_MASSBALANCE "$Id$"
51
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 FORWARD DECLARATIONSS
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55
56 namespace JSBSim {
57
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 CLASS DOCUMENTATION
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61
62 /** Models weight and balance information.
63   */
64
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 CLASS DECLARATION
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68
69 class FGMassBalance : public FGModel
70 {
71
72 public:
73   FGMassBalance(FGFDMExec*);
74   ~FGMassBalance();
75
76   bool Run(void);
77
78   inline double GetMass(void) const {return Mass;}
79   inline double GetWeight(void) const {return Weight;}
80   inline FGColumnVector3& GetXYZcg(void) {return vXYZcg;}
81   inline double GetXYZcg(int axis) const  {return vXYZcg(axis);}
82
83   /** Computes the inertia contribution of a pointmass.
84       Computes and returns the inertia matrix of a pointmass of mass
85       slugs at the given vector r in the structural frame. The units
86       should be for the mass in slug and the vector in the structural
87       frame as usual in inches.
88       @param slugs the mass of this single pointmass given in slugs
89       @param r the location of this single pointmass in the structural frame
90    */
91   FGMatrix33 GetPointmassInertia(double slugs, const FGColumnVector3& r) const
92   {
93     FGColumnVector3 v = StructuralToBody( r );
94     FGColumnVector3 sv = slugs*v;
95     double xx = sv(1)*v(1);
96     double yy = sv(2)*v(2);
97     double zz = sv(3)*v(3);
98     double xy = -sv(1)*v(2);
99     double xz = -sv(1)*v(3);
100     double yz = -sv(2)*v(3);
101     return FGMatrix33( yy+zz, xy, xz,
102                        xy, xx+zz, yz,
103                        xz, yz, xx+yy );
104   }
105
106   /** Conversion from the structural frame to the body frame.
107       Converts the location given in the structural frame
108       coordinate system to the body frame. The units of the structural
109       frame are assumed to be in inches. The unit of the result is in
110       ft.
111       @param r vector coordinate in the structural reference frame (X positive
112                aft, measurements in inches).
113       @return vector coordinate in the body frame, in feet.
114    */
115   FGColumnVector3 StructuralToBody(const FGColumnVector3& r) const;
116
117   inline void SetEmptyWeight(double EW) { EmptyWeight = EW;}
118   inline void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
119
120   void AddPointMass(double weight, double X, double Y, double Z);
121   double GetPointMassWeight(void);
122   FGColumnVector3& GetPointMassMoment(void);
123   FGMatrix33& GetJ(void) {return mJ;}
124   FGMatrix33& GetJinv(void) {return mJinv;}
125   void SetAircraftBaseInertias(FGMatrix33 BaseJ) {baseJ = BaseJ;}
126
127   void bind(void);
128   void unbind(void);
129
130 private:
131   double Weight;
132   double EmptyWeight;
133   double Mass;
134   FGMatrix33 mJ;
135   FGMatrix33 mJinv;
136   FGMatrix33 pmJ;
137   FGMatrix33 baseJ;
138   FGColumnVector3 vXYZcg;
139   FGColumnVector3 vXYZtank;
140   FGColumnVector3 vbaseXYZcg;
141   FGColumnVector3 vPMxyz;
142   vector <FGColumnVector3> PointMassLoc;
143   vector <double> PointMassWeight;
144   FGColumnVector3 PointMassCG;
145   FGMatrix33& CalculatePMInertias(void);
146
147   void Debug(int from);
148 };
149 }
150 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 #endif