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