Branch data Line data Source code
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 (jon@jsbsim.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 : : #include <string>
47 : :
48 : : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 : : DEFINITIONS
50 : : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 : :
52 : : #define ID_MASSBALANCE "$Id: FGMassBalance.h,v 1.21 2010/08/12 04:07:11 jberndt Exp $"
53 : :
54 : : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 : : FORWARD DECLARATIONSS
56 : : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 : :
58 : : using std::string;
59 : :
60 : : namespace JSBSim {
61 : :
62 : : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 : : CLASS DOCUMENTATION
64 : : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 : :
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. There
69 : : can be any number of <pointmasses>. Each can also have a shape which - if
70 : : present - causes an associated moment of inertia to be calculated based on
71 : : the shape. Note that a cylinder is solid, a tube is hollow, a ball is solid
72 : : and a sphere is hollow.
73 : :
74 : : <h3>Configuration File Format:</h3>
75 : : @code
76 : : <mass_balance>
77 : : <ixx unit="{SLUG*FT2 | KG*M2}"> {number} </ixx>
78 : : <iyy unit="{SLUG*FT2 | KG*M2}"> {number} </iyy>
79 : : <izz unit="{SLUG*FT2 | KG*M2}"> {number} </izz>
80 : : <ixy unit="{SLUG*FT2 | KG*M2}"> {number} </ixy>
81 : : <ixz unit="{SLUG*FT2 | KG*M2}"> {number} </ixz>
82 : : <iyz unit="{SLUG*FT2 | KG*M2}"> {number} </iyz>
83 : : <emptywt unit="{LBS | KG"> {number} </emptywt>
84 : : <location name="CG" unit="{IN | FT | M}">
85 : : <x> {number} </x>
86 : : <y> {number} </y>
87 : : <z> {number} </z>
88 : : </location>
89 : : [<pointmass name="{string}">
90 : : <form shape="{tube | cylinder | sphere | ball}">
91 : : <radius unit="{IN | FT | M}"> {number} </radius>
92 : : <length unit="{IN | FT | M}"> {number} </length>
93 : : </form>
94 : : <weight unit="{LBS | KG}"> {number} </weight>
95 : : <location name="{string}" unit="{IN | FT | M}">
96 : : <x> {number} </x>
97 : : <y> {number} </y>
98 : : <z> {number} </z>
99 : : </location>
100 : : </pointmass>
101 : : ... other point masses ...]
102 : : </mass_balance>
103 : : @endcode
104 : : */
105 : :
106 : : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 : : CLASS DECLARATION
108 : : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
109 : :
110 : : class FGMassBalance : public FGModel
111 : : {
112 : :
113 : : public:
114 : : FGMassBalance(FGFDMExec*);
115 : : ~FGMassBalance();
116 : :
117 : : bool Load(Element* el);
118 : : bool InitModel(void);
119 : : bool Run(void);
120 : :
121 : 220030 : double GetMass(void) const {return Mass;}
122 : 55459 : double GetWeight(void) const {return Weight;}
123 : 1 : double GetEmptyWeight(void) const {return EmptyWeight;}
124 : 4909 : const FGColumnVector3& GetXYZcg(void) const {return vXYZcg;}
125 : 3 : double GetXYZcg(int axis) const {return vXYZcg(axis);}
126 : : const FGColumnVector3& GetDeltaXYZcg(void) const {return vDeltaXYZcg;}
127 : : double GetDeltaXYZcg(int axis) const {return vDeltaXYZcg(axis);}
128 : :
129 : : /** Computes the inertia contribution of a pointmass.
130 : : Computes and returns the inertia matrix of a pointmass of mass
131 : : slugs at the given vector r in the structural frame. The units
132 : : should be for the mass in slug and the vector in the structural
133 : : frame as usual in inches.
134 : : @param slugs the mass of this single pointmass given in slugs
135 : : @param r the location of this single pointmass in the structural frame
136 : : */
137 : 1080120 : FGMatrix33 GetPointmassInertia(double slugs, const FGColumnVector3& r) const
138 : : {
139 : 1404162 : FGColumnVector3 v = StructuralToBody( r );
140 : : FGColumnVector3 sv = slugs*v;
141 : 2808324 : double xx = sv(1)*v(1);
142 : 2808324 : double yy = sv(2)*v(2);
143 : 2808324 : double zz = sv(3)*v(3);
144 : 2808324 : double xy = -sv(1)*v(2);
145 : 2808324 : double xz = -sv(1)*v(3);
146 : 2808324 : double yz = -sv(2)*v(3);
147 : : return FGMatrix33( yy+zz, xy, xz,
148 : : xy, xx+zz, yz,
149 : 1404162 : xz, yz, xx+yy );
150 : : }
151 : :
152 : : /** Conversion from the structural frame to the body frame.
153 : : Converts the location given in the structural frame
154 : : coordinate system to the body frame. The units of the structural
155 : : frame are assumed to be in inches. The unit of the result is in
156 : : ft.
157 : : @param r vector coordinate in the structural reference frame (X positive
158 : : aft, measurements in inches).
159 : : @return vector coordinate in the body frame, in feet.
160 : : */
161 : : FGColumnVector3 StructuralToBody(const FGColumnVector3& r) const;
162 : :
163 : : inline void SetEmptyWeight(double EW) { EmptyWeight = EW;}
164 : : inline void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
165 : :
166 : : void AddPointMass(Element* el);
167 : : double GetTotalPointMassWeight(void);
168 : :
169 : : FGColumnVector3& GetPointMassMoment(void);
170 : 58915 : FGMatrix33& GetJ(void) {return mJ;}
171 : 108012 : FGMatrix33& GetJinv(void) {return mJinv;}
172 : 1 : void SetAircraftBaseInertias(FGMatrix33 BaseJ) {baseJ = BaseJ;}
173 : : void GetMassPropertiesReport(void) const;
174 : :
175 : : private:
176 : : double Weight;
177 : : double EmptyWeight;
178 : : double Mass;
179 : : FGMatrix33 mJ;
180 : : FGMatrix33 mJinv;
181 : : FGMatrix33 pmJ;
182 : : FGMatrix33 baseJ;
183 : : FGColumnVector3 vXYZcg;
184 : : FGColumnVector3 vLastXYZcg;
185 : : FGColumnVector3 vDeltaXYZcg;
186 : : FGColumnVector3 vDeltaXYZcgBody;
187 : : FGColumnVector3 vXYZtank;
188 : : FGColumnVector3 vbaseXYZcg;
189 : : FGColumnVector3 vPMxyz;
190 : : FGColumnVector3 PointMassCG;
191 : : FGMatrix33& CalculatePMInertias(void);
192 : :
193 : :
194 : : /** The PointMass structure encapsulates a point mass object, moments of inertia
195 : : mass, location, etc. */
196 : 19 : struct PointMass {
197 : 19 : PointMass(double w, FGColumnVector3& vXYZ) {
198 : 19 : Weight = w;
199 : 19 : Location = vXYZ;
200 : 19 : mPMInertia.InitMatrix();
201 : 19 : Radius = 0.0;
202 : 19 : Length = 0.0;
203 : 0 : }
204 : :
205 : 19 : void CalculateShapeInertia(void) {
206 [ + + - - : 19 : switch(eShapeType) {
- ]
207 : : case esTube:
208 : 12 : mPMInertia(1,1) = (Weight/(slugtolb))*Radius*Radius; // mr^2
209 : 12 : mPMInertia(2,2) = (Weight/(slugtolb*12))*(6*Radius*Radius + Length*Length);
210 : 18 : mPMInertia(3,3) = mPMInertia(2,2);
211 : 6 : break;
212 : : case esCylinder:
213 : 26 : mPMInertia(1,1) = (Weight/(slugtolb*2))*Radius*Radius; // 0.5*mr^2
214 : 26 : mPMInertia(2,2) = (Weight/(slugtolb*12))*(3*Radius*Radius + Length*Length);
215 : 39 : mPMInertia(3,3) = mPMInertia(2,2);
216 : 13 : break;
217 : : case esSphere:
218 : 0 : mPMInertia(1,1) = (Weight/(slugtolb*3))*Radius*Radius*2; // (2mr^2)/3
219 : 0 : mPMInertia(2,2) = mPMInertia(1,1);
220 : 0 : mPMInertia(3,3) = mPMInertia(1,1);
221 : : case esBall:
222 : 0 : mPMInertia(1,1) = (Weight/(slugtolb*5))*Radius*Radius*2; // (2mr^2)/5
223 : 0 : mPMInertia(2,2) = mPMInertia(1,1);
224 : 0 : mPMInertia(3,3) = mPMInertia(1,1);
225 : : break;
226 : : default:
227 : : break;
228 : : }
229 : 19 : }
230 : :
231 : : enum esShape {esUnspecified, esTube, esCylinder, esSphere, esBall} eShapeType;
232 : : FGColumnVector3 Location;
233 : : double Weight; /// Weight in pounds.
234 : : double Radius; /// Radius in feet.
235 : : double Length; /// Length in feet.
236 : : string Name;
237 : : FGMatrix33 mPMInertia;
238 : :
239 : 57 : double GetPointMassLocation(int axis) const {return Location(axis);}
240 : 22 : double GetPointMassWeight(void) const {return Weight;}
241 : : esShape GetShapeType(void) {return eShapeType;}
242 : 57 : FGColumnVector3 GetLocation(void) {return Location;}
243 : 1026114 : FGMatrix33 GetPointMassInertia(void) {return mPMInertia;}
244 : 19 : string GetName(void) {return Name;}
245 : :
246 : 0 : void SetPointMassLocation(int axis, double value) {Location(axis) = value;}
247 : 3 : void SetPointMassWeight(double wt) {Weight = wt;}
248 : 19 : void SetPointMassShapeType(esShape st) {eShapeType = st;}
249 : 19 : void SetRadius(double r) {Radius = r;}
250 : 19 : void SetLength(double l) {Length = l;}
251 : 19 : void SetName(string name) {Name = name;}
252 : 114 : double GetPointMassMoI(int r, int c) {return mPMInertia(r,c);}
253 : :
254 : : void bind(FGPropertyManager* PropertyManager, int num);
255 : : };
256 : :
257 : : std::vector <struct PointMass*> PointMasses;
258 : :
259 : : void bind(void);
260 : : void Debug(int from);
261 : : };
262 : : }
263 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 : : #endif
|