1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Header: FGMassBalance.h
5 Date started: 09/12/2000
7 ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) --------------
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
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
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.
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.
27 --------------------------------------------------------------------------------
28 09/12/2000 JSB Created
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34 #ifndef FGMASSBALANCE_H
35 #define FGMASSBALANCE_H
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 #include "math/FGColumnVector3.h"
43 #include "math/FGMatrix33.h"
44 #include "input_output/FGXMLElement.h"
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52 #define ID_MASSBALANCE "$Id: FGMassBalance.h,v 1.20 2010/02/04 13:09:26 jberndt Exp $"
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66 /** Models weight, balance and moment of inertia information. Maintains a vector
67 of point masses. Sums the contribution of all, and provides this to FGPropagate.
68 Loads the \<mass_balance> section of the aircraft configuration file.
70 <h3>Configuration File Format:</h3>
73 <ixx unit="{SLUG*FT2 | KG*M2}"> {number} </ixx>
74 <iyy unit="{SLUG*FT2 | KG*M2}"> {number} </iyy>
75 <izz unit="{SLUG*FT2 | KG*M2}"> {number} </izz>
76 <ixy unit="{SLUG*FT2 | KG*M2}"> {number} </ixy>
77 <ixz unit="{SLUG*FT2 | KG*M2}"> {number} </ixz>
78 <iyz unit="{SLUG*FT2 | KG*M2}"> {number} </iyz>
79 <emptywt unit="{LBS | KG"> {number} </emptywt>
80 <location name="CG" unit="{IN | M}">
85 <pointmass name="{string}">
86 <weight unit="{LBS | KG}"> {number} </weight>
87 <location name="POINTMASS" unit="{IN | M}">
93 ... other point masses ...
98 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
102 class FGMassBalance : public FGModel
106 FGMassBalance(FGFDMExec*);
109 bool Load(Element* el);
110 bool InitModel(void);
113 double GetMass(void) const {return Mass;}
114 double GetWeight(void) const {return Weight;}
115 double GetEmptyWeight(void) const {return EmptyWeight;}
116 const FGColumnVector3& GetXYZcg(void) const {return vXYZcg;}
117 double GetXYZcg(int axis) const {return vXYZcg(axis);}
118 const FGColumnVector3& GetDeltaXYZcg(void) const {return vDeltaXYZcg;}
119 double GetDeltaXYZcg(int axis) const {return vDeltaXYZcg(axis);}
121 /** Computes the inertia contribution of a pointmass.
122 Computes and returns the inertia matrix of a pointmass of mass
123 slugs at the given vector r in the structural frame. The units
124 should be for the mass in slug and the vector in the structural
125 frame as usual in inches.
126 @param slugs the mass of this single pointmass given in slugs
127 @param r the location of this single pointmass in the structural frame
129 FGMatrix33 GetPointmassInertia(double slugs, const FGColumnVector3& r) const
131 FGColumnVector3 v = StructuralToBody( r );
132 FGColumnVector3 sv = slugs*v;
133 double xx = sv(1)*v(1);
134 double yy = sv(2)*v(2);
135 double zz = sv(3)*v(3);
136 double xy = -sv(1)*v(2);
137 double xz = -sv(1)*v(3);
138 double yz = -sv(2)*v(3);
139 return FGMatrix33( yy+zz, xy, xz,
144 /** Conversion from the structural frame to the body frame.
145 Converts the location given in the structural frame
146 coordinate system to the body frame. The units of the structural
147 frame are assumed to be in inches. The unit of the result is in
149 @param r vector coordinate in the structural reference frame (X positive
150 aft, measurements in inches).
151 @return vector coordinate in the body frame, in feet.
153 FGColumnVector3 StructuralToBody(const FGColumnVector3& r) const;
155 inline void SetEmptyWeight(double EW) { EmptyWeight = EW;}
156 inline void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
158 void AddPointMass(Element* el);
159 double GetTotalPointMassWeight(void);
161 FGColumnVector3& GetPointMassMoment(void);
162 FGMatrix33& GetJ(void) {return mJ;}
163 FGMatrix33& GetJinv(void) {return mJinv;}
164 void SetAircraftBaseInertias(FGMatrix33 BaseJ) {baseJ = BaseJ;}
165 void GetMassPropertiesReport(void) const;
175 FGColumnVector3 vXYZcg;
176 FGColumnVector3 vLastXYZcg;
177 FGColumnVector3 vDeltaXYZcg;
178 FGColumnVector3 vDeltaXYZcgBody;
179 FGColumnVector3 vXYZtank;
180 FGColumnVector3 vbaseXYZcg;
181 FGColumnVector3 vPMxyz;
182 FGColumnVector3 PointMassCG;
183 FGMatrix33& CalculatePMInertias(void);
186 /** The PointMass structure encapsulates a point mass object, moments of inertia
187 mass, location, etc. */
189 PointMass(double w, FGColumnVector3& vXYZ) {
192 mPMInertia.InitMatrix();
197 void CalculateShapeInertia(void) {
200 mPMInertia(1,1) = (Weight/(32.16))*Radius*Radius; // mr^2
201 mPMInertia(2,2) = (Weight/(32.16*12))*(6*Radius*Radius + Length*Length);
202 mPMInertia(3,3) = mPMInertia(2,2);
205 mPMInertia(1,1) = (Weight/(32.16*2))*Radius*Radius; // 0.5*mr^2
206 mPMInertia(2,2) = (Weight/(32.16*12))*(3*Radius*Radius + Length*Length);
207 mPMInertia(3,3) = mPMInertia(2,2);
214 enum esShape {esUnspecified, esTube, esCylinder, esSphere} eShapeType;
215 FGColumnVector3 Location;
216 double Weight; /// Weight in pounds.
217 double Radius; /// Radius in feet.
218 double Length; /// Length in feet.
220 FGMatrix33 mPMInertia;
222 double GetPointMassLocation(int axis) const {return Location(axis);}
223 double GetPointMassWeight(void) const {return Weight;}
224 esShape GetShapeType(void) {return eShapeType;}
225 FGColumnVector3 GetLocation(void) {return Location;}
226 FGMatrix33 GetPointMassInertia(void) {return mPMInertia;}
227 string GetName(void) {return Name;}
229 void SetPointMassLocation(int axis, double value) {Location(axis) = value;}
230 void SetPointMassWeight(double wt) {Weight = wt;}
231 void SetPointMassShapeType(esShape st) {eShapeType = st;}
232 void SetRadius(double r) {Radius = r;}
233 void SetLength(double l) {Length = l;}
234 void SetName(string name) {Name = name;}
235 double GetPointMassMoI(int r, int c) {return mPMInertia(r,c);}
237 void bind(FGPropertyManager* PropertyManager, int num);
240 std::vector <struct PointMass*> PointMasses;
243 void Debug(int from);
246 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%