]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGMassBalance.h
Sync. with JSBSim CVS
[flightgear.git] / src / FDM / JSBSim / models / 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 Lesser 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 Lesser General Public License for more
17  details.
18
19  You should have received a copy of the GNU Lesser 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 Lesser 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 <math/FGColumnVector3.h>
43 #include <math/FGMatrix33.h>
44 #include <input_output/FGXMLElement.h>
45 #include <vector>
46
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 DEFINITIONS
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50
51 #define ID_MASSBALANCE "$Id$"
52
53 #if defined(WIN32) && !defined(__CYGWIN__)
54 #define snprintf _snprintf
55 #endif
56
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 FORWARD DECLARATIONSS
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60
61 namespace JSBSim {
62
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 CLASS DOCUMENTATION
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66
67 /** Models weight, balance and moment of inertia information.  Maintains a vector
68     of point masses. Sums the contribution of all, and provides this to FGPropagate.
69     Loads the \<mass_balance> section of the aircraft configuration file.
70
71     <h3>Configuration File Format:</h3>
72 @code
73     <mass_balance>
74         <ixx unit="{SLUG*FT2 | KG*M2}"> {number} </ixx>
75         <iyy unit="{SLUG*FT2 | KG*M2}"> {number} </iyy>
76         <izz unit="{SLUG*FT2 | KG*M2}"> {number} </izz>
77         <ixy unit="{SLUG*FT2 | KG*M2}"> {number} </ixy>
78         <ixz unit="{SLUG*FT2 | KG*M2}"> {number} </ixz>
79         <iyz unit="{SLUG*FT2 | KG*M2}"> {number} </iyz>
80         <emptywt unit="{LBS | KG"> {number} </emptywt>
81         <location name="CG" unit="{IN | M}">
82             <x> {number} </x>
83             <y> {number} </y>
84             <z> {number} </z>
85         </location>
86         <pointmass name="{string}">
87             <weight unit="{LBS | KG}"> {number} </weight>
88             <location name="POINTMASS" unit="{IN | M}">
89                 <x> {number} </x>
90                 <y> {number} </y>
91                 <z> {number} </z>
92             </location>
93         </pointmass>
94         ... other point masses ...
95     </mass_balance>
96 @endcode
97   */
98
99 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 CLASS DECLARATION
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
102
103 class FGMassBalance : public FGModel
104 {
105
106 public:
107   FGMassBalance(FGFDMExec*);
108   ~FGMassBalance();
109
110   bool Load(Element* el);
111   bool InitModel(void);
112   bool Run(void);
113
114   inline double GetMass(void) const {return Mass;}
115   inline double GetWeight(void) const {return Weight;}
116   inline FGColumnVector3& GetXYZcg(void) {return vXYZcg;}
117   inline double GetXYZcg(int axis) const  {return vXYZcg(axis);}
118
119   /** Computes the inertia contribution of a pointmass.
120       Computes and returns the inertia matrix of a pointmass of mass
121       slugs at the given vector r in the structural frame. The units
122       should be for the mass in slug and the vector in the structural
123       frame as usual in inches.
124       @param slugs the mass of this single pointmass given in slugs
125       @param r the location of this single pointmass in the structural frame
126    */
127   FGMatrix33 GetPointmassInertia(double slugs, const FGColumnVector3& r) const
128   {
129     FGColumnVector3 v = StructuralToBody( r );
130     FGColumnVector3 sv = slugs*v;
131     double xx = sv(1)*v(1);
132     double yy = sv(2)*v(2);
133     double zz = sv(3)*v(3);
134     double xy = -sv(1)*v(2);
135     double xz = -sv(1)*v(3);
136     double yz = -sv(2)*v(3);
137     return FGMatrix33( yy+zz, xy, xz,
138                        xy, xx+zz, yz,
139                        xz, yz, xx+yy );
140   }
141
142   /** Conversion from the structural frame to the body frame.
143       Converts the location given in the structural frame
144       coordinate system to the body frame. The units of the structural
145       frame are assumed to be in inches. The unit of the result is in
146       ft.
147       @param r vector coordinate in the structural reference frame (X positive
148                aft, measurements in inches).
149       @return vector coordinate in the body frame, in feet.
150    */
151   FGColumnVector3 StructuralToBody(const FGColumnVector3& r) const;
152
153   inline void SetEmptyWeight(double EW) { EmptyWeight = EW;}
154   inline void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
155
156   void AddPointMass(Element* el);
157   double GetTotalPointMassWeight(void);
158
159   FGColumnVector3& GetPointMassMoment(void);
160   FGMatrix33& GetJ(void) {return mJ;}
161   FGMatrix33& GetJinv(void) {return mJinv;}
162   void SetAircraftBaseInertias(FGMatrix33 BaseJ) {baseJ = BaseJ;}
163   
164 private:
165   double Weight;
166   double EmptyWeight;
167   double Mass;
168   FGMatrix33 mJ;
169   FGMatrix33 mJinv;
170   FGMatrix33 pmJ;
171   FGMatrix33 baseJ;
172   FGColumnVector3 vXYZcg;
173   FGColumnVector3 vXYZtank;
174   FGColumnVector3 vbaseXYZcg;
175   FGColumnVector3 vPMxyz;
176   FGColumnVector3 PointMassCG;
177   FGMatrix33& CalculatePMInertias(void);
178
179   struct PointMass {
180     char tmp[80];
181     PointMass(double w, FGColumnVector3& vXYZ) {
182       Weight = w;
183       Location = vXYZ;
184     }
185     FGColumnVector3 Location;
186     double Weight;
187     double GetPointMassLocation(int axis) const {return Location(axis);}
188     void SetPointMassLocation(int axis, double value) {Location(axis) = value;}
189     void SetPointMassWeight(double wt) {Weight = wt;}
190     double GetPointMassWeight(void) const {return Weight;}
191
192     void bind(FGPropertyManager* PropertyManager, int num) {
193       snprintf(tmp, 80, "inertia/pointmass-weight-lbs[%u]", num);
194       PropertyManager->Tie( tmp, this, &PointMass::GetPointMassWeight,
195                                        &PointMass::SetPointMassWeight);
196
197       snprintf(tmp, 80, "inertia/pointmass-location-X-inches[%u]", num);
198       PropertyManager->Tie( tmp, this, eX, &PointMass::GetPointMassLocation,
199                                            &PointMass::SetPointMassLocation);
200       snprintf(tmp, 80, "inertia/pointmass-location-Y-inches[%u]", num);
201       PropertyManager->Tie( tmp, this, eY, &PointMass::GetPointMassLocation,
202                                            &PointMass::SetPointMassLocation);
203       snprintf(tmp, 80, "inertia/pointmass-location-Z-inches[%u]", num);
204       PropertyManager->Tie( tmp, this, eZ, &PointMass::GetPointMassLocation,
205                                            &PointMass::SetPointMassLocation);
206     }
207   };
208
209   vector <struct PointMass*> PointMasses;
210
211   void bind(void);
212   void Debug(int from);
213 };
214 }
215 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216 #endif