]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGState.h
JSBSim tweaks.
[flightgear.git] / src / FDM / JSBSim / FGState.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2  
3  Header:       FGState.h
4  Author:       Jon S. Berndt
5  Date started: 11/17/98
6  
7  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
8  
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13  
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  details.
18  
19  You should have received a copy of the GNU General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22  
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25  
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
28  
29 Based on Flightgear code, which is based on LaRCSim. This class wraps all
30 global state variables (such as velocity, position, orientation, etc.).
31  
32 HISTORY
33 --------------------------------------------------------------------------------
34 11/17/98   JSB   Created
35  
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 SENTRY
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40 #ifndef FGSTATE_H
41 #define FGSTATE_H
42
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 INCLUDES
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47 #ifdef FGFS
48 #  include <simgear/compiler.h>
49 #  ifdef SG_HAVE_STD_INCLUDES
50 #    include <fstream>
51 #  else
52 #    include <fstream.h>
53 #  endif
54 #else
55 #  include <fstream>
56 #endif
57
58 #include <string>
59 #include <map>
60 #include "FGDefs.h"
61 #include "FGInitialCondition.h"
62 #include "FGMatrix.h"
63
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 DEFINITIONS
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
67
68 #define ID_STATE "$Id$"
69
70 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 FORWARD DECLARATIONS
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
73
74 class FGAircraft;
75 class FGTranslation;
76 class FGRotation;
77 class FGAtmosphere;
78 class FGOutput;
79 class FGPosition;
80
81 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
84
85 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 CLASS DOCUMENTATION
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
88
89 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 CLASS DECLARATION
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
92
93 class FGFDMExec;
94
95 class FGState {
96 public:
97   FGState(FGFDMExec*);
98   ~FGState();
99
100   enum {ePhi=1, eTht, ePsi};
101   enum {eP=1, eQ, eR};
102   enum {eU=1, eV, eW};
103   enum {eDrag=1, eSide, eLift};
104
105   bool Reset(string, string, string);
106   void Initialize(float, float, float, float, float, float, float, float, float);
107   void Initialize(FGInitialCondition *FGIC);
108   bool StoreData(string);
109
110   inline float Geta(void) { return a; }
111
112   inline float Getsim_time(void) { return sim_time; }
113   inline float Getdt(void) { return dt; }
114
115   inline void Suspend(void) {saved_dt = dt; dt = 0.0;}
116   inline void Resume(void)  {dt = saved_dt;}
117
118   float GetParameter(eParam val_idx);
119   float GetParameter(string val_string);
120   eParam GetParameterIndex(string val_string);
121
122   inline void Seta(float tt) { a = tt; }
123
124   inline float Setsim_time(float tt) {
125     sim_time = tt;
126     return sim_time;
127   }
128   inline void  Setdt(float tt) { dt = tt; }
129
130   void SetParameter(eParam, float);
131
132   inline float IncrTime(void) {
133     sim_time+=dt;
134     return sim_time;
135   }
136   void InitMatrices(float phi, float tht, float psi);
137   void CalcMatrices(void);
138   void IntegrateQuat(FGColumnVector vPQR, int rate);
139   FGColumnVector CalcEuler(void);
140   FGMatrix GetTs2b(float alpha, float beta);
141   FGMatrix GetTl2b(void) { return mTl2b; }
142   float GetTl2b(int i, int j) { return mTl2b(i,j);}
143   FGMatrix GetTb2l(void) { return mTb2l; }
144   float GetTb2l(int i, int j) { return mTb2l(i,j);}
145   typedef map<eParam, string> ParamMap;
146   ParamMap paramdef;
147
148 private:
149
150   float a;                          // speed of sound
151   float sim_time, dt;
152   float saved_dt;
153
154   FGFDMExec* FDMExec;
155   FGMatrix mTb2l;
156   FGMatrix mTl2b;
157   FGMatrix mTs2b;
158   FGColumnVector vQtrn;
159   FGColumnVector vlastQdot;
160
161   FGAircraft* Aircraft;
162   FGPosition* Position;
163   FGTranslation* Translation;
164   FGRotation* Rotation;
165   FGOutput* Output;
166   FGAtmosphere* Atmosphere;
167   FGFCS* FCS;
168   FGAerodynamics* Aerodynamics;
169
170   typedef map<string, eParam> CoeffMap;
171   CoeffMap coeffdef;
172   void Debug(void);
173   int ActiveEngine;
174
175   FGColumnVector vQdot;
176   FGColumnVector vTmp;
177   FGColumnVector vEuler;
178 };
179
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181
182 #include "FGFDMExec.h"
183 #include "FGAtmosphere.h"
184 #include "FGFCS.h"
185 #include "FGTranslation.h"
186 #include "FGRotation.h"
187 #include "FGPosition.h"
188 #include "FGAerodynamics.h"
189 #include "FGOutput.h"
190 #include "FGAircraft.h"
191
192 #endif
193