]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAircraft.cpp
Latest round of 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 = "$Id$";
141 static const char *IdHdr = ID_AIRCRAFT;
142
143 extern char highint[5];
144 extern char halfint[5];
145 extern char normint[6];
146 extern char reset[5];
147 extern char underon[5];
148 extern char underoff[6];
149 extern char fgblue[6];
150 extern char fgcyan[6];
151 extern char fgred[6];
152 extern char fggreen[6];
153 extern char fgdef[6];
154
155 extern short debug_lvl;
156
157 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 CLASS IMPLEMENTATION
159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
160
161 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex),
162     vMoments(3),
163     vForces(3),
164     vFs(3),
165     vXYZrp(3),
166     vbaseXYZcg(3),
167     vXYZcg(3),
168     vXYZep(3),
169     vEuler(3)
170
171 {
172   Name = "FGAircraft";
173
174   AxisIdx["DRAG"]  = 0;
175   AxisIdx["SIDE"]  = 1;
176   AxisIdx["LIFT"]  = 2;
177   AxisIdx["ROLL"]  = 3;
178   AxisIdx["PITCH"] = 4;
179   AxisIdx["YAW"]   = 5;
180
181   Coeff = new CoeffArray[6];
182
183   GearUp = false;
184
185   alphaclmin = alphaclmax = 0;
186
187   if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
188 }
189
190
191 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192
193
194 FGAircraft::~FGAircraft() {
195   unsigned int i,j;
196   for (i=0; i<6; i++) {
197     for (j=0; j<Coeff[i].size(); j++) {
198       delete Coeff[i][j];
199     }
200   }
201   delete[] Coeff;
202   
203   if (debug_lvl & 2) cout << "Destroyed:    FGAircraft" << endl;
204 }
205
206 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207
208 bool FGAircraft::LoadAircraft(string aircraft_path, string engine_path, string fname) {
209   string path;
210   string filename;
211   string aircraftCfgFileName;
212   string token;
213
214   AircraftPath = aircraft_path;
215   EnginePath = engine_path;
216
217 # ifndef macintosh
218   aircraftCfgFileName = AircraftPath + "/" + fname + "/" + fname + ".xml";
219 # else
220   aircraftCfgFileName = AircraftPath + ";" + fname + ";" + fname + ".xml";
221 # endif
222
223   FGConfigFile AC_cfg(aircraftCfgFileName);
224   if (!AC_cfg.IsOpen()) return false;
225
226   ReadPrologue(&AC_cfg);
227
228   while ((AC_cfg.GetNextConfigLine() != "EOF") &&
229          (token = AC_cfg.GetValue()) != "/FDM_CONFIG") {
230     if (token == "METRICS") {
231       cout << fgcyan << "\n  Reading Metrics" << fgdef << endl;
232       ReadMetrics(&AC_cfg);
233     } else if (token == "AERODYNAMICS") {
234       cout << fgcyan << "\n  Reading Aerodynamics" << fgdef << endl;
235       ReadAerodynamics(&AC_cfg);
236     } else if (token == "UNDERCARRIAGE") {
237       cout << fgcyan << "\n  Reading Landing Gear" << fgdef << endl;
238       ReadUndercarriage(&AC_cfg);
239     } else if (token == "PROPULSION") {
240       cout << fgcyan << "\n  Reading Propulsion" << fgdef << endl;
241       ReadPropulsion(&AC_cfg);
242     } else if (token == "FLIGHT_CONTROL") {
243       cout << fgcyan << "\n  Reading Flight Control" << fgdef << endl;
244       ReadFlightControls(&AC_cfg);
245     } else if (token == "OUTPUT") {
246       cout << fgcyan << "\n  Reading Output directives" << fgdef << endl;
247       ReadOutput(&AC_cfg);
248     }
249   }
250
251   return true;
252 }
253
254 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
255
256 bool FGAircraft::Run(void) {
257   if (!FGModel::Run()) {                 // if false then execute this Run()
258     GetState();
259
260     for (int i = 1; i <= 3; i++)  vForces(i) = vMoments(i) = 0.0;
261
262     MassChange();
263     FMProp();
264     FMAero();
265     FMGear();
266     FMMass();
267
268     nlf = 0;
269     if (fabs(Position->GetGamma()) < 1.57) {
270         nlf = vFs(eZ)/(Weight*cos(Position->GetGamma()));
271     }    
272         
273   } else {                               // skip Run() execution this time
274   }
275
276
277   return false;
278 }
279
280 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
281
282 void FGAircraft::MassChange() {
283   static FGColumnVector vXYZtank(3);
284   float Tw;
285   float IXXt, IYYt, IZZt, IXZt;
286 //  unsigned int t;
287 //  unsigned int axis_ctr;
288 /*
289   for (axis_ctr=1; axis_ctr<=3; axis_ctr++) vXYZtank(axis_ctr) = 0.0;
290
291   // UPDATE TANK CONTENTS
292   //
293   // For each engine, cycle through the tanks and draw an equal amount of
294   // fuel (or oxidizer) from each active tank. The needed amount of fuel is
295   // determined by the engine in the FGEngine class. If more fuel is needed
296   // than is available in the tank, then that amount is considered a shortage,
297   // and will be drawn from the next tank. If the engine cannot be fed what it
298   // needs, it will be considered to be starved, and will shut down.
299
300   float Oshortage, Fshortage;
301
302   for (unsigned int e=0; e<numEngines; e++) {
303     Fshortage = Oshortage = 0.0;
304     for (t=0; t<numTanks; t++) {
305       switch(Engine[e]->GetType()) {
306       case FGEngine::etRocket:
307
308         switch(Tank[t]->GetType()) {
309         case FGTank::ttFUEL:
310           if (Tank[t]->GetSelected()) {
311             Fshortage = Tank[t]->Reduce((Engine[e]->CalcFuelNeed()/
312                                          numSelectedFuelTanks)*(dt*rate) + Fshortage);
313           }
314           break;
315         case FGTank::ttOXIDIZER:
316           if (Tank[t]->GetSelected()) {
317             Oshortage = Tank[t]->Reduce((Engine[e]->CalcOxidizerNeed()/
318                                          numSelectedOxiTanks)*(dt*rate) + Oshortage);
319           }
320           break;
321         }
322         break;
323
324       case FGEngine::etPiston:
325       case FGEngine::etTurboJet:
326       case FGEngine::etTurboProp:
327
328         if (Tank[t]->GetSelected()) {
329           Fshortage = Tank[t]->Reduce((Engine[e]->CalcFuelNeed()/
330                                        numSelectedFuelTanks)*(dt*rate) + Fshortage);
331         }
332         break;
333       }
334     }
335     if ((Fshortage <= 0.0) || (Oshortage <= 0.0)) Engine[e]->SetStarved();
336     else Engine[e]->SetStarved(false);
337   }
338 */
339   Weight = EmptyWeight;
340 //  for (t=0; t<numTanks; t++)
341 //    Weight += Tank[t]->GetContents();
342
343   Mass = Weight / GRAVITY;
344   // Calculate new CG here.
345
346   Tw = 0;
347 //  for (t=0; t<numTanks; t++) {
348 //    vXYZtank(eX) += Tank[t]->GetX()*Tank[t]->GetContents();
349 //    vXYZtank(eY) += Tank[t]->GetY()*Tank[t]->GetContents();
350 //    vXYZtank(eZ) += Tank[t]->GetZ()*Tank[t]->GetContents();
351 //
352 //    Tw += Tank[t]->GetContents();
353 //  }
354
355   vXYZcg = (vXYZtank + EmptyWeight*vbaseXYZcg) / (Tw + EmptyWeight);
356
357   // Calculate new moments of inertia here
358
359   IXXt = IYYt = IZZt = IXZt = 0.0;
360 //  for (t=0; t<numTanks; t++) {
361 //    IXXt += ((Tank[t]->GetX()-vXYZcg(eX))/12.0)*((Tank[t]->GetX() - vXYZcg(eX))/12.0)*Tank[t]->GetContents()/GRAVITY;
362 //    IYYt += ((Tank[t]->GetY()-vXYZcg(eY))/12.0)*((Tank[t]->GetY() - vXYZcg(eY))/12.0)*Tank[t]->GetContents()/GRAVITY;
363 //    IZZt += ((Tank[t]->GetZ()-vXYZcg(eZ))/12.0)*((Tank[t]->GetZ() - vXYZcg(eZ))/12.0)*Tank[t]->GetContents()/GRAVITY;
364 //    IXZt += ((Tank[t]->GetX()-vXYZcg(eX))/12.0)*((Tank[t]->GetZ() - vXYZcg(eZ))/12.0)*Tank[t]->GetContents()/GRAVITY;
365 //  }
366
367   Ixx = baseIxx + IXXt;
368   Iyy = baseIyy + IYYt;
369   Izz = baseIzz + IZZt;
370   Ixz = baseIxz + IXZt;
371
372 }
373
374 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
375
376 void FGAircraft::FMAero(void) {
377   static FGColumnVector vDXYZcg(3);
378   static FGColumnVector vAeroBodyForces(3);
379   unsigned int axis_ctr,ctr;
380
381   for (axis_ctr=1; axis_ctr<=3; axis_ctr++) vFs(axis_ctr) = 0.0;
382
383   for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
384     for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
385       vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
386     }
387   }
388
389   vAeroBodyForces = State->GetTs2b(alpha, beta)*vFs;
390   vForces += vAeroBodyForces;
391
392   // see http://home.earthlink.net/~apeden/jsbsim_moments_due_to_forces.txt
393   // for details on this
394   vDXYZcg(eX) = -(vXYZrp(eX) - vXYZcg(eX))/12.0;  //cg and rp values are in inches
395   vDXYZcg(eY) =  (vXYZrp(eY) - vXYZcg(eY))/12.0;
396   vDXYZcg(eZ) = -(vXYZrp(eZ) - vXYZcg(eZ))/12.0;
397
398   vMoments(eL) += vAeroBodyForces(eZ)*vDXYZcg(eY) - vAeroBodyForces(eY)*vDXYZcg(eZ); // rolling moment
399   vMoments(eM) += vAeroBodyForces(eX)*vDXYZcg(eZ) - vAeroBodyForces(eZ)*vDXYZcg(eX); // pitching moment
400   vMoments(eN) += vAeroBodyForces(eY)*vDXYZcg(eX) - vAeroBodyForces(eX)*vDXYZcg(eY); // yawing moment
401   
402   for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
403     for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
404       vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
405     }
406   }
407 }
408
409 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410
411 void FGAircraft::FMGear(void) {
412
413   if ( !GearUp ) {
414     vector <FGLGear>::iterator iGear = lGear.begin();
415     while (iGear != lGear.end()) {
416       vForces  += iGear->Force();
417       vMoments += iGear->Moment();
418       iGear++;
419     }
420   } else {
421     // Crash Routine
422   }
423 }
424
425 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426
427 void FGAircraft::FMMass(void) {
428   vForces(eX) += -GRAVITY*sin(vEuler(eTht)) * Mass;
429   vForces(eY) +=  GRAVITY*sin(vEuler(ePhi))*cos(vEuler(eTht)) * Mass;
430   vForces(eZ) +=  GRAVITY*cos(vEuler(ePhi))*cos(vEuler(eTht)) * Mass;
431 }
432
433 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
434
435 void FGAircraft::FMProp(void) {
436     vForces += Propulsion->GetForces();
437     vMoments += Propulsion->GetMoments();
438 }
439
440 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
441
442 void FGAircraft::GetState(void) {
443   dt = State->Getdt();
444
445   alpha = Translation->Getalpha();
446   beta = Translation->Getbeta();
447   vEuler = Rotation->GetEuler();
448 }
449
450 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
452 void FGAircraft::ReadMetrics(FGConfigFile* AC_cfg) {
453   string token = "";
454   string parameter;
455
456   AC_cfg->GetNextConfigLine();
457
458   while ((token = AC_cfg->GetValue()) != "/METRICS") {
459     *AC_cfg >> parameter;
460     if (parameter == "AC_WINGAREA") {
461         *AC_cfg >> WingArea;
462         cout << "    WingArea: " << WingArea  << endl; 
463     } else if (parameter == "AC_WINGSPAN") {
464         *AC_cfg >> WingSpan;
465         cout << "    WingSpan: " << WingSpan  << endl;
466     } else if (parameter == "AC_CHORD") {
467         *AC_cfg >> cbar;
468         cout << "    Chord: " << cbar << endl;
469     } else if (parameter == "AC_IXX") {
470         *AC_cfg >> baseIxx;
471         cout << "    baseIxx: " << baseIxx << endl;
472     } else if (parameter == "AC_IYY") {
473         *AC_cfg >> baseIyy;
474         cout << "    baseIyy: " << baseIyy << endl;
475     } else if (parameter == "AC_IZZ") { 
476         *AC_cfg >> baseIzz;
477         cout << "    baseIzz: " << baseIzz << endl;
478     } else if (parameter == "AC_IXZ") { 
479         *AC_cfg >> baseIxz;
480         cout << "    baseIxz: " << baseIxz  << endl;
481     } else if (parameter == "AC_EMPTYWT") {
482         *AC_cfg >> EmptyWeight;
483         cout << "    EmptyWeight: " << EmptyWeight  << endl;
484     } else if (parameter == "AC_CGLOC") {
485         *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
486         cout << "    CG (x, y, z): " << vbaseXYZcg << endl;
487     } else if (parameter == "AC_EYEPTLOC") {
488         *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
489         cout << "    Eyepoint (x, y, z): " << vXYZep << endl;
490     } else if (parameter == "AC_AERORP") {
491         *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
492         cout << "    Ref Pt (x, y, z): " << vXYZrp << endl;
493     } else if (parameter == "AC_ALPHALIMITS") {
494         *AC_cfg >> alphaclmin >> alphaclmax;
495         cout << "    Maximum Alpha: " << alphaclmax
496              << "    Minimum Alpha: " << alphaclmin 
497              << endl;
498     }         
499   }
500 }
501
502 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
503
504 void FGAircraft::ReadPropulsion(FGConfigFile* AC_cfg) {
505   if (!Propulsion->LoadPropulsion(AC_cfg)) {
506     cerr << "Propulsion not successfully loaded" << endl;
507   }
508 }
509
510 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
511
512 void FGAircraft::ReadFlightControls(FGConfigFile* AC_cfg) {
513   if (!FCS->LoadFCS(AC_cfg)) {
514     cerr << "Flight Controls not successfully loaded" << endl;
515   }
516 }
517
518 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
519
520 void FGAircraft::ReadAerodynamics(FGConfigFile* AC_cfg) {
521   string token, axis;
522
523   AC_cfg->GetNextConfigLine();
524   
525   while ((token = AC_cfg->GetValue()) != "/AERODYNAMICS") {
526     if (token == "AXIS") {
527       CoeffArray ca;
528       axis = AC_cfg->GetValue("NAME");
529       AC_cfg->GetNextConfigLine();
530       while ((token = AC_cfg->GetValue()) != "/AXIS") {
531         ca.push_back(new FGCoefficient(FDMExec, AC_cfg));
532         DisplayCoeffFactors(ca.back()->Getmultipliers());
533       }
534       Coeff[AxisIdx[axis]]=ca;
535       AC_cfg->GetNextConfigLine();
536     }
537   }
538 }
539
540 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541
542 void FGAircraft::ReadUndercarriage(FGConfigFile* AC_cfg) {
543   string token;
544
545   AC_cfg->GetNextConfigLine();
546
547   while ((token = AC_cfg->GetValue()) != "/UNDERCARRIAGE") {
548     lGear.push_back(FGLGear(AC_cfg, FDMExec));
549   }
550 }
551
552 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
553
554 void FGAircraft::ReadOutput(FGConfigFile* AC_cfg) {
555   string token, parameter;
556   int OutRate = 0;
557   int subsystems = 0;
558
559   token = AC_cfg->GetValue("NAME");
560   Output->SetFilename(token);
561   token = AC_cfg->GetValue("TYPE");
562   Output->SetType(token);
563   AC_cfg->GetNextConfigLine();
564
565   while ((token = AC_cfg->GetValue()) != "/OUTPUT") {
566     *AC_cfg >> parameter;
567     if (parameter == "RATE_IN_HZ") *AC_cfg >> OutRate;
568     if (parameter == "SIMULATION") {
569       *AC_cfg >> parameter;
570       if (parameter == "ON") subsystems += ssSimulation;
571     }
572     if (parameter == "AEROSURFACES") {
573       *AC_cfg >> parameter;
574       if (parameter == "ON") subsystems += ssAerosurfaces;
575     }
576     if (parameter == "RATES") {
577       *AC_cfg >> parameter;
578       if (parameter == "ON") subsystems += ssRates;
579     }
580     if (parameter == "VELOCITIES") {
581       *AC_cfg >> parameter;
582       if (parameter == "ON") subsystems += ssVelocities;
583     }
584     if (parameter == "FORCES") {
585       *AC_cfg >> parameter;
586       if (parameter == "ON") subsystems += ssForces;
587     }
588     if (parameter == "MOMENTS") {
589       *AC_cfg >> parameter;
590       if (parameter == "ON") subsystems += ssMoments;
591     }
592     if (parameter == "ATMOSPHERE") {
593       *AC_cfg >> parameter;
594       if (parameter == "ON") subsystems += ssAtmosphere;
595     }
596     if (parameter == "MASSPROPS") {
597       *AC_cfg >> parameter;
598       if (parameter == "ON") subsystems += ssMassProps;
599     }
600     if (parameter == "POSITION") {
601       *AC_cfg >> parameter;
602       if (parameter == "ON") subsystems += ssPosition;
603     }
604     if (parameter == "COEFFICIENTS") {
605       *AC_cfg >> parameter;
606       if (parameter == "ON") subsystems += ssCoefficients;
607     }
608     if (parameter == "GROUND_REACTIONS") {
609       *AC_cfg >> parameter;
610       if (parameter == "ON") subsystems += ssGroundReactions;
611     }
612     if (parameter == "FCS") {
613       *AC_cfg >> parameter;
614       if (parameter == "ON") subsystems += ssFCS;
615     }
616   }
617
618   Output->SetSubsystems(subsystems);
619
620   OutRate = OutRate>120?120:(OutRate<0?0:OutRate);
621   Output->SetRate( (int)(0.5 + 1.0/(State->Getdt()*OutRate)) );
622 }
623
624 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
625
626 void FGAircraft::ReadPrologue(FGConfigFile* AC_cfg) {
627   string token = AC_cfg->GetValue();
628   string scratch;
629   AircraftName = AC_cfg->GetValue("NAME");
630   cout << underon << "Reading Aircraft Configuration File" << underoff << ": "
631                        << highint << AircraftName << normint << endl;
632   scratch = AC_cfg->GetValue("VERSION").c_str();
633
634   CFGVersion = AC_cfg->GetValue("VERSION");
635   cout << "                            Version: " << highint << CFGVersion
636                                                              << normint << endl;
637   if (CFGVersion != NEEDED_CFG_VERSION) {
638     cout << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
639     " RESULTS WILL BE UNPREDICTABLE !!" << endl;
640     cout << "Current version needed is: " << NEEDED_CFG_VERSION << endl;
641     cout << "         You have version: " << CFGVersion << endl << fgdef << endl;
642     //exit(-1);
643   }
644
645
646 }
647
648 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
649
650 void FGAircraft::DisplayCoeffFactors(vector <eParam> multipliers) {
651   cout << "   Non-Dimensionalized by: ";
652
653   for (unsigned int i=0; i<multipliers.size();i++)
654     cout << State->paramdef[multipliers[i]];
655
656   cout << endl;
657 }
658
659 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
660
661 string FGAircraft::GetCoefficientStrings(void) {
662   string CoeffStrings = "";
663   bool firstime = true;
664
665   for (unsigned int axis = 0; axis < 6; axis++) {
666     for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
667       if (firstime) {
668         firstime = false;
669       } else {
670         CoeffStrings += ", ";
671       }
672       CoeffStrings += Coeff[axis][sd]->Getname();
673     }
674   }
675
676   return CoeffStrings;
677 }
678
679 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
680
681 string FGAircraft::GetCoefficientValues(void) {
682   string SDValues = "";
683   char buffer[10];
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         SDValues += ", ";
692       }
693       sprintf(buffer, "%9.6f", Coeff[axis][sd]->GetSD());
694       SDValues += string(buffer);
695     }
696   }
697
698   return SDValues;
699 }
700
701 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
702
703 string FGAircraft::GetGroundReactionStrings(void) {
704   string GroundReactionStrings = "";
705   bool firstime = true;
706
707   for (unsigned int i=0;i<lGear.size();i++) {
708     if (!firstime) GroundReactionStrings += ", ";
709     GroundReactionStrings += (lGear[i].GetName() + "_WOW, ");
710     GroundReactionStrings += (lGear[i].GetName() + "_compressLength, ");
711     GroundReactionStrings += (lGear[i].GetName() + "_compressSpeed, ");
712     GroundReactionStrings += (lGear[i].GetName() + "_Force");
713
714     firstime = false;
715   }
716
717   return GroundReactionStrings;
718 }
719
720 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
721
722 string FGAircraft::GetGroundReactionValues(void) {
723   char buff[20];
724   string GroundReactionValues = "";
725
726   bool firstime = true;
727
728   for (unsigned int i=0;i<lGear.size();i++) {
729     if (!firstime) GroundReactionValues += ", ";
730     GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", ";
731     GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(),    5, buff)) + ", ");
732     GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(),    6, buff)) + ", ");
733     GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff)));
734
735     firstime = false;
736   }
737
738   return GroundReactionValues;
739 }
740
741 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742
743 void FGAircraft::Debug(void)
744 {
745     //TODO: Add your source code here
746 }
747