]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGModel.cpp
Sync. with JSBSim CVS.
[flightgear.git] / src / FDM / JSBSim / FGModel.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGModel.cpp
4  Author:       Jon Berndt
5  Date started: 11/11/98
6  Purpose:      Base class for all models
7  Called by:    FGSimExec, et. al.
8
9  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
10
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
14  version.
15
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
19  details.
20
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.
24
25  Further information about the GNU General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This base class for the FGAero, FGRotational, etc. classes defines methods
31 common to all models.
32
33 HISTORY
34 --------------------------------------------------------------------------------
35 11/11/98   JSB   Created
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include "FGModel.h"
42 #include "FGState.h"
43 #include "FGFDMExec.h"
44 #include "FGAtmosphere.h"
45 #include "FGFCS.h"
46 #include "FGPropulsion.h"
47 #include "FGMassBalance.h"
48 #include "FGAerodynamics.h"
49 #include "FGInertial.h"
50 #include "FGGroundReactions.h"
51 #include "FGAircraft.h"
52 #include "FGTranslation.h"
53 #include "FGRotation.h"
54 #include "FGPosition.h"
55 #include "FGAuxiliary.h"
56 #include "FGOutput.h"
57
58 namespace JSBSim {
59
60 static const char *IdSrc = "$Id$";
61 static const char *IdHdr = ID_MODEL;
62
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 GLOBAL DECLARATIONS
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 CLASS IMPLEMENTATION
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70
71 FGModel::FGModel(FGFDMExec* fdmex)
72 {
73   FDMExec     = fdmex;
74   NextModel   = 0L;
75
76   State           = 0;
77   Atmosphere      = 0;
78   FCS             = 0;
79   Propulsion      = 0;
80   MassBalance     = 0;
81   Aerodynamics    = 0;
82   Inertial        = 0;
83   GroundReactions = 0;
84   Aircraft        = 0;
85   Translation     = 0;
86   Rotation        = 0;
87   Position        = 0;
88   Auxiliary       = 0;
89   Output          = 0;
90   
91   //in order for FGModel derived classes to self-bind (that is, call
92   //their bind function in the constructor, the PropertyManager pointer
93   //must be brought up now.
94   PropertyManager = FDMExec->GetPropertyManager();
95   
96   exe_ctr     = 1;
97   rate        = 1;
98
99   if (debug_lvl & 2) cout << "              FGModel Base Class" << endl;
100 }
101
102 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103
104 FGModel::~FGModel()
105 {
106   if (debug_lvl & 2) cout << "Destroyed:    FGModel" << endl;
107 }
108
109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110
111 bool FGModel::InitModel(void)
112 {
113   State           = FDMExec->GetState();
114   Atmosphere      = FDMExec->GetAtmosphere();
115   FCS             = FDMExec->GetFCS();
116   Propulsion      = FDMExec->GetPropulsion();
117   MassBalance     = FDMExec->GetMassBalance();
118   Aerodynamics    = FDMExec->GetAerodynamics();
119   Inertial        = FDMExec->GetInertial();
120   GroundReactions = FDMExec->GetGroundReactions();
121   Aircraft        = FDMExec->GetAircraft();
122   Translation     = FDMExec->GetTranslation();
123   Rotation        = FDMExec->GetRotation();
124   Position        = FDMExec->GetPosition();
125   Auxiliary       = FDMExec->GetAuxiliary();
126   Output          = FDMExec->GetOutput();
127   
128   if (!State ||
129       !Atmosphere ||
130       !FCS ||
131       !Propulsion ||
132       !MassBalance ||
133       !Aerodynamics ||
134       !Inertial ||
135       !GroundReactions ||
136       !Aircraft ||
137       !Translation ||
138       !Rotation ||
139       !Position ||
140       !Auxiliary ||
141       !Output) return(false);
142   else return(true);
143 }
144
145 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146
147 bool FGModel::Run()
148 {
149   if (debug_lvl & 4) cout << "Entering Run() for model " << Name << endl;
150
151   if (exe_ctr == 1) {
152     if (exe_ctr++ >= rate) exe_ctr = 1;
153     return false;
154   } else {
155     if (exe_ctr++ >= rate) exe_ctr = 1;
156     return true;
157   }
158 }
159
160 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 //    The bitmasked value choices are as follows:
162 //    unset: In this case (the default) JSBSim would only print
163 //       out the normally expected messages, essentially echoing
164 //       the config files as they are read. If the environment
165 //       variable is not set, debug_lvl is set to 1 internally
166 //    0: This requests JSBSim not to output any messages
167 //       whatsoever.
168 //    1: This value explicity requests the normal JSBSim
169 //       startup messages
170 //    2: This value asks for a message to be printed out when
171 //       a class is instantiated
172 //    4: When this value is set, a message is displayed when a
173 //       FGModel object executes its Run() method
174 //    8: When this value is set, various runtime state variables
175 //       are printed out periodically
176 //    16: When set various parameters are sanity checked and
177 //       a message is printed out when they go out of bounds
178
179 void FGModel::Debug(int from)
180 {
181   if (debug_lvl <= 0) return;
182
183   if (debug_lvl & 1) { // Standard console startup message output
184     if (from == 0) { // Constructor
185
186     }
187   }
188   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
189     if (from == 0) cout << "Instantiated: FGModel" << endl;
190     if (from == 1) cout << "Destroyed:    FGModel" << endl;
191   }
192   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
193   }
194   if (debug_lvl & 8 ) { // Runtime state variables
195   }
196   if (debug_lvl & 16) { // Sanity checking
197   }
198   if (debug_lvl & 64) {
199     if (from == 0) { // Constructor
200       cout << IdSrc << endl;
201       cout << IdHdr << endl;
202     }
203   }
204 }
205 }