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