1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Schedules and runs the model routines.
8 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.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"
45 #include "models/FGAtmosphere.h"
46 #include "models/atmosphere/FGMSIS.h"
47 #include "models/atmosphere/FGMars.h"
48 #include "models/FGFCS.h"
49 #include "models/FGPropulsion.h"
50 #include "models/FGMassBalance.h"
51 #include "models/FGGroundReactions.h"
52 #include "models/FGExternalReactions.h"
53 #include "models/FGBuoyantForces.h"
54 #include "models/FGAerodynamics.h"
55 #include "models/FGInertial.h"
56 #include "models/FGAircraft.h"
57 #include "models/FGPropagate.h"
58 #include "models/FGAuxiliary.h"
59 #include "models/FGInput.h"
60 #include "models/FGOutput.h"
61 #include "initialization/FGInitialCondition.h"
62 //#include "initialization/FGTrimAnalysis.h" // Remove until later
63 #include "input_output/FGPropertyManager.h"
64 #include "input_output/FGScript.h"
74 static const char *IdSrc = "$Id: FGFDMExec.cpp,v 1.84 2011/01/16 16:26:14 bcoconni Exp $";
75 static const char *IdHdr = ID_FDMEXEC;
77 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
81 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 FGFDMExec::FGFDMExec(FGPropertyManager* root, unsigned int* fdmctr) : Root(root), FDMctr(fdmctr)
97 ExternalReactions = 0;
116 dT = 1.0/120.0; // a default timestep size. This is needed for when JSBSim is
117 // run in standalone mode with no initialization file.
120 char* num = getenv("JSBSIM_DEBUG");
121 if (num) debug_lvl = atoi(num); // set debug level
122 } catch (...) { // if error set to 1
126 if (Root == 0) { // Then this is the root FDM
127 Root = new FGPropertyManager; // Create the property manager
132 FDMctr = new unsigned int; // Create and initialize the child FDM counter
136 // Store this FDM's ID
137 IdFDM = (*FDMctr); // The main (parent) JSBSim instance is always the "zeroth"
139 // Prepare FDMctr for the next child FDM id
140 (*FDMctr)++; // instance. "child" instances are loaded last.
142 instance = Root->GetNode("/fdm/jsbsim",IdFDM,true);
144 // this is to catch errors in binding member functions to the property tree.
147 } catch ( string msg ) {
148 cout << "Caught error: " << msg << endl;
156 typedef int (FGFDMExec::*iPMF)(void) const;
157 // instance->Tie("simulation/do_trim_analysis", this, (iPMF)0, &FGFDMExec::DoTrimAnalysis);
158 instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim);
159 instance->Tie("simulation/reset", this, (iPMF)0, &FGFDMExec::ResetToInitialConditions);
160 instance->Tie("simulation/terminate", (int *)&Terminate);
161 instance->Tie("simulation/sim-time-sec", this, &FGFDMExec::GetSimTime);
162 instance->Tie("simulation/jsbsim-debug", this, &FGFDMExec::GetDebugLevel, &FGFDMExec::SetDebugLevel);
164 Constructing = false;
167 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 FGFDMExec::~FGFDMExec()
175 if (IdFDM == 0) { // Meaning this is no child FDM
186 } catch ( string msg ) {
187 cout << "Caught error: " << msg << endl;
190 for (unsigned int i=1; i<ChildFDMList.size(); i++) delete ChildFDMList[i]->exec;
191 ChildFDMList.clear();
193 PropertyCatalog.clear();
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 // Schedule a model. The second arg (the integer) is the pass number. For
224 // instance, the atmosphere model could get executed every fifth pass it is called.
227 Schedule(Atmosphere, 1);
229 Schedule(Propulsion, 1);
230 Schedule(MassBalance, 1);
231 Schedule(Aerodynamics, 1);
232 Schedule(Inertial, 1);
233 Schedule(GroundReactions, 1);
234 Schedule(ExternalReactions, 1);
235 Schedule(BuoyantForces, 1);
236 Schedule(Aircraft, 1);
237 Schedule(Propagate, 1);
238 Schedule(Auxiliary, 1);
240 // Initialize models so they can communicate with each other
242 vector <FGModel*>::iterator it;
243 for (it = Models.begin(); it != Models.end(); ++it) (*it)->InitModel();
245 IC = new FGInitialCondition(this);
252 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254 bool FGFDMExec::DeAllocate(void)
263 delete GroundReactions;
264 delete ExternalReactions;
265 delete BuoyantForces;
271 for (unsigned i=0; i<Outputs.size(); i++) delete Outputs[i];
277 delete GroundCallback;
289 ExternalReactions = 0;
302 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 void FGFDMExec::Schedule(FGModel* model, int rate)
306 model->SetRate(rate);
307 Models.push_back(model);
310 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312 bool FGFDMExec::Run(void)
318 for (unsigned int i=1; i<ChildFDMList.size(); i++) {
319 ChildFDMList[i]->AssignState(Propagate); // Transfer state to the child FDM
320 ChildFDMList[i]->Run();
323 // returns true if success, false if complete
324 if (Script != 0 && !IntegrationSuspended()) success = Script->RunScript();
326 vector <FGModel*>::iterator it;
327 for (it = Models.begin(); it != Models.end(); ++it) (*it)->Run();
330 if (!Holding()) IncrTime();
331 if (Terminate) success = false;
336 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 // This call will cause the sim time to reset to 0.0
339 bool FGFDMExec::RunIC(void)
341 SuspendIntegration(); // saves the integration rate, dt, then sets it to 0.0.
344 ResumeIntegration(); // Restores the integration rate to what it was.
349 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351 void FGFDMExec::Initialize(FGInitialCondition *FGIC)
353 Propagate->SetInitialState( FGIC );
356 Atmosphere->SetWindNED( FGIC->GetWindNFpsIC(),
357 FGIC->GetWindEFpsIC(),
358 FGIC->GetWindDFpsIC() );
360 FGColumnVector3 vAeroUVW;
361 vAeroUVW = Propagate->GetUVW() + Propagate->GetTl2b()*Atmosphere->GetTotalWindNED();
364 if (vAeroUVW(eW) != 0.0)
365 alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
368 if (vAeroUVW(eV) != 0.0)
369 beta = vAeroUVW(eU)*vAeroUVW(eU)+vAeroUVW(eW)*vAeroUVW(eW) > 0.0 ? atan2(vAeroUVW(eV), (fabs(vAeroUVW(eU))/vAeroUVW(eU))*sqrt(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW))) : 0.0;
373 Auxiliary->SetAB(alpha, beta);
375 double Vt = vAeroUVW.Magnitude();
376 Auxiliary->SetVt(Vt);
378 Auxiliary->SetMach(Vt/Atmosphere->GetSoundSpeed());
380 double qbar = 0.5*Vt*Vt*Atmosphere->GetDensity();
381 Auxiliary->Setqbar(qbar);
384 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
386 // A private, internal function call for Tie-ing to a property, so it needs an
389 void FGFDMExec::ResetToInitialConditions(int mode)
392 for (unsigned int i=0; i<Outputs.size(); i++) {
393 Outputs[i]->SetStartNewFile(true);
397 ResetToInitialConditions();
400 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402 void FGFDMExec::ResetToInitialConditions(void)
404 if (Constructing) return;
406 vector <FGModel*>::iterator it;
407 for (it = Models.begin(); it != Models.end(); ++it) (*it)->InitModel();
410 if (Script) Script->ResetEvents();
413 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
415 void FGFDMExec::SetGroundCallback(FGGroundCallback* p)
417 delete GroundCallback;
421 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423 vector <string> FGFDMExec::EnumerateFDMs(void)
425 vector <string> FDMList;
427 FDMList.push_back(Aircraft->GetAircraftName());
429 for (unsigned int i=1; i<ChildFDMList.size(); i++) {
430 FDMList.push_back(ChildFDMList[i]->exec->GetAircraft()->GetAircraftName());
436 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
438 bool FGFDMExec::LoadScript(const string& script, double deltaT)
442 Script = new FGScript(this);
443 result = Script->LoadScript(RootDir + script, deltaT);
448 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
450 bool FGFDMExec::LoadModel(const string& AircraftPath, const string& EnginePath, const string& SystemsPath,
451 const string& model, bool addModelToPath)
453 FGFDMExec::AircraftPath = RootDir + AircraftPath;
454 FGFDMExec::EnginePath = RootDir + EnginePath;
455 FGFDMExec::SystemsPath = RootDir + SystemsPath;
457 return LoadModel(model, addModelToPath);
460 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462 bool FGFDMExec::LoadModel(const string& model, bool addModelToPath)
465 string aircraftCfgFileName;
466 Element* element = 0L;
467 bool result = false; // initialize result to false, indicating input file not yet read
469 modelName = model; // Set the class modelName attribute
471 if( AircraftPath.empty() || EnginePath.empty() || SystemsPath.empty()) {
472 cerr << "Error: attempted to load aircraft with undefined ";
473 cerr << "aircraft, engine, and system paths" << endl;
477 FullAircraftPath = AircraftPath;
478 if (addModelToPath) FullAircraftPath += "/" + model;
479 aircraftCfgFileName = FullAircraftPath + "/" + model + ".xml";
486 int saved_debug_lvl = debug_lvl;
488 document = LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
490 if (IsChild) debug_lvl = 0;
492 ReadPrologue(document);
494 if (IsChild) debug_lvl = saved_debug_lvl;
496 // Process the fileheader element in the aircraft config file. This element is OPTIONAL.
497 element = document->FindElement("fileheader");
499 result = ReadFileHeader(element);
501 cerr << endl << "Aircraft fileheader element has problems in file " << aircraftCfgFileName << endl;
506 if (IsChild) debug_lvl = 0;
508 // Process the metrics element. This element is REQUIRED.
509 element = document->FindElement("metrics");
511 result = Aircraft->Load(element);
513 cerr << endl << "Aircraft metrics element has problems in file " << aircraftCfgFileName << endl;
517 cerr << endl << "No metrics element was found in the aircraft config file." << endl;
521 // Process the mass_balance element. This element is REQUIRED.
522 element = document->FindElement("mass_balance");
524 result = MassBalance->Load(element);
526 cerr << endl << "Aircraft mass_balance element has problems in file " << aircraftCfgFileName << endl;
530 cerr << endl << "No mass_balance element was found in the aircraft config file." << endl;
534 // Process the ground_reactions element. This element is REQUIRED.
535 element = document->FindElement("ground_reactions");
537 result = GroundReactions->Load(element);
539 cerr << endl << "Aircraft ground_reactions element has problems in file " << aircraftCfgFileName << endl;
543 cerr << endl << "No ground_reactions element was found in the aircraft config file." << endl;
547 // Process the external_reactions element. This element is OPTIONAL.
548 element = document->FindElement("external_reactions");
550 result = ExternalReactions->Load(element);
552 cerr << endl << "Aircraft external_reactions element has problems in file " << aircraftCfgFileName << endl;
557 // Process the buoyant_forces element. This element is OPTIONAL.
558 element = document->FindElement("buoyant_forces");
560 result = BuoyantForces->Load(element);
562 cerr << endl << "Aircraft buoyant_forces element has problems in file " << aircraftCfgFileName << endl;
567 // Process the propulsion element. This element is OPTIONAL.
568 element = document->FindElement("propulsion");
570 result = Propulsion->Load(element);
572 cerr << endl << "Aircraft propulsion element has problems in file " << aircraftCfgFileName << endl;
577 // Process the system element[s]. This element is OPTIONAL, and there may be more than one.
578 element = document->FindElement("system");
580 result = FCS->Load(element, FGFCS::stSystem);
582 cerr << endl << "Aircraft system element has problems in file " << aircraftCfgFileName << endl;
585 element = document->FindNextElement("system");
588 // Process the autopilot element. This element is OPTIONAL.
589 element = document->FindElement("autopilot");
591 result = FCS->Load(element, FGFCS::stAutoPilot);
593 cerr << endl << "Aircraft autopilot element has problems in file " << aircraftCfgFileName << endl;
598 // Process the flight_control element. This element is OPTIONAL.
599 element = document->FindElement("flight_control");
601 result = FCS->Load(element, FGFCS::stFCS);
603 cerr << endl << "Aircraft flight_control element has problems in file " << aircraftCfgFileName << endl;
608 // Process the aerodynamics element. This element is OPTIONAL, but almost always expected.
609 element = document->FindElement("aerodynamics");
611 result = Aerodynamics->Load(element);
613 cerr << endl << "Aircraft aerodynamics element has problems in file " << aircraftCfgFileName << endl;
617 cerr << endl << "No expected aerodynamics element was found in the aircraft config file." << endl;
620 // Process the input element. This element is OPTIONAL.
621 element = document->FindElement("input");
623 result = Input->Load(element);
625 cerr << endl << "Aircraft input element has problems in file " << aircraftCfgFileName << endl;
630 // Process the output element[s]. This element is OPTIONAL, and there may be more than one.
632 typedef int (FGOutput::*iOPMF)(void) const;
633 element = document->FindElement("output");
635 if (debug_lvl > 0) cout << endl << " Output data set: " << idx << " ";
636 FGOutput* Output = new FGOutput(this);
639 result = Output->Load(element);
641 cerr << endl << "Aircraft output element has problems in file " << aircraftCfgFileName << endl;
644 Outputs.push_back(Output);
645 string outputProp = CreateIndexedPropertyName("simulation/output",idx);
646 instance->Tie(outputProp+"/log_rate_hz", Output, (iOPMF)0, &FGOutput::SetRate);
649 element = document->FindNextElement("output");
652 // Lastly, process the child element. This element is OPTIONAL - and NOT YET SUPPORTED.
653 element = document->FindElement("child");
655 result = ReadChild(element);
657 cerr << endl << "Aircraft child element has problems in file " << aircraftCfgFileName << endl;
665 MassBalance->Run(); // Update all mass properties for the report.
666 MassBalance->GetMassPropertiesReport();
668 cout << endl << fgblue << highint
669 << "End of vehicle configuration loading." << endl
670 << "-------------------------------------------------------------------------------"
674 if (IsChild) debug_lvl = saved_debug_lvl;
678 << " JSBSim failed to open the configuration file: " << aircraftCfgFileName
682 // Late bind previously undefined FCS inputs.
685 } catch (string prop) {
686 cerr << endl << fgred << " Could not late bind property " << prop
687 << ". Aborting." << reset << endl;
692 struct PropertyCatalogStructure masterPCS;
693 masterPCS.base_string = "";
694 masterPCS.node = (FGPropertyManager*)Root;
695 BuildPropertyCatalog(&masterPCS);
701 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
703 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
705 struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
708 for (int i=0; i<pcs->node->nChildren(); i++) {
709 pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
710 node_idx = pcs->node->getChild(i)->getIndex();
712 pcsNew->base_string = CreateIndexedPropertyName(pcsNew->base_string, node_idx);
714 if (pcs->node->getChild(i)->nChildren() == 0) {
715 if (pcsNew->base_string.substr(0,11) == string("/fdm/jsbsim")) {
716 pcsNew->base_string = pcsNew->base_string.erase(0,12);
718 PropertyCatalog.push_back(pcsNew->base_string);
720 pcsNew->node = (FGPropertyManager*)pcs->node->getChild(i);
721 BuildPropertyCatalog(pcsNew);
727 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
729 string FGFDMExec::QueryPropertyCatalog(const string& in)
732 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
733 if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
735 if (results.empty()) return "No matches found\n";
739 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
741 void FGFDMExec::PrintPropertyCatalog(void)
744 cout << " " << fgblue << highint << underon << "Property Catalog for "
745 << modelName << reset << endl << endl;
746 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
747 cout << " " << PropertyCatalog[i] << endl;
751 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
753 bool FGFDMExec::ReadFileHeader(Element* el)
755 bool result = true; // true for success
757 if (debug_lvl == 0) return result;
760 cout << endl <<highint << fgblue << "Reading child model: " << IdFDM << reset << endl << endl;
763 if (el->FindElement("description"))
764 cout << " Description: " << el->FindElement("description")->GetDataLine() << endl;
765 if (el->FindElement("author"))
766 cout << " Model Author: " << el->FindElement("author")->GetDataLine() << endl;
767 if (el->FindElement("filecreationdate"))
768 cout << " Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
769 if (el->FindElement("version"))
770 cout << " Version: " << el->FindElement("version")->GetDataLine() << endl;
775 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
777 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
779 bool result = true; // true for success
781 if (!el) return false;
783 string AircraftName = el->GetAttributeValue("name");
784 Aircraft->SetAircraftName(AircraftName);
786 if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
787 << underoff << ": " << highint << AircraftName << normint << endl;
789 CFGVersion = el->GetAttributeValue("version");
790 Release = el->GetAttributeValue("release");
793 cout << " Version: " << highint << CFGVersion
795 if (CFGVersion != needed_cfg_version) {
796 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
797 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
798 cerr << "Current version needed is: " << needed_cfg_version << endl;
799 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
803 if (Release == "ALPHA" && (debug_lvl & 1)) {
805 << highint << "This aircraft model is an " << fgred << Release
806 << reset << highint << " release!!!" << endl << endl << reset
807 << "This aircraft model may not even properly load, and probably"
808 << " will not fly as expected." << endl << endl
809 << fgred << highint << "Use this model for development purposes ONLY!!!"
810 << normint << reset << endl << endl;
811 } else if (Release == "BETA" && (debug_lvl & 1)) {
813 << highint << "This aircraft model is a " << fgred << Release
814 << reset << highint << " release!!!" << endl << endl << reset
815 << "This aircraft model probably will not fly as expected." << endl << endl
816 << fgblue << highint << "Use this model for development purposes ONLY!!!"
817 << normint << reset << endl << endl;
818 } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
820 << highint << "This aircraft model is a " << fgblue << Release
821 << reset << highint << " release." << endl << endl << reset;
822 } else if (debug_lvl & 1) {
824 << highint << "This aircraft model is an " << fgred << Release
825 << reset << highint << " release!!!" << endl << endl << reset
826 << "This aircraft model may not even properly load, and probably"
827 << " will not fly as expected." << endl << endl
828 << fgred << highint << "Use this model for development purposes ONLY!!!"
829 << normint << reset << endl << endl;
835 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
837 bool FGFDMExec::ReadChild(Element* el)
839 // Add a new childData object to the child FDM list
840 // Populate that childData element with a new FDMExec object
841 // Set the IsChild flag for that FDMExec object
842 // Get the aircraft name
843 // set debug level to print out no additional data for child objects
844 // Load the model given the aircraft name
845 // reset debug level to prior setting
849 struct childData* child = new childData;
851 child->exec = new FGFDMExec(Root, FDMctr);
852 child->exec->SetChild(true);
854 string childAircraft = el->GetAttributeValue("name");
855 string sMated = el->GetAttributeValue("mated");
856 if (sMated == "false") child->mated = false; // child objects are mated by default.
857 string sInternal = el->GetAttributeValue("internal");
858 if (sInternal == "true") child->internal = true; // child objects are external by default.
860 child->exec->SetAircraftPath( AircraftPath );
861 child->exec->SetEnginePath( EnginePath );
862 child->exec->SetSystemsPath( SystemsPath );
863 child->exec->LoadModel(childAircraft);
865 Element* location = el->FindElement("location");
867 child->Loc = location->FindElementTripletConvertTo("IN");
869 cerr << endl << highint << fgred << " No location was found for this child object!" << reset << endl;
873 Element* orientation = el->FindElement("orient");
875 child->Orient = orientation->FindElementTripletConvertTo("RAD");
876 } else if (debug_lvl > 0) {
877 cerr << endl << highint << " No orientation was found for this child object! Assuming 0,0,0." << reset << endl;
880 ChildFDMList.push_back(child);
885 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
887 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
892 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
894 FGTrim* FGFDMExec::GetTrim(void)
897 Trim = new FGTrim(this,tNone);
901 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
903 void FGFDMExec::DisableOutput(void)
905 for (unsigned i=0; i<Outputs.size(); i++) {
906 Outputs[i]->Disable();
910 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
912 void FGFDMExec::EnableOutput(void)
914 for (unsigned i=0; i<Outputs.size(); i++) {
915 Outputs[i]->Enable();
919 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
921 bool FGFDMExec::SetOutputDirectives(const string& fname)
925 FGOutput* Output = new FGOutput(this);
926 Output->SetDirectivesFile(RootDir + fname);
929 result = Output->Load(0);
932 Outputs.push_back(Output);
933 typedef int (FGOutput::*iOPMF)(void) const;
934 string outputProp = CreateIndexedPropertyName("simulation/output",Outputs.size()-1);
935 instance->Tie(outputProp+"/log_rate_hz", Output, (iOPMF)0, &FGOutput::SetRate);
941 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
943 void FGFDMExec::DoTrim(int mode)
947 if (Constructing) return;
949 if (mode < 0 || mode > JSBSim::tNone) {
950 cerr << endl << "Illegal trimming mode!" << endl << endl;
953 saved_time = sim_time;
954 FGTrim trim(this, (JSBSim::TrimMode)mode);
955 if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
957 sim_time = saved_time;
960 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
962 void FGFDMExec::DoTrimAnalysis(int mode)
965 if (Constructing) return;
967 if (mode < 0 || mode > JSBSim::taNone) {
968 cerr << endl << "Illegal trimming mode!" << endl << endl;
971 saved_time = sim_time;
973 FGTrimAnalysis trimAnalysis(this, (JSBSim::TrimAnalysisMode)mode);
975 if ( !trimAnalysis.Load(IC->GetInitFile(), false) ) {
976 cerr << "A problem occurred with trim configuration file " << trimAnalysis.Load(IC->GetInitFile()) << endl;
980 bool result = trimAnalysis.DoTrim();
982 if ( !result ) cerr << endl << "Trim Failed" << endl << endl;
984 trimAnalysis.Report();
985 Setsim_time(saved_time);
988 cout << "\nOutput: " << GetOutputFileName() << endl;
992 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
994 void FGFDMExec::UseAtmosphereMSIS(void)
996 FGAtmosphere *oldAtmosphere = Atmosphere;
997 Atmosphere = new MSIS(this);
998 if (!Atmosphere->InitModel()) {
999 cerr << fgred << "MSIS Atmosphere model init failed" << fgdef << endl;
1002 delete oldAtmosphere;
1005 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1007 void FGFDMExec::UseAtmosphereMars(void)
1010 FGAtmosphere *oldAtmosphere = Atmosphere;
1011 Atmosphere = new FGMars(this);
1012 if (!Atmosphere->InitModel()) {
1013 cerr << fgred << "Mars Atmosphere model init failed" << fgdef << endl;
1016 delete oldAtmosphere;
1020 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1021 // The bitmasked value choices are as follows:
1022 // unset: In this case (the default) JSBSim would only print
1023 // out the normally expected messages, essentially echoing
1024 // the config files as they are read. If the environment
1025 // variable is not set, debug_lvl is set to 1 internally
1026 // 0: This requests JSBSim not to output any messages
1028 // 1: This value explicity requests the normal JSBSim
1030 // 2: This value asks for a message to be printed out when
1031 // a class is instantiated
1032 // 4: When this value is set, a message is displayed when a
1033 // FGModel object executes its Run() method
1034 // 8: When this value is set, various runtime state variables
1035 // are printed out periodically
1036 // 16: When set various parameters are sanity checked and
1037 // a message is printed out when they go out of bounds
1039 void FGFDMExec::Debug(int from)
1041 if (debug_lvl <= 0) return;
1043 if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
1044 if (from == 0) { // Constructor
1045 cout << "\n\n " << highint << underon << "JSBSim Flight Dynamics Model v"
1046 << JSBSim_version << underoff << normint << endl;
1047 cout << halfint << " [JSBSim-ML v" << needed_cfg_version << "]\n\n";
1048 cout << normint << "JSBSim startup beginning ...\n\n";
1049 } else if (from == 3) {
1050 cout << "\n\nJSBSim startup complete\n\n";
1053 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1054 if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
1055 if (from == 1) cout << "Destroyed: FGFDMExec" << endl;
1057 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1059 cout << "================== Frame: " << Frame << " Time: "
1060 << sim_time << " dt: " << dT << endl;
1063 if (debug_lvl & 8 ) { // Runtime state variables
1065 if (debug_lvl & 16) { // Sanity checking
1067 if (debug_lvl & 64) {
1068 if (from == 0) { // Constructor
1069 cout << IdSrc << endl;
1070 cout << IdHdr << endl;