]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFDMExec.cpp
ab37dac38e85e7ad9b76ec32644b1227fa1347f4
[flightgear.git] / src / FDM / JSBSim / FGFDMExec.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGFDMExec.cpp
4  Author:       Jon S. Berndt
5  Date started: 11/17/98
6  Purpose:      Schedules and runs the model routines.
7
8  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
9
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  details.
19
20  You should have received a copy of the GNU General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29
30 This class wraps up the simulation scheduling routines.
31
32 HISTORY
33 --------------------------------------------------------------------------------
34 11/17/98   JSB   Created
35
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 COMMENTS, REFERENCES,  and NOTES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 INCLUDES
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43
44 #ifdef HAVE_CONFIG_H
45 #  include <config.h>
46 #endif
47
48 #ifdef FGFS
49 #  include <simgear/compiler.h>
50 #  include STL_IOSTREAM
51 #  include STL_ITERATOR
52 #else
53 #  if defined(sgi) && !defined(__GNUC__) && (_COMPILER_VERSION < 740)
54 #    include <iostream.h>
55 #  else
56 #    include <iostream>
57 #  endif
58 #  include <iterator>
59 #endif
60
61 #include "FGFDMExec.h"
62 #include "FGState.h"
63 #include "FGAtmosphere.h"
64 #include "FGFCS.h"
65 #include "FGGroundCallback.h"
66 #include "FGPropulsion.h"
67 #include "FGMassBalance.h"
68 #include "FGGroundReactions.h"
69 #include "FGAerodynamics.h"
70 #include "FGInertial.h"
71 #include "FGAircraft.h"
72 #include "FGPropagate.h"
73 #include "FGAuxiliary.h"
74 #include "FGOutput.h"
75 #include "FGConfigFile.h"
76 #include "FGInitialCondition.h"
77 #include "FGPropertyManager.h"
78
79 namespace JSBSim {
80
81 static const char *IdSrc = "$Id$";
82 static const char *IdHdr = ID_FDMEXEC;
83
84 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 GLOBAL DECLARATIONS
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
87
88 unsigned int FGFDMExec::FDMctr = 0;
89 FGPropertyManager* FGFDMExec::master=0;
90
91 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 CLASS IMPLEMENTATION
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
94
95 void checkTied ( FGPropertyManager *node )
96 {
97   int N = node->nChildren();
98   string name;
99
100   for (int i=0; i<N; i++) {
101     if (node->getChild(i)->nChildren() ) {
102       checkTied( (FGPropertyManager*)node->getChild(i) );
103     } else if ( node->getChild(i)->isTied() ) {
104       name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
105       cerr << name << " is tied" << endl;
106     }
107   }
108 }
109
110 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 // Constructor
112
113 FGFDMExec::FGFDMExec(FGPropertyManager* root)
114 {
115
116   Frame           = 0;
117   FirstModel      = 0;
118   Error           = 0;
119   State           = 0;
120   Atmosphere      = 0;
121   FCS             = 0;
122   Propulsion      = 0;
123   MassBalance     = 0;
124   Aerodynamics    = 0;
125   Inertial        = 0;
126   GroundReactions = 0;
127   Aircraft        = 0;
128   GroundCallback  = 0;
129   Propagate       = 0;
130   Auxiliary       = 0;
131   Output          = 0;
132   IC              = 0;
133   Trim            = 0;
134
135   terminate = false;
136   frozen = false;
137   modelLoaded = false;
138   IsSlave = false;
139
140   // Multiple FDM's are stopped for now.  We need to ensure that
141   // the "user" instance always gets the zeroeth instance number,
142   // because there may be instruments or scripts tied to properties
143   // in the jsbsim[0] node.
144   IdFDM = FDMctr;
145   //FDMctr++;
146
147   try {
148     char* num = getenv("JSBSIM_DEBUG");
149     if (num) debug_lvl = atoi(num); // set debug level
150   } catch (...) {               // if error set to 1
151     debug_lvl = 1;
152   }
153
154   if (root == 0)  master= new FGPropertyManager;
155   else            master = root;
156
157   instance = master->GetNode("/fdm/jsbsim",IdFDM,true);
158
159
160   Debug(0);
161
162   // this is here to catch errors in binding member functions
163   // to the property tree.
164   try {
165     Allocate();
166   } catch ( string msg ) {
167     cout << "Caught error: " << msg << endl;
168     exit(1);
169   }
170 }
171
172 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173
174 FGFDMExec::~FGFDMExec()
175 {
176   try {
177     DeAllocate();
178     checkTied( instance );
179   } catch ( string msg ) {
180     cout << "Caught error: " << msg << endl;
181   }
182
183   for (unsigned int i=1; i<SlaveFDMList.size(); i++) delete SlaveFDMList[i]->exec;
184   SlaveFDMList.clear();
185
186   Debug(1);
187 }
188
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190
191 bool FGFDMExec::Allocate(void)
192 {
193   bool result=true;
194
195   Atmosphere      = new FGAtmosphere(this);
196   FCS             = new FGFCS(this);
197   Propulsion      = new FGPropulsion(this);
198   MassBalance     = new FGMassBalance(this);
199   Aerodynamics    = new FGAerodynamics (this);
200   Inertial        = new FGInertial(this);
201   GroundReactions = new FGGroundReactions(this);
202   Aircraft        = new FGAircraft(this);
203   GroundCallback  = new FGGroundCallback();
204   Propagate       = new FGPropagate(this);
205   Auxiliary       = new FGAuxiliary(this);
206   Output          = new FGOutput(this);
207
208   State        = new FGState(this); // This must be done here, as the FGState
209                                     // class needs valid pointers to the above
210                                     // model classes
211
212   // Initialize models so they can communicate with each other
213
214   if (!Atmosphere->InitModel()) {
215     cerr << fgred << "Atmosphere model init failed" << fgdef << endl;
216     Error+=1;}
217   if (!FCS->InitModel())        {
218     cerr << fgred << "FCS model init failed" << fgdef << endl;
219     Error+=2;}
220   if (!Propulsion->InitModel()) {
221     cerr << fgred << "FGPropulsion model init failed" << fgdef << endl;
222     Error+=4;}
223   if (!MassBalance->InitModel()) {
224     cerr << fgred << "FGMassBalance model init failed" << fgdef << endl;
225     Error+=8;}
226   if (!Aerodynamics->InitModel()) {
227     cerr << fgred << "FGAerodynamics model init failed" << fgdef << endl;
228     Error+=16;}
229   if (!Inertial->InitModel()) {
230     cerr << fgred << "FGInertial model init failed" << fgdef << endl;
231     Error+=32;}
232   if (!GroundReactions->InitModel())   {
233     cerr << fgred << "Ground Reactions model init failed" << fgdef << endl;
234     Error+=64;}
235   if (!Aircraft->InitModel())   {
236     cerr << fgred << "Aircraft model init failed" << fgdef << endl;
237     Error+=128;}
238   if (!Propagate->InitModel())   {
239     cerr << fgred << "Propagate model init failed" << fgdef << endl;
240     Error+=512;}
241   if (!Auxiliary->InitModel())  {
242     cerr << fgred << "Auxiliary model init failed" << fgdef << endl;
243     Error+=2058;}
244   if (!Output->InitModel())     {
245     cerr << fgred << "Output model init failed" << fgdef << endl;
246     Error+=4096;}
247
248   if (Error > 0) result = false;
249
250   IC = new FGInitialCondition(this);
251
252   // Schedule a model. The second arg (the integer) is the pass number. For
253   // instance, the atmosphere model gets executed every fifth pass it is called
254   // by the executive. Everything else here gets executed each pass.
255   // IC and Trim objects are NOT scheduled.
256
257   Schedule(Atmosphere,      1);
258   Schedule(FCS,             1);
259   Schedule(Propulsion,      1);
260   Schedule(MassBalance,     1);
261   Schedule(Aerodynamics,    1);
262   Schedule(Inertial,        1);
263   Schedule(GroundReactions, 1);
264   Schedule(Aircraft,        1);
265   Schedule(Propagate,       1);
266   Schedule(Auxiliary,       1);
267   Schedule(Output,          1);
268
269   modelLoaded = false;
270
271   return result;
272 }
273
274 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275
276 bool FGFDMExec::DeAllocate(void)
277 {
278   delete Atmosphere;
279   delete FCS;
280   delete Propulsion;
281   delete MassBalance;
282   delete Aerodynamics;
283   delete Inertial;
284   delete GroundReactions;
285   delete Aircraft;
286   delete Propagate;
287   delete Auxiliary;
288   delete Output;
289   delete State;
290
291   delete IC;
292   delete Trim;
293
294   delete GroundCallback;
295
296   FirstModel  = 0L;
297   Error       = 0;
298
299   State           = 0;
300   Atmosphere      = 0;
301   FCS             = 0;
302   Propulsion      = 0;
303   MassBalance     = 0;
304   Aerodynamics    = 0;
305   Inertial        = 0;
306   GroundReactions = 0;
307   Aircraft        = 0;
308   Propagate       = 0;
309   Auxiliary       = 0;
310   Output          = 0;
311
312   modelLoaded = false;
313   return modelLoaded;
314 }
315
316 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
317
318 int FGFDMExec::Schedule(FGModel* model, int rate)
319 {
320   FGModel* model_iterator;
321
322   model_iterator = FirstModel;
323
324   if (model_iterator == 0L) {                  // this is the first model
325
326     FirstModel = model;
327     FirstModel->NextModel = 0L;
328     FirstModel->SetRate(rate);
329
330   } else {                                     // subsequent model
331
332     while (model_iterator->NextModel != 0L) {
333       model_iterator = model_iterator->NextModel;
334     }
335     model_iterator->NextModel = model;
336     model_iterator->NextModel->SetRate(rate);
337
338   }
339
340   return 0;
341 }
342
343 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344
345 bool FGFDMExec::Run(void)
346 {
347   FGModel* model_iterator;
348
349   if (frozen) return true;
350
351   model_iterator = FirstModel;
352   if (model_iterator == 0L) return false;
353
354   Debug(2);
355
356   for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
357 //    SlaveFDMList[i]->exec->State->Initialize(); // Transfer state to the slave FDM
358 //    SlaveFDMList[i]->exec->Run();
359   }
360
361   while (model_iterator != 0L) {
362     model_iterator->Run();
363     model_iterator = model_iterator->NextModel;
364   }
365
366   frame = Frame++;
367   State->IncrTime();
368   return true;
369 }
370
371 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372
373 bool FGFDMExec::RunIC(void)
374 {
375   State->Suspend();
376   State->Initialize(IC);
377   Run();
378   State->Resume();
379
380   return true;
381 }
382
383 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
384
385 void FGFDMExec::SetGroundCallback(FGGroundCallback* p) {
386   if (GroundCallback)
387     delete GroundCallback;
388   GroundCallback = p;
389 }
390
391 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392
393 vector <string> FGFDMExec::EnumerateFDMs(void)
394 {
395   vector <string> FDMList;
396
397   FDMList.push_back(Aircraft->GetAircraftName());
398
399   for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
400     FDMList.push_back(SlaveFDMList[i]->exec->GetAircraft()->GetAircraftName());
401   }
402
403   return FDMList;
404 }
405
406 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
407
408 bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string model,
409                 bool addModelToPath)
410 {
411
412   FGFDMExec::AircraftPath = AircraftPath;
413   FGFDMExec::EnginePath = EnginePath;
414
415   return LoadModel(model, addModelToPath);
416 }
417
418 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
419
420
421 bool FGFDMExec::LoadModel(string model, bool addModelToPath)
422 {
423   
424   bool result = true;
425   string token;
426   string aircraftCfgFileName;
427
428   if( AircraftPath.empty() || EnginePath.empty() ) {
429     cerr << "Error: attempted to load aircraft with undefined ";
430     cerr << "aircraft and engine paths" << endl;
431     return false;
432   }
433
434   aircraftCfgFileName = AircraftPath;
435 # ifndef macintosh
436   if (addModelToPath) aircraftCfgFileName += "/" + model;
437   aircraftCfgFileName += "/" + model + ".xml";
438 # else
439   if (addModelToPath) aircraftCfgFileName += ";"  + model;
440   aircraftCfgFileName += ";"  + model + ".xml";
441 # endif
442
443   FGConfigFile AC_cfg(aircraftCfgFileName);
444   if (!AC_cfg.IsOpen()) return false;
445
446   modelName = model;
447
448   if (modelLoaded) {
449     DeAllocate();
450     Allocate();
451   }
452
453   if (!ReadPrologue(&AC_cfg)) return false;
454
455   while ((AC_cfg.GetNextConfigLine() != string("EOF")) &&
456          (token = AC_cfg.GetValue()) != string("/FDM_CONFIG")) {
457     if (token == "METRICS") {
458       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Metrics" << fgdef << endl;
459       if (!ReadMetrics(&AC_cfg)) result = false;
460     } else if (token == "SLAVE") {
461       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Slave flight vehicle: " << fgdef
462                                         << AC_cfg.GetValue("NAME") << endl;
463       if (!ReadSlave(&AC_cfg)) result = false;
464     } else if (token == "AERODYNAMICS") {
465       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Aerodynamics" << fgdef << endl;
466       if (!ReadAerodynamics(&AC_cfg)) result = false;
467     } else if (token == "UNDERCARRIAGE") {
468       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Landing Gear" << fgdef << endl;
469       if (!ReadUndercarriage(&AC_cfg)) result = false;
470     } else if (token == "PROPULSION") {
471       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Propulsion" << fgdef << endl;
472       if (!ReadPropulsion(&AC_cfg)) result = false;
473     } else if (token == "FLIGHT_CONTROL") {
474       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Flight Control" << fgdef << endl;
475       if (!ReadFlightControls(&AC_cfg)) result = false;
476     } else if (token == "AUTOPILOT") {
477       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Autopilot" << fgdef << endl;
478       if (!ReadFlightControls(&AC_cfg)) result = false;
479     } else if (token == "OUTPUT") {
480       if (debug_lvl > 0) cout << fgcyan << "\n  Reading Output directives" << fgdef << endl;
481       if (!ReadOutput(&AC_cfg)) result = false;
482     }
483   }
484
485   if (result) {
486     modelLoaded = true;
487     Debug(3);
488   } else {
489     cerr << fgred
490          << "  FGFDMExec: Failed to load aircraft and/or engine model"
491          << fgdef << endl;
492   }
493
494   return result;
495 }
496
497 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
498
499 bool FGFDMExec::ReadPrologue(FGConfigFile* AC_cfg)
500 {
501   string token = AC_cfg->GetValue();
502   string scratch;
503   string AircraftName;
504
505   AircraftName = AC_cfg->GetValue("NAME");
506   Aircraft->SetAircraftName(AircraftName);
507
508   if (debug_lvl > 0) cout << underon << "Reading Aircraft Configuration File"
509             << underoff << ": " << highint << AircraftName << normint << endl;
510   scratch = AC_cfg->GetValue("VERSION").c_str();
511
512   CFGVersion = AC_cfg->GetValue("VERSION");
513   Release    = AC_cfg->GetValue("RELEASE");
514
515   if (debug_lvl > 0)
516     cout << "                            Version: " << highint << CFGVersion
517                                                     << normint << endl;
518   if (CFGVersion != needed_cfg_version) {
519     cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
520             " RESULTS WILL BE UNPREDICTABLE !!" << endl;
521     cerr << "Current version needed is: " << needed_cfg_version << endl;
522     cerr << "         You have version: " << CFGVersion << endl << fgdef << endl;
523     return false;
524   }
525
526   if (Release == "ALPHA" && debug_lvl > 0) {
527 #ifndef _MSC_VER
528     system("banner ALPHA");
529 #endif
530     cout << endl << endl
531          << highint << "This aircraft model is an " << fgred << Release
532          << reset << highint << " release!!!" << endl << endl << reset
533          << "This aircraft model may not even properly load, and probably"
534          << " will not fly as expected." << endl << endl
535          << fgred << highint << "Use this model for development purposes ONLY!!!"
536          << normint << reset << endl << endl;
537   } else if (Release == "BETA" && debug_lvl > 0) {
538 #ifndef _MSC_VER
539     system("banner BETA");
540 #endif
541     cout << endl << endl
542          << highint << "This aircraft model is a " << fgred << Release
543          << reset << highint << " release!!!" << endl << endl << reset
544          << "This aircraft model probably will not fly as expected." << endl << endl
545          << fgblue << highint << "Use this model for development purposes ONLY!!!"
546          << normint << reset << endl << endl;
547   }
548
549   return true;
550 }
551
552 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
553
554 bool FGFDMExec::ReadSlave(FGConfigFile* AC_cfg)
555 {
556   // Add a new slaveData object to the slave FDM list
557   // Populate that slaveData element with a new FDMExec object
558   // Set the IsSlave flag for that FDMExec object
559   // Get the aircraft name
560   // set debug level to print out no additional data for slave objects
561   // Load the model given the aircraft name
562   // reset debug level to prior setting
563
564   int saved_debug_lvl = debug_lvl;
565   string token;
566
567   SlaveFDMList.push_back(new slaveData);
568   SlaveFDMList.back()->exec = new FGFDMExec();
569   SlaveFDMList.back()->exec->SetSlave();
570
571   string AircraftName = AC_cfg->GetValue("FILE");
572
573   debug_lvl = 0;                 // turn off debug output for slave vehicle
574
575   SlaveFDMList.back()->exec->SetAircraftPath( AircraftPath );
576   SlaveFDMList.back()->exec->SetEnginePath( EnginePath );
577   SlaveFDMList.back()->exec->LoadModel(AircraftName);
578   debug_lvl = saved_debug_lvl;   // turn debug output back on for master vehicle
579
580   AC_cfg->GetNextConfigLine();
581   while ((token = AC_cfg->GetValue()) != string("/SLAVE")) {
582     *AC_cfg >> token;
583     if      (token == "XLOC")  { *AC_cfg >> SlaveFDMList.back()->x;    }
584     else if (token == "YLOC")  { *AC_cfg >> SlaveFDMList.back()->y;    }
585     else if (token == "ZLOC")  { *AC_cfg >> SlaveFDMList.back()->z;    }
586     else if (token == "PITCH") { *AC_cfg >> SlaveFDMList.back()->pitch;}
587     else if (token == "YAW")   { *AC_cfg >> SlaveFDMList.back()->yaw;  }
588     else if (token == "ROLL")  { *AC_cfg >> SlaveFDMList.back()->roll;  }
589     else cerr << "Unknown identifier: " << token << " in slave vehicle definition" << endl;
590   }
591
592   if (debug_lvl > 0)  {
593     cout << "      X = " << SlaveFDMList.back()->x << endl;
594     cout << "      Y = " << SlaveFDMList.back()->y << endl;
595     cout << "      Z = " << SlaveFDMList.back()->z << endl;
596     cout << "      Pitch = " << SlaveFDMList.back()->pitch << endl;
597     cout << "      Yaw = " << SlaveFDMList.back()->yaw << endl;
598     cout << "      Roll = " << SlaveFDMList.back()->roll << endl;
599   }
600
601   return true;
602 }
603
604 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
605
606 bool FGFDMExec::ReadPropulsion(FGConfigFile* AC_cfg)
607 {
608   if (!Propulsion->Load(AC_cfg)) {
609     cerr << "  Propulsion not successfully loaded" << endl;
610     return false;
611   }
612   return true;
613 }
614
615 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
616
617 bool FGFDMExec::ReadFlightControls(FGConfigFile* AC_cfg)
618 {
619   if (!FCS->Load(AC_cfg)) {
620     cerr << "  Flight Controls not successfully loaded" << endl;
621     return false;
622   }
623   return true;
624 }
625
626 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
627
628 bool FGFDMExec::ReadAerodynamics(FGConfigFile* AC_cfg)
629 {
630   if (!Aerodynamics->Load(AC_cfg)) {
631     cerr << "  Aerodynamics not successfully loaded" << endl;
632     return false;
633   }
634   return true;
635 }
636
637 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
638
639 bool FGFDMExec::ReadUndercarriage(FGConfigFile* AC_cfg)
640 {
641   if (!GroundReactions->Load(AC_cfg)) {
642     cerr << "  Ground Reactions not successfully loaded" << endl;
643     return false;
644   }
645   return true;
646 }
647
648 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
649
650 bool FGFDMExec::ReadMetrics(FGConfigFile* AC_cfg)
651 {
652   if (!Aircraft->Load(AC_cfg)) {
653     cerr << "  Aircraft metrics not successfully loaded" << endl;
654     return false;
655   }
656   return true;
657 }
658
659 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
660
661 bool FGFDMExec::ReadOutput(FGConfigFile* AC_cfg)
662 {
663   if (!Output->Load(AC_cfg)) {
664     cerr << "  Output not successfully loaded" << endl;
665     return false;
666   }
667   return true;
668 }
669
670 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
671
672 FGPropertyManager* FGFDMExec::GetPropertyManager(void) {
673   return instance;
674 }
675
676 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
677
678 FGTrim* FGFDMExec::GetTrim(void) {
679   delete Trim;
680   Trim = new FGTrim(this,tNone);
681   return Trim;
682 }
683
684 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
685 //    The bitmasked value choices are as follows:
686 //    unset: In this case (the default) JSBSim would only print
687 //       out the normally expected messages, essentially echoing
688 //       the config files as they are read. If the environment
689 //       variable is not set, debug_lvl is set to 1 internally
690 //    0: This requests JSBSim not to output any messages
691 //       whatsoever.
692 //    1: This value explicity requests the normal JSBSim
693 //       startup messages
694 //    2: This value asks for a message to be printed out when
695 //       a class is instantiated
696 //    4: When this value is set, a message is displayed when a
697 //       FGModel object executes its Run() method
698 //    8: When this value is set, various runtime state variables
699 //       are printed out periodically
700 //    16: When set various parameters are sanity checked and
701 //       a message is printed out when they go out of bounds
702
703 void FGFDMExec::Debug(int from)
704 {
705   if (debug_lvl <= 0) return;
706
707   if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
708     if (from == 0) { // Constructor
709       cout << "\n\n     " << highint << underon << "JSBSim Flight Dynamics Model v"
710                                      << JSBSim_version << underoff << normint << endl;
711       cout << halfint << "            [cfg file spec v" << needed_cfg_version << "]\n\n";
712       cout << normint << "JSBSim startup beginning ...\n\n";
713     } else if (from == 3) {
714       cout << "\n\nJSBSim startup complete\n\n";
715     }
716   }
717   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
718     if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
719     if (from == 1) cout << "Destroyed:    FGFDMExec" << endl;
720   }
721   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
722     if (from == 2) {
723       cout << "================== Frame: " << Frame << "  Time: "
724            << State->Getsim_time() << endl;
725     }
726   }
727   if (debug_lvl & 8 ) { // Runtime state variables
728   }
729   if (debug_lvl & 16) { // Sanity checking
730   }
731   if (debug_lvl & 64) {
732     if (from == 0) { // Constructor
733       cout << IdSrc << endl;
734       cout << IdHdr << endl;
735     }
736   }
737 }
738 }
739