]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGModel.cpp
First steps in a weather reorganization. Note especially that
[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 static const char *IdSrc = "$Id$";
59 static const char *IdHdr = ID_MODEL;
60
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 GLOBAL DECLARATIONS
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 CLASS IMPLEMENTATION
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68
69 FGModel::FGModel(FGFDMExec* fdmex)
70 {
71   FDMExec     = fdmex;
72   NextModel   = 0L;
73
74   State           = 0;
75   Atmosphere      = 0;
76   FCS             = 0;
77   Propulsion      = 0;
78   MassBalance     = 0;
79   Aerodynamics    = 0;
80   Inertial        = 0;
81   GroundReactions = 0;
82   Aircraft        = 0;
83   Translation     = 0;
84   Rotation        = 0;
85   Position        = 0;
86   Auxiliary       = 0;
87   Output          = 0;
88
89   exe_ctr     = 1;
90
91   if (debug_lvl & 2) cout << "              FGModel Base Class" << endl;
92 }
93
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95
96 FGModel::~FGModel()
97 {
98   if (debug_lvl & 2) cout << "Destroyed:    FGModel" << endl;
99 }
100
101 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102
103 bool FGModel::InitModel(void)
104 {
105   State           = FDMExec->GetState();
106   Atmosphere      = FDMExec->GetAtmosphere();
107   FCS             = FDMExec->GetFCS();
108   Propulsion      = FDMExec->GetPropulsion();
109   MassBalance     = FDMExec->GetMassBalance();
110   Aerodynamics    = FDMExec->GetAerodynamics();
111   Inertial        = FDMExec->GetInertial();
112   GroundReactions = FDMExec->GetGroundReactions();
113   Aircraft        = FDMExec->GetAircraft();
114   Translation     = FDMExec->GetTranslation();
115   Rotation        = FDMExec->GetRotation();
116   Position        = FDMExec->GetPosition();
117   Auxiliary       = FDMExec->GetAuxiliary();
118   Output          = FDMExec->GetOutput();
119
120   if (!State ||
121       !Atmosphere ||
122       !FCS ||
123       !Propulsion ||
124       !MassBalance ||
125       !Aerodynamics ||
126       !Inertial ||
127       !GroundReactions ||
128       !Aircraft ||
129       !Translation ||
130       !Rotation ||
131       !Position ||
132       !Auxiliary ||
133       !Output) return(false);
134   else return(true);
135 }
136
137 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138
139 bool FGModel::Run()
140 {
141   if (debug_lvl & 4) cout << "Entering Run() for model " << Name << endl;
142
143   if (exe_ctr == 1) {
144     if (exe_ctr++ >= rate) exe_ctr = 1;
145     return false;
146   } else {
147     if (exe_ctr++ >= rate) exe_ctr = 1;
148     return true;
149   }
150 }
151
152 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 //    The bitmasked value choices are as follows:
154 //    unset: In this case (the default) JSBSim would only print
155 //       out the normally expected messages, essentially echoing
156 //       the config files as they are read. If the environment
157 //       variable is not set, debug_lvl is set to 1 internally
158 //    0: This requests JSBSim not to output any messages
159 //       whatsoever.
160 //    1: This value explicity requests the normal JSBSim
161 //       startup messages
162 //    2: This value asks for a message to be printed out when
163 //       a class is instantiated
164 //    4: When this value is set, a message is displayed when a
165 //       FGModel object executes its Run() method
166 //    8: When this value is set, various runtime state variables
167 //       are printed out periodically
168 //    16: When set various parameters are sanity checked and
169 //       a message is printed out when they go out of bounds
170
171 void FGModel::Debug(int from)
172 {
173   if (debug_lvl <= 0) return;
174
175   if (debug_lvl & 1) { // Standard console startup message output
176     if (from == 0) { // Constructor
177
178     }
179   }
180   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
181     if (from == 0) cout << "Instantiated: FGModel" << endl;
182     if (from == 1) cout << "Destroyed:    FGModel" << endl;
183   }
184   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
185   }
186   if (debug_lvl & 8 ) { // Runtime state variables
187   }
188   if (debug_lvl & 16) { // Sanity checking
189   }
190   if (debug_lvl & 64) {
191     if (from == 0) { // Constructor
192       cout << IdSrc << endl;
193       cout << IdHdr << endl;
194     }
195   }
196 }
197