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 <Include/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)
87 // Instantiate this FDM Executive's Models
89 Atmosphere = new FGAtmosphere(this);
90 FCS = new FGFCS(this);
91 Aircraft = new FGAircraft(this);
92 Translation = new FGTranslation(this);
93 Rotation = new FGRotation(this);
94 Position = new FGPosition(this);
95 Auxiliary = new FGAuxiliary(this);
96 Output = new FGOutput(this);
98 State = new FGState(this);
100 // Initialize models so they can communicate with each other
102 if (!Atmosphere->InitModel()) {cerr << "Atmosphere model init failed"; Error+=1;}
103 if (!FCS->InitModel()) {cerr << "FCS model init failed"; Error+=2;}
104 if (!Aircraft->InitModel()) {cerr << "Aircraft model init failed"; Error+=4;}
105 if (!Translation->InitModel()){cerr << "Translation model init failed"; Error+=8;}
106 if (!Rotation->InitModel()) {cerr << "Rotation model init failed"; Error+=16;}
107 if (!Position->InitModel()) {cerr << "Position model init failed"; Error+=32;}
108 if (!Auxiliary->InitModel()) {cerr << "Auxiliary model init failed"; Error+=64;}
109 if (!Output->InitModel()) {cerr << "Output model init failed"; Error+=128;}
111 // Schedule a model. The second arg (the integer) is the pass number. For
112 // instance, the atmosphere model gets executed every fifth pass it is called
113 // by the executive. Everything else here gets executed each pass.
115 Schedule(Atmosphere, 5);
117 Schedule(Aircraft, 1);
118 Schedule(Rotation, 1);
119 Schedule(Translation, 1);
120 Schedule(Position, 1);
121 Schedule(Auxiliary, 1);
122 Schedule(Output, 120);
129 FGFDMExec::~FGFDMExec(void)
134 int FGFDMExec::Schedule(FGModel* model, int rate)
136 FGModel* model_iterator;
138 model_iterator = FirstModel;
140 if (model_iterator == 0L) { // this is the first model
143 FirstModel->NextModel = 0L;
144 FirstModel->SetRate(rate);
146 } else { // subsequent model
148 while (model_iterator->NextModel != 0L) {
149 model_iterator = model_iterator->NextModel;
151 model_iterator->NextModel = model;
152 model_iterator->NextModel->SetRate(rate);
159 bool FGFDMExec::Run(void)
161 FGModel* model_iterator;
163 if (frozen) return true;
165 model_iterator = FirstModel;
166 if (model_iterator == 0L) return false;
168 while (!model_iterator->Run())
170 model_iterator = model_iterator->NextModel;
171 if (model_iterator == 0L) break;
179 bool FGFDMExec::RunIC(FGInitialCondition *fgic)
181 float save_dt=State->Getdt();
183 State->Initialize(fgic);
185 State->Setdt(save_dt);