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>
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 checkTied( (FGPropertyManager*)node->getChild(i) );
94 } else if ( node->getChild(i)->isTied() ) {
95 name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
101 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 FGFDMExec::FGFDMExec(FGPropertyManager* root) : Root(root)
119 ExternalReactions = 0;
134 IdFDM = FDMctr; // The main (parent) JSBSim instance is always the "zeroth"
135 FDMctr++; // instance. "child" instances are loaded last.
138 char* num = getenv("JSBSIM_DEBUG");
139 if (num) debug_lvl = atoi(num); // set debug level
140 } catch (...) { // if error set to 1
146 master = new FGPropertyManager;
150 instance = Root->GetNode("/fdm/jsbsim",IdFDM,true);
152 // this is to catch errors in binding member functions to the property tree.
155 } catch ( string msg ) {
156 cout << "Caught error: " << msg << endl;
164 typedef int (FGFDMExec::*iPMF)(void) const;
165 // instance->Tie("simulation/do_trim_analysis", this, (iPMF)0, &FGFDMExec::DoTrimAnalysis);
166 instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim);
167 instance->Tie("simulation/reset", this, (iPMF)0, &FGFDMExec::ResetToInitialConditions);
168 instance->Tie("simulation/terminate", (int *)&Terminate);
169 Constructing = false;
172 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 FGFDMExec::~FGFDMExec()
177 checkTied( instance );
179 if (Root == 0) delete master;
180 } catch ( string msg ) {
181 cout << "Caught error: " << msg << endl;
184 for (unsigned int i=1; i<ChildFDMList.size(); i++) delete ChildFDMList[i]->exec;
185 ChildFDMList.clear();
187 PropertyCatalog.clear();
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 bool FGFDMExec::Allocate(void)
200 Atmosphere = new FGAtmosphere(this);
201 FCS = new FGFCS(this);
202 Propulsion = new FGPropulsion(this);
203 MassBalance = new FGMassBalance(this);
204 Aerodynamics = new FGAerodynamics (this);
205 Inertial = new FGInertial(this);
207 GroundCallback = new FGGroundCallback(Inertial->GetRefRadius());
209 GroundReactions = new FGGroundReactions(this);
210 ExternalReactions = new FGExternalReactions(this);
211 BuoyantForces = new FGBuoyantForces(this);
212 Aircraft = new FGAircraft(this);
213 Propagate = new FGPropagate(this);
214 Auxiliary = new FGAuxiliary(this);
215 Input = new FGInput(this);
217 State = new FGState(this); // This must be done here, as the FGState
218 // class needs valid pointers to the above
221 // Initialize models so they can communicate with each other
223 Atmosphere->InitModel();
225 Propulsion->InitModel();
226 MassBalance->InitModel();
227 Aerodynamics->InitModel();
228 Inertial->InitModel();
229 GroundReactions->InitModel();
230 ExternalReactions->InitModel();
231 BuoyantForces->InitModel();
232 Aircraft->InitModel();
233 Propagate->InitModel();
234 Auxiliary->InitModel();
237 IC = new FGInitialCondition(this);
239 // Schedule a model. The second arg (the integer) is the pass number. For
240 // instance, the atmosphere model could get executed every fifth pass it is called
241 // by the executive. IC and Trim objects are NOT scheduled.
244 Schedule(Atmosphere, 1);
246 Schedule(Propulsion, 1);
247 Schedule(MassBalance, 1);
248 Schedule(Aerodynamics, 1);
249 Schedule(Inertial, 1);
250 Schedule(GroundReactions, 1);
251 Schedule(ExternalReactions, 1);
252 Schedule(BuoyantForces, 1);
253 Schedule(Aircraft, 1);
254 Schedule(Propagate, 1);
255 Schedule(Auxiliary, 1);
262 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 bool FGFDMExec::DeAllocate(void)
273 delete GroundReactions;
274 delete ExternalReactions;
275 delete BuoyantForces;
282 for (unsigned i=0; i<Outputs.size(); i++) delete Outputs[i];
288 delete GroundCallback;
302 ExternalReactions = 0;
313 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315 int FGFDMExec::Schedule(FGModel* model, int rate)
317 FGModel* model_iterator;
319 model_iterator = FirstModel;
321 if (model_iterator == 0L) { // this is the first model
324 FirstModel->NextModel = 0L;
325 FirstModel->SetRate(rate);
327 } else { // subsequent model
329 while (model_iterator->NextModel != 0L) {
330 model_iterator = model_iterator->NextModel;
332 model_iterator->NextModel = model;
333 model_iterator->NextModel->SetRate(rate);
340 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
342 bool FGFDMExec::Run(void)
345 FGModel* model_iterator;
347 model_iterator = FirstModel;
348 if (model_iterator == 0L) return false;
352 for (unsigned int i=1; i<ChildFDMList.size(); i++) {
353 ChildFDMList[i]->AssignState(Propagate); // Transfer state to the child FDM
354 ChildFDMList[i]->Run();
357 // returns true if success
359 if (Script != 0 && !State->IntegrationSuspended()) success = Script->RunScript();
361 while (model_iterator != 0L) {
362 model_iterator->Run();
363 model_iterator = model_iterator->NextModel;
367 if (!Holding()) State->IncrTime();
368 if (Terminate) success = false;
373 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
374 // This call will cause the sim time to reset to 0.0
376 bool FGFDMExec::RunIC(void)
378 State->SuspendIntegration();
379 State->Initialize(IC);
381 State->ResumeIntegration();
386 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388 // A private, internal function call for Tie-ing to a property, so it needs an
391 void FGFDMExec::ResetToInitialConditions(int mode)
394 for (unsigned int i=0; i<Outputs.size(); i++) {
395 Outputs[i]->SetStartNewFile(true);
399 ResetToInitialConditions();
402 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
404 void FGFDMExec::ResetToInitialConditions(void)
406 FGModel* model_iterator;
408 model_iterator = FirstModel;
409 if (model_iterator == 0L || Constructing) 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<ChildFDMList.size(); i++) {
451 FDMList.push_back(ChildFDMList[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 int saved_debug_lvl = debug_lvl;
510 document = LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
512 if (IsChild) debug_lvl = 0;
514 ReadPrologue(document);
516 if (IsChild) debug_lvl = saved_debug_lvl;
518 // Process the fileheader element in the aircraft config file. This element is OPTIONAL.
519 element = document->FindElement("fileheader");
521 result = ReadFileHeader(element);
523 cerr << endl << "Aircraft fileheader element has problems in file " << aircraftCfgFileName << endl;
528 if (IsChild) debug_lvl = 0;
530 // Process the metrics element. This element is REQUIRED.
531 element = document->FindElement("metrics");
533 result = Aircraft->Load(element);
535 cerr << endl << "Aircraft metrics element has problems in file " << aircraftCfgFileName << endl;
539 cerr << endl << "No metrics element was found in the aircraft config file." << endl;
543 // Process the mass_balance element. This element is REQUIRED.
544 element = document->FindElement("mass_balance");
546 result = MassBalance->Load(element);
548 cerr << endl << "Aircraft mass_balance element has problems in file " << aircraftCfgFileName << endl;
552 cerr << endl << "No mass_balance element was found in the aircraft config file." << endl;
556 // Process the ground_reactions element. This element is REQUIRED.
557 element = document->FindElement("ground_reactions");
559 result = GroundReactions->Load(element);
561 cerr << endl << "Aircraft ground_reactions element has problems in file " << aircraftCfgFileName << endl;
565 cerr << endl << "No ground_reactions element was found in the aircraft config file." << endl;
569 // Process the external_reactions element. This element is OPTIONAL.
570 element = document->FindElement("external_reactions");
572 result = ExternalReactions->Load(element);
574 cerr << endl << "Aircraft external_reactions element has problems in file " << aircraftCfgFileName << endl;
579 // Process the buoyant_forces element. This element is OPTIONAL.
580 element = document->FindElement("buoyant_forces");
582 result = BuoyantForces->Load(element);
584 cerr << endl << "Aircraft buoyant_forces element has problems in file " << aircraftCfgFileName << endl;
589 // Process the propulsion element. This element is OPTIONAL.
590 element = document->FindElement("propulsion");
592 result = Propulsion->Load(element);
594 cerr << endl << "Aircraft propulsion element has problems in file " << aircraftCfgFileName << endl;
599 // Process the system element[s]. This element is OPTIONAL, and there may be more than one.
600 element = document->FindElement("system");
602 result = FCS->Load(element, FGFCS::stSystem);
604 cerr << endl << "Aircraft system element has problems in file " << aircraftCfgFileName << endl;
607 element = document->FindNextElement("system");
610 // Process the autopilot element. This element is OPTIONAL.
611 element = document->FindElement("autopilot");
613 result = FCS->Load(element, FGFCS::stAutoPilot);
615 cerr << endl << "Aircraft autopilot element has problems in file " << aircraftCfgFileName << endl;
620 // Process the flight_control element. This element is OPTIONAL.
621 element = document->FindElement("flight_control");
623 result = FCS->Load(element, FGFCS::stFCS);
625 cerr << endl << "Aircraft flight_control element has problems in file " << aircraftCfgFileName << endl;
630 // Process the aerodynamics element. This element is OPTIONAL, but almost always expected.
631 element = document->FindElement("aerodynamics");
633 result = Aerodynamics->Load(element);
635 cerr << endl << "Aircraft aerodynamics element has problems in file " << aircraftCfgFileName << endl;
639 cerr << endl << "No expected aerodynamics element was found in the aircraft config file." << endl;
642 // Process the input element. This element is OPTIONAL.
643 element = document->FindElement("input");
645 result = Input->Load(element);
647 cerr << endl << "Aircraft input element has problems in file " << aircraftCfgFileName << endl;
652 // Process the output element[s]. This element is OPTIONAL, and there may be more than one.
654 typedef int (FGOutput::*iOPMF)(void) const;
655 element = document->FindElement("output");
657 if (debug_lvl > 0) cout << endl << " Output data set: " << idx << " ";
658 FGOutput* Output = new FGOutput(this);
661 result = Output->Load(element);
663 cerr << endl << "Aircraft output element has problems in file " << aircraftCfgFileName << endl;
666 Outputs.push_back(Output);
667 string outputProp = CreateIndexedPropertyName("simulation/output",idx);
668 instance->Tie(outputProp+"/log_rate_hz", Output, (iOPMF)0, &FGOutput::SetRate);
671 element = document->FindNextElement("output");
674 // Lastly, process the child element. This element is OPTIONAL - and NOT YET SUPPORTED.
675 element = document->FindElement("child");
677 result = ReadChild(element);
679 cerr << endl << "Aircraft child element has problems in file " << aircraftCfgFileName << endl;
687 cout << endl << fgblue << highint
688 << "End of vehicle configuration loading." << endl
689 << "-------------------------------------------------------------------------------"
693 if (IsChild) debug_lvl = saved_debug_lvl;
697 << " JSBSim failed to open the configuration file: " << aircraftCfgFileName
701 struct PropertyCatalogStructure masterPCS;
702 masterPCS.base_string = "";
703 masterPCS.node = (FGPropertyManager*)Root;
705 BuildPropertyCatalog(&masterPCS);
710 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
712 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
714 struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
718 for (unsigned int i=0; i<pcs->node->nChildren(); i++) {
719 pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
720 node_idx = pcs->node->getChild(i)->getIndex();
721 sprintf(int_buf, "[%d]", node_idx);
722 if (node_idx != 0) pcsNew->base_string += string(int_buf);
723 if (pcs->node->getChild(i)->nChildren() == 0) {
724 if (pcsNew->base_string.substr(0,11) == string("/fdm/jsbsim")) {
725 pcsNew->base_string = pcsNew->base_string.erase(0,12);
727 PropertyCatalog.push_back(pcsNew->base_string);
729 pcsNew->node = (FGPropertyManager*)pcs->node->getChild(i);
730 BuildPropertyCatalog(pcsNew);
736 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
738 string FGFDMExec::QueryPropertyCatalog(string in)
741 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
742 if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
744 if (results.empty()) return "No matches found\n";
748 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750 void FGFDMExec::PrintPropertyCatalog(void)
753 cout << " " << fgblue << highint << underon << "Property Catalog for "
754 << modelName << reset << endl << endl;
755 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
756 cout << " " << PropertyCatalog[i] << endl;
760 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
762 bool FGFDMExec::ReadFileHeader(Element* el)
764 bool result = true; // true for success
766 if (debug_lvl == 0) return result;
769 cout << endl <<highint << fgblue << "Reading child model: " << IdFDM << reset << endl << endl;
772 if (el->FindElement("description"))
773 cout << " Description: " << el->FindElement("description")->GetDataLine() << endl;
774 if (el->FindElement("author"))
775 cout << " Model Author: " << el->FindElement("author")->GetDataLine() << endl;
776 if (el->FindElement("filecreationdate"))
777 cout << " Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
778 if (el->FindElement("version"))
779 cout << " Version: " << el->FindElement("version")->GetDataLine() << endl;
784 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
786 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
788 bool result = true; // true for success
790 if (!el) return false;
792 string AircraftName = el->GetAttributeValue("name");
793 Aircraft->SetAircraftName(AircraftName);
795 if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
796 << underoff << ": " << highint << AircraftName << normint << endl;
798 CFGVersion = el->GetAttributeValue("version");
799 Release = el->GetAttributeValue("release");
802 cout << " Version: " << highint << CFGVersion
804 if (CFGVersion != needed_cfg_version) {
805 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
806 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
807 cerr << "Current version needed is: " << needed_cfg_version << endl;
808 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
812 if (Release == "ALPHA" && (debug_lvl & 1)) {
814 << highint << "This aircraft model is an " << fgred << Release
815 << reset << highint << " release!!!" << endl << endl << reset
816 << "This aircraft model may not even properly load, and probably"
817 << " will not fly as expected." << endl << endl
818 << fgred << highint << "Use this model for development purposes ONLY!!!"
819 << normint << reset << endl << endl;
820 } else if (Release == "BETA" && (debug_lvl & 1)) {
822 << highint << "This aircraft model is a " << fgred << Release
823 << reset << highint << " release!!!" << endl << endl << reset
824 << "This aircraft model probably will not fly as expected." << endl << endl
825 << fgblue << highint << "Use this model for development purposes ONLY!!!"
826 << normint << reset << endl << endl;
827 } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
829 << highint << "This aircraft model is a " << fgblue << Release
830 << reset << highint << " release." << endl << endl << reset;
831 } else if (debug_lvl & 1) {
833 << highint << "This aircraft model is an " << fgred << Release
834 << reset << highint << " release!!!" << endl << endl << reset
835 << "This aircraft model may not even properly load, and probably"
836 << " will not fly as expected." << endl << endl
837 << fgred << highint << "Use this model for development purposes ONLY!!!"
838 << normint << reset << endl << endl;
844 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
846 bool FGFDMExec::ReadChild(Element* el)
848 // Add a new childData object to the child FDM list
849 // Populate that childData element with a new FDMExec object
850 // Set the IsChild flag for that FDMExec object
851 // Get the aircraft name
852 // set debug level to print out no additional data for child objects
853 // Load the model given the aircraft name
854 // reset debug level to prior setting
858 struct childData* child = new childData;
860 child->exec = new FGFDMExec();
861 child->exec->SetChild(true);
863 string childAircraft = el->GetAttributeValue("name");
864 string sMated = el->GetAttributeValue("mated");
865 if (sMated == "false") child->mated = false; // child objects are mated by default.
866 string sInternal = el->GetAttributeValue("internal");
867 if (sInternal == "true") child->internal = true; // child objects are external by default.
869 child->exec->SetAircraftPath( AircraftPath );
870 child->exec->SetEnginePath( EnginePath );
871 child->exec->SetSystemsPath( SystemsPath );
872 child->exec->LoadModel(childAircraft);
874 Element* location = el->FindElement("location");
876 child->Loc = location->FindElementTripletConvertTo("IN");
878 cerr << endl << highint << fgred << " No location was found for this child object!" << reset << endl;
882 Element* orientation = el->FindElement("orient");
884 child->Orient = orientation->FindElementTripletConvertTo("RAD");
885 } else if (debug_lvl > 0) {
886 cerr << endl << highint << " No orientation was found for this child object! Assuming 0,0,0." << reset << endl;
889 ChildFDMList.push_back(child);
894 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
896 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
901 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
903 FGTrim* FGFDMExec::GetTrim(void)
906 Trim = new FGTrim(this,tNone);
910 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
912 void FGFDMExec::DisableOutput(void)
914 for (unsigned i=0; i<Outputs.size(); i++) {
915 Outputs[i]->Disable();
919 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
921 void FGFDMExec::EnableOutput(void)
923 for (unsigned i=0; i<Outputs.size(); i++) {
924 Outputs[i]->Enable();
928 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
930 bool FGFDMExec::SetOutputDirectives(string fname)
934 FGOutput* Output = new FGOutput(this);
935 Output->SetDirectivesFile(fname);
938 result = Output->Load(0);
939 Outputs.push_back(Output);
941 typedef int (FGOutput::*iOPMF)(void) const;
942 string outputProp = CreateIndexedPropertyName("simulation/output",Outputs.size()-1);
943 instance->Tie(outputProp+"/log_rate_hz", Output, (iOPMF)0, &FGOutput::SetRate);
948 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
950 void FGFDMExec::DoTrim(int mode)
954 if (Constructing) return;
956 if (mode < 0 || mode > JSBSim::tNone) {
957 cerr << endl << "Illegal trimming mode!" << endl << endl;
960 saved_time = State->Getsim_time();
961 FGTrim trim(this, (JSBSim::TrimMode)mode);
962 if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
964 State->Setsim_time(saved_time);
967 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
969 void FGFDMExec::DoTrimAnalysis(int mode)
972 if (Constructing) return;
974 if (mode < 0 || mode > JSBSim::taNone) {
975 cerr << endl << "Illegal trimming mode!" << endl << endl;
978 saved_time = State->Getsim_time();
980 FGTrimAnalysis trimAnalysis(this, (JSBSim::TrimAnalysisMode)mode);
982 if ( !trimAnalysis.Load(IC->GetInitFile(), false) ) {
983 cerr << "A problem occurred with trim configuration file " << trimAnalysis.Load(IC->GetInitFile()) << endl;
987 bool result = trimAnalysis.DoTrim();
989 if ( !result ) cerr << endl << "Trim Failed" << endl << endl;
991 trimAnalysis.Report();
992 State->Setsim_time(saved_time);
995 cout << "\nOutput: " << GetOutputFileName() << endl;
999 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1001 void FGFDMExec::UseAtmosphereMSIS(void)
1003 FGAtmosphere *oldAtmosphere = Atmosphere;
1004 Atmosphere = new MSIS(this);
1005 if (!Atmosphere->InitModel()) {
1006 cerr << fgred << "MSIS Atmosphere model init failed" << fgdef << endl;
1009 delete oldAtmosphere;
1012 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1014 void FGFDMExec::UseAtmosphereMars(void)
1017 FGAtmosphere *oldAtmosphere = Atmosphere;
1018 Atmosphere = new FGMars(this);
1019 if (!Atmosphere->InitModel()) {
1020 cerr << fgred << "Mars Atmosphere model init failed" << fgdef << endl;
1023 delete oldAtmosphere;
1027 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1028 // The bitmasked value choices are as follows:
1029 // unset: In this case (the default) JSBSim would only print
1030 // out the normally expected messages, essentially echoing
1031 // the config files as they are read. If the environment
1032 // variable is not set, debug_lvl is set to 1 internally
1033 // 0: This requests JSBSim not to output any messages
1035 // 1: This value explicity requests the normal JSBSim
1037 // 2: This value asks for a message to be printed out when
1038 // a class is instantiated
1039 // 4: When this value is set, a message is displayed when a
1040 // FGModel object executes its Run() method
1041 // 8: When this value is set, various runtime state variables
1042 // are printed out periodically
1043 // 16: When set various parameters are sanity checked and
1044 // a message is printed out when they go out of bounds
1046 void FGFDMExec::Debug(int from)
1048 if (debug_lvl <= 0) return;
1050 if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
1051 if (from == 0) { // Constructor
1052 cout << "\n\n " << highint << underon << "JSBSim Flight Dynamics Model v"
1053 << JSBSim_version << underoff << normint << endl;
1054 cout << halfint << " [JSBSim-ML v" << needed_cfg_version << "]\n\n";
1055 cout << normint << "JSBSim startup beginning ...\n\n";
1056 } else if (from == 3) {
1057 cout << "\n\nJSBSim startup complete\n\n";
1060 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1061 if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
1062 if (from == 1) cout << "Destroyed: FGFDMExec" << endl;
1064 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1066 cout << "================== Frame: " << Frame << " Time: "
1067 << State->Getsim_time() << " dt: " << State->Getdt() << endl;
1070 if (debug_lvl & 8 ) { // Runtime state variables
1072 if (debug_lvl & 16) { // Sanity checking
1074 if (debug_lvl & 64) {
1075 if (from == 0) { // Constructor
1076 cout << IdSrc << endl;
1077 cout << IdHdr << endl;