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