1 /*******************************************************************************
6 Purpose: Schedules and runs the model routines.
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
31 This class wraps up the simulation scheduling routines.
34 --------------------------------------------------------------------------------
37 ********************************************************************************
39 *******************************************************************************/
42 # include <simgear/compiler.h>
43 # ifdef FG_HAVE_STD_INCLUDES
47 # include <iostream.h>
55 #include "FGFDMExec.h"
57 #include "FGAtmosphere.h"
59 #include "FGAircraft.h"
60 #include "FGTranslation.h"
61 #include "FGRotation.h"
62 #include "FGPosition.h"
63 #include "FGAuxiliary.h"
66 static const char *IdSrc = "$Header$";
67 static const char *IdHdr = "ID_FDMEXEC";
69 /*******************************************************************************
70 ************************************ CODE **************************************
71 *******************************************************************************/
76 FGFDMExec::FGFDMExec(void)
98 FGFDMExec::~FGFDMExec(void){
104 bool FGFDMExec::Allocate(void) {
106 cout << "FGFDMExec::Allocate ... ";
109 Atmosphere = new FGAtmosphere(this);
110 FCS = new FGFCS(this);
111 Aircraft = new FGAircraft(this);
112 Translation = new FGTranslation(this);
113 Rotation = new FGRotation(this);
114 Position = new FGPosition(this);
115 Auxiliary = new FGAuxiliary(this);
116 Output = new FGOutput(this);
118 State = new FGState(this);
120 // Initialize models so they can communicate with each other
122 if (!Atmosphere->InitModel()) {cerr << "Atmosphere model init failed"; Error+=1;}
123 if (!FCS->InitModel()) {cerr << "FCS model init failed"; Error+=2;}
124 if (!Aircraft->InitModel()) {cerr << "Aircraft model init failed"; Error+=4;}
125 if (!Translation->InitModel()){cerr << "Translation model init failed"; Error+=8;}
126 if (!Rotation->InitModel()) {cerr << "Rotation model init failed"; Error+=16;}
127 if (!Position->InitModel()) {cerr << "Position model init failed"; Error+=32;}
128 if (!Auxiliary->InitModel()) {cerr << "Auxiliary model init failed"; Error+=64;}
129 if (!Output->InitModel()) {cerr << "Output model init failed"; Error+=128;}
131 if(Error > 0) result=false;
133 // Schedule a model. The second arg (the integer) is the pass number. For
134 // instance, the atmosphere model gets executed every fifth pass it is called
135 // by the executive. Everything else here gets executed each pass.
137 Schedule(Atmosphere, 1);
139 Schedule(Aircraft, 1);
140 Schedule(Rotation, 1);
141 Schedule(Translation, 1);
142 Schedule(Position, 1);
143 Schedule(Auxiliary, 1);
147 cout << "done." << endl;
152 bool FGFDMExec::DeAllocate(void) {
153 cout << "FGFDMExec::DeAllocate ... ";
155 if ( Atmosphere != 0 ) delete Atmosphere;
156 if ( FCS != 0 ) delete FCS;
157 if ( Aircraft != 0 ) delete Aircraft;
158 if ( Translation != 0 ) delete Translation;
159 if ( Rotation != 0 ) delete Rotation;
160 if ( Position != 0 ) delete Position;
161 if ( Auxiliary != 0 ) delete Auxiliary;
162 if ( Output != 0 ) delete Output;
163 if ( State != 0 ) delete State;
180 cout << "done" << endl;
184 int FGFDMExec::Schedule(FGModel* model, int rate)
186 FGModel* model_iterator;
188 model_iterator = FirstModel;
190 if (model_iterator == 0L) { // this is the first model
193 FirstModel->NextModel = 0L;
194 FirstModel->SetRate(rate);
196 } else { // subsequent model
198 while (model_iterator->NextModel != 0L) {
199 model_iterator = model_iterator->NextModel;
201 model_iterator->NextModel = model;
202 model_iterator->NextModel->SetRate(rate);
209 bool FGFDMExec::Run(void)
211 FGModel* model_iterator;
213 if (frozen) return true;
215 model_iterator = FirstModel;
216 if (model_iterator == 0L) return false;
218 while (!model_iterator->Run())
220 model_iterator = model_iterator->NextModel;
221 if (model_iterator == 0L) break;
230 bool FGFDMExec::RunIC(FGInitialCondition *fgic)
233 State->Initialize(fgic);
240 bool FGFDMExec::LoadModel(string APath, string EPath, string model)
243 cout << "FGFDMExec::LoadModel ..." << endl;
248 AircraftPath = APath;
250 result = Aircraft->LoadAircraft(AircraftPath, EnginePath, model);
254 cerr << "FGFDMExec: Failed to load aircraft and/or engine model" << endl;
256 cout << "FGFDMExec::LoadModel complete." << endl;;
261 bool FGFDMExec::RunScript(string script)