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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 # include <simgear/compiler.h>
46 # include STL_IOSTREAM
47 # include STL_ITERATOR
49 # if defined(sgi) && !defined(__GNUC__) && (_COMPILER_VERSION < 740)
50 # include <iostream.h>
57 #include "FGFDMExec.h"
59 #include <models/FGAtmosphere.h>
60 #include <models/atmosphere/FGMSIS.h>
61 #include <models/atmosphere/FGMars.h>
62 #include <models/FGFCS.h>
63 #include <models/FGPropulsion.h>
64 #include <models/FGMassBalance.h>
65 #include <models/FGGroundReactions.h>
66 #include <models/FGExternalReactions.h>
67 #include <models/FGBuoyantForces.h>
68 #include <models/FGAerodynamics.h>
69 #include <models/FGInertial.h>
70 #include <models/FGAircraft.h>
71 #include <models/FGPropagate.h>
72 #include <models/FGAuxiliary.h>
73 #include <models/FGInput.h>
74 #include <models/FGOutput.h>
75 #include <initialization/FGInitialCondition.h>
76 //#include <initialization/FGTrimAnalysis.h> // Remove until later
77 #include <input_output/FGPropertyManager.h>
78 #include <input_output/FGScript.h>
82 static const char *IdSrc = "$Id$";
83 static const char *IdHdr = ID_FDMEXEC;
85 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
89 unsigned int FGFDMExec::FDMctr = 0;
90 FGPropertyManager* FGFDMExec::master=0;
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
96 void checkTied ( FGPropertyManager *node )
98 int N = node->nChildren();
101 for (int i=0; i<N; i++) {
102 if (node->getChild(i)->nChildren() ) {
103 // cout << "Untieing " << node->getChild(i)->getName() << " property branch." << endl;
104 checkTied( (FGPropertyManager*)node->getChild(i) );
105 } else if ( node->getChild(i)->isTied() ) {
106 name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 FGFDMExec::FGFDMExec(FGPropertyManager* root) : Root(root)
130 ExternalReactions = 0;
145 // Multiple FDM's are stopped for now. We need to ensure that
146 // the "user" instance always gets the zeroeth instance number,
147 // because there may be instruments or scripts tied to properties
148 // in the jsbsim[0] node.
149 // ToDo: it could be that when JSBSim is reset and a new FDM is wanted, that
150 // process might try setting FDMctr = 0. Then the line below would not need
151 // to be commented out.
156 char* num = getenv("JSBSIM_DEBUG");
157 if (num) debug_lvl = atoi(num); // set debug level
158 } catch (...) { // if error set to 1
164 master = new FGPropertyManager;
168 instance = Root->GetNode("/fdm/jsbsim",IdFDM,true);
170 // this is to catch errors in binding member functions to the property tree.
173 } catch ( string msg ) {
174 cout << "Caught error: " << msg << endl;
182 typedef int (FGFDMExec::*iPMF)(void) const;
183 // instance->Tie("simulation/do_trim_analysis", this, (iPMF)0, &FGFDMExec::DoTrimAnalysis);
184 instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim);
185 instance->Tie("simulation/terminate", (int *)&Terminate);
186 Constructing = false;
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 FGFDMExec::~FGFDMExec()
194 checkTied( instance );
196 if (Root == 0) delete master;
197 } catch ( string msg ) {
198 cout << "Caught error: " << msg << endl;
201 for (unsigned int i=1; i<SlaveFDMList.size(); i++) delete SlaveFDMList[i]->exec;
202 SlaveFDMList.clear();
204 //ToDo remove property catalog.
209 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211 bool FGFDMExec::Allocate(void)
215 Atmosphere = new FGAtmosphere(this);
216 FCS = new FGFCS(this);
217 Propulsion = new FGPropulsion(this);
218 MassBalance = new FGMassBalance(this);
219 Aerodynamics = new FGAerodynamics (this);
220 Inertial = new FGInertial(this);
222 GroundCallback = new FGGroundCallback(Inertial->GetRefRadius());
224 GroundReactions = new FGGroundReactions(this);
225 ExternalReactions = new FGExternalReactions(this);
226 BuoyantForces = new FGBuoyantForces(this);
227 Aircraft = new FGAircraft(this);
228 Propagate = new FGPropagate(this);
229 Auxiliary = new FGAuxiliary(this);
230 Input = new FGInput(this);
232 State = new FGState(this); // This must be done here, as the FGState
233 // class needs valid pointers to the above
236 // Initialize models so they can communicate with each other
238 Atmosphere->InitModel();
240 Propulsion->InitModel();
241 MassBalance->InitModel();
242 Aerodynamics->InitModel();
243 Inertial->InitModel();
244 GroundReactions->InitModel();
245 ExternalReactions->InitModel();
246 BuoyantForces->InitModel();
247 Aircraft->InitModel();
248 Propagate->InitModel();
249 Auxiliary->InitModel();
252 IC = new FGInitialCondition(this);
254 // Schedule a model. The second arg (the integer) is the pass number. For
255 // instance, the atmosphere model could get executed every fifth pass it is called
256 // by the executive. IC and Trim objects are NOT scheduled.
259 Schedule(Atmosphere, 1);
261 Schedule(Propulsion, 1);
262 Schedule(MassBalance, 1);
263 Schedule(Aerodynamics, 1);
264 Schedule(Inertial, 1);
265 Schedule(GroundReactions, 1);
266 Schedule(ExternalReactions, 1);
267 Schedule(BuoyantForces, 1);
268 Schedule(Aircraft, 1);
269 Schedule(Propagate, 1);
270 Schedule(Auxiliary, 1);
277 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279 bool FGFDMExec::DeAllocate(void)
288 delete GroundReactions;
289 delete ExternalReactions;
290 delete BuoyantForces;
297 for (unsigned i=0; i<Outputs.size(); i++) delete Outputs[i];
303 delete GroundCallback;
317 ExternalReactions = 0;
328 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
330 int FGFDMExec::Schedule(FGModel* model, int rate)
332 FGModel* model_iterator;
334 model_iterator = FirstModel;
336 if (model_iterator == 0L) { // this is the first model
339 FirstModel->NextModel = 0L;
340 FirstModel->SetRate(rate);
342 } else { // subsequent model
344 while (model_iterator->NextModel != 0L) {
345 model_iterator = model_iterator->NextModel;
347 model_iterator->NextModel = model;
348 model_iterator->NextModel->SetRate(rate);
355 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
357 bool FGFDMExec::Run(void)
360 FGModel* model_iterator;
362 model_iterator = FirstModel;
363 if (model_iterator == 0L) return false;
367 for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
368 // SlaveFDMList[i]->exec->State->Initialize(); // Transfer state to the slave FDM
369 // SlaveFDMList[i]->exec->Run();
372 // returns true if success
374 if (Script != 0 && !State->IntegrationSuspended()) success = Script->RunScript();
376 while (model_iterator != 0L) {
377 model_iterator->Run();
378 model_iterator = model_iterator->NextModel;
382 if (!Holding()) State->IncrTime();
383 if (Terminate) success = false;
388 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
389 // This call will cause the sim time to reset to 0.0
391 bool FGFDMExec::RunIC(void)
393 State->SuspendIntegration();
394 State->Initialize(IC);
396 State->ResumeIntegration();
401 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
403 void FGFDMExec::ResetToInitialConditions(void)
405 FGModel* model_iterator;
407 model_iterator = FirstModel;
408 if (model_iterator == 0L) return;
410 while (model_iterator != 0L) {
411 model_iterator->InitModel();
412 model_iterator = model_iterator->NextModel;
416 if (Script) Script->ResetEvents();
419 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421 void FGFDMExec::SetGroundCallback(FGGroundCallback* p)
423 delete GroundCallback;
427 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 double FGFDMExec::GetSimTime(void)
431 return (State->Getsim_time());
434 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
436 double FGFDMExec::GetDeltaT(void)
438 return (State->Getdt());
441 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
443 vector <string> FGFDMExec::EnumerateFDMs(void)
445 vector <string> FDMList;
447 FDMList.push_back(Aircraft->GetAircraftName());
449 for (unsigned int i=1; i<SlaveFDMList.size(); i++) {
450 FDMList.push_back(SlaveFDMList[i]->exec->GetAircraft()->GetAircraftName());
456 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
458 bool FGFDMExec::LoadScript(string script)
462 Script = new FGScript(this);
463 result = Script->LoadScript(script);
468 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
470 bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string SystemsPath,
471 string model, bool addModelToPath)
473 FGFDMExec::AircraftPath = AircraftPath;
474 FGFDMExec::EnginePath = EnginePath;
475 FGFDMExec::SystemsPath = SystemsPath;
477 return LoadModel(model, addModelToPath);
480 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
482 bool FGFDMExec::LoadModel(string model, bool addModelToPath)
485 string aircraftCfgFileName;
486 string separator = "/";
487 Element* element = 0L;
488 bool result = false; // initialize result to false, indicating input file not yet read
490 modelName = model; // Set the class modelName attribute
496 if( AircraftPath.empty() || EnginePath.empty() || SystemsPath.empty()) {
497 cerr << "Error: attempted to load aircraft with undefined ";
498 cerr << "aircraft, engine, and system paths" << endl;
502 FullAircraftPath = AircraftPath;
503 if (addModelToPath) FullAircraftPath += separator + model;
504 aircraftCfgFileName = FullAircraftPath + separator + model + ".xml";
511 document = LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
513 ReadPrologue(document);
514 element = document->GetElement();
517 while (element && result) {
518 string element_name = element->GetName();
519 if (element_name == "fileheader" ) result = ReadFileHeader(element);
520 else if (element_name == "slave") result = ReadSlave(element);
521 else if (element_name == "metrics") result = Aircraft->Load(element);
522 else if (element_name == "mass_balance") result = MassBalance->Load(element);
523 else if (element_name == "ground_reactions") result = GroundReactions->Load(element);
524 else if (element_name == "external_reactions") result = ExternalReactions->Load(element);
525 else if (element_name == "buoyant_forces") result = BuoyantForces->Load(element);
526 else if (element_name == "propulsion") result = Propulsion->Load(element);
527 else if (element_name == "system") result = FCS->Load(element,
529 else if (element_name == "autopilot") result = FCS->Load(element,
531 else if (element_name == "flight_control") result = FCS->Load(element,
533 else if (element_name == "aerodynamics") result = Aerodynamics->Load(element);
534 else if (element_name == "input") result = Input->Load(element);
535 else if (element_name == "output") {
536 FGOutput* Output = new FGOutput(this);
539 result = Output->Load(element);
540 Outputs.push_back(Output);
543 cerr << "Found unexpected subsystem: " << element_name << ", exiting." << endl;
547 element = document->GetNextElement();
551 << " JSBSim failed to load aircraft model."
561 << " JSBSim failed to load properly."
566 struct PropertyCatalogStructure masterPCS;
567 masterPCS.base_string = "";
568 masterPCS.node = (FGPropertyManager*)Root;
570 BuildPropertyCatalog(&masterPCS);
575 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
579 struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
583 for (unsigned int i=0; i<pcs->node->nChildren(); i++) {
584 pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
585 node_idx = pcs->node->getChild(i)->getIndex();
586 sprintf(int_buf, "[%d]", node_idx);
587 if (node_idx != 0) pcsNew->base_string += string(int_buf);
588 if (pcs->node->getChild(i)->nChildren() == 0) {
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;