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) 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);
517 element = document->GetElement();
520 while (element && result) {
521 string element_name = element->GetName();
522 if (element_name == "fileheader" ) result = ReadFileHeader(element);
523 else if (element_name == "slave") result = ReadSlave(element);
524 else if (element_name == "metrics") result = Aircraft->Load(element);
525 else if (element_name == "mass_balance") result = MassBalance->Load(element);
526 else if (element_name == "ground_reactions") result = GroundReactions->Load(element);
527 else if (element_name == "external_reactions") result = ExternalReactions->Load(element);
528 else if (element_name == "buoyant_forces") result = BuoyantForces->Load(element);
529 else if (element_name == "propulsion") result = Propulsion->Load(element);
530 else if (element_name == "system") result = FCS->Load(element,
532 else if (element_name == "autopilot") result = FCS->Load(element,
534 else if (element_name == "flight_control") result = FCS->Load(element,
536 else if (element_name == "aerodynamics") result = Aerodynamics->Load(element);
537 else if (element_name == "input") result = Input->Load(element);
538 else if (element_name == "output") {
539 FGOutput* Output = new FGOutput(this);
542 result = Output->Load(element);
543 Outputs.push_back(Output);
546 cerr << "Found unexpected subsystem: " << element_name << ", exiting." << endl;
550 element = document->GetNextElement();
554 << " JSBSim failed to load aircraft model."
564 << " JSBSim failed to load properly."
569 struct PropertyCatalogStructure masterPCS;
570 masterPCS.base_string = "";
571 masterPCS.node = (FGPropertyManager*)Root;
573 BuildPropertyCatalog(&masterPCS);
578 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
580 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
582 struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
586 for (unsigned int i=0; i<pcs->node->nChildren(); i++) {
587 pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
588 node_idx = pcs->node->getChild(i)->getIndex();
589 sprintf(int_buf, "[%d]", node_idx);
590 if (node_idx != 0) pcsNew->base_string += string(int_buf);
591 if (pcs->node->getChild(i)->nChildren() == 0) {
592 if (pcsNew->base_string.substr(0,11) == string("/fdm/jsbsim")) {
593 pcsNew->base_string = pcsNew->base_string.erase(0,12);
595 PropertyCatalog.push_back(pcsNew->base_string);
597 pcsNew->node = (FGPropertyManager*)pcs->node->getChild(i);
598 BuildPropertyCatalog(pcsNew);
604 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
606 string FGFDMExec::QueryPropertyCatalog(string in)
609 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
610 if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
612 if (results.empty()) return "No matches found\n";
616 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
618 void FGFDMExec::PrintPropertyCatalog(void)
621 cout << " " << fgblue << highint << underon << "Property Catalog for "
622 << modelName << reset << endl << endl;
623 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
624 cout << " " << PropertyCatalog[i] << endl;
628 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
630 bool FGFDMExec::ReadFileHeader(Element* el)
632 bool result = true; // true for success
634 if (debug_lvl & ~1) return result;
636 if (el->FindElement("author"))
637 cout << " Model Author: " << el->FindElement("author")->GetDataLine() << endl;
638 if (el->FindElement("filecreationdate"))
639 cout << " Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
640 if (el->FindElement("version"))
641 cout << " Version: " << el->FindElement("version")->GetDataLine() << endl;
642 if (el->FindElement("description"))
643 cout << " Description: " << el->FindElement("description")->GetDataLine() << endl;
648 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
650 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
652 bool result = true; // true for success
654 if (!el) return false;
656 string AircraftName = el->GetAttributeValue("name");
657 Aircraft->SetAircraftName(AircraftName);
659 if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
660 << underoff << ": " << highint << AircraftName << normint << endl;
662 CFGVersion = el->GetAttributeValue("version");
663 Release = el->GetAttributeValue("release");
666 cout << " Version: " << highint << CFGVersion
668 if (CFGVersion != needed_cfg_version) {
669 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
670 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
671 cerr << "Current version needed is: " << needed_cfg_version << endl;
672 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
676 if (Release == "ALPHA" && (debug_lvl & 1)) {
678 << highint << "This aircraft model is an " << fgred << Release
679 << reset << highint << " release!!!" << endl << endl << reset
680 << "This aircraft model may not even properly load, and probably"
681 << " will not fly as expected." << endl << endl
682 << fgred << highint << "Use this model for development purposes ONLY!!!"
683 << normint << reset << endl << endl;
684 } else if (Release == "BETA" && (debug_lvl & 1)) {
686 << highint << "This aircraft model is a " << fgred << Release
687 << reset << highint << " release!!!" << endl << endl << reset
688 << "This aircraft model probably will not fly as expected." << endl << endl
689 << fgblue << highint << "Use this model for development purposes ONLY!!!"
690 << normint << reset << endl << endl;
691 } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
693 << highint << "This aircraft model is a " << fgblue << Release
694 << reset << highint << " release." << endl << endl << reset;
695 } else if (debug_lvl & 1) {
697 << highint << "This aircraft model is an " << fgred << Release
698 << reset << highint << " release!!!" << endl << endl << reset
699 << "This aircraft model may not even properly load, and probably"
700 << " will not fly as expected." << endl << endl
701 << fgred << highint << "Use this model for development purposes ONLY!!!"
702 << normint << reset << endl << endl;
708 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
710 bool FGFDMExec::ReadSlave(Element* el)
712 // Add a new slaveData object to the slave FDM list
713 // Populate that slaveData element with a new FDMExec object
714 // Set the IsSlave flag for that FDMExec object
715 // Get the aircraft name
716 // set debug level to print out no additional data for slave objects
717 // Load the model given the aircraft name
718 // reset debug level to prior setting
720 int saved_debug_lvl = debug_lvl;
723 SlaveFDMList.push_back(new slaveData);
724 SlaveFDMList.back()->exec = new FGFDMExec();
725 SlaveFDMList.back()->exec->SetSlave(true);
727 string AircraftName = AC_cfg->GetValue("file");
729 debug_lvl = 0; // turn off debug output for slave vehicle
731 SlaveFDMList.back()->exec->SetAircraftPath( AircraftPath );
732 SlaveFDMList.back()->exec->SetEnginePath( EnginePath );
733 SlaveFDMList.back()->exec->SetSystemsPath( SystemsPath );
734 SlaveFDMList.back()->exec->LoadModel(AircraftName);
735 debug_lvl = saved_debug_lvl; // turn debug output back on for master vehicle
737 AC_cfg->GetNextConfigLine();
738 while ((token = AC_cfg->GetValue()) != string("/SLAVE")) {
740 if (token == "xloc") { *AC_cfg >> SlaveFDMList.back()->x; }
741 else if (token == "yloc") { *AC_cfg >> SlaveFDMList.back()->y; }
742 else if (token == "zloc") { *AC_cfg >> SlaveFDMList.back()->z; }
743 else if (token == "pitch") { *AC_cfg >> SlaveFDMList.back()->pitch;}
744 else if (token == "yaw") { *AC_cfg >> SlaveFDMList.back()->yaw; }
745 else if (token == "roll") { *AC_cfg >> SlaveFDMList.back()->roll; }
746 else cerr << "Unknown identifier: " << token << " in slave vehicle definition" << endl;
750 cout << " X = " << SlaveFDMList.back()->x << endl;
751 cout << " Y = " << SlaveFDMList.back()->y << endl;
752 cout << " Z = " << SlaveFDMList.back()->z << endl;
753 cout << " Pitch = " << SlaveFDMList.back()->pitch << endl;
754 cout << " Yaw = " << SlaveFDMList.back()->yaw << endl;
755 cout << " Roll = " << SlaveFDMList.back()->roll << endl;
761 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
763 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
768 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
770 FGTrim* FGFDMExec::GetTrim(void)
773 Trim = new FGTrim(this,tNone);
777 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
779 void FGFDMExec::DisableOutput(void)
781 for (unsigned i=0; i<Outputs.size(); i++) {
782 Outputs[i]->Disable();
786 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
788 void FGFDMExec::EnableOutput(void)
790 for (unsigned i=0; i<Outputs.size(); i++) {
791 Outputs[i]->Enable();
795 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
797 bool FGFDMExec::SetOutputDirectives(string fname)
801 FGOutput* Output = new FGOutput(this);
802 Output->SetDirectivesFile(fname);
805 result = Output->Load(0);
806 Outputs.push_back(Output);
811 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
813 void FGFDMExec::DoTrim(int mode)
817 if (Constructing) return;
819 if (mode < 0 || mode > JSBSim::tNone) {
820 cerr << endl << "Illegal trimming mode!" << endl << endl;
823 saved_time = State->Getsim_time();
824 FGTrim trim(this, (JSBSim::TrimMode)mode);
825 if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
827 State->Setsim_time(saved_time);
830 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
832 void FGFDMExec::DoTrimAnalysis(int mode)
835 if (Constructing) return;
837 if (mode < 0 || mode > JSBSim::taNone) {
838 cerr << endl << "Illegal trimming mode!" << endl << endl;
841 saved_time = State->Getsim_time();
843 FGTrimAnalysis trimAnalysis(this, (JSBSim::TrimAnalysisMode)mode);
845 if ( !trimAnalysis.Load(IC->GetInitFile(), false) ) {
846 cerr << "A problem occurred with trim configuration file " << trimAnalysis.Load(IC->GetInitFile()) << endl;
850 bool result = trimAnalysis.DoTrim();
852 if ( !result ) cerr << endl << "Trim Failed" << endl << endl;
854 trimAnalysis.Report();
855 State->Setsim_time(saved_time);
858 cout << "\nOutput: " << GetOutputFileName() << endl;
862 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
864 void FGFDMExec::UseAtmosphereMSIS(void)
866 FGAtmosphere *oldAtmosphere = Atmosphere;
867 Atmosphere = new MSIS(this);
868 if (!Atmosphere->InitModel()) {
869 cerr << fgred << "MSIS Atmosphere model init failed" << fgdef << endl;
872 delete oldAtmosphere;
875 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
877 void FGFDMExec::UseAtmosphereMars(void)
880 FGAtmosphere *oldAtmosphere = Atmosphere;
881 Atmosphere = new FGMars(this);
882 if (!Atmosphere->InitModel()) {
883 cerr << fgred << "Mars Atmosphere model init failed" << fgdef << endl;
886 delete oldAtmosphere;
890 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
891 // The bitmasked value choices are as follows:
892 // unset: In this case (the default) JSBSim would only print
893 // out the normally expected messages, essentially echoing
894 // the config files as they are read. If the environment
895 // variable is not set, debug_lvl is set to 1 internally
896 // 0: This requests JSBSim not to output any messages
898 // 1: This value explicity requests the normal JSBSim
900 // 2: This value asks for a message to be printed out when
901 // a class is instantiated
902 // 4: When this value is set, a message is displayed when a
903 // FGModel object executes its Run() method
904 // 8: When this value is set, various runtime state variables
905 // are printed out periodically
906 // 16: When set various parameters are sanity checked and
907 // a message is printed out when they go out of bounds
909 void FGFDMExec::Debug(int from)
911 if (debug_lvl <= 0) return;
913 if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
914 if (from == 0) { // Constructor
915 cout << "\n\n " << highint << underon << "JSBSim Flight Dynamics Model v"
916 << JSBSim_version << underoff << normint << endl;
917 cout << halfint << " [JSBSim-ML v" << needed_cfg_version << "]\n\n";
918 cout << normint << "JSBSim startup beginning ...\n\n";
919 } else if (from == 3) {
920 cout << "\n\nJSBSim startup complete\n\n";
923 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
924 if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
925 if (from == 1) cout << "Destroyed: FGFDMExec" << endl;
927 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
929 cout << "================== Frame: " << Frame << " Time: "
930 << State->Getsim_time() << " dt: " << State->Getdt() << endl;
933 if (debug_lvl & 8 ) { // Runtime state variables
935 if (debug_lvl & 16) { // Sanity checking
937 if (debug_lvl & 64) {
938 if (from == 0) { // Constructor
939 cout << IdSrc << endl;
940 cout << IdHdr << endl;