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