]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAircraft.cpp
Typo
[flightgear.git] / src / FDM / JSBSim / FGAircraft.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGAircraft.cpp
4  Author:       Jon S. Berndt
5  Date started: 12/12/98
6  Purpose:      Encapsulates an aircraft
7  Called by:    FGFDMExec
8
9  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
10
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  details.
20
21  You should have received a copy of the GNU General Public License along with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA  02111-1307, USA.
24
25  Further information about the GNU General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 Models the aircraft reactions and forces. This class is instantiated by the
31 FGFDMExec class and scheduled as an FDM entry.
32
33 HISTORY
34 --------------------------------------------------------------------------------
35 12/12/98   JSB   Created
36 04/03/99   JSB   Changed Aero() method to correct body axis force calculation
37                  from wind vector. Fix provided by Tony Peden.
38 05/03/99   JSB   Changed (for the better?) the way configurations are read in.
39 9/17/99     TP   Combined force and moment functions. Added aero reference
40                  point to config file. Added calculations for moments due to
41                  difference in cg and aero reference point
42
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 COMMENTS, REFERENCES,  and NOTES
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 INCLUDES
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50
51 #ifdef HAVE_CONFIG_H
52 #  include <config.h>
53 #endif
54
55 #include <sys/stat.h>
56 #include <sys/types.h>
57
58 #ifdef FGFS
59 #  ifndef __BORLANDC__
60 #    include <simgear/compiler.h>
61 #  endif
62 #  ifdef SG_HAVE_STD_INCLUDES
63 #    include <cmath>
64 #  else
65 #    include <math.h>
66 #  endif
67 #else
68 #  if defined (sgi) && !defined(__GNUC__)
69 #    include <math.h>
70 #  else
71 #    include <cmath>
72 #  endif
73 #endif
74
75 #include "FGAircraft.h"
76 #include "FGMassBalance.h"
77 #include "FGInertial.h"
78 #include "FGGroundReactions.h"
79 #include "FGAerodynamics.h"
80 #include "FGState.h"
81 #include "FGFDMExec.h"
82 #include "FGPropagate.h"
83 #include "FGPropertyManager.h"
84
85 namespace JSBSim {
86
87 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 DEFINITIONS
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
90
91 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 GLOBAL DATA
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
94
95 static const char *IdSrc = "$Id$";
96 static const char *IdHdr = ID_AIRCRAFT;
97
98 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 CLASS IMPLEMENTATION
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
101
102 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
103 {
104   Name = "FGAircraft";
105   WingSpan = 0.0;
106   HTailArea = VTailArea = 0.0;
107   HTailArm  = VTailArm  = 0.0;
108   lbarh = lbarv = 0.0;
109   vbarh = vbarv = 0.0;
110   WingIncidence = 0.0;
111
112   bind();
113
114   Debug(0);
115 }
116
117 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118
119 FGAircraft::~FGAircraft()
120 {
121   unbind();
122   Debug(1);
123 }
124
125 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126
127 bool FGAircraft::Run(void)
128 {
129   if (!FGModel::Run()) {                 // if false then execute this Run()
130     vForces.InitMatrix();
131     vForces += Aerodynamics->GetForces();
132     vForces += Propulsion->GetForces();
133     vForces += GroundReactions->GetForces();
134
135     vMoments.InitMatrix();
136     vMoments += Aerodynamics->GetMoments();
137     vMoments += Propulsion->GetMoments();
138     vMoments += GroundReactions->GetMoments();
139
140     vBodyAccel = vForces/MassBalance->GetMass();
141
142     vNcg = vBodyAccel/Inertial->gravity();
143
144     vNwcg = State->GetTb2s() * vNcg;
145     vNwcg(3) = -1*vNwcg(3) + 1;
146
147     return false;
148   } else {                               // skip Run() execution this time
149     return true;
150   }
151 }
152
153 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154
155 double FGAircraft::GetNlf(void)
156 {
157   return -1*Aerodynamics->GetvFs(3)/MassBalance->GetWeight();
158 }
159
160 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161
162 bool FGAircraft::Load(FGConfigFile* AC_cfg)
163 {
164   string token = "";
165   string parameter;
166   double EW, bixx, biyy, bizz, bixy, bixz, biyz;
167   double pmWt, pmX, pmY, pmZ;
168   FGColumnVector3 vbaseXYZcg;
169
170   bixx = biyy = bizz = bixy = bixz = biyz = 0.0;
171
172   AC_cfg->GetNextConfigLine();
173
174   while ((token = AC_cfg->GetValue()) != string("/METRICS")) {
175     *AC_cfg >> parameter;
176     if (parameter == "AC_WINGAREA") {
177       *AC_cfg >> WingArea;
178       if (debug_lvl > 0) cout << "    WingArea: " << WingArea  << endl;
179     } else if (parameter == "AC_WINGSPAN") {
180       *AC_cfg >> WingSpan;
181       if (debug_lvl > 0) cout << "    WingSpan: " << WingSpan  << endl;
182     } else if (parameter == "AC_WINGINCIDENCE") {
183       *AC_cfg >> WingIncidence;
184       if (debug_lvl > 0) cout << "    Incidence: " << WingIncidence << endl;
185     } else if (parameter == "AC_CHORD") {
186       *AC_cfg >> cbar;
187       if (debug_lvl > 0) cout << "    Chord: " << cbar << endl;
188     } else if (parameter == "AC_HTAILAREA") {
189       *AC_cfg >> HTailArea;
190       if (debug_lvl > 0) cout << "    H. Tail Area: " << HTailArea << endl;
191     } else if (parameter == "AC_HTAILARM") {
192       *AC_cfg >> HTailArm;
193       if (debug_lvl > 0) cout << "    H. Tail Arm: " << HTailArm << endl;
194     } else if (parameter == "AC_VTAILAREA") {
195       *AC_cfg >> VTailArea;
196       if (debug_lvl > 0) cout << "    V. Tail Area: " << VTailArea << endl;
197     } else if (parameter == "AC_VTAILARM") {
198       *AC_cfg >> VTailArm;
199       if (debug_lvl > 0) cout << "    V. Tail Arm: " << VTailArm << endl;
200     } else if (parameter == "AC_IXX") {
201       *AC_cfg >> bixx;
202       if (debug_lvl > 0) cout << "    baseIxx: " << bixx << " slug-ft2" << endl;
203     } else if (parameter == "AC_IYY") {
204       *AC_cfg >> biyy;
205       if (debug_lvl > 0) cout << "    baseIyy: " << biyy << " slug-ft2" << endl;
206     } else if (parameter == "AC_IZZ") {
207       *AC_cfg >> bizz;
208       if (debug_lvl > 0) cout << "    baseIzz: " << bizz << " slug-ft2" << endl;
209     } else if (parameter == "AC_IXY") {
210       *AC_cfg >> bixy;
211       if (debug_lvl > 0) cout << "    baseIxy: " << bixy << " slug-ft2" << endl;
212     } else if (parameter == "AC_IXZ") {
213       *AC_cfg >> bixz;
214       if (debug_lvl > 0) cout << "    baseIxz: " << bixz << " slug-ft2" << endl;
215     } else if (parameter == "AC_IYZ") {
216       *AC_cfg >> biyz;
217       if (debug_lvl > 0) cout << "    baseIyz: " << biyz << " slug-ft2" << endl;
218     } else if (parameter == "AC_EMPTYWT") {
219       *AC_cfg >> EW;
220       MassBalance->SetEmptyWeight(EW);
221       if (debug_lvl > 0) cout << "    EmptyWeight: " << EW << " lbm" << endl;
222     } else if (parameter == "AC_CGLOC") {
223       *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
224       MassBalance->SetBaseCG(vbaseXYZcg);
225       if (debug_lvl > 0) cout << "    CG (x, y, z): " << vbaseXYZcg << endl;
226     } else if (parameter == "AC_EYEPTLOC") {
227       *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
228       if (debug_lvl > 0) cout << "    Eyepoint (x, y, z): " << vXYZep << endl;
229     } else if (parameter == "AC_AERORP") {
230       *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
231       if (debug_lvl > 0) cout << "    Ref Pt (x, y, z): " << vXYZrp << endl;
232     } else if (parameter == "AC_VRP") {
233       *AC_cfg >> vXYZvrp(eX) >> vXYZvrp(eY) >> vXYZvrp(eZ);
234       if (debug_lvl > 0) cout << "    Visual Ref Pt (x, y, z): " << vXYZvrp << endl;
235     } else if (parameter == "AC_POINTMASS") {
236       *AC_cfg >> pmWt >> pmX >> pmY >> pmZ;
237       MassBalance->AddPointMass(pmWt, pmX, pmY, pmZ);
238       if (debug_lvl > 0) cout << "    Point Mass Object: " << pmWt << " lbs. at "
239                          << "X, Y, Z (in.): " << pmX << "  " << pmY << "  " << pmZ
240                          << endl;
241     }
242   }
243
244   MassBalance->SetAircraftBaseInertias(FGMatrix33(  bixx,  -bixy,  -bixz,
245                                                     -bixy,  biyy,  -biyz,
246                                                     -bixz,  -biyz,  bizz ));
247
248   // calculate some derived parameters
249   if (cbar != 0.0) {
250     lbarh = HTailArm/cbar;
251     lbarv = VTailArm/cbar;
252     if (WingArea != 0.0) {
253       vbarh = HTailArm*HTailArea / (cbar*WingArea);
254       vbarv = VTailArm*VTailArea / (cbar*WingArea);
255     }
256   }
257   return true;
258 }
259
260 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261
262 void FGAircraft::bind(void)
263 {
264   typedef double (FGAircraft::*PMF)(int) const;
265   PropertyManager->Tie("metrics/Sw-sqft", this,
266                        &FGAircraft::GetWingArea);
267   PropertyManager->Tie("metrics/bw-ft", this,
268                        &FGAircraft::GetWingSpan);
269   PropertyManager->Tie("metrics/cbarw-ft", this,
270                        &FGAircraft::Getcbar);
271   PropertyManager->Tie("metrics/iw-deg", this,
272                        &FGAircraft::GetWingIncidence);
273   PropertyManager->Tie("metrics/Sh-sqft", this,
274                        &FGAircraft::GetHTailArea);
275   PropertyManager->Tie("metrics/lh-ft", this,
276                        &FGAircraft::GetHTailArm);
277   PropertyManager->Tie("metrics/Sv-sqft", this,
278                        &FGAircraft::GetVTailArea);
279   PropertyManager->Tie("metrics/lv-ft", this,
280                        &FGAircraft::GetVTailArm);
281   PropertyManager->Tie("metrics/lh-norm", this,
282                        &FGAircraft::Getlbarh);
283   PropertyManager->Tie("metrics/lv-norm", this,
284                        &FGAircraft::Getlbarv);
285   PropertyManager->Tie("metrics/vbarh-norm", this,
286                        &FGAircraft::Getvbarh);
287   PropertyManager->Tie("metrics/vbarv-norm", this,
288                        &FGAircraft::Getvbarv);
289   PropertyManager->Tie("moments/l-total-lbsft", this,1,
290                        (PMF)&FGAircraft::GetMoments);
291   PropertyManager->Tie("moments/m-total-lbsft", this,2,
292                        (PMF)&FGAircraft::GetMoments);
293   PropertyManager->Tie("moments/n-total-lbsft", this,3,
294                        (PMF)&FGAircraft::GetMoments);
295   PropertyManager->Tie("forces/fbx-total-lbs", this,1,
296                        (PMF)&FGAircraft::GetForces);
297   PropertyManager->Tie("forces/fby-total-lbs", this,2,
298                        (PMF)&FGAircraft::GetForces);
299   PropertyManager->Tie("forces/fbz-total-lbs", this,3,
300                        (PMF)&FGAircraft::GetForces);
301   PropertyManager->Tie("metrics/aero-rp-x-in", this,1,
302                        (PMF)&FGAircraft::GetXYZrp);
303   PropertyManager->Tie("metrics/aero-rp-y-in", this,2,
304                        (PMF)&FGAircraft::GetXYZrp);
305   PropertyManager->Tie("metrics/aero-rp-z-in", this,3,
306                        (PMF)&FGAircraft::GetXYZrp);
307   PropertyManager->Tie("metrics/eyepoint-x-in", this,1,
308                        (PMF)&FGAircraft::GetXYZep);
309   PropertyManager->Tie("metrics/eyepoint-y-in", this,2,
310                        (PMF)&FGAircraft::GetXYZep);
311   PropertyManager->Tie("metrics/eyepoint-z-in", this,3,
312                        (PMF)&FGAircraft::GetXYZep);
313   PropertyManager->Tie("metrics/visualrefpoint-x-in", this,1,
314                        (PMF)&FGAircraft::GetXYZvrp);
315   PropertyManager->Tie("metrics/visualrefpoint-y-in", this,2,
316                        (PMF)&FGAircraft::GetXYZvrp);
317   PropertyManager->Tie("metrics/visualrefpoint-z-in", this,3,
318                        (PMF)&FGAircraft::GetXYZvrp);
319 }
320
321 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
322
323 void FGAircraft::unbind(void)
324 {
325   PropertyManager->Untie("metrics/Sw-sqft");
326   PropertyManager->Untie("metrics/bw-ft");
327   PropertyManager->Untie("metrics/cbarw-ft");
328   PropertyManager->Untie("metrics/iw-deg");
329   PropertyManager->Untie("metrics/Sh-sqft");
330   PropertyManager->Untie("metrics/lh-ft");
331   PropertyManager->Untie("metrics/Sv-sqft");
332   PropertyManager->Untie("metrics/lv-ft");
333   PropertyManager->Untie("metrics/lh-norm");
334   PropertyManager->Untie("metrics/lv-norm");
335   PropertyManager->Untie("metrics/vbarh-norm");
336   PropertyManager->Untie("metrics/vbarv-norm");
337   PropertyManager->Untie("moments/l-total-lbsft");
338   PropertyManager->Untie("moments/m-total-lbsft");
339   PropertyManager->Untie("moments/n-total-lbsft");
340   PropertyManager->Untie("forces/fbx-total-lbs");
341   PropertyManager->Untie("forces/fby-total-lbs");
342   PropertyManager->Untie("forces/fbz-total-lbs");
343   PropertyManager->Untie("metrics/aero-rp-x-in");
344   PropertyManager->Untie("metrics/aero-rp-y-in");
345   PropertyManager->Untie("metrics/aero-rp-z-in");
346   PropertyManager->Untie("metrics/eyepoint-x-in");
347   PropertyManager->Untie("metrics/eyepoint-y-in");
348   PropertyManager->Untie("metrics/eyepoint-z-in");
349   PropertyManager->Untie("metrics/visualrefpoint-x-in");
350   PropertyManager->Untie("metrics/visualrefpoint-y-in");
351   PropertyManager->Untie("metrics/visualrefpoint-z-in");
352 }
353
354 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
355 //    The bitmasked value choices are as follows:
356 //    unset: In this case (the default) JSBSim would only print
357 //       out the normally expected messages, essentially echoing
358 //       the config files as they are read. If the environment
359 //       variable is not set, debug_lvl is set to 1 internally
360 //    0: This requests JSBSim not to output any messages
361 //       whatsoever.
362 //    1: This value explicity requests the normal JSBSim
363 //       startup messages
364 //    2: This value asks for a message to be printed out when
365 //       a class is instantiated
366 //    4: When this value is set, a message is displayed when a
367 //       FGModel object executes its Run() method
368 //    8: When this value is set, various runtime state variables
369 //       are printed out periodically
370 //    16: When set various parameters are sanity checked and
371 //       a message is printed out when they go out of bounds
372
373 void FGAircraft::Debug(int from)
374 {
375   if (debug_lvl <= 0) return;
376
377   if (debug_lvl & 1) { // Standard console startup message output
378     if (from == 0) { // Constructor
379     }
380   }
381   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
382     if (from == 0) cout << "Instantiated: FGAircraft" << endl;
383     if (from == 1) cout << "Destroyed:    FGAircraft" << endl;
384   }
385   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
386   }
387   if (debug_lvl & 8 ) { // Runtime state variables
388   }
389   if (debug_lvl & 16) { // Sanity checking
390   }
391   if (debug_lvl & 64) {
392     if (from == 0) { // Constructor
393       cout << IdSrc << endl;
394       cout << IdHdr << endl;
395     }
396   }
397 }
398
399 } // namespace JSBSim