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
395 // argument. Nothing is done with the argument, yet.
397 void FGFDMExec::ResetToInitialConditions(int mode)
399 ResetToInitialConditions();
402 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
404 void FGFDMExec::ResetToInitialConditions(void)
406 FGModel* model_iterator;
408 model_iterator = FirstModel;
409 if (model_iterator == 0L) return;
411 while (model_iterator != 0L) {
412 model_iterator->InitModel();
413 model_iterator = model_iterator->NextModel;
417 if (Script) Script->ResetEvents();
420 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422 void FGFDMExec::SetGroundCallback(FGGroundCallback* p)
424 delete GroundCallback;
428 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430 double FGFDMExec::GetSimTime(void)
432 return (State->Getsim_time());
435 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
437 double FGFDMExec::GetDeltaT(void)
439 return (State->Getdt());
442 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
444 vector <string> FGFDMExec::EnumerateFDMs(void)
446 vector <string> FDMList;
448 FDMList.push_back(Aircraft->GetAircraftName());
450 for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
451 FDMList.push_back(SlaveFDMList[i]->exec->GetAircraft()->GetAircraftName());
457 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
459 bool FGFDMExec::LoadScript(string script)
463 Script = new FGScript(this);
464 result = Script->LoadScript(script);
469 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
471 bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string SystemsPath,
472 string model, bool addModelToPath)
474 FGFDMExec::AircraftPath = AircraftPath;
475 FGFDMExec::EnginePath = EnginePath;
476 FGFDMExec::SystemsPath = SystemsPath;
478 return LoadModel(model, addModelToPath);
481 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
483 bool FGFDMExec::LoadModel(string model, bool addModelToPath)
486 string aircraftCfgFileName;
487 string separator = "/";
488 Element* element = 0L;
489 bool result = false; // initialize result to false, indicating input file not yet read
491 modelName = model; // Set the class modelName attribute
493 if( AircraftPath.empty() || EnginePath.empty() || SystemsPath.empty()) {
494 cerr << "Error: attempted to load aircraft with undefined ";
495 cerr << "aircraft, engine, and system paths" << endl;
499 FullAircraftPath = AircraftPath;
500 if (addModelToPath) FullAircraftPath += separator + model;
501 aircraftCfgFileName = FullAircraftPath + separator + model + ".xml";
508 document = LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
510 ReadPrologue(document);
511 element = document->GetElement();
514 while (element && result) {
515 string element_name = element->GetName();
516 if (element_name == "fileheader" ) result = ReadFileHeader(element);
517 else if (element_name == "slave") result = ReadSlave(element);
518 else if (element_name == "metrics") result = Aircraft->Load(element);
519 else if (element_name == "mass_balance") result = MassBalance->Load(element);
520 else if (element_name == "ground_reactions") result = GroundReactions->Load(element);
521 else if (element_name == "external_reactions") result = ExternalReactions->Load(element);
522 else if (element_name == "buoyant_forces") result = BuoyantForces->Load(element);
523 else if (element_name == "propulsion") result = Propulsion->Load(element);
524 else if (element_name == "system") result = FCS->Load(element,
526 else if (element_name == "autopilot") result = FCS->Load(element,
528 else if (element_name == "flight_control") result = FCS->Load(element,
530 else if (element_name == "aerodynamics") result = Aerodynamics->Load(element);
531 else if (element_name == "input") result = Input->Load(element);
532 else if (element_name == "output") {
533 FGOutput* Output = new FGOutput(this);
536 result = Output->Load(element);
537 Outputs.push_back(Output);
540 cerr << "Found unexpected subsystem: " << element_name << ", exiting." << endl;
544 element = document->GetNextElement();
548 << " JSBSim failed to load aircraft model."
558 << " JSBSim failed to load properly."
563 struct PropertyCatalogStructure masterPCS;
564 masterPCS.base_string = "";
565 masterPCS.node = (FGPropertyManager*)Root;
567 BuildPropertyCatalog(&masterPCS);
572 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
574 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
576 struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
580 for (unsigned int i=0; i<pcs->node->nChildren(); i++) {
581 pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
582 node_idx = pcs->node->getChild(i)->getIndex();
583 sprintf(int_buf, "[%d]", node_idx);
584 if (node_idx != 0) pcsNew->base_string += string(int_buf);
585 if (pcs->node->getChild(i)->nChildren() == 0) {
586 if (pcsNew->base_string.substr(0,11) == string("/fdm/jsbsim")) {
587 pcsNew->base_string = pcsNew->base_string.erase(0,12);
589 PropertyCatalog.push_back(pcsNew->base_string);
591 pcsNew->node = (FGPropertyManager*)pcs->node->getChild(i);
592 BuildPropertyCatalog(pcsNew);
598 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
600 string FGFDMExec::QueryPropertyCatalog(string in)
603 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
604 if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
606 if (results.empty()) return "No matches found\n";
610 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
612 void FGFDMExec::PrintPropertyCatalog(void)
615 cout << " " << fgblue << highint << underon << "Property Catalog for "
616 << modelName << reset << endl << endl;
617 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
618 cout << " " << PropertyCatalog[i] << endl;
622 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
624 bool FGFDMExec::ReadFileHeader(Element* el)
626 bool result = true; // true for success
628 if (debug_lvl & ~1) return result;
630 if (el->FindElement("author"))
631 cout << " Model Author: " << el->FindElement("author")->GetDataLine() << endl;
632 if (el->FindElement("filecreationdate"))
633 cout << " Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
634 if (el->FindElement("version"))
635 cout << " Version: " << el->FindElement("version")->GetDataLine() << endl;
636 if (el->FindElement("description"))
637 cout << " Description: " << el->FindElement("description")->GetDataLine() << endl;
642 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
644 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
646 bool result = true; // true for success
648 if (!el) return false;
650 string AircraftName = el->GetAttributeValue("name");
651 Aircraft->SetAircraftName(AircraftName);
653 if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
654 << underoff << ": " << highint << AircraftName << normint << endl;
656 CFGVersion = el->GetAttributeValue("version");
657 Release = el->GetAttributeValue("release");
660 cout << " Version: " << highint << CFGVersion
662 if (CFGVersion != needed_cfg_version) {
663 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
664 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
665 cerr << "Current version needed is: " << needed_cfg_version << endl;
666 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
670 if (Release == "ALPHA" && (debug_lvl & 1)) {
672 << highint << "This aircraft model is an " << fgred << Release
673 << reset << highint << " release!!!" << endl << endl << reset
674 << "This aircraft model may not even properly load, and probably"
675 << " will not fly as expected." << endl << endl
676 << fgred << highint << "Use this model for development purposes ONLY!!!"
677 << normint << reset << endl << endl;
678 } else if (Release == "BETA" && (debug_lvl & 1)) {
680 << highint << "This aircraft model is a " << fgred << Release
681 << reset << highint << " release!!!" << endl << endl << reset
682 << "This aircraft model probably will not fly as expected." << endl << endl
683 << fgblue << highint << "Use this model for development purposes ONLY!!!"
684 << normint << reset << endl << endl;
685 } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
687 << highint << "This aircraft model is a " << fgblue << Release
688 << reset << highint << " release." << endl << endl << reset;
689 } else if (debug_lvl & 1) {
691 << highint << "This aircraft model is an " << fgred << Release
692 << reset << highint << " release!!!" << endl << endl << reset
693 << "This aircraft model may not even properly load, and probably"
694 << " will not fly as expected." << endl << endl
695 << fgred << highint << "Use this model for development purposes ONLY!!!"
696 << normint << reset << endl << endl;
702 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
704 bool FGFDMExec::ReadSlave(Element* el)
706 // Add a new slaveData object to the slave FDM list
707 // Populate that slaveData element with a new FDMExec object
708 // Set the IsSlave flag for that FDMExec object
709 // Get the aircraft name
710 // set debug level to print out no additional data for slave objects
711 // Load the model given the aircraft name
712 // reset debug level to prior setting
714 int saved_debug_lvl = debug_lvl;
717 SlaveFDMList.push_back(new slaveData);
718 SlaveFDMList.back()->exec = new FGFDMExec();
719 SlaveFDMList.back()->exec->SetSlave(true);
721 string AircraftName = AC_cfg->GetValue("file");
723 debug_lvl = 0; // turn off debug output for slave vehicle
725 SlaveFDMList.back()->exec->SetAircraftPath( AircraftPath );
726 SlaveFDMList.back()->exec->SetEnginePath( EnginePath );
727 SlaveFDMList.back()->exec->SetSystemsPath( SystemsPath );
728 SlaveFDMList.back()->exec->LoadModel(AircraftName);
729 debug_lvl = saved_debug_lvl; // turn debug output back on for master vehicle
731 AC_cfg->GetNextConfigLine();
732 while ((token = AC_cfg->GetValue()) != string("/SLAVE")) {
734 if (token == "xloc") { *AC_cfg >> SlaveFDMList.back()->x; }
735 else if (token == "yloc") { *AC_cfg >> SlaveFDMList.back()->y; }
736 else if (token == "zloc") { *AC_cfg >> SlaveFDMList.back()->z; }
737 else if (token == "pitch") { *AC_cfg >> SlaveFDMList.back()->pitch;}
738 else if (token == "yaw") { *AC_cfg >> SlaveFDMList.back()->yaw; }
739 else if (token == "roll") { *AC_cfg >> SlaveFDMList.back()->roll; }
740 else cerr << "Unknown identifier: " << token << " in slave vehicle definition" << endl;
744 cout << " X = " << SlaveFDMList.back()->x << endl;
745 cout << " Y = " << SlaveFDMList.back()->y << endl;
746 cout << " Z = " << SlaveFDMList.back()->z << endl;
747 cout << " Pitch = " << SlaveFDMList.back()->pitch << endl;
748 cout << " Yaw = " << SlaveFDMList.back()->yaw << endl;
749 cout << " Roll = " << SlaveFDMList.back()->roll << endl;
755 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
757 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
762 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
764 FGTrim* FGFDMExec::GetTrim(void)
767 Trim = new FGTrim(this,tNone);
771 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
773 void FGFDMExec::DisableOutput(void)
775 for (unsigned i=0; i<Outputs.size(); i++) {
776 Outputs[i]->Disable();
780 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
782 void FGFDMExec::EnableOutput(void)
784 for (unsigned i=0; i<Outputs.size(); i++) {
785 Outputs[i]->Enable();
789 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
791 bool FGFDMExec::SetOutputDirectives(string fname)
795 FGOutput* Output = new FGOutput(this);
796 Output->SetDirectivesFile(fname);
799 result = Output->Load(0);
800 Outputs.push_back(Output);
805 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
807 void FGFDMExec::DoTrim(int mode)
811 if (Constructing) return;
813 if (mode < 0 || mode > JSBSim::tNone) {
814 cerr << endl << "Illegal trimming mode!" << endl << endl;
817 saved_time = State->Getsim_time();
818 FGTrim trim(this, (JSBSim::TrimMode)mode);
819 if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
821 State->Setsim_time(saved_time);
824 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
826 void FGFDMExec::DoTrimAnalysis(int mode)
829 if (Constructing) return;
831 if (mode < 0 || mode > JSBSim::taNone) {
832 cerr << endl << "Illegal trimming mode!" << endl << endl;
835 saved_time = State->Getsim_time();
837 FGTrimAnalysis trimAnalysis(this, (JSBSim::TrimAnalysisMode)mode);
839 if ( !trimAnalysis.Load(IC->GetInitFile(), false) ) {
840 cerr << "A problem occurred with trim configuration file " << trimAnalysis.Load(IC->GetInitFile()) << endl;
844 bool result = trimAnalysis.DoTrim();
846 if ( !result ) cerr << endl << "Trim Failed" << endl << endl;
848 trimAnalysis.Report();
849 State->Setsim_time(saved_time);
852 cout << "\nOutput: " << GetOutputFileName() << endl;
856 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
858 void FGFDMExec::UseAtmosphereMSIS(void)
860 FGAtmosphere *oldAtmosphere = Atmosphere;
861 Atmosphere = new MSIS(this);
862 if (!Atmosphere->InitModel()) {
863 cerr << fgred << "MSIS Atmosphere model init failed" << fgdef << endl;
866 delete oldAtmosphere;
869 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
871 void FGFDMExec::UseAtmosphereMars(void)
874 FGAtmosphere *oldAtmosphere = Atmosphere;
875 Atmosphere = new FGMars(this);
876 if (!Atmosphere->InitModel()) {
877 cerr << fgred << "Mars Atmosphere model init failed" << fgdef << endl;
880 delete oldAtmosphere;
884 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
885 // The bitmasked value choices are as follows:
886 // unset: In this case (the default) JSBSim would only print
887 // out the normally expected messages, essentially echoing
888 // the config files as they are read. If the environment
889 // variable is not set, debug_lvl is set to 1 internally
890 // 0: This requests JSBSim not to output any messages
892 // 1: This value explicity requests the normal JSBSim
894 // 2: This value asks for a message to be printed out when
895 // a class is instantiated
896 // 4: When this value is set, a message is displayed when a
897 // FGModel object executes its Run() method
898 // 8: When this value is set, various runtime state variables
899 // are printed out periodically
900 // 16: When set various parameters are sanity checked and
901 // a message is printed out when they go out of bounds
903 void FGFDMExec::Debug(int from)
905 if (debug_lvl <= 0) return;
907 if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
908 if (from == 0) { // Constructor
909 cout << "\n\n " << highint << underon << "JSBSim Flight Dynamics Model v"
910 << JSBSim_version << underoff << normint << endl;
911 cout << halfint << " [JSBSim-ML v" << needed_cfg_version << "]\n\n";
912 cout << normint << "JSBSim startup beginning ...\n\n";
913 } else if (from == 3) {
914 cout << "\n\nJSBSim startup complete\n\n";
917 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
918 if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
919 if (from == 1) cout << "Destroyed: FGFDMExec" << endl;
921 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
923 cout << "================== Frame: " << Frame << " Time: "
924 << State->Getsim_time() << " dt: " << State->Getdt() << endl;
927 if (debug_lvl & 8 ) { // Runtime state variables
929 if (debug_lvl & 16) { // Sanity checking
931 if (debug_lvl & 64) {
932 if (from == 0) { // Constructor
933 cout << IdSrc << endl;
934 cout << IdHdr << endl;