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