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"
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"
75 static const char *IdSrc = "$Id$";
76 static const char *IdHdr = ID_FDMEXEC;
78 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
82 unsigned int FGFDMExec::FDMctr = 0;
83 FGPropertyManager* FGFDMExec::master=0;
85 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
89 void checkTied ( FGPropertyManager *node )
91 int N = node->nChildren();
94 for (int i=0; i<N; i++) {
95 if (node->getChild(i)->nChildren() ) {
96 checkTied( (FGPropertyManager*)node->getChild(i) );
98 if ( node->getChild(i)->isTied() ) {
99 name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 FGFDMExec::FGFDMExec(FGPropertyManager* root) : Root(root)
122 ExternalReactions = 0;
137 IdFDM = FDMctr; // The main (parent) JSBSim instance is always the "zeroth"
138 FDMctr++; // instance. "child" instances are loaded last.
141 char* num = getenv("JSBSIM_DEBUG");
142 if (num) debug_lvl = atoi(num); // set debug level
143 } catch (...) { // if error set to 1
149 master = new FGPropertyManager;
153 instance = Root->GetNode("/fdm/jsbsim",IdFDM,true);
155 // this is to catch errors in binding member functions to the property tree.
158 } catch ( string msg ) {
159 cout << "Caught error: " << msg << endl;
167 typedef int (FGFDMExec::*iPMF)(void) const;
168 // instance->Tie("simulation/do_trim_analysis", this, (iPMF)0, &FGFDMExec::DoTrimAnalysis);
169 instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim);
170 instance->Tie("simulation/reset", this, (iPMF)0, &FGFDMExec::ResetToInitialConditions);
171 instance->Tie("simulation/terminate", (int *)&Terminate);
172 Constructing = false;
175 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 FGFDMExec::~FGFDMExec()
180 checkTied( instance );
182 if (Root == 0) delete master;
183 } catch ( string msg ) {
184 cout << "Caught error: " << msg << endl;
187 for (unsigned int i=1; i<ChildFDMList.size(); i++) delete ChildFDMList[i]->exec;
188 ChildFDMList.clear();
190 PropertyCatalog.clear();
197 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 bool FGFDMExec::Allocate(void)
203 Atmosphere = new FGAtmosphere(this);
204 FCS = new FGFCS(this);
205 Propulsion = new FGPropulsion(this);
206 MassBalance = new FGMassBalance(this);
207 Aerodynamics = new FGAerodynamics (this);
208 Inertial = new FGInertial(this);
210 GroundCallback = new FGGroundCallback(Inertial->GetRefRadius());
212 GroundReactions = new FGGroundReactions(this);
213 ExternalReactions = new FGExternalReactions(this);
214 BuoyantForces = new FGBuoyantForces(this);
215 Aircraft = new FGAircraft(this);
216 Propagate = new FGPropagate(this);
217 Auxiliary = new FGAuxiliary(this);
218 Input = new FGInput(this);
220 State = new FGState(this); // This must be done here, as the FGState
221 // class needs valid pointers to the above
224 // Schedule a model. The second arg (the integer) is the pass number. For
225 // instance, the atmosphere model could get executed every fifth pass it is called.
228 Schedule(Atmosphere, 30);
230 Schedule(Propulsion, 1);
231 Schedule(MassBalance, 1);
232 Schedule(Aerodynamics, 1);
233 Schedule(Inertial, 1);
234 Schedule(GroundReactions, 1);
235 Schedule(ExternalReactions, 1);
236 Schedule(BuoyantForces, 1);
237 Schedule(Aircraft, 1);
238 Schedule(Propagate, 1);
239 Schedule(Auxiliary, 1);
241 // Initialize models so they can communicate with each other
243 vector <FGModel*>::iterator it;
244 for (it = Models.begin(); it != Models.end(); ++it) (*it)->InitModel();
246 IC = new FGInitialCondition(this);
253 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
255 bool FGFDMExec::DeAllocate(void)
264 delete GroundReactions;
265 delete ExternalReactions;
266 delete BuoyantForces;
273 for (unsigned i=0; i<Outputs.size(); i++) delete Outputs[i];
279 delete GroundCallback;
292 ExternalReactions = 0;
305 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
307 void FGFDMExec::Schedule(FGModel* model, int rate)
309 model->SetRate(rate);
310 Models.push_back(model);
313 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315 bool FGFDMExec::Run(void)
321 for (unsigned int i=1; i<ChildFDMList.size(); i++) {
322 ChildFDMList[i]->AssignState(Propagate); // Transfer state to the child FDM
323 ChildFDMList[i]->Run();
326 // returns true if success, false if complete
327 if (Script != 0 && !State->IntegrationSuspended()) success = Script->RunScript();
329 vector <FGModel*>::iterator it;
330 for (it = Models.begin(); it != Models.end(); ++it) (*it)->Run();
333 if (!Holding()) State->IncrTime();
334 if (Terminate) success = false;
339 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340 // This call will cause the sim time to reset to 0.0
342 bool FGFDMExec::RunIC(void)
344 State->SuspendIntegration();
345 State->Initialize(IC);
347 State->ResumeIntegration();
352 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354 // A private, internal function call for Tie-ing to a property, so it needs an
357 void FGFDMExec::ResetToInitialConditions(int mode)
360 for (unsigned int i=0; i<Outputs.size(); i++) {
361 Outputs[i]->SetStartNewFile(true);
365 ResetToInitialConditions();
368 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
370 void FGFDMExec::ResetToInitialConditions(void)
372 if (Constructing) return;
374 vector <FGModel*>::iterator it;
375 for (it = Models.begin(); it != Models.end(); ++it) (*it)->InitModel();
378 if (Script) Script->ResetEvents();
381 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
383 void FGFDMExec::SetGroundCallback(FGGroundCallback* p)
385 delete GroundCallback;
389 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
391 double FGFDMExec::GetSimTime(void)
393 return (State->Getsim_time());
396 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398 double FGFDMExec::GetDeltaT(void)
400 return (State->Getdt());
403 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
405 vector <string> FGFDMExec::EnumerateFDMs(void)
407 vector <string> FDMList;
409 FDMList.push_back(Aircraft->GetAircraftName());
411 for (unsigned int i=1; i<ChildFDMList.size(); i++) {
412 FDMList.push_back(ChildFDMList[i]->exec->GetAircraft()->GetAircraftName());
418 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
420 bool FGFDMExec::LoadScript(string script)
424 Script = new FGScript(this);
425 result = Script->LoadScript(script);
430 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
432 bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string SystemsPath,
433 string model, bool addModelToPath)
435 FGFDMExec::AircraftPath = AircraftPath;
436 FGFDMExec::EnginePath = EnginePath;
437 FGFDMExec::SystemsPath = SystemsPath;
439 return LoadModel(model, addModelToPath);
442 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
444 bool FGFDMExec::LoadModel(string model, bool addModelToPath)
447 string aircraftCfgFileName;
448 string separator = "/";
449 Element* element = 0L;
450 bool result = false; // initialize result to false, indicating input file not yet read
452 modelName = model; // Set the class modelName attribute
454 if( AircraftPath.empty() || EnginePath.empty() || SystemsPath.empty()) {
455 cerr << "Error: attempted to load aircraft with undefined ";
456 cerr << "aircraft, engine, and system paths" << endl;
460 FullAircraftPath = AircraftPath;
461 if (addModelToPath) FullAircraftPath += separator + model;
462 aircraftCfgFileName = FullAircraftPath + separator + model + ".xml";
469 int saved_debug_lvl = debug_lvl;
471 document = LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
473 if (IsChild) debug_lvl = 0;
475 ReadPrologue(document);
477 if (IsChild) debug_lvl = saved_debug_lvl;
479 // Process the fileheader element in the aircraft config file. This element is OPTIONAL.
480 element = document->FindElement("fileheader");
482 result = ReadFileHeader(element);
484 cerr << endl << "Aircraft fileheader element has problems in file " << aircraftCfgFileName << endl;
489 if (IsChild) debug_lvl = 0;
491 // Process the metrics element. This element is REQUIRED.
492 element = document->FindElement("metrics");
494 result = Aircraft->Load(element);
496 cerr << endl << "Aircraft metrics element has problems in file " << aircraftCfgFileName << endl;
500 cerr << endl << "No metrics element was found in the aircraft config file." << endl;
504 // Process the mass_balance element. This element is REQUIRED.
505 element = document->FindElement("mass_balance");
507 result = MassBalance->Load(element);
509 cerr << endl << "Aircraft mass_balance element has problems in file " << aircraftCfgFileName << endl;
513 cerr << endl << "No mass_balance element was found in the aircraft config file." << endl;
517 // Process the ground_reactions element. This element is REQUIRED.
518 element = document->FindElement("ground_reactions");
520 result = GroundReactions->Load(element);
522 cerr << endl << "Aircraft ground_reactions element has problems in file " << aircraftCfgFileName << endl;
526 cerr << endl << "No ground_reactions element was found in the aircraft config file." << endl;
530 // Process the external_reactions element. This element is OPTIONAL.
531 element = document->FindElement("external_reactions");
533 result = ExternalReactions->Load(element);
535 cerr << endl << "Aircraft external_reactions element has problems in file " << aircraftCfgFileName << endl;
540 // Process the buoyant_forces element. This element is OPTIONAL.
541 element = document->FindElement("buoyant_forces");
543 result = BuoyantForces->Load(element);
545 cerr << endl << "Aircraft buoyant_forces element has problems in file " << aircraftCfgFileName << endl;
550 // Process the propulsion element. This element is OPTIONAL.
551 element = document->FindElement("propulsion");
553 result = Propulsion->Load(element);
555 cerr << endl << "Aircraft propulsion element has problems in file " << aircraftCfgFileName << endl;
560 // Process the system element[s]. This element is OPTIONAL, and there may be more than one.
561 element = document->FindElement("system");
563 result = FCS->Load(element, FGFCS::stSystem);
565 cerr << endl << "Aircraft system element has problems in file " << aircraftCfgFileName << endl;
568 element = document->FindNextElement("system");
571 // Process the autopilot element. This element is OPTIONAL.
572 element = document->FindElement("autopilot");
574 result = FCS->Load(element, FGFCS::stAutoPilot);
576 cerr << endl << "Aircraft autopilot element has problems in file " << aircraftCfgFileName << endl;
581 // Process the flight_control element. This element is OPTIONAL.
582 element = document->FindElement("flight_control");
584 result = FCS->Load(element, FGFCS::stFCS);
586 cerr << endl << "Aircraft flight_control element has problems in file " << aircraftCfgFileName << endl;
591 // Process the aerodynamics element. This element is OPTIONAL, but almost always expected.
592 element = document->FindElement("aerodynamics");
594 result = Aerodynamics->Load(element);
596 cerr << endl << "Aircraft aerodynamics element has problems in file " << aircraftCfgFileName << endl;
600 cerr << endl << "No expected aerodynamics element was found in the aircraft config file." << endl;
603 // Process the input element. This element is OPTIONAL.
604 element = document->FindElement("input");
606 result = Input->Load(element);
608 cerr << endl << "Aircraft input element has problems in file " << aircraftCfgFileName << endl;
613 // Process the output element[s]. This element is OPTIONAL, and there may be more than one.
615 typedef int (FGOutput::*iOPMF)(void) const;
616 element = document->FindElement("output");
618 if (debug_lvl > 0) cout << endl << " Output data set: " << idx << " ";
619 FGOutput* Output = new FGOutput(this);
622 result = Output->Load(element);
624 cerr << endl << "Aircraft output element has problems in file " << aircraftCfgFileName << endl;
627 Outputs.push_back(Output);
628 string outputProp = CreateIndexedPropertyName("simulation/output",idx);
629 instance->Tie(outputProp+"/log_rate_hz", Output, (iOPMF)0, &FGOutput::SetRate);
632 element = document->FindNextElement("output");
635 // Lastly, process the child element. This element is OPTIONAL - and NOT YET SUPPORTED.
636 element = document->FindElement("child");
638 result = ReadChild(element);
640 cerr << endl << "Aircraft child element has problems in file " << aircraftCfgFileName << endl;
648 cout << endl << fgblue << highint
649 << "End of vehicle configuration loading." << endl
650 << "-------------------------------------------------------------------------------"
654 if (IsChild) debug_lvl = saved_debug_lvl;
658 << " JSBSim failed to open the configuration file: " << aircraftCfgFileName
662 struct PropertyCatalogStructure masterPCS;
663 masterPCS.base_string = "";
664 masterPCS.node = (FGPropertyManager*)Root;
666 BuildPropertyCatalog(&masterPCS);
671 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
673 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
675 struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
678 for (int i=0; i<pcs->node->nChildren(); i++) {
679 pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
680 node_idx = pcs->node->getChild(i)->getIndex();
682 pcsNew->base_string = CreateIndexedPropertyName(pcsNew->base_string, node_idx);
684 if (pcs->node->getChild(i)->nChildren() == 0) {
685 if (pcsNew->base_string.substr(0,11) == string("/fdm/jsbsim")) {
686 pcsNew->base_string = pcsNew->base_string.erase(0,12);
688 PropertyCatalog.push_back(pcsNew->base_string);
690 pcsNew->node = (FGPropertyManager*)pcs->node->getChild(i);
691 BuildPropertyCatalog(pcsNew);
697 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
699 string FGFDMExec::QueryPropertyCatalog(string in)
702 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
703 if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
705 if (results.empty()) return "No matches found\n";
709 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
711 void FGFDMExec::PrintPropertyCatalog(void)
714 cout << " " << fgblue << highint << underon << "Property Catalog for "
715 << modelName << reset << endl << endl;
716 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
717 cout << " " << PropertyCatalog[i] << endl;
721 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
723 bool FGFDMExec::ReadFileHeader(Element* el)
725 bool result = true; // true for success
727 if (debug_lvl == 0) return result;
730 cout << endl <<highint << fgblue << "Reading child model: " << IdFDM << reset << endl << endl;
733 if (el->FindElement("description"))
734 cout << " Description: " << el->FindElement("description")->GetDataLine() << endl;
735 if (el->FindElement("author"))
736 cout << " Model Author: " << el->FindElement("author")->GetDataLine() << endl;
737 if (el->FindElement("filecreationdate"))
738 cout << " Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
739 if (el->FindElement("version"))
740 cout << " Version: " << el->FindElement("version")->GetDataLine() << endl;
745 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
747 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
749 bool result = true; // true for success
751 if (!el) return false;
753 string AircraftName = el->GetAttributeValue("name");
754 Aircraft->SetAircraftName(AircraftName);
756 if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
757 << underoff << ": " << highint << AircraftName << normint << endl;
759 CFGVersion = el->GetAttributeValue("version");
760 Release = el->GetAttributeValue("release");
763 cout << " Version: " << highint << CFGVersion
765 if (CFGVersion != needed_cfg_version) {
766 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
767 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
768 cerr << "Current version needed is: " << needed_cfg_version << endl;
769 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
773 if (Release == "ALPHA" && (debug_lvl & 1)) {
775 << highint << "This aircraft model is an " << fgred << Release
776 << reset << highint << " release!!!" << endl << endl << reset
777 << "This aircraft model may not even properly load, and probably"
778 << " will not fly as expected." << endl << endl
779 << fgred << highint << "Use this model for development purposes ONLY!!!"
780 << normint << reset << endl << endl;
781 } else if (Release == "BETA" && (debug_lvl & 1)) {
783 << highint << "This aircraft model is a " << fgred << Release
784 << reset << highint << " release!!!" << endl << endl << reset
785 << "This aircraft model probably will not fly as expected." << endl << endl
786 << fgblue << highint << "Use this model for development purposes ONLY!!!"
787 << normint << reset << endl << endl;
788 } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
790 << highint << "This aircraft model is a " << fgblue << Release
791 << reset << highint << " release." << endl << endl << reset;
792 } else if (debug_lvl & 1) {
794 << highint << "This aircraft model is an " << fgred << Release
795 << reset << highint << " release!!!" << endl << endl << reset
796 << "This aircraft model may not even properly load, and probably"
797 << " will not fly as expected." << endl << endl
798 << fgred << highint << "Use this model for development purposes ONLY!!!"
799 << normint << reset << endl << endl;
805 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
807 bool FGFDMExec::ReadChild(Element* el)
809 // Add a new childData object to the child FDM list
810 // Populate that childData element with a new FDMExec object
811 // Set the IsChild flag for that FDMExec object
812 // Get the aircraft name
813 // set debug level to print out no additional data for child objects
814 // Load the model given the aircraft name
815 // reset debug level to prior setting
819 struct childData* child = new childData;
821 child->exec = new FGFDMExec();
822 child->exec->SetChild(true);
824 string childAircraft = el->GetAttributeValue("name");
825 string sMated = el->GetAttributeValue("mated");
826 if (sMated == "false") child->mated = false; // child objects are mated by default.
827 string sInternal = el->GetAttributeValue("internal");
828 if (sInternal == "true") child->internal = true; // child objects are external by default.
830 child->exec->SetAircraftPath( AircraftPath );
831 child->exec->SetEnginePath( EnginePath );
832 child->exec->SetSystemsPath( SystemsPath );
833 child->exec->LoadModel(childAircraft);
835 Element* location = el->FindElement("location");
837 child->Loc = location->FindElementTripletConvertTo("IN");
839 cerr << endl << highint << fgred << " No location was found for this child object!" << reset << endl;
843 Element* orientation = el->FindElement("orient");
845 child->Orient = orientation->FindElementTripletConvertTo("RAD");
846 } else if (debug_lvl > 0) {
847 cerr << endl << highint << " No orientation was found for this child object! Assuming 0,0,0." << reset << endl;
850 ChildFDMList.push_back(child);
855 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
857 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
862 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
864 FGTrim* FGFDMExec::GetTrim(void)
867 Trim = new FGTrim(this,tNone);
871 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
873 void FGFDMExec::DisableOutput(void)
875 for (unsigned i=0; i<Outputs.size(); i++) {
876 Outputs[i]->Disable();
880 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
882 void FGFDMExec::EnableOutput(void)
884 for (unsigned i=0; i<Outputs.size(); i++) {
885 Outputs[i]->Enable();
889 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
891 bool FGFDMExec::SetOutputDirectives(string fname)
895 FGOutput* Output = new FGOutput(this);
896 Output->SetDirectivesFile(fname);
899 result = Output->Load(0);
900 Outputs.push_back(Output);
902 typedef int (FGOutput::*iOPMF)(void) const;
903 string outputProp = CreateIndexedPropertyName("simulation/output",Outputs.size()-1);
904 instance->Tie(outputProp+"/log_rate_hz", Output, (iOPMF)0, &FGOutput::SetRate);
909 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
911 void FGFDMExec::DoTrim(int mode)
915 if (Constructing) return;
917 if (mode < 0 || mode > JSBSim::tNone) {
918 cerr << endl << "Illegal trimming mode!" << endl << endl;
921 saved_time = State->Getsim_time();
922 FGTrim trim(this, (JSBSim::TrimMode)mode);
923 if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
925 State->Setsim_time(saved_time);
928 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
930 void FGFDMExec::DoTrimAnalysis(int mode)
933 if (Constructing) return;
935 if (mode < 0 || mode > JSBSim::taNone) {
936 cerr << endl << "Illegal trimming mode!" << endl << endl;
939 saved_time = State->Getsim_time();
941 FGTrimAnalysis trimAnalysis(this, (JSBSim::TrimAnalysisMode)mode);
943 if ( !trimAnalysis.Load(IC->GetInitFile(), false) ) {
944 cerr << "A problem occurred with trim configuration file " << trimAnalysis.Load(IC->GetInitFile()) << endl;
948 bool result = trimAnalysis.DoTrim();
950 if ( !result ) cerr << endl << "Trim Failed" << endl << endl;
952 trimAnalysis.Report();
953 State->Setsim_time(saved_time);
956 cout << "\nOutput: " << GetOutputFileName() << endl;
960 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
962 void FGFDMExec::UseAtmosphereMSIS(void)
964 FGAtmosphere *oldAtmosphere = Atmosphere;
965 Atmosphere = new MSIS(this);
966 if (!Atmosphere->InitModel()) {
967 cerr << fgred << "MSIS Atmosphere model init failed" << fgdef << endl;
970 delete oldAtmosphere;
973 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
975 void FGFDMExec::UseAtmosphereMars(void)
978 FGAtmosphere *oldAtmosphere = Atmosphere;
979 Atmosphere = new FGMars(this);
980 if (!Atmosphere->InitModel()) {
981 cerr << fgred << "Mars Atmosphere model init failed" << fgdef << endl;
984 delete oldAtmosphere;
988 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
989 // The bitmasked value choices are as follows:
990 // unset: In this case (the default) JSBSim would only print
991 // out the normally expected messages, essentially echoing
992 // the config files as they are read. If the environment
993 // variable is not set, debug_lvl is set to 1 internally
994 // 0: This requests JSBSim not to output any messages
996 // 1: This value explicity requests the normal JSBSim
998 // 2: This value asks for a message to be printed out when
999 // a class is instantiated
1000 // 4: When this value is set, a message is displayed when a
1001 // FGModel object executes its Run() method
1002 // 8: When this value is set, various runtime state variables
1003 // are printed out periodically
1004 // 16: When set various parameters are sanity checked and
1005 // a message is printed out when they go out of bounds
1007 void FGFDMExec::Debug(int from)
1009 if (debug_lvl <= 0) return;
1011 if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
1012 if (from == 0) { // Constructor
1013 cout << "\n\n " << highint << underon << "JSBSim Flight Dynamics Model v"
1014 << JSBSim_version << underoff << normint << endl;
1015 cout << halfint << " [JSBSim-ML v" << needed_cfg_version << "]\n\n";
1016 cout << normint << "JSBSim startup beginning ...\n\n";
1017 } else if (from == 3) {
1018 cout << "\n\nJSBSim startup complete\n\n";
1021 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1022 if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
1023 if (from == 1) cout << "Destroyed: FGFDMExec" << endl;
1025 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1027 cout << "================== Frame: " << Frame << " Time: "
1028 << State->Getsim_time() << " dt: " << State->Getdt() << endl;
1031 if (debug_lvl & 8 ) { // Runtime state variables
1033 if (debug_lvl & 16) { // Sanity checking
1035 if (debug_lvl & 64) {
1036 if (from == 0) { // Constructor
1037 cout << IdSrc << endl;
1038 cout << IdHdr << endl;