]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAircraft.cpp
- fixed fuel-need calculations
[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 #include <sys/stat.h>
52 #include <sys/types.h>
53
54 #ifdef FGFS
55 #  ifndef __BORLANDC__
56 #    include <simgear/compiler.h>
57 #  endif
58 #  ifdef SG_HAVE_STD_INCLUDES
59 #    include <cmath>
60 #  else
61 #    include <math.h>
62 #  endif
63 #else
64 #  if defined (sgi) && !defined(__GNUC__)
65 #    include <math.h>
66 #  else
67 #    include <cmath>
68 #  endif
69 #endif
70
71 #include "FGAircraft.h"
72 #include "FGMassBalance.h"
73 #include "FGInertial.h"
74 #include "FGGroundReactions.h"
75 #include "FGAerodynamics.h"
76 #include "FGTranslation.h"
77 #include "FGRotation.h"
78 #include "FGAtmosphere.h"
79 #include "FGState.h"
80 #include "FGFDMExec.h"
81 #include "FGFCS.h"
82 #include "FGPosition.h"
83 #include "FGAuxiliary.h"
84 #include "FGOutput.h"
85
86 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 DEFINITIONS
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
89
90 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 GLOBAL DATA
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
93
94 static const char *IdSrc = "$Id$";
95 static const char *IdHdr = ID_AIRCRAFT;
96
97 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 CLASS IMPLEMENTATION
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
100
101 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
102 {
103   Name = "FGAircraft";
104   alphaclmin = alphaclmax = 0;
105   HTailArea = VTailArea = HTailArm = VTailArm = 0.0;
106   lbarh = lbarv = vbarh = vbarv = 0.0;
107   WingIncidence=0;
108   impending_stall = 0;
109
110   Debug(0);
111 }
112
113 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114
115 FGAircraft::~FGAircraft()
116 {
117   Debug(1);
118 }
119
120 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121
122 bool FGAircraft::Run(void)
123 {
124   if (!FGModel::Run()) {                 // if false then execute this Run()
125     vForces.InitMatrix();
126     vForces += Aerodynamics->GetForces();
127     vForces += Inertial->GetForces();
128     vForces += Propulsion->GetForces();
129     vForces += GroundReactions->GetForces();
130
131     vMoments.InitMatrix();
132     vMoments += Aerodynamics->GetMoments();
133     vMoments += Propulsion->GetMoments();
134     vMoments += GroundReactions->GetMoments();
135     
136     vBodyAccel = vForces/MassBalance->GetMass();
137     
138     vNcg = vBodyAccel/Inertial->gravity();
139
140     vNwcg = State->GetTb2s() * vNcg;
141     vNwcg(3) = -1*vNwcg(3) + 1;
142     
143     if (alphaclmax != 0) {
144       if (Translation->Getalpha() > 0.85*alphaclmax) {
145         impending_stall = 10*(Translation->Getalpha()/alphaclmax - 0.85);
146       } else {
147         impending_stall = 0;
148       }
149     }      
150     
151     return false;
152   } else {                               // skip Run() execution this time
153     return true;
154   }
155 }
156
157 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158
159 float FGAircraft::GetNlf(void)
160 {
161   return vNwcg(3);
162 }
163
164 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165
166 bool FGAircraft::Load(FGConfigFile* AC_cfg)
167 {
168   string token = "";
169   string parameter;
170   double EW, bixx, biyy, bizz, bixy, bixz;
171   double pmWt, pmX, pmY, pmZ;
172   FGColumnVector3 vbaseXYZcg;
173
174   AC_cfg->GetNextConfigLine();
175
176   while ((token = AC_cfg->GetValue()) != string("/METRICS")) {
177     *AC_cfg >> parameter;
178     if (parameter == "AC_WINGAREA") {
179       *AC_cfg >> WingArea;
180       if (debug_lvl > 0) cout << "    WingArea: " << WingArea  << endl;
181     } else if (parameter == "AC_WINGSPAN") {
182       *AC_cfg >> WingSpan;
183       if (debug_lvl > 0) cout << "    WingSpan: " << WingSpan  << endl;
184     } else if (parameter == "AC_WINGINCIDENCE") {
185       *AC_cfg >> WingIncidence;
186       if (debug_lvl > 0) cout << "    Chord: " << cbar << endl;
187     } else if (parameter == "AC_CHORD") {
188       *AC_cfg >> cbar;
189       if (debug_lvl > 0) cout << "    Chord: " << cbar << endl;
190     } else if (parameter == "AC_HTAILAREA") {
191       *AC_cfg >> HTailArea;
192       if (debug_lvl > 0) cout << "    H. Tail Area: " << HTailArea << endl;
193     } else if (parameter == "AC_HTAILARM") {
194       *AC_cfg >> HTailArm;
195       if (debug_lvl > 0) cout << "    H. Tail Arm: " << HTailArm << endl;
196     } else if (parameter == "AC_VTAILAREA") {
197       *AC_cfg >> VTailArea;
198       if (debug_lvl > 0) cout << "    V. Tail Area: " << VTailArea << endl;
199     } else if (parameter == "AC_VTAILARM") {
200       *AC_cfg >> VTailArm;
201       if (debug_lvl > 0) cout << "    V. Tail Arm: " << VTailArm << endl;
202     } else if (parameter == "AC_IXX") {
203       *AC_cfg >> bixx;
204       if (debug_lvl > 0) cout << "    baseIxx: " << bixx << endl;
205       MassBalance->SetBaseIxx(bixx);
206     } else if (parameter == "AC_IYY") {
207       *AC_cfg >> biyy;
208       if (debug_lvl > 0) cout << "    baseIyy: " << biyy << endl;
209       MassBalance->SetBaseIyy(biyy);
210     } else if (parameter == "AC_IZZ") {
211       *AC_cfg >> bizz;
212       if (debug_lvl > 0) cout << "    baseIzz: " << bizz << endl;
213       MassBalance->SetBaseIzz(bizz);
214     } else if (parameter == "AC_IXY") {
215       *AC_cfg >> bixy;
216       if (debug_lvl > 0) cout << "    baseIxy: " << bixy  << endl;
217       MassBalance->SetBaseIxy(bixy);
218     } else if (parameter == "AC_IXZ") {
219       *AC_cfg >> bixz;
220       if (debug_lvl > 0) cout << "    baseIxz: " << bixz  << endl;
221       MassBalance->SetBaseIxz(bixz);
222     } else if (parameter == "AC_EMPTYWT") {
223       *AC_cfg >> EW;
224       MassBalance->SetEmptyWeight(EW);
225       if (debug_lvl > 0) cout << "    EmptyWeight: " << EW  << endl;
226     } else if (parameter == "AC_CGLOC") {
227       *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
228       MassBalance->SetBaseCG(vbaseXYZcg);
229       if (debug_lvl > 0) cout << "    CG (x, y, z): " << vbaseXYZcg << endl;
230     } else if (parameter == "AC_EYEPTLOC") {
231       *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
232       if (debug_lvl > 0) cout << "    Eyepoint (x, y, z): " << vXYZep << endl;
233     } else if (parameter == "AC_AERORP") {
234       *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
235       if (debug_lvl > 0) cout << "    Ref Pt (x, y, z): " << vXYZrp << endl;
236     } else if (parameter == "AC_ALPHALIMITS") {
237       *AC_cfg >> alphaclmin >> alphaclmax;
238       if (debug_lvl > 0) cout << "    Maximum Alpha: " << alphaclmax
239              << "    Minimum Alpha: " << alphaclmin
240              << endl;
241     } else if (parameter == "AC_POINTMASS") {
242       *AC_cfg >> pmWt >> pmX >> pmY >> pmZ;
243       if (debug_lvl > 0) cout << "    Point Mass Object: " << pmWt << " lbs. at "
244                          << "X, Y, Z (in.): " << pmX << "  " << pmY << "  " << pmZ
245                          << endl;
246     }
247   }
248   
249   // calculate some derived parameters
250   if (cbar != 0.0) {
251     lbarh = HTailArm/cbar;
252     lbarv = VTailArm/cbar;
253     if (WingArea != 0.0) {
254       vbarh = HTailArm*HTailArea / (cbar*WingArea);
255       vbarv = VTailArm*VTailArea / (cbar*WingArea);
256     }
257   }     
258   return true;
259 }
260
261 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 //    The bitmasked value choices are as follows:
263 //    unset: In this case (the default) JSBSim would only print
264 //       out the normally expected messages, essentially echoing
265 //       the config files as they are read. If the environment
266 //       variable is not set, debug_lvl is set to 1 internally
267 //    0: This requests JSBSim not to output any messages
268 //       whatsoever.
269 //    1: This value explicity requests the normal JSBSim
270 //       startup messages
271 //    2: This value asks for a message to be printed out when
272 //       a class is instantiated
273 //    4: When this value is set, a message is displayed when a
274 //       FGModel object executes its Run() method
275 //    8: When this value is set, various runtime state variables
276 //       are printed out periodically
277 //    16: When set various parameters are sanity checked and
278 //       a message is printed out when they go out of bounds
279
280 void FGAircraft::Debug(int from)
281 {
282   if (debug_lvl <= 0) return;
283
284   if (debug_lvl & 1) { // Standard console startup message output
285     if (from == 0) { // Constructor
286     }
287   }
288   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
289     if (from == 0) cout << "Instantiated: FGAircraft" << endl;
290     if (from == 1) cout << "Destroyed:    FGAircraft" << endl;
291   }
292   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
293   }
294   if (debug_lvl & 8 ) { // Runtime state variables
295   }
296   if (debug_lvl & 16) { // Sanity checking
297   }
298   if (debug_lvl & 64) {
299     if (from == 0) { // Constructor
300       cout << IdSrc << endl;
301       cout << IdHdr << endl;
302     }
303   }
304 }
305