]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAircraft.cpp
Nov. 14, 2000 JSBSim updates
[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. LoadAircraft() is supplied with a
32 name of a valid, registered aircraft, and the data file is parsed.
33  
34 HISTORY
35 --------------------------------------------------------------------------------
36 12/12/98   JSB   Created
37 04/03/99   JSB   Changed Aero() method to correct body axis force calculation
38                  from wind vector. Fix provided by Tony Peden.
39 05/03/99   JSB   Changed (for the better?) the way configurations are read in.
40 9/17/99     TP   Combined force and moment functions. Added aero reference 
41                  point to config file. Added calculations for moments due to 
42                  difference in cg and aero reference point
43  
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 COMMENTS, REFERENCES,  and NOTES
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47
48 [1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
49       Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420  Naval Postgraduate
50       School, January 1994
51 [2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
52       JSC 12960, July 1977
53 [3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
54       NASA-Ames", NASA CR-2497, January 1975
55 [4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
56       Wiley & Sons, 1979 ISBN 0-471-03032-5
57 [5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
58       1982 ISBN 0-471-08936-2
59  
60 The aerodynamic coefficients used in this model are:
61  
62 Longitudinal
63   CL0 - Reference lift at zero alpha
64   CD0 - Reference drag at zero alpha
65   CDM - Drag due to Mach
66   CLa - Lift curve slope (w.r.t. alpha)
67   CDa - Drag curve slope (w.r.t. alpha)
68   CLq - Lift due to pitch rate
69   CLM - Lift due to Mach
70   CLadt - Lift due to alpha rate
71  
72   Cmadt - Pitching Moment due to alpha rate
73   Cm0 - Reference Pitching moment at zero alpha
74   Cma - Pitching moment slope (w.r.t. alpha)
75   Cmq - Pitch damping (pitch moment due to pitch rate)
76   CmM - Pitch Moment due to Mach
77  
78 Lateral
79   Cyb - Side force due to sideslip
80   Cyr - Side force due to yaw rate
81  
82   Clb - Dihedral effect (roll moment due to sideslip)
83   Clp - Roll damping (roll moment due to roll rate)
84   Clr - Roll moment due to yaw rate
85   Cnb - Weathercocking stability (yaw moment due to sideslip)
86   Cnp - Rudder adverse yaw (yaw moment due to roll rate)
87   Cnr - Yaw damping (yaw moment due to yaw rate)
88  
89 Control
90   CLDe - Lift due to elevator
91   CDDe - Drag due to elevator
92   CyDr - Side force due to rudder
93   CyDa - Side force due to aileron
94  
95   CmDe - Pitch moment due to elevator
96   ClDa - Roll moment due to aileron
97   ClDr - Roll moment due to rudder
98   CnDr - Yaw moment due to rudder
99   CnDa - Yaw moment due to aileron
100  
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 INCLUDES
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
104
105 #include <sys/stat.h>
106 #include <sys/types.h>
107
108 #ifdef FGFS
109 #  ifndef __BORLANDC__
110 #    include <simgear/compiler.h>
111 #  endif
112 #  ifdef FG_HAVE_STD_INCLUDES
113 #    include <cmath>
114 #  else
115 #    include <math.h>
116 #  endif
117 #else
118 #  include <cmath>
119 #endif
120
121 #include "FGAircraft.h"
122 #include "FGTranslation.h"
123 #include "FGRotation.h"
124 #include "FGAtmosphere.h"
125 #include "FGState.h"
126 #include "FGFDMExec.h"
127 #include "FGFCS.h"
128 #include "FGPosition.h"
129 #include "FGAuxiliary.h"
130 #include "FGOutput.h"
131
132 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 DEFINITIONS
134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
135
136 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 GLOBAL DATA
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
139
140 static const char *IdSrc = "$Header$";
141 static const char *IdHdr = ID_AIRCRAFT;
142
143 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 CLASS IMPLEMENTATION
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
146
147 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex),
148     vMoments(3),
149     vForces(3),
150     vFs(3),
151     vXYZrp(3),
152     vbaseXYZcg(3),
153     vXYZcg(3),
154     vXYZep(3),
155     vEuler(3)
156     
157 {
158   Name = "FGAircraft";
159
160   AxisIdx["DRAG"]  = 0;
161   AxisIdx["SIDE"]  = 1;
162   AxisIdx["LIFT"]  = 2;
163   AxisIdx["ROLL"]  = 3;
164   AxisIdx["PITCH"] = 4;
165   AxisIdx["YAW"]   = 5;
166   
167   Coeff = new CoeffArray[6];
168
169   GearUp = false;
170   
171   alphaclmin = alphaclmax = 0;
172
173   numTanks = numEngines = numSelectedFuelTanks = numSelectedOxiTanks = 0;
174 }
175
176
177 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178
179
180 FGAircraft::~FGAircraft(void) { 
181   unsigned int i,j;
182
183   if (Engine != NULL) {
184     for (i=0; i<numEngines; i++)
185       delete Engine[i];
186   }    
187   if (Tank != NULL) {
188     for (i=0; i<numTanks; i++)
189       delete Tank[i];
190   }    
191   for (i=0; i<6; i++) {
192     for (j=0; j<Coeff[i].size(); j++) {
193       delete Coeff[i][j];
194     }
195   }
196   delete[] Coeff;
197 }
198
199 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200
201 bool FGAircraft::LoadAircraft(string aircraft_path, string engine_path, string fname) {
202   string path;
203   string filename;
204   string aircraftCfgFileName;
205   string token;
206
207   AircraftPath = aircraft_path;
208   EnginePath = engine_path;
209
210 # ifndef macintosh
211   aircraftCfgFileName = AircraftPath + "/" + fname + "/" + fname + ".xml";
212 # else  
213   aircraftCfgFileName = AircraftPath + ";" + fname + ";" + fname + ".xml";
214 # endif
215
216   FGConfigFile AC_cfg(aircraftCfgFileName);
217   if (!AC_cfg.IsOpen()) return false;
218
219   ReadPrologue(&AC_cfg);
220
221   while ((AC_cfg.GetNextConfigLine() != "EOF") &&
222          (token = AC_cfg.GetValue()) != "/FDM_CONFIG") {
223     if (token == "METRICS") {
224       cout << "  Reading Metrics" << endl;
225       ReadMetrics(&AC_cfg);
226     } else if (token == "AERODYNAMICS") {
227       cout << "  Reading Aerodynamics" << endl;
228       ReadAerodynamics(&AC_cfg);
229     } else if (token == "UNDERCARRIAGE") {
230       cout << "  Reading Landing Gear" << endl;
231       ReadUndercarriage(&AC_cfg);
232     } else if (token == "PROPULSION") {
233       cout << "  Reading Propulsion" << endl;
234       ReadPropulsion(&AC_cfg);
235     } else if (token == "FLIGHT_CONTROL") {
236       cout << "  Reading Flight Control" << endl;
237       ReadFlightControls(&AC_cfg);
238     } else if (token == "OUTPUT") {
239       ReadOutput(&AC_cfg);
240     }
241   }
242
243   return true;
244 }
245
246 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247
248 bool FGAircraft::Run(void) {
249   if (!FGModel::Run()) {                 // if false then execute this Run()
250     GetState();
251
252     for (int i = 1; i <= 3; i++)  vForces(i) = vMoments(i) = 0.0;
253
254     MassChange();
255     FMProp();
256     FMAero();
257     FMGear();
258     FMMass();
259
260     nlf = 0;
261     if (fabs(Position->GetGamma()) < 1.57) {
262         nlf = vFs(eZ)/(Weight*cos(Position->GetGamma()));
263     }    
264         
265   } else {                               // skip Run() execution this time
266   }
267
268
269   return false;
270 }
271
272 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273
274 void FGAircraft::MassChange() {
275   static FGColumnVector vXYZtank(3);
276   float Tw;
277   float IXXt, IYYt, IZZt, IXZt;
278   unsigned int t;
279   unsigned int axis_ctr;
280
281   for (axis_ctr=1; axis_ctr<=3; axis_ctr++) vXYZtank(axis_ctr) = 0.0;
282
283   // UPDATE TANK CONTENTS
284   //
285   // For each engine, cycle through the tanks and draw an equal amount of
286   // fuel (or oxidizer) from each active tank. The needed amount of fuel is
287   // determined by the engine in the FGEngine class. If more fuel is needed
288   // than is available in the tank, then that amount is considered a shortage,
289   // and will be drawn from the next tank. If the engine cannot be fed what it
290   // needs, it will be considered to be starved, and will shut down.
291
292   float Oshortage, Fshortage;
293
294   for (unsigned int e=0; e<numEngines; e++) {
295     Fshortage = Oshortage = 0.0;
296     for (t=0; t<numTanks; t++) {
297       switch(Engine[e]->GetType()) {
298       case FGEngine::etRocket:
299
300         switch(Tank[t]->GetType()) {
301         case FGTank::ttFUEL:
302           if (Tank[t]->GetSelected()) {
303             Fshortage = Tank[t]->Reduce((Engine[e]->CalcFuelNeed()/
304                                          numSelectedFuelTanks)*(dt*rate) + Fshortage);
305           }
306           break;
307         case FGTank::ttOXIDIZER:
308           if (Tank[t]->GetSelected()) {
309             Oshortage = Tank[t]->Reduce((Engine[e]->CalcOxidizerNeed()/
310                                          numSelectedOxiTanks)*(dt*rate) + Oshortage);
311           }
312           break;
313         }
314         break;
315
316       case FGEngine::etPiston:
317       case FGEngine::etTurboJet:
318       case FGEngine::etTurboProp:
319
320         if (Tank[t]->GetSelected()) {
321           Fshortage = Tank[t]->Reduce((Engine[e]->CalcFuelNeed()/
322                                        numSelectedFuelTanks)*(dt*rate) + Fshortage);
323         }
324         break;
325       }
326     }
327     if ((Fshortage <= 0.0) || (Oshortage <= 0.0)) Engine[e]->SetStarved();
328     else Engine[e]->SetStarved(false);
329   }
330
331   Weight = EmptyWeight;
332   for (t=0; t<numTanks; t++)
333     Weight += Tank[t]->GetContents();
334
335   Mass = Weight / GRAVITY;
336   // Calculate new CG here.
337
338   Tw = 0;
339   for (t=0; t<numTanks; t++) {
340     vXYZtank(eX) += Tank[t]->GetX()*Tank[t]->GetContents();
341     vXYZtank(eY) += Tank[t]->GetY()*Tank[t]->GetContents();
342     vXYZtank(eZ) += Tank[t]->GetZ()*Tank[t]->GetContents();
343
344     Tw += Tank[t]->GetContents();
345   }
346
347   vXYZcg = (vXYZtank + EmptyWeight*vbaseXYZcg) / (Tw + EmptyWeight);
348
349   // Calculate new moments of inertia here
350
351   IXXt = IYYt = IZZt = IXZt = 0.0;
352   for (t=0; t<numTanks; t++) {
353     IXXt += ((Tank[t]->GetX()-vXYZcg(eX))/12.0)*((Tank[t]->GetX() - vXYZcg(eX))/12.0)*Tank[t]->GetContents()/GRAVITY;
354     IYYt += ((Tank[t]->GetY()-vXYZcg(eY))/12.0)*((Tank[t]->GetY() - vXYZcg(eY))/12.0)*Tank[t]->GetContents()/GRAVITY;
355     IZZt += ((Tank[t]->GetZ()-vXYZcg(eZ))/12.0)*((Tank[t]->GetZ() - vXYZcg(eZ))/12.0)*Tank[t]->GetContents()/GRAVITY;
356     IXZt += ((Tank[t]->GetX()-vXYZcg(eX))/12.0)*((Tank[t]->GetZ() - vXYZcg(eZ))/12.0)*Tank[t]->GetContents()/GRAVITY;
357   }
358
359   Ixx = baseIxx + IXXt;
360   Iyy = baseIyy + IYYt;
361   Izz = baseIzz + IZZt;
362   Ixz = baseIxz + IXZt;
363
364 }
365
366 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
367
368 void FGAircraft::FMAero(void) {
369   static FGColumnVector vDXYZcg(3);
370   static FGColumnVector vAeroBodyForces(3);
371   unsigned int axis_ctr,ctr;
372
373   for (axis_ctr=1; axis_ctr<=3; axis_ctr++) vFs(axis_ctr) = 0.0;
374
375   for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
376     for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
377       vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
378     }
379   }
380
381   vAeroBodyForces = State->GetTs2b(alpha, beta)*vFs;
382   vForces += vAeroBodyForces;
383
384   // see http://home.earthlink.net/~apeden/jsbsim_moments_due_to_forces.txt
385   // for details on this
386   vDXYZcg(eX) = -(vXYZrp(eX) - vXYZcg(eX))/12.0;  //cg and rp values are in inches
387   vDXYZcg(eY) =  (vXYZrp(eY) - vXYZcg(eY))/12.0;
388   vDXYZcg(eZ) = -(vXYZrp(eZ) - vXYZcg(eZ))/12.0;
389
390   vMoments(eL) += vAeroBodyForces(eZ)*vDXYZcg(eY) - vAeroBodyForces(eY)*vDXYZcg(eZ); // rolling moment
391   vMoments(eM) += vAeroBodyForces(eX)*vDXYZcg(eZ) - vAeroBodyForces(eZ)*vDXYZcg(eX); // pitching moment
392   vMoments(eN) += vAeroBodyForces(eY)*vDXYZcg(eX) - vAeroBodyForces(eX)*vDXYZcg(eY); // yawing moment
393   
394   for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
395     for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
396       vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
397     }
398   }
399 }
400
401 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402
403 void FGAircraft::FMGear(void) {
404
405   if ( !GearUp ) {
406     vector <FGLGear>::iterator iGear = lGear.begin();
407     while (iGear != lGear.end()) {
408       vForces  += iGear->Force();
409       vMoments += iGear->Moment();
410       iGear++;
411     }
412   } else {
413     // Crash Routine
414   }
415 }
416
417 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
418
419 void FGAircraft::FMMass(void) {
420   vForces(eX) += -GRAVITY*sin(vEuler(eTht)) * Mass;
421   vForces(eY) +=  GRAVITY*sin(vEuler(ePhi))*cos(vEuler(eTht)) * Mass;
422   vForces(eZ) +=  GRAVITY*cos(vEuler(ePhi))*cos(vEuler(eTht)) * Mass;
423 }
424
425 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426
427 void FGAircraft::FMProp(void) {
428   for (unsigned int i=0;i<numEngines;i++) {
429
430     // Changes required here for new engine placement parameters (i.e. location and direction)
431
432     vForces(eX) += Engine[i]->CalcThrust();
433   }
434   
435 }
436
437 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
438
439 void FGAircraft::GetState(void) {
440   dt = State->Getdt();
441
442   alpha = Translation->Getalpha();
443   beta = Translation->Getbeta();
444   vEuler = Rotation->GetEuler();
445 }
446
447 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
448
449 void FGAircraft::ReadMetrics(FGConfigFile* AC_cfg) {
450   string token = "";
451   string parameter;
452
453   AC_cfg->GetNextConfigLine();
454
455   while ((token = AC_cfg->GetValue()) != "/METRICS") {
456     *AC_cfg >> parameter;
457     if (parameter == "AC_WINGAREA") {
458         *AC_cfg >> WingArea;
459         cout << "    WingArea: " << WingArea  << endl; 
460     } else if (parameter == "AC_WINGSPAN") {
461         *AC_cfg >> WingSpan;
462         cout << "    WingSpan: " << WingSpan  << endl;
463     } else if (parameter == "AC_CHORD") {
464         *AC_cfg >> cbar;
465         cout << "    Chord: " << cbar << endl;
466     } else if (parameter == "AC_IXX") {
467         *AC_cfg >> baseIxx;
468         cout << "    baseIxx: " << baseIxx << endl;
469     } else if (parameter == "AC_IYY") {
470         *AC_cfg >> baseIyy;
471         cout << "    baseIyy: " << baseIyy << endl;
472     } else if (parameter == "AC_IZZ") { 
473         *AC_cfg >> baseIzz;
474         cout << "    baseIzz: " << baseIzz << endl;
475     } else if (parameter == "AC_IXZ") { 
476         *AC_cfg >> baseIxz;
477         cout << "    baseIxz: " << baseIxz  << endl;
478     } else if (parameter == "AC_EMPTYWT") {
479         *AC_cfg >> EmptyWeight;
480         cout << "    EmptyWeight: " << EmptyWeight  << endl;
481     } else if (parameter == "AC_CGLOC") {
482         *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
483         cout << "    CG (x, y, z): " << vbaseXYZcg << endl;
484     } else if (parameter == "AC_EYEPTLOC") {
485         *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
486         cout << "    Eyepoint (x, y, z): " << vXYZep << endl;
487     } else if (parameter == "AC_AERORP") {
488         *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
489         cout << "    Ref Pt (x, y, z): " << vXYZrp << endl;
490     } else if (parameter == "AC_ALPHALIMITS") {
491         *AC_cfg >> alphaclmin >> alphaclmax;
492         cout << "    Maximum Alpha: " << alphaclmax
493              << "    Minimum Alpha: " << alphaclmin 
494              << endl;
495     }         
496   }
497 }
498
499 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
500
501 void FGAircraft::ReadPropulsion(FGConfigFile* AC_cfg) {
502   string token;
503   string engine_name;
504   string parameter;
505
506   AC_cfg->GetNextConfigLine();
507
508   while ((token = AC_cfg->GetValue()) != "/PROPULSION") {
509     *AC_cfg >> parameter;
510
511     if (parameter == "AC_ENGINE") {
512
513       *AC_cfg >> engine_name;
514       Engine[numEngines] = new FGEngine(FDMExec, EnginePath, engine_name, numEngines);
515       numEngines++;
516
517     } else if (parameter == "AC_TANK") {
518
519       Tank[numTanks] = new FGTank(AC_cfg);
520       switch(Tank[numTanks]->GetType()) {
521       case FGTank::ttFUEL:
522         numSelectedFuelTanks++;
523         break;
524       case FGTank::ttOXIDIZER:
525         numSelectedOxiTanks++;
526         break;
527       }
528       numTanks++;
529     }
530   }
531 }
532
533 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
534
535 void FGAircraft::ReadFlightControls(FGConfigFile* AC_cfg) {
536   string token;
537
538   FCS->LoadFCS(AC_cfg);
539 }
540
541 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
542
543 void FGAircraft::ReadAerodynamics(FGConfigFile* AC_cfg) {
544   string token, axis;
545
546   AC_cfg->GetNextConfigLine();
547   
548   while ((token = AC_cfg->GetValue()) != "/AERODYNAMICS") {
549     if (token == "AXIS") {
550       CoeffArray ca;
551       axis = AC_cfg->GetValue("NAME");
552       AC_cfg->GetNextConfigLine();
553       while ((token = AC_cfg->GetValue()) != "/AXIS") {
554         ca.push_back(new FGCoefficient(FDMExec, AC_cfg));
555         DisplayCoeffFactors(ca.back()->Getmultipliers());
556       }
557       Coeff[AxisIdx[axis]]=ca;
558       AC_cfg->GetNextConfigLine();
559     }
560   }
561 }
562
563 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
564
565 void FGAircraft::ReadUndercarriage(FGConfigFile* AC_cfg) {
566   string token;
567
568   AC_cfg->GetNextConfigLine();
569
570   while ((token = AC_cfg->GetValue()) != "/UNDERCARRIAGE") {
571     lGear.push_back(FGLGear(AC_cfg, FDMExec));
572   }
573 }
574
575 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
576
577 void FGAircraft::ReadOutput(FGConfigFile* AC_cfg) {
578   string token, parameter;
579   int OutRate = 0;
580   int subsystems = 0;
581
582   token = AC_cfg->GetValue("NAME");
583   Output->SetFilename(token);
584   token = AC_cfg->GetValue("TYPE");
585   Output->SetType(token);
586   AC_cfg->GetNextConfigLine();
587
588   while ((token = AC_cfg->GetValue()) != "/OUTPUT") {
589     *AC_cfg >> parameter;
590     if (parameter == "RATE_IN_HZ") *AC_cfg >> OutRate;
591     if (parameter == "SIMULATION") {
592       *AC_cfg >> parameter;
593       if (parameter == "ON") subsystems += ssSimulation;
594     }
595     if (parameter == "AEROSURFACES") {
596       *AC_cfg >> parameter;
597       if (parameter == "ON") subsystems += ssAerosurfaces;
598     }
599     if (parameter == "RATES") {
600       *AC_cfg >> parameter;
601       if (parameter == "ON") subsystems += ssRates;
602     }
603     if (parameter == "VELOCITIES") {
604       *AC_cfg >> parameter;
605       if (parameter == "ON") subsystems += ssVelocities;
606     }
607     if (parameter == "FORCES") {
608       *AC_cfg >> parameter;
609       if (parameter == "ON") subsystems += ssForces;
610     }
611     if (parameter == "MOMENTS") {
612       *AC_cfg >> parameter;
613       if (parameter == "ON") subsystems += ssMoments;
614     }
615     if (parameter == "ATMOSPHERE") {
616       *AC_cfg >> parameter;
617       if (parameter == "ON") subsystems += ssAtmosphere;
618     }
619     if (parameter == "MASSPROPS") {
620       *AC_cfg >> parameter;
621       if (parameter == "ON") subsystems += ssMassProps;
622     }
623     if (parameter == "POSITION") {
624       *AC_cfg >> parameter;
625       if (parameter == "ON") subsystems += ssPosition;
626     }
627     if (parameter == "COEFFICIENTS") {
628       *AC_cfg >> parameter;
629       if (parameter == "ON") subsystems += ssCoefficients;
630     }
631     if (parameter == "GROUND_REACTIONS") {
632       *AC_cfg >> parameter;
633       if (parameter == "ON") subsystems += ssGroundReactions;
634     }
635     if (parameter == "FCS") {
636       *AC_cfg >> parameter;
637       if (parameter == "ON") subsystems += ssFCS;
638     }
639   }
640
641   Output->SetSubsystems(subsystems);
642
643   OutRate = OutRate>120?120:(OutRate<0?0:OutRate);
644   Output->SetRate( (int)(0.5 + 1.0/(State->Getdt()*OutRate)) );
645 }
646
647 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
648
649 void FGAircraft::ReadPrologue(FGConfigFile* AC_cfg) {
650   string token = AC_cfg->GetValue();
651   string scratch;
652   AircraftName = AC_cfg->GetValue("NAME");
653   cout << "Reading Aircraft Configuration File: " << AircraftName << endl;
654   scratch=AC_cfg->GetValue("VERSION").c_str();
655
656   CFGVersion = AC_cfg->GetValue("VERSION");
657   cout << "                            Version: " << CFGVersion << endl;
658   if (CFGVersion != NEEDED_CFG_VERSION) {
659     cout << endl << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
660     " RESULTS WILL BE UNPREDICTABLE !!" << endl;
661     cout << "Current version needed is: " << NEEDED_CFG_VERSION << endl;
662     cout << "         You have version: " << CFGVersion << endl << endl;
663     //exit(-1);
664   }
665
666
667 }
668
669 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
670
671 void FGAircraft::DisplayCoeffFactors(vector <eParam> multipliers) {
672   cout << "   Non-Dimensionalized by: ";
673
674   for (unsigned int i=0; i<multipliers.size();i++)
675     cout << State->paramdef[multipliers[i]];
676
677   cout << endl;
678 }
679
680 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681
682 string FGAircraft::GetCoefficientStrings(void) {
683   string CoeffStrings = "";
684   bool firstime = true;
685
686   for (unsigned int axis = 0; axis < 6; axis++) {
687     for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
688       if (firstime) {
689         firstime = false;
690       } else {
691         CoeffStrings += ", ";
692       }
693       CoeffStrings += Coeff[axis][sd]->Getname();
694     }
695   }
696
697   return CoeffStrings;
698 }
699
700 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
701
702 string FGAircraft::GetCoefficientValues(void) {
703   string SDValues = "";
704   char buffer[10];
705   bool firstime = true;
706
707   for (unsigned int axis = 0; axis < 6; axis++) {
708     for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
709       if (firstime) {
710         firstime = false;
711       } else {
712         SDValues += ", ";
713       }
714       sprintf(buffer, "%9.6f", Coeff[axis][sd]->GetSD());
715       SDValues += string(buffer);
716     }
717   }
718
719   return SDValues;
720 }
721
722 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
723
724 string FGAircraft::GetGroundReactionStrings(void) {
725   string GroundReactionStrings = "";
726   bool firstime = true;
727
728   for (unsigned int i=0;i<lGear.size();i++) {
729     if (!firstime) GroundReactionStrings += ", ";
730     GroundReactionStrings += (lGear[i].GetName() + "_WOW, ");
731     GroundReactionStrings += (lGear[i].GetName() + "_compressLength, ");
732     GroundReactionStrings += (lGear[i].GetName() + "_compressSpeed, ");
733     GroundReactionStrings += (lGear[i].GetName() + "_Force");
734
735     firstime = false;
736   }
737
738   return GroundReactionStrings;
739 }
740
741 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742
743 string FGAircraft::GetGroundReactionValues(void) {
744   char buff[20];
745   string GroundReactionValues = "";
746
747   bool firstime = true;
748
749   for (unsigned int i=0;i<lGear.size();i++) {
750     if (!firstime) GroundReactionValues += ", ";
751     GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", ";
752     GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(),    5, buff)) + ", ");
753     GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(),    6, buff)) + ", ");
754     GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff)));
755
756     firstime = false;
757   }
758
759   return GroundReactionValues;
760 }
761