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 /*******************************************************************************
67 ************************************ CODE **************************************
68 *******************************************************************************/
73 FGFDMExec::FGFDMExec(void)
92 FGFDMExec::~FGFDMExec(void){
98 bool FGFDMExec::Allocate(void) {
102 Atmosphere = new FGAtmosphere(this);
103 FCS = new FGFCS(this);
104 Aircraft = new FGAircraft(this);
105 Translation = new FGTranslation(this);
106 Rotation = new FGRotation(this);
107 Position = new FGPosition(this);
108 Auxiliary = new FGAuxiliary(this);
109 Output = new FGOutput(this);
111 State = new FGState(this);
113 // Initialize models so they can communicate with each other
115 if (!Atmosphere->InitModel()) {cerr << "Atmosphere model init failed"; Error+=1;}
116 if (!FCS->InitModel()) {cerr << "FCS model init failed"; Error+=2;}
117 if (!Aircraft->InitModel()) {cerr << "Aircraft model init failed"; Error+=4;}
118 if (!Translation->InitModel()){cerr << "Translation model init failed"; Error+=8;}
119 if (!Rotation->InitModel()) {cerr << "Rotation model init failed"; Error+=16;}
120 if (!Position->InitModel()) {cerr << "Position model init failed"; Error+=32;}
121 if (!Auxiliary->InitModel()) {cerr << "Auxiliary model init failed"; Error+=64;}
122 if (!Output->InitModel()) {cerr << "Output model init failed"; Error+=128;}
124 if(Error > 0) result=false;
126 // Schedule a model. The second arg (the integer) is the pass number. For
127 // instance, the atmosphere model gets executed every fifth pass it is called
128 // by the executive. Everything else here gets executed each pass.
130 Schedule(Atmosphere, 1);
132 Schedule(Aircraft, 1);
133 Schedule(Rotation, 1);
134 Schedule(Translation, 1);
135 Schedule(Position, 1);
136 Schedule(Auxiliary, 1);
145 bool FGFDMExec::DeAllocate(void) {
147 if ( Atmosphere != 0 ) delete Atmosphere;
148 if ( FCS != 0 ) delete FCS;
149 if ( Aircraft != 0 ) delete Aircraft;
150 if ( Translation != 0 ) delete Translation;
151 if ( Rotation != 0 ) delete Rotation;
152 if ( Position != 0 ) delete Position;
153 if ( Auxiliary != 0 ) delete Auxiliary;
154 if ( Output != 0 ) delete Output;
155 if ( State != 0 ) delete State;
176 int FGFDMExec::Schedule(FGModel* model, int rate)
178 FGModel* model_iterator;
180 model_iterator = FirstModel;
182 if (model_iterator == 0L) { // this is the first model
185 FirstModel->NextModel = 0L;
186 FirstModel->SetRate(rate);
188 } else { // subsequent model
190 while (model_iterator->NextModel != 0L) {
191 model_iterator = model_iterator->NextModel;
193 model_iterator->NextModel = model;
194 model_iterator->NextModel->SetRate(rate);
201 bool FGFDMExec::Run(void)
203 FGModel* model_iterator;
205 if (frozen) return true;
207 model_iterator = FirstModel;
208 if (model_iterator == 0L) return false;
210 while (!model_iterator->Run())
212 model_iterator = model_iterator->NextModel;
213 if (model_iterator == 0L) break;
222 bool FGFDMExec::RunIC(FGInitialCondition *fgic)
225 State->Initialize(fgic);
232 bool FGFDMExec::LoadModel(string APath, string EPath, string model)
236 AircraftPath = APath;
238 return Aircraft->LoadAircraft(AircraftPath, EnginePath, model);
242 bool FGFDMExec::RunScript(string script)