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 // cout << "Untieing " << node->getChild(i)->getName() << " property branch." << endl;
94 checkTied( (FGPropertyManager*)node->getChild(i) );
95 } else if ( node->getChild(i)->isTied() ) {
96 name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
102 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 FGFDMExec::FGFDMExec(FGPropertyManager* root) : Root(root)
120 ExternalReactions = 0;
135 // Multiple FDM's are stopped for now. We need to ensure that
136 // the "user" instance always gets the zeroeth instance number,
137 // because there may be instruments or scripts tied to properties
138 // in the jsbsim[0] node.
139 // ToDo: it could be that when JSBSim is reset and a new FDM is wanted, that
140 // process might try setting FDMctr = 0. Then the line below would not need
141 // to be commented out.
146 char* num = getenv("JSBSIM_DEBUG");
147 if (num) debug_lvl = atoi(num); // set debug level
148 } catch (...) { // if error set to 1
154 master = new FGPropertyManager;
158 instance = Root->GetNode("/fdm/jsbsim",IdFDM,true);
160 // this is to catch errors in binding member functions to the property tree.
163 } catch ( string msg ) {
164 cout << "Caught error: " << msg << endl;
172 typedef int (FGFDMExec::*iPMF)(void) const;
173 // instance->Tie("simulation/do_trim_analysis", this, (iPMF)0, &FGFDMExec::DoTrimAnalysis);
174 instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim);
175 instance->Tie("simulation/reset", this, (iPMF)0, &FGFDMExec::ResetToInitialConditions);
176 instance->Tie("simulation/terminate", (int *)&Terminate);
177 Constructing = false;
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 FGFDMExec::~FGFDMExec()
185 checkTied( instance );
187 if (Root == 0) delete master;
188 } catch ( string msg ) {
189 cout << "Caught error: " << msg << endl;
192 for (unsigned int i=1; i<SlaveFDMList.size(); i++) delete SlaveFDMList[i]->exec;
193 SlaveFDMList.clear();
195 //ToDo remove property catalog.
200 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 bool FGFDMExec::Allocate(void)
206 Atmosphere = new FGAtmosphere(this);
207 FCS = new FGFCS(this);
208 Propulsion = new FGPropulsion(this);
209 MassBalance = new FGMassBalance(this);
210 Aerodynamics = new FGAerodynamics (this);
211 Inertial = new FGInertial(this);
213 GroundCallback = new FGGroundCallback(Inertial->GetRefRadius());
215 GroundReactions = new FGGroundReactions(this);
216 ExternalReactions = new FGExternalReactions(this);
217 BuoyantForces = new FGBuoyantForces(this);
218 Aircraft = new FGAircraft(this);
219 Propagate = new FGPropagate(this);
220 Auxiliary = new FGAuxiliary(this);
221 Input = new FGInput(this);
223 State = new FGState(this); // This must be done here, as the FGState
224 // class needs valid pointers to the above
227 // Initialize models so they can communicate with each other
229 Atmosphere->InitModel();
231 Propulsion->InitModel();
232 MassBalance->InitModel();
233 Aerodynamics->InitModel();
234 Inertial->InitModel();
235 GroundReactions->InitModel();
236 ExternalReactions->InitModel();
237 BuoyantForces->InitModel();
238 Aircraft->InitModel();
239 Propagate->InitModel();
240 Auxiliary->InitModel();
243 IC = new FGInitialCondition(this);
245 // Schedule a model. The second arg (the integer) is the pass number. For
246 // instance, the atmosphere model could get executed every fifth pass it is called
247 // by the executive. IC and Trim objects are NOT scheduled.
250 Schedule(Atmosphere, 1);
252 Schedule(Propulsion, 1);
253 Schedule(MassBalance, 1);
254 Schedule(Aerodynamics, 1);
255 Schedule(Inertial, 1);
256 Schedule(GroundReactions, 1);
257 Schedule(ExternalReactions, 1);
258 Schedule(BuoyantForces, 1);
259 Schedule(Aircraft, 1);
260 Schedule(Propagate, 1);
261 Schedule(Auxiliary, 1);
268 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 bool FGFDMExec::DeAllocate(void)
279 delete GroundReactions;
280 delete ExternalReactions;
281 delete BuoyantForces;
288 for (unsigned i=0; i<Outputs.size(); i++) delete Outputs[i];
294 delete GroundCallback;
308 ExternalReactions = 0;
319 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321 int FGFDMExec::Schedule(FGModel* model, int rate)
323 FGModel* model_iterator;
325 model_iterator = FirstModel;
327 if (model_iterator == 0L) { // this is the first model
330 FirstModel->NextModel = 0L;
331 FirstModel->SetRate(rate);
333 } else { // subsequent model
335 while (model_iterator->NextModel != 0L) {
336 model_iterator = model_iterator->NextModel;
338 model_iterator->NextModel = model;
339 model_iterator->NextModel->SetRate(rate);
346 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
348 bool FGFDMExec::Run(void)
351 FGModel* model_iterator;
353 model_iterator = FirstModel;
354 if (model_iterator == 0L) return false;
358 for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
359 // SlaveFDMList[i]->exec->State->Initialize(); // Transfer state to the slave FDM
360 // SlaveFDMList[i]->exec->Run();
363 // returns true if success
365 if (Script != 0 && !State->IntegrationSuspended()) success = Script->RunScript();
367 while (model_iterator != 0L) {
368 model_iterator->Run();
369 model_iterator = model_iterator->NextModel;
373 if (!Holding()) State->IncrTime();
374 if (Terminate) success = false;
379 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380 // This call will cause the sim time to reset to 0.0
382 bool FGFDMExec::RunIC(void)
384 State->SuspendIntegration();
385 State->Initialize(IC);
387 State->ResumeIntegration();
392 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
394 // A private, internal function call for Tie-ing to a property, so it needs an
397 void FGFDMExec::ResetToInitialConditions(int mode)
400 for (unsigned int i=0; i<Outputs.size(); i++) {
401 Outputs[i]->SetStartNewFile(true);
405 ResetToInitialConditions();
408 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410 void FGFDMExec::ResetToInitialConditions(void)
412 FGModel* model_iterator;
414 model_iterator = FirstModel;
415 if (model_iterator == 0L || Constructing) return;
417 while (model_iterator != 0L) {
418 model_iterator->InitModel();
419 model_iterator = model_iterator->NextModel;
423 if (Script) Script->ResetEvents();
426 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428 void FGFDMExec::SetGroundCallback(FGGroundCallback* p)
430 delete GroundCallback;
434 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
436 double FGFDMExec::GetSimTime(void)
438 return (State->Getsim_time());
441 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
443 double FGFDMExec::GetDeltaT(void)
445 return (State->Getdt());
448 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
450 vector <string> FGFDMExec::EnumerateFDMs(void)
452 vector <string> FDMList;
454 FDMList.push_back(Aircraft->GetAircraftName());
456 for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
457 FDMList.push_back(SlaveFDMList[i]->exec->GetAircraft()->GetAircraftName());
463 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
465 bool FGFDMExec::LoadScript(string script)
469 Script = new FGScript(this);
470 result = Script->LoadScript(script);
475 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
477 bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string SystemsPath,
478 string model, bool addModelToPath)
480 FGFDMExec::AircraftPath = AircraftPath;
481 FGFDMExec::EnginePath = EnginePath;
482 FGFDMExec::SystemsPath = SystemsPath;
484 return LoadModel(model, addModelToPath);
487 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
489 bool FGFDMExec::LoadModel(string model, bool addModelToPath)
492 string aircraftCfgFileName;
493 string separator = "/";
494 Element* element = 0L;
495 bool result = false; // initialize result to false, indicating input file not yet read
497 modelName = model; // Set the class modelName attribute
499 if( AircraftPath.empty() || EnginePath.empty() || SystemsPath.empty()) {
500 cerr << "Error: attempted to load aircraft with undefined ";
501 cerr << "aircraft, engine, and system paths" << endl;
505 FullAircraftPath = AircraftPath;
506 if (addModelToPath) FullAircraftPath += separator + model;
507 aircraftCfgFileName = FullAircraftPath + separator + model + ".xml";
514 document = LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
516 ReadPrologue(document);
518 // Process the fileheader element in the aircraft config file. This element is OPTIONAL.
519 element = document->FindElement("fileheader");
521 result = ReadFileHeader(element);
523 cerr << endl << "Aircraft fileheader element has problems in file " << aircraftCfgFileName << endl;
528 // Process the metrics element. This element is REQUIRED.
529 element = document->FindElement("metrics");
531 result = Aircraft->Load(element);
533 cerr << endl << "Aircraft metrics element has problems in file " << aircraftCfgFileName << endl;
537 cerr << endl << "No metrics element was found in the aircraft config file." << endl;
541 // Process the mass_balance element. This element is REQUIRED.
542 element = document->FindElement("mass_balance");
544 result = MassBalance->Load(element);
546 cerr << endl << "Aircraft mass_balance element has problems in file " << aircraftCfgFileName << endl;
550 cerr << endl << "No mass_balance element was found in the aircraft config file." << endl;
554 // Process the ground_reactions element. This element is REQUIRED.
555 element = document->FindElement("ground_reactions");
557 result = GroundReactions->Load(element);
559 cerr << endl << "Aircraft ground_reactions element has problems in file " << aircraftCfgFileName << endl;
563 cerr << endl << "No ground_reactions element was found in the aircraft config file." << endl;
567 // Process the external_reactions element. This element is OPTIONAL.
568 element = document->FindElement("external_reactions");
570 result = ExternalReactions->Load(element);
572 cerr << endl << "Aircraft external_reactions element has problems in file " << aircraftCfgFileName << endl;
577 // Process the buoyant_forces element. This element is OPTIONAL.
578 element = document->FindElement("buoyant_forces");
580 result = BuoyantForces->Load(element);
582 cerr << endl << "Aircraft buoyant_forces element has problems in file " << aircraftCfgFileName << endl;
587 // Process the propulsion element. This element is OPTIONAL.
588 element = document->FindElement("propulsion");
590 result = Propulsion->Load(element);
592 cerr << endl << "Aircraft propulsion element has problems in file " << aircraftCfgFileName << endl;
597 // Process the system element[s]. This element is OPTIONAL, and there may be more than one.
598 element = document->FindElement("system");
600 result = FCS->Load(element, FGFCS::stSystem);
602 cerr << endl << "Aircraft system element has problems in file " << aircraftCfgFileName << endl;
605 element = document->FindNextElement("system");
608 // Process the autopilot element. This element is OPTIONAL.
609 element = document->FindElement("autopilot");
611 result = FCS->Load(element, FGFCS::stAutoPilot);
613 cerr << endl << "Aircraft autopilot element has problems in file " << aircraftCfgFileName << endl;
618 // Process the flight_control element. This element is OPTIONAL.
619 element = document->FindElement("flight_control");
621 result = FCS->Load(element, FGFCS::stFCS);
623 cerr << endl << "Aircraft flight_control element has problems in file " << aircraftCfgFileName << endl;
628 // Process the aerodynamics element. This element is OPTIONAL, but almost always expected.
629 element = document->FindElement("aerodynamics");
631 result = Aerodynamics->Load(element);
633 cerr << endl << "Aircraft aerodynamics element has problems in file " << aircraftCfgFileName << endl;
637 cerr << endl << "No expected aerodynamics element was found in the aircraft config file." << endl;
640 // Process the input element. This element is OPTIONAL.
641 element = document->FindElement("input");
643 result = Input->Load(element);
645 cerr << endl << "Aircraft input element has problems in file " << aircraftCfgFileName << endl;
650 // Process the output element[s]. This element is OPTIONAL, and there may be more than one.
651 element = document->FindElement("output");
653 FGOutput* Output = new FGOutput(this);
656 result = Output->Load(element);
657 Outputs.push_back(Output);
659 cerr << endl << "Aircraft output element has problems in file " << aircraftCfgFileName << endl;
662 element = document->FindNextElement("output");
665 // Lastly, process the slave element. This element is OPTIONAL - and NOT YET SUPPORTED.
666 element = document->FindElement("slave");
668 result = ReadSlave(element);
670 cerr << endl << "Aircraft slave element has problems in file " << aircraftCfgFileName << endl;
679 << " JSBSim failed to open the configuration file: " << aircraftCfgFileName
683 struct PropertyCatalogStructure masterPCS;
684 masterPCS.base_string = "";
685 masterPCS.node = (FGPropertyManager*)Root;
687 BuildPropertyCatalog(&masterPCS);
692 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
694 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
696 struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
700 for (unsigned int i=0; i<pcs->node->nChildren(); i++) {
701 pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
702 node_idx = pcs->node->getChild(i)->getIndex();
703 sprintf(int_buf, "[%d]", node_idx);
704 if (node_idx != 0) pcsNew->base_string += string(int_buf);
705 if (pcs->node->getChild(i)->nChildren() == 0) {
706 if (pcsNew->base_string.substr(0,11) == string("/fdm/jsbsim")) {
707 pcsNew->base_string = pcsNew->base_string.erase(0,12);
709 PropertyCatalog.push_back(pcsNew->base_string);
711 pcsNew->node = (FGPropertyManager*)pcs->node->getChild(i);
712 BuildPropertyCatalog(pcsNew);
718 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
720 string FGFDMExec::QueryPropertyCatalog(string in)
723 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
724 if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
726 if (results.empty()) return "No matches found\n";
730 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
732 void FGFDMExec::PrintPropertyCatalog(void)
735 cout << " " << fgblue << highint << underon << "Property Catalog for "
736 << modelName << reset << endl << endl;
737 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
738 cout << " " << PropertyCatalog[i] << endl;
742 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
744 bool FGFDMExec::ReadFileHeader(Element* el)
746 bool result = true; // true for success
748 if (debug_lvl & ~1) return result;
750 if (el->FindElement("author"))
751 cout << " Model Author: " << el->FindElement("author")->GetDataLine() << endl;
752 if (el->FindElement("filecreationdate"))
753 cout << " Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
754 if (el->FindElement("version"))
755 cout << " Version: " << el->FindElement("version")->GetDataLine() << endl;
756 if (el->FindElement("description"))
757 cout << " Description: " << el->FindElement("description")->GetDataLine() << endl;
762 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
764 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
766 bool result = true; // true for success
768 if (!el) return false;
770 string AircraftName = el->GetAttributeValue("name");
771 Aircraft->SetAircraftName(AircraftName);
773 if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
774 << underoff << ": " << highint << AircraftName << normint << endl;
776 CFGVersion = el->GetAttributeValue("version");
777 Release = el->GetAttributeValue("release");
780 cout << " Version: " << highint << CFGVersion
782 if (CFGVersion != needed_cfg_version) {
783 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
784 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
785 cerr << "Current version needed is: " << needed_cfg_version << endl;
786 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
790 if (Release == "ALPHA" && (debug_lvl & 1)) {
792 << highint << "This aircraft model is an " << fgred << Release
793 << reset << highint << " release!!!" << endl << endl << reset
794 << "This aircraft model may not even properly load, and probably"
795 << " will not fly as expected." << endl << endl
796 << fgred << highint << "Use this model for development purposes ONLY!!!"
797 << normint << reset << endl << endl;
798 } else if (Release == "BETA" && (debug_lvl & 1)) {
800 << highint << "This aircraft model is a " << fgred << Release
801 << reset << highint << " release!!!" << endl << endl << reset
802 << "This aircraft model probably will not fly as expected." << endl << endl
803 << fgblue << highint << "Use this model for development purposes ONLY!!!"
804 << normint << reset << endl << endl;
805 } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
807 << highint << "This aircraft model is a " << fgblue << Release
808 << reset << highint << " release." << endl << endl << reset;
809 } else if (debug_lvl & 1) {
811 << highint << "This aircraft model is an " << fgred << Release
812 << reset << highint << " release!!!" << endl << endl << reset
813 << "This aircraft model may not even properly load, and probably"
814 << " will not fly as expected." << endl << endl
815 << fgred << highint << "Use this model for development purposes ONLY!!!"
816 << normint << reset << endl << endl;
822 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
824 bool FGFDMExec::ReadSlave(Element* el)
826 // Add a new slaveData object to the slave FDM list
827 // Populate that slaveData element with a new FDMExec object
828 // Set the IsSlave flag for that FDMExec object
829 // Get the aircraft name
830 // set debug level to print out no additional data for slave objects
831 // Load the model given the aircraft name
832 // reset debug level to prior setting
834 int saved_debug_lvl = debug_lvl;
837 SlaveFDMList.push_back(new slaveData);
838 SlaveFDMList.back()->exec = new FGFDMExec();
839 SlaveFDMList.back()->exec->SetSlave(true);
841 string AircraftName = AC_cfg->GetValue("file");
843 debug_lvl = 0; // turn off debug output for slave vehicle
845 SlaveFDMList.back()->exec->SetAircraftPath( AircraftPath );
846 SlaveFDMList.back()->exec->SetEnginePath( EnginePath );
847 SlaveFDMList.back()->exec->SetSystemsPath( SystemsPath );
848 SlaveFDMList.back()->exec->LoadModel(AircraftName);
849 debug_lvl = saved_debug_lvl; // turn debug output back on for master vehicle
851 AC_cfg->GetNextConfigLine();
852 while ((token = AC_cfg->GetValue()) != string("/SLAVE")) {
854 if (token == "xloc") { *AC_cfg >> SlaveFDMList.back()->x; }
855 else if (token == "yloc") { *AC_cfg >> SlaveFDMList.back()->y; }
856 else if (token == "zloc") { *AC_cfg >> SlaveFDMList.back()->z; }
857 else if (token == "pitch") { *AC_cfg >> SlaveFDMList.back()->pitch;}
858 else if (token == "yaw") { *AC_cfg >> SlaveFDMList.back()->yaw; }
859 else if (token == "roll") { *AC_cfg >> SlaveFDMList.back()->roll; }
860 else cerr << "Unknown identifier: " << token << " in slave vehicle definition" << endl;
864 cout << " X = " << SlaveFDMList.back()->x << endl;
865 cout << " Y = " << SlaveFDMList.back()->y << endl;
866 cout << " Z = " << SlaveFDMList.back()->z << endl;
867 cout << " Pitch = " << SlaveFDMList.back()->pitch << endl;
868 cout << " Yaw = " << SlaveFDMList.back()->yaw << endl;
869 cout << " Roll = " << SlaveFDMList.back()->roll << endl;
875 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
877 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
882 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
884 FGTrim* FGFDMExec::GetTrim(void)
887 Trim = new FGTrim(this,tNone);
891 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
893 void FGFDMExec::DisableOutput(void)
895 for (unsigned i=0; i<Outputs.size(); i++) {
896 Outputs[i]->Disable();
900 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
902 void FGFDMExec::EnableOutput(void)
904 for (unsigned i=0; i<Outputs.size(); i++) {
905 Outputs[i]->Enable();
909 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
911 bool FGFDMExec::SetOutputDirectives(string fname)
915 FGOutput* Output = new FGOutput(this);
916 Output->SetDirectivesFile(fname);
919 result = Output->Load(0);
920 Outputs.push_back(Output);
925 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
927 void FGFDMExec::DoTrim(int mode)
931 if (Constructing) return;
933 if (mode < 0 || mode > JSBSim::tNone) {
934 cerr << endl << "Illegal trimming mode!" << endl << endl;
937 saved_time = State->Getsim_time();
938 FGTrim trim(this, (JSBSim::TrimMode)mode);
939 if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
941 State->Setsim_time(saved_time);
944 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
946 void FGFDMExec::DoTrimAnalysis(int mode)
949 if (Constructing) return;
951 if (mode < 0 || mode > JSBSim::taNone) {
952 cerr << endl << "Illegal trimming mode!" << endl << endl;
955 saved_time = State->Getsim_time();
957 FGTrimAnalysis trimAnalysis(this, (JSBSim::TrimAnalysisMode)mode);
959 if ( !trimAnalysis.Load(IC->GetInitFile(), false) ) {
960 cerr << "A problem occurred with trim configuration file " << trimAnalysis.Load(IC->GetInitFile()) << endl;
964 bool result = trimAnalysis.DoTrim();
966 if ( !result ) cerr << endl << "Trim Failed" << endl << endl;
968 trimAnalysis.Report();
969 State->Setsim_time(saved_time);
972 cout << "\nOutput: " << GetOutputFileName() << endl;
976 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
978 void FGFDMExec::UseAtmosphereMSIS(void)
980 FGAtmosphere *oldAtmosphere = Atmosphere;
981 Atmosphere = new MSIS(this);
982 if (!Atmosphere->InitModel()) {
983 cerr << fgred << "MSIS Atmosphere model init failed" << fgdef << endl;
986 delete oldAtmosphere;
989 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
991 void FGFDMExec::UseAtmosphereMars(void)
994 FGAtmosphere *oldAtmosphere = Atmosphere;
995 Atmosphere = new FGMars(this);
996 if (!Atmosphere->InitModel()) {
997 cerr << fgred << "Mars Atmosphere model init failed" << fgdef << endl;
1000 delete oldAtmosphere;
1004 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1005 // The bitmasked value choices are as follows:
1006 // unset: In this case (the default) JSBSim would only print
1007 // out the normally expected messages, essentially echoing
1008 // the config files as they are read. If the environment
1009 // variable is not set, debug_lvl is set to 1 internally
1010 // 0: This requests JSBSim not to output any messages
1012 // 1: This value explicity requests the normal JSBSim
1014 // 2: This value asks for a message to be printed out when
1015 // a class is instantiated
1016 // 4: When this value is set, a message is displayed when a
1017 // FGModel object executes its Run() method
1018 // 8: When this value is set, various runtime state variables
1019 // are printed out periodically
1020 // 16: When set various parameters are sanity checked and
1021 // a message is printed out when they go out of bounds
1023 void FGFDMExec::Debug(int from)
1025 if (debug_lvl <= 0) return;
1027 if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
1028 if (from == 0) { // Constructor
1029 cout << "\n\n " << highint << underon << "JSBSim Flight Dynamics Model v"
1030 << JSBSim_version << underoff << normint << endl;
1031 cout << halfint << " [JSBSim-ML v" << needed_cfg_version << "]\n\n";
1032 cout << normint << "JSBSim startup beginning ...\n\n";
1033 } else if (from == 3) {
1034 cout << "\n\nJSBSim startup complete\n\n";
1037 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1038 if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
1039 if (from == 1) cout << "Destroyed: FGFDMExec" << endl;
1041 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1043 cout << "================== Frame: " << Frame << " Time: "
1044 << State->Getsim_time() << " dt: " << State->Getdt() << endl;
1047 if (debug_lvl & 8 ) { // Runtime state variables
1049 if (debug_lvl & 16) { // Sanity checking
1051 if (debug_lvl & 64) {
1052 if (from == 0) { // Constructor
1053 cout << IdSrc << endl;
1054 cout << IdHdr << endl;