FlightGear next
FGMassBalance.h
Go to the documentation of this file.
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
11 Software Foundation; either version 2 of the License, or (at your option) any
12 later 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
20 with this program; if not, write to the Free Software Foundation, Inc., 59
21 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Further information about the GNU Lesser General Public License can also be
24 found on the world wide web at http://www.gnu.org.
25
26HISTORY
27--------------------------------------------------------------------------------
2809/12/2000 JSB Created
29
30%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31SENTRY
32%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34#ifndef FGMASSBALANCE_H
35#define FGMASSBALANCE_H
36
37/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38INCLUDES
39%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41#include "FGModel.h"
42#include "math/FGMatrix33.h"
43
44/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45FORWARD DECLARATIONSS
46%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47
48namespace JSBSim {
49
50class FGPropagate;
52
53/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54CLASS DOCUMENTATION
55%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56
117
118/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119CLASS DECLARATION
120%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
121
122class FGMassBalance : public FGModel
123{
124
125public:
126 explicit FGMassBalance(FGFDMExec*);
128
129 bool Load(Element* el) override;
130 bool InitModel(void) override;
139 bool Run(bool Holding) override;
140
141 double GetMass(void) const {return Mass;}
142 double GetWeight(void) const {return Weight;}
143 double GetEmptyWeight(void) const {return EmptyWeight;}
146 const FGColumnVector3& GetXYZcg(void) const {return vXYZcg;}
147 double GetXYZcg(int axis) const {return vXYZcg(axis);}
148 const FGColumnVector3& GetDeltaXYZcg(void) const {return vDeltaXYZcg;}
149 double GetDeltaXYZcg(int axis) const {return vDeltaXYZcg(axis);}
150
159 FGMatrix33 GetPointmassInertia(double mass_sl, const FGColumnVector3& r) const
160 {
162 FGColumnVector3 sv = mass_sl*v;
163 double xx = sv(1)*v(1);
164 double yy = sv(2)*v(2);
165 double zz = sv(3)*v(3);
166 double xy = -sv(1)*v(2);
167 double xz = -sv(1)*v(3);
168 double yz = -sv(2)*v(3);
169 return FGMatrix33( yy+zz, xy, xz,
170 xy, xx+zz, yz,
171 xz, yz, xx+yy );
172 }
173
184
185 void SetEmptyWeight(double EW) { EmptyWeight = EW;}
186 void SetBaseCG(const FGColumnVector3& CG) {vbaseXYZcg = vXYZcg = CG;}
187
188 void AddPointMass(Element* el);
189 double GetTotalPointMassWeight(void) const;
190
193 const FGMatrix33& GetJ(void) const {return mJ;}
195 const FGMatrix33& GetJinv(void) const {return mJinv;}
196 void SetAircraftBaseInertias(const FGMatrix33& BaseJ) {baseJ = BaseJ;}
197 void GetMassPropertiesReport(int i);
198
208
209private:
210 FGPropagate* Propagate;
211 double Weight;
212 double EmptyWeight;
213 double Mass;
214 FGMatrix33 mJ;
215 FGMatrix33 mJinv;
216 FGMatrix33 pmJ;
217 FGMatrix33 baseJ;
218 FGColumnVector3 vXYZcg;
219 FGColumnVector3 vLastXYZcg;
220 FGColumnVector3 vDeltaXYZcg;
221 FGColumnVector3 vDeltaXYZcgBody;
222 FGColumnVector3 vXYZtank;
223 FGColumnVector3 vbaseXYZcg;
224 FGColumnVector3 vPMxyz;
225 FGColumnVector3 PointMassCG;
226 const FGMatrix33& CalculatePMInertias(void);
227 double GetIxx(void) const { return mJ(1,1); }
228 double GetIyy(void) const { return mJ(2,2); }
229 double GetIzz(void) const { return mJ(3,3); }
230 double GetIxy(void) const { return -mJ(1,2); }
231 double GetIxz(void) const { return mJ(1,3); }
232 double GetIyz(void) const { return -mJ(2,3); }
233
236 struct PointMass {
237 PointMass(double w, FGColumnVector3& vXYZ) :
238 eShapeType(esUnspecified), Location(vXYZ), Weight(w), Radius(0.0),
239 Length(0.0) {}
240
241 void CalculateShapeInertia(void) {
242 switch(eShapeType) {
243 case esTube:
244 mPMInertia(1,1) = (Weight/(slugtolb))*Radius*Radius; // mr^2
245 mPMInertia(2,2) = (Weight/(slugtolb*12))*(6*Radius*Radius + Length*Length);
246 mPMInertia(3,3) = mPMInertia(2,2);
247 break;
248 case esCylinder:
249 mPMInertia(1,1) = (Weight/(slugtolb*2))*Radius*Radius; // 0.5*mr^2
250 mPMInertia(2,2) = (Weight/(slugtolb*12))*(3*Radius*Radius + Length*Length);
251 mPMInertia(3,3) = mPMInertia(2,2);
252 break;
253 case esSphere:
254 mPMInertia(1,1) = (Weight/(slugtolb*3))*Radius*Radius*2; // (2mr^2)/3
255 mPMInertia(2,2) = mPMInertia(1,1);
256 mPMInertia(3,3) = mPMInertia(1,1);
257 break;
258 case esBall:
259 mPMInertia(1,1) = (Weight/(slugtolb*5))*Radius*Radius*2; // (2mr^2)/5
260 mPMInertia(2,2) = mPMInertia(1,1);
261 mPMInertia(3,3) = mPMInertia(1,1);
262 break;
263 default:
264 break;
265 }
266 }
267
268 enum esShape {esUnspecified, esTube, esCylinder, esSphere, esBall} eShapeType;
269 FGColumnVector3 Location;
270 double Weight;
271 double Radius;
272 double Length;
273 std::string Name;
274 FGMatrix33 mPMInertia;
275
276 double GetPointMassLocation(int axis) const {return Location(axis);}
277 double GetPointMassWeight(void) const {return Weight;}
278 esShape GetShapeType(void) {return eShapeType;}
279 const FGColumnVector3& GetLocation(void) {return Location;}
280 const FGMatrix33& GetPointMassInertia(void) {return mPMInertia;}
281 const std::string& GetName(void) {return Name;}
282
283 void SetPointMassLocation(int axis, double value) {Location(axis) = value;}
284 void SetPointMassWeight(double wt) {
285 Weight = wt;
286 CalculateShapeInertia();
287 }
288 void SetPointMassShapeType(esShape st) {eShapeType = st;}
289 void SetRadius(double r) {Radius = r;}
290 void SetLength(double l) {Length = l;}
291 void SetName(const std::string& name) {Name = name;}
292 void SetPointMassMoI(const FGMatrix33& MoI) { mPMInertia = MoI; }
293 double GetPointMassMoI(int r, int c) {return mPMInertia(r,c);}
294
295 void bind(FGPropertyManager* PropertyManager, unsigned int num);
296 };
297
298 std::vector <struct PointMass*> PointMasses;
299
300 void bind(void);
301 void Debug(int from) override;
302};
303}
304//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305#endif
#define i(x)
This class implements a 3 element column vector.
Manages ground reactions modeling.
static constexpr double slugtolb
Note that definition of lbtoslug by the inverse of slugtolb and not to a different constant you can a...
Definition FGJSBBase.h:366
double GetDeltaXYZcg(int axis) const
void SetAircraftBaseInertias(const FGMatrix33 &BaseJ)
FGMatrix33 GetPointmassInertia(double mass_sl, const FGColumnVector3 &r) const
Computes the inertia contribution of a pointmass.
bool InitModel(void) override
FGColumnVector3 StructuralToBody(const FGColumnVector3 &r) const
Conversion from the structural frame to the body frame.
void SetBaseCG(const FGColumnVector3 &CG)
double GetEmptyWeight(void) const
double GetWeight(void) const
void AddPointMass(Element *el)
double GetTotalPointMassWeight(void) const
bool Run(bool Holding) override
Runs the Mass Balance model; called by the Executive Can pass in a value indicating if the executive ...
double GetMass(void) const
const FGColumnVector3 & GetDeltaXYZcg(void) const
const FGColumnVector3 & GetXYZcg(void) const
Returns the coordinates of the center of gravity expressed in the structural frame.
const FGColumnVector3 & GetPointMassMoment(void)
double GetXYZcg(int axis) const
struct JSBSim::FGMassBalance::Inputs in
void GetMassPropertiesReport(int i)
bool Load(Element *el) override
const FGMatrix33 & GetJinv(void) const
Returns the inverse of the inertia matrix expressed in the body frame.
void SetEmptyWeight(double EW)
const FGMatrix33 & GetJ(void) const
Returns the inertia matrix expressed in the body frame.
Handles matrix math operations.
Definition FGMatrix33.h:70
FGPropertyManager * PropertyManager
Definition FGModel.h:117
FGModel(FGFDMExec *)
Constructor.
Definition FGModel.cpp:57
Models the EOM and integration/propagation of state.
Definition FGPropagate.h:93
const char * name