]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGModel.cpp
JSBSim tweaks.
[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 "FGAircraft.h"
51 #include "FGTranslation.h"
52 #include "FGRotation.h"
53 #include "FGPosition.h"
54 #include "FGAuxiliary.h"
55 #include "FGOutput.h"
56
57 static const char *IdSrc = "$Id$";
58 static const char *IdHdr = ID_MODEL;
59
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 GLOBAL DECLARATIONS
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63
64 extern short debug_lvl;
65
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 CLASS IMPLEMENTATION
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69
70 FGModel::FGModel(FGFDMExec* fdmex)
71 {
72   FDMExec     = fdmex;
73   NextModel   = 0L;
74
75   State        = 0;
76   Atmosphere   = 0;
77   FCS          = 0;
78   Propulsion   = 0;
79   MassBalance  = 0;
80   Aerodynamics = 0;
81   Inertial     = 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   Aircraft     = FDMExec->GetAircraft();
113   Translation  = FDMExec->GetTranslation();
114   Rotation     = FDMExec->GetRotation();
115   Position     = FDMExec->GetPosition();
116   Auxiliary    = FDMExec->GetAuxiliary();
117   Output       = FDMExec->GetOutput();
118
119   if (!State ||
120       !Atmosphere ||
121       !FCS ||
122       !Propulsion ||
123       !MassBalance ||
124       !Aerodynamics ||
125       !Inertial ||
126       !Aircraft ||
127       !Translation ||
128       !Rotation ||
129       !Position ||
130       !Auxiliary ||
131       !Output) return(false);
132   else return(true);
133 }
134
135 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136
137 bool FGModel::Run()
138 {
139   if (debug_lvl & 4) cout << "Entering Run() for model " << Name << endl;
140
141   if (exe_ctr == 1) {
142     if (exe_ctr++ >= rate) exe_ctr = 1;
143     return false;
144   } else {
145     if (exe_ctr++ >= rate) exe_ctr = 1;
146     return true;
147   }
148 }
149
150 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151
152 void FGModel::Debug(void)
153 {
154     //TODO: Add your source code here
155 }
156