1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Schedules and runs the model routines.
8 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
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 Lesser General Public License for more
20 You should have received a copy of the GNU Lesser 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.
24 Further information about the GNU Lesser General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
30 This class wraps up the simulation scheduling routines.
33 --------------------------------------------------------------------------------
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 COMMENTS, REFERENCES, and NOTES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 #include "FGFDMExec.h"
46 #include <models/FGAtmosphere.h>
47 #include <models/atmosphere/FGMSIS.h>
48 #include <models/atmosphere/FGMars.h>
49 #include <models/FGFCS.h>
50 #include <models/FGPropulsion.h>
51 #include <models/FGMassBalance.h>
52 #include <models/FGGroundReactions.h>
53 #include <models/FGExternalReactions.h>
54 #include <models/FGBuoyantForces.h>
55 #include <models/FGAerodynamics.h>
56 #include <models/FGInertial.h>
57 #include <models/FGAircraft.h>
58 #include <models/FGPropagate.h>
59 #include <models/FGAuxiliary.h>
60 #include <models/FGInput.h>
61 #include <models/FGOutput.h>
62 #include <initialization/FGInitialCondition.h>
63 //#include <initialization/FGTrimAnalysis.h> // Remove until later
64 #include <input_output/FGPropertyManager.h>
65 #include <input_output/FGScript.h>
72 static const char *IdSrc = "$Id$";
73 static const char *IdHdr = ID_FDMEXEC;
75 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
79 unsigned int FGFDMExec::FDMctr = 0;
80 FGPropertyManager* FGFDMExec::master=0;
82 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
86 void checkTied ( FGPropertyManager *node )
88 int N = node->nChildren();
91 for (int i=0; i<N; i++) {
92 if (node->getChild(i)->nChildren() ) {
93 checkTied( (FGPropertyManager*)node->getChild(i) );
94 } else if ( node->getChild(i)->isTied() ) {
95 name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
101 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 FGFDMExec::FGFDMExec(FGPropertyManager* root) : Root(root)
119 ExternalReactions = 0;
134 IdFDM = FDMctr; // The main (parent) JSBSim instance is always the "zeroth"
135 // instance. "child" instances are loaded last.
138 char* num = getenv("JSBSIM_DEBUG");
139 if (num) debug_lvl = atoi(num); // set debug level
140 } catch (...) { // if error set to 1
146 master = new FGPropertyManager;
149 // JSBSim Standalone, multiple childs are allowed
153 instance = Root->GetNode("/fdm/jsbsim",IdFDM,true);
155 // this is to catch errors in binding member functions to the property tree.
158 } catch ( string msg ) {
159 cout << "Caught error: " << msg << endl;
167 typedef int (FGFDMExec::*iPMF)(void) const;
168 // instance->Tie("simulation/do_trim_analysis", this, (iPMF)0, &FGFDMExec::DoTrimAnalysis);
169 instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim);
170 instance->Tie("simulation/reset", this, (iPMF)0, &FGFDMExec::ResetToInitialConditions);
171 instance->Tie("simulation/terminate", (int *)&Terminate);
172 Constructing = false;
175 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 FGFDMExec::~FGFDMExec()
180 checkTied( instance );
182 if (Root == 0) delete master;
183 } catch ( string msg ) {
184 cout << "Caught error: " << msg << endl;
187 for (unsigned int i=1; i<ChildFDMList.size(); i++) delete ChildFDMList[i]->exec;
188 ChildFDMList.clear();
190 PropertyCatalog.clear();
195 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197 bool FGFDMExec::Allocate(void)
201 Atmosphere = new FGAtmosphere(this);
202 FCS = new FGFCS(this);
203 Propulsion = new FGPropulsion(this);
204 MassBalance = new FGMassBalance(this);
205 Aerodynamics = new FGAerodynamics (this);
206 Inertial = new FGInertial(this);
208 GroundCallback = new FGGroundCallback(Inertial->GetRefRadius());
210 GroundReactions = new FGGroundReactions(this);
211 ExternalReactions = new FGExternalReactions(this);
212 BuoyantForces = new FGBuoyantForces(this);
213 Aircraft = new FGAircraft(this);
214 Propagate = new FGPropagate(this);
215 Auxiliary = new FGAuxiliary(this);
216 Input = new FGInput(this);
218 State = new FGState(this); // This must be done here, as the FGState
219 // class needs valid pointers to the above
222 // Initialize models so they can communicate with each other
224 Atmosphere->InitModel();
226 Propulsion->InitModel();
227 MassBalance->InitModel();
228 Aerodynamics->InitModel();
229 Inertial->InitModel();
230 GroundReactions->InitModel();
231 ExternalReactions->InitModel();
232 BuoyantForces->InitModel();
233 Aircraft->InitModel();
234 Propagate->InitModel();
235 Auxiliary->InitModel();
238 IC = new FGInitialCondition(this);
240 // Schedule a model. The second arg (the integer) is the pass number. For
241 // instance, the atmosphere model could get executed every fifth pass it is called
242 // by the executive. IC and Trim objects are NOT scheduled.
245 Schedule(Atmosphere, 1);
247 Schedule(Propulsion, 1);
248 Schedule(MassBalance, 1);
249 Schedule(Aerodynamics, 1);
250 Schedule(Inertial, 1);
251 Schedule(GroundReactions, 1);
252 Schedule(ExternalReactions, 1);
253 Schedule(BuoyantForces, 1);
254 Schedule(Aircraft, 1);
255 Schedule(Propagate, 1);
256 Schedule(Auxiliary, 1);
263 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265 bool FGFDMExec::DeAllocate(void)
274 delete GroundReactions;
275 delete ExternalReactions;
276 delete BuoyantForces;
283 for (unsigned i=0; i<Outputs.size(); i++) delete Outputs[i];
289 delete GroundCallback;
303 ExternalReactions = 0;
314 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316 int FGFDMExec::Schedule(FGModel* model, int rate)
318 FGModel* model_iterator;
320 model_iterator = FirstModel;
322 if (model_iterator == 0L) { // this is the first model
325 FirstModel->NextModel = 0L;
326 FirstModel->SetRate(rate);
328 } else { // subsequent model
330 while (model_iterator->NextModel != 0L) {
331 model_iterator = model_iterator->NextModel;
333 model_iterator->NextModel = model;
334 model_iterator->NextModel->SetRate(rate);
341 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343 bool FGFDMExec::Run(void)
346 FGModel* model_iterator;
348 model_iterator = FirstModel;
349 if (model_iterator == 0L) return false;
353 for (unsigned int i=1; i<ChildFDMList.size(); i++) {
354 ChildFDMList[i]->AssignState(Propagate); // Transfer state to the child FDM
355 ChildFDMList[i]->Run();
358 // returns true if success
360 if (Script != 0 && !State->IntegrationSuspended()) success = Script->RunScript();
362 while (model_iterator != 0L) {
363 model_iterator->Run();
364 model_iterator = model_iterator->NextModel;
368 if (!Holding()) State->IncrTime();
369 if (Terminate) success = false;
374 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
375 // This call will cause the sim time to reset to 0.0
377 bool FGFDMExec::RunIC(void)
379 State->SuspendIntegration();
380 State->Initialize(IC);
382 State->ResumeIntegration();
387 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
389 // A private, internal function call for Tie-ing to a property, so it needs an
392 void FGFDMExec::ResetToInitialConditions(int mode)
395 for (unsigned int i=0; i<Outputs.size(); i++) {
396 Outputs[i]->SetStartNewFile(true);
400 ResetToInitialConditions();
403 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
405 void FGFDMExec::ResetToInitialConditions(void)
407 FGModel* model_iterator;
409 model_iterator = FirstModel;
410 if (model_iterator == 0L || Constructing) return;
412 while (model_iterator != 0L) {
413 model_iterator->InitModel();
414 model_iterator = model_iterator->NextModel;
418 if (Script) Script->ResetEvents();
421 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423 void FGFDMExec::SetGroundCallback(FGGroundCallback* p)
425 delete GroundCallback;
429 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
431 double FGFDMExec::GetSimTime(void)
433 return (State->Getsim_time());
436 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
438 double FGFDMExec::GetDeltaT(void)
440 return (State->Getdt());
443 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
445 vector <string> FGFDMExec::EnumerateFDMs(void)
447 vector <string> FDMList;
449 FDMList.push_back(Aircraft->GetAircraftName());
451 for (unsigned int i=1; i<ChildFDMList.size(); i++) {
452 FDMList.push_back(ChildFDMList[i]->exec->GetAircraft()->GetAircraftName());
458 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
460 bool FGFDMExec::LoadScript(string script)
464 Script = new FGScript(this);
465 result = Script->LoadScript(script);
470 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
472 bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string SystemsPath,
473 string model, bool addModelToPath)
475 FGFDMExec::AircraftPath = AircraftPath;
476 FGFDMExec::EnginePath = EnginePath;
477 FGFDMExec::SystemsPath = SystemsPath;
479 return LoadModel(model, addModelToPath);
482 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
484 bool FGFDMExec::LoadModel(string model, bool addModelToPath)
487 string aircraftCfgFileName;
488 string separator = "/";
489 Element* element = 0L;
490 bool result = false; // initialize result to false, indicating input file not yet read
492 modelName = model; // Set the class modelName attribute
494 if( AircraftPath.empty() || EnginePath.empty() || SystemsPath.empty()) {
495 cerr << "Error: attempted to load aircraft with undefined ";
496 cerr << "aircraft, engine, and system paths" << endl;
500 FullAircraftPath = AircraftPath;
501 if (addModelToPath) FullAircraftPath += separator + model;
502 aircraftCfgFileName = FullAircraftPath + separator + model + ".xml";
509 int saved_debug_lvl = debug_lvl;
511 document = LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
513 if (IsChild) debug_lvl = 0;
515 ReadPrologue(document);
517 if (IsChild) debug_lvl = saved_debug_lvl;
519 // Process the fileheader element in the aircraft config file. This element is OPTIONAL.
520 element = document->FindElement("fileheader");
522 result = ReadFileHeader(element);
524 cerr << endl << "Aircraft fileheader element has problems in file " << aircraftCfgFileName << endl;
529 if (IsChild) debug_lvl = 0;
531 // Process the metrics element. This element is REQUIRED.
532 element = document->FindElement("metrics");
534 result = Aircraft->Load(element);
536 cerr << endl << "Aircraft metrics element has problems in file " << aircraftCfgFileName << endl;
540 cerr << endl << "No metrics element was found in the aircraft config file." << endl;
544 // Process the mass_balance element. This element is REQUIRED.
545 element = document->FindElement("mass_balance");
547 result = MassBalance->Load(element);
549 cerr << endl << "Aircraft mass_balance element has problems in file " << aircraftCfgFileName << endl;
553 cerr << endl << "No mass_balance element was found in the aircraft config file." << endl;
557 // Process the ground_reactions element. This element is REQUIRED.
558 element = document->FindElement("ground_reactions");
560 result = GroundReactions->Load(element);
562 cerr << endl << "Aircraft ground_reactions element has problems in file " << aircraftCfgFileName << endl;
566 cerr << endl << "No ground_reactions element was found in the aircraft config file." << endl;
570 // Process the external_reactions element. This element is OPTIONAL.
571 element = document->FindElement("external_reactions");
573 result = ExternalReactions->Load(element);
575 cerr << endl << "Aircraft external_reactions element has problems in file " << aircraftCfgFileName << endl;
580 // Process the buoyant_forces element. This element is OPTIONAL.
581 element = document->FindElement("buoyant_forces");
583 result = BuoyantForces->Load(element);
585 cerr << endl << "Aircraft buoyant_forces element has problems in file " << aircraftCfgFileName << endl;
590 // Process the propulsion element. This element is OPTIONAL.
591 element = document->FindElement("propulsion");
593 result = Propulsion->Load(element);
595 cerr << endl << "Aircraft propulsion element has problems in file " << aircraftCfgFileName << endl;
600 // Process the system element[s]. This element is OPTIONAL, and there may be more than one.
601 element = document->FindElement("system");
603 result = FCS->Load(element, FGFCS::stSystem);
605 cerr << endl << "Aircraft system element has problems in file " << aircraftCfgFileName << endl;
608 element = document->FindNextElement("system");
611 // Process the autopilot element. This element is OPTIONAL.
612 element = document->FindElement("autopilot");
614 result = FCS->Load(element, FGFCS::stAutoPilot);
616 cerr << endl << "Aircraft autopilot element has problems in file " << aircraftCfgFileName << endl;
621 // Process the flight_control element. This element is OPTIONAL.
622 element = document->FindElement("flight_control");
624 result = FCS->Load(element, FGFCS::stFCS);
626 cerr << endl << "Aircraft flight_control element has problems in file " << aircraftCfgFileName << endl;
631 // Process the aerodynamics element. This element is OPTIONAL, but almost always expected.
632 element = document->FindElement("aerodynamics");
634 result = Aerodynamics->Load(element);
636 cerr << endl << "Aircraft aerodynamics element has problems in file " << aircraftCfgFileName << endl;
640 cerr << endl << "No expected aerodynamics element was found in the aircraft config file." << endl;
643 // Process the input element. This element is OPTIONAL.
644 element = document->FindElement("input");
646 result = Input->Load(element);
648 cerr << endl << "Aircraft input element has problems in file " << aircraftCfgFileName << endl;
653 // Process the output element[s]. This element is OPTIONAL, and there may be more than one.
654 element = document->FindElement("output");
656 FGOutput* Output = new FGOutput(this);
659 result = Output->Load(element);
660 Outputs.push_back(Output);
662 cerr << endl << "Aircraft output element has problems in file " << aircraftCfgFileName << endl;
665 element = document->FindNextElement("output");
668 // Lastly, process the child element. This element is OPTIONAL - and NOT YET SUPPORTED.
669 element = document->FindElement("child");
671 result = ReadChild(element);
673 cerr << endl << "Aircraft child element has problems in file " << aircraftCfgFileName << endl;
681 cout << endl << fgblue << highint
682 << "End of vehicle configuration loading." << endl
683 << "-------------------------------------------------------------------------------"
687 if (IsChild) debug_lvl = saved_debug_lvl;
691 << " JSBSim failed to open the configuration file: " << aircraftCfgFileName
695 struct PropertyCatalogStructure masterPCS;
696 masterPCS.base_string = "";
697 masterPCS.node = (FGPropertyManager*)Root;
699 BuildPropertyCatalog(&masterPCS);
704 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
706 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
708 struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
712 for (unsigned int i=0; i<pcs->node->nChildren(); i++) {
713 pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
714 node_idx = pcs->node->getChild(i)->getIndex();
715 sprintf(int_buf, "[%d]", node_idx);
716 if (node_idx != 0) pcsNew->base_string += string(int_buf);
717 if (pcs->node->getChild(i)->nChildren() == 0) {
718 if (pcsNew->base_string.substr(0,11) == string("/fdm/jsbsim")) {
719 pcsNew->base_string = pcsNew->base_string.erase(0,12);
721 PropertyCatalog.push_back(pcsNew->base_string);
723 pcsNew->node = (FGPropertyManager*)pcs->node->getChild(i);
724 BuildPropertyCatalog(pcsNew);
730 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
732 string FGFDMExec::QueryPropertyCatalog(string in)
735 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
736 if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
738 if (results.empty()) return "No matches found\n";
742 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
744 void FGFDMExec::PrintPropertyCatalog(void)
747 cout << " " << fgblue << highint << underon << "Property Catalog for "
748 << modelName << reset << endl << endl;
749 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
750 cout << " " << PropertyCatalog[i] << endl;
754 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
756 bool FGFDMExec::ReadFileHeader(Element* el)
758 bool result = true; // true for success
760 if (debug_lvl == 0) return result;
763 cout << endl <<highint << fgblue << "Reading child model: " << IdFDM << reset << endl << endl;
766 if (el->FindElement("description"))
767 cout << " Description: " << el->FindElement("description")->GetDataLine() << endl;
768 if (el->FindElement("author"))
769 cout << " Model Author: " << el->FindElement("author")->GetDataLine() << endl;
770 if (el->FindElement("filecreationdate"))
771 cout << " Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
772 if (el->FindElement("version"))
773 cout << " Version: " << el->FindElement("version")->GetDataLine() << endl;
778 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
780 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
782 bool result = true; // true for success
784 if (!el) return false;
786 string AircraftName = el->GetAttributeValue("name");
787 Aircraft->SetAircraftName(AircraftName);
789 if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
790 << underoff << ": " << highint << AircraftName << normint << endl;
792 CFGVersion = el->GetAttributeValue("version");
793 Release = el->GetAttributeValue("release");
796 cout << " Version: " << highint << CFGVersion
798 if (CFGVersion != needed_cfg_version) {
799 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
800 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
801 cerr << "Current version needed is: " << needed_cfg_version << endl;
802 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
806 if (Release == "ALPHA" && (debug_lvl & 1)) {
808 << highint << "This aircraft model is an " << fgred << Release
809 << reset << highint << " release!!!" << endl << endl << reset
810 << "This aircraft model may not even properly load, and probably"
811 << " will not fly as expected." << endl << endl
812 << fgred << highint << "Use this model for development purposes ONLY!!!"
813 << normint << reset << endl << endl;
814 } else if (Release == "BETA" && (debug_lvl & 1)) {
816 << highint << "This aircraft model is a " << fgred << Release
817 << reset << highint << " release!!!" << endl << endl << reset
818 << "This aircraft model probably will not fly as expected." << endl << endl
819 << fgblue << highint << "Use this model for development purposes ONLY!!!"
820 << normint << reset << endl << endl;
821 } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
823 << highint << "This aircraft model is a " << fgblue << Release
824 << reset << highint << " release." << endl << endl << reset;
825 } else if (debug_lvl & 1) {
827 << highint << "This aircraft model is an " << fgred << Release
828 << reset << highint << " release!!!" << endl << endl << reset
829 << "This aircraft model may not even properly load, and probably"
830 << " will not fly as expected." << endl << endl
831 << fgred << highint << "Use this model for development purposes ONLY!!!"
832 << normint << reset << endl << endl;
838 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
840 bool FGFDMExec::ReadChild(Element* el)
842 // Add a new childData object to the child FDM list
843 // Populate that childData element with a new FDMExec object
844 // Set the IsChild flag for that FDMExec object
845 // Get the aircraft name
846 // set debug level to print out no additional data for child objects
847 // Load the model given the aircraft name
848 // reset debug level to prior setting
852 struct childData* child = new childData;
854 child->exec = new FGFDMExec();
855 child->exec->SetChild(true);
857 string childAircraft = el->GetAttributeValue("name");
858 string sMated = el->GetAttributeValue("mated");
859 if (sMated == "false") child->mated = false; // child objects are mated by default.
860 string sInternal = el->GetAttributeValue("internal");
861 if (sInternal == "true") child->internal = true; // child objects are external by default.
863 child->exec->SetAircraftPath( AircraftPath );
864 child->exec->SetEnginePath( EnginePath );
865 child->exec->SetSystemsPath( SystemsPath );
866 child->exec->LoadModel(childAircraft);
868 Element* location = el->FindElement("location");
870 child->Loc = location->FindElementTripletConvertTo("IN");
872 cerr << endl << highint << fgred << " No location was found for this child object!" << reset << endl;
876 Element* orientation = el->FindElement("orient");
878 child->Orient = orientation->FindElementTripletConvertTo("RAD");
879 } else if (debug_lvl > 0) {
880 cerr << endl << highint << " No orientation was found for this child object! Assuming 0,0,0." << reset << endl;
883 ChildFDMList.push_back(child);
888 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
890 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
895 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
897 FGTrim* FGFDMExec::GetTrim(void)
900 Trim = new FGTrim(this,tNone);
904 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
906 void FGFDMExec::DisableOutput(void)
908 for (unsigned i=0; i<Outputs.size(); i++) {
909 Outputs[i]->Disable();
913 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
915 void FGFDMExec::EnableOutput(void)
917 for (unsigned i=0; i<Outputs.size(); i++) {
918 Outputs[i]->Enable();
922 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
924 bool FGFDMExec::SetOutputDirectives(string fname)
928 FGOutput* Output = new FGOutput(this);
929 Output->SetDirectivesFile(fname);
932 result = Output->Load(0);
933 Outputs.push_back(Output);
938 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
940 void FGFDMExec::DoTrim(int mode)
944 if (Constructing) return;
946 if (mode < 0 || mode > JSBSim::tNone) {
947 cerr << endl << "Illegal trimming mode!" << endl << endl;
950 saved_time = State->Getsim_time();
951 FGTrim trim(this, (JSBSim::TrimMode)mode);
952 if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
954 State->Setsim_time(saved_time);
957 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
959 void FGFDMExec::DoTrimAnalysis(int mode)
962 if (Constructing) return;
964 if (mode < 0 || mode > JSBSim::taNone) {
965 cerr << endl << "Illegal trimming mode!" << endl << endl;
968 saved_time = State->Getsim_time();
970 FGTrimAnalysis trimAnalysis(this, (JSBSim::TrimAnalysisMode)mode);
972 if ( !trimAnalysis.Load(IC->GetInitFile(), false) ) {
973 cerr << "A problem occurred with trim configuration file " << trimAnalysis.Load(IC->GetInitFile()) << endl;
977 bool result = trimAnalysis.DoTrim();
979 if ( !result ) cerr << endl << "Trim Failed" << endl << endl;
981 trimAnalysis.Report();
982 State->Setsim_time(saved_time);
985 cout << "\nOutput: " << GetOutputFileName() << endl;
989 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
991 void FGFDMExec::UseAtmosphereMSIS(void)
993 FGAtmosphere *oldAtmosphere = Atmosphere;
994 Atmosphere = new MSIS(this);
995 if (!Atmosphere->InitModel()) {
996 cerr << fgred << "MSIS Atmosphere model init failed" << fgdef << endl;
999 delete oldAtmosphere;
1002 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1004 void FGFDMExec::UseAtmosphereMars(void)
1007 FGAtmosphere *oldAtmosphere = Atmosphere;
1008 Atmosphere = new FGMars(this);
1009 if (!Atmosphere->InitModel()) {
1010 cerr << fgred << "Mars Atmosphere model init failed" << fgdef << endl;
1013 delete oldAtmosphere;
1017 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1018 // The bitmasked value choices are as follows:
1019 // unset: In this case (the default) JSBSim would only print
1020 // out the normally expected messages, essentially echoing
1021 // the config files as they are read. If the environment
1022 // variable is not set, debug_lvl is set to 1 internally
1023 // 0: This requests JSBSim not to output any messages
1025 // 1: This value explicity requests the normal JSBSim
1027 // 2: This value asks for a message to be printed out when
1028 // a class is instantiated
1029 // 4: When this value is set, a message is displayed when a
1030 // FGModel object executes its Run() method
1031 // 8: When this value is set, various runtime state variables
1032 // are printed out periodically
1033 // 16: When set various parameters are sanity checked and
1034 // a message is printed out when they go out of bounds
1036 void FGFDMExec::Debug(int from)
1038 if (debug_lvl <= 0) return;
1040 if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
1041 if (from == 0) { // Constructor
1042 cout << "\n\n " << highint << underon << "JSBSim Flight Dynamics Model v"
1043 << JSBSim_version << underoff << normint << endl;
1044 cout << halfint << " [JSBSim-ML v" << needed_cfg_version << "]\n\n";
1045 cout << normint << "JSBSim startup beginning ...\n\n";
1046 } else if (from == 3) {
1047 cout << "\n\nJSBSim startup complete\n\n";
1050 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1051 if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
1052 if (from == 1) cout << "Destroyed: FGFDMExec" << endl;
1054 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1056 cout << "================== Frame: " << Frame << " Time: "
1057 << State->Getsim_time() << " dt: " << State->Getdt() << endl;
1060 if (debug_lvl & 8 ) { // Runtime state variables
1062 if (debug_lvl & 16) { // Sanity checking
1064 if (debug_lvl & 64) {
1065 if (from == 0) { // Constructor
1066 cout << IdSrc << endl;
1067 cout << IdHdr << endl;