]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGState.h
Patch from Melchior Franz:
[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 HISTORY
30 --------------------------------------------------------------------------------
31 11/17/98   JSB   Created
32  
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 SENTRY
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36
37 #ifndef FGSTATE_H
38 #define FGSTATE_H
39
40 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 INCLUDES
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43
44 #ifdef FGFS
45 #  include <simgear/compiler.h>
46 #  ifdef SG_HAVE_STD_INCLUDES
47 #    include <fstream>
48 #  else
49 #    include <fstream.h>
50 #  endif
51 #else
52 #  if defined(sgi) && !defined(__GNUC__)
53 #    include <fstream.h>
54 #  else
55 #    include <fstream>
56 #  endif
57 #endif
58
59 #include <string>
60 #include <map>
61 #include "FGJSBBase.h"
62 #include "FGInitialCondition.h"
63 #include "FGMatrix33.h"
64 #include "FGColumnVector3.h"
65 #include "FGColumnVector4.h"
66
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 DEFINITIONS
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70
71 #define ID_STATE "$Id$"
72
73 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 FORWARD DECLARATIONS
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
76
77 class FGAircraft;
78 class FGTranslation;
79 class FGRotation;
80 class FGAtmosphere;
81 class FGOutput;
82 class FGPosition;
83 class FGFDMExec;
84 class FGGroundReactions;
85 class FGPropulsion;
86
87 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
90
91 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 CLASS DOCUMENTATION
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
94
95 /** Encapsulates the calculation of aircraft state.
96     @author Jon S. Berndt
97     @version $Id$
98     @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGState.h?rev=HEAD&content-type=text/vnd.viewcvs-markup">
99          Header File </a>
100     @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGState.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">
101          Source File </a>
102 */
103
104 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 CLASS DECLARATION
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
107
108 class FGState : public FGJSBBase
109 {
110 public:
111   /** Constructor
112       @param Executive a pointer to the parent executive object */
113   FGState(FGFDMExec*);
114   /// Destructor
115   ~FGState();
116
117   /** Specifies the Reset file to use.
118       The reset file normally resides in the same directory as an aircraft config file.
119       it includes the following information:
120       <ul>
121       <li>U, the body X-Axis velocity</li>
122       <li>V, the body Y-Axis velocity</li>
123       <li>W, the body Z-Axis velocity</li>
124       <li>Latitude measured in radians from the equator, negative values are south.</li>
125       <li>Longitude, measured in radians from the Greenwich meridian, negative values are west.</li>
126       <li>Phi, the roll angle in radians.</li>
127       <li>Theta, the pitch attitude in radians.</li>
128       <li>Psi, the heading angle in radians.</li>
129       <li>H, the altitude in feet</li>
130       <li>Wind Direction, the direction the wind is coming <u>from</u>.</li>
131       <li>Wind magnitude, the wind speed in fps.</li>
132       </ul>
133       @param path the path string leading to the specific aircraft file, i.e. "aircraft".
134       @param aircraft the name of the aircraft, i.e. "c172".
135       @param filename the name of the reset file without an extension, i.e. "reset00".
136       @return true if successful, false if the file could not be opened.
137       */
138   bool Reset(string path, string aircraft, string filename);
139
140   /** Initializes the simulation state based on the passed-in parameters.
141       @param U the body X-Axis velocity in fps.
142       @param V the body Y-Axis velocity in fps.
143       @param W the body Z-Axis velocity in fps.
144       @param lat latitude measured in radians from the equator, negative values are south.
145       @param lon longitude, measured in radians from the Greenwich meridian, negative values are west.
146       @param phi the roll angle in radians.
147       @param tht the pitch angle in radians.
148       @param psi the heading angle in radians measured clockwise from north.
149       @param h altitude in feet.
150       @param wnorth north velocity in feet per second
151       @param weast eastward velocity in feet per second
152       @param wdown downward velocity in feet per second
153       */
154   void Initialize(double U,
155                   double V,
156                   double W,
157                   double lat,
158                   double lon,
159                   double phi,
160                   double tht,
161                   double psi,
162                   double h,
163                   double wnorth,
164                   double weast,
165                   double wdown);
166
167   /** Initializes the simulation state based on parameters from an Initial Conditions object.
168       @param FGIC pointer to an initial conditions object.
169       @see FGInitialConditions.
170       */
171   void Initialize(FGInitialCondition *FGIC);
172
173   /// returns the speed of sound in feet per second.
174   inline double Geta(void) { return a; }
175
176   /// Returns the simulation time in seconds.
177   inline double Getsim_time(void) const { return sim_time; }
178   /// Returns the simulation delta T.
179   inline double Getdt(void) { return dt; }
180
181   /// Suspends the simulation and sets the delta T to zero.
182   inline void Suspend(void) {saved_dt = dt; dt = 0.0;}
183   /// Resumes the simulation by resetting delta T to the correct value.
184   inline void Resume(void)  {dt = saved_dt;}
185
186   /** Sets the speed of sound.
187       @param speed the speed of sound in feet per second.
188       */
189   inline void Seta(double speed) { a = speed; }
190
191   /** Sets the current sim time.
192       @param cur_time the current time
193       @return the current time.
194       */
195   inline double Setsim_time(double cur_time) {
196     sim_time = cur_time;
197     return sim_time;
198   }
199   
200   /** Sets the integration time step for the simulation executive.
201       @param delta_t the time step in seconds.
202       */
203   inline void  Setdt(double delta_t) { dt = delta_t; }
204
205   /** Increments the simulation time.
206       @return the new simulation time.
207       */
208   inline double IncrTime(void) {
209     sim_time+=dt;
210     return sim_time;
211   }
212
213   /** Initializes the transformation matrices.
214       @param phi the roll angle in radians.
215       @param tht the pitch angle in radians.
216       @param psi the heading angle in radians
217       */
218   void InitMatrices(double phi, double tht, double psi);
219
220   /** Calculates the local-to-body and body-to-local conversion matrices.
221       */
222   void CalcMatrices(void);
223
224   /** Integrates the quaternion.
225       Given the supplied rotational rate vector and integration rate, the quaternion
226       is integrated. The quaternion is later used to update the transformation
227       matrices.
228       @param vPQR the body rotational rate column vector.
229       @param rate the integration rate in seconds.
230       */
231   void IntegrateQuat(FGColumnVector3 vPQR, int rate);
232
233   /** Calculates Euler angles from the local-to-body matrix.
234       @return a reference to the vEuler column vector.
235       */
236   FGColumnVector3& CalcEuler(void);
237
238   /** Calculates and returns the stability-to-body axis transformation matrix.
239       @return a reference to the stability-to-body transformation matrix.
240       */
241   FGMatrix33& GetTs2b(void);
242   
243   /** Calculates and returns the body-to-stability axis transformation matrix.
244       @return a reference to the stability-to-body transformation matrix.
245       */
246   FGMatrix33& GetTb2s(void);
247
248   /** Retrieves the local-to-body transformation matrix.
249       @return a reference to the local-to-body transformation matrix.
250       */
251   FGMatrix33& GetTl2b(void) { return mTl2b; }
252
253   /** Retrieves a specific local-to-body matrix element.
254       @param r matrix row index.
255       @param c matrix column index.
256       @return the matrix element described by the row and column supplied.
257       */
258   double GetTl2b(int r, int c) { return mTl2b(r,c);}
259
260   /** Retrieves the body-to-local transformation matrix.
261       @return a reference to the body-to-local matrix.
262       */
263   FGMatrix33& GetTb2l(void) { return mTb2l; }
264
265   /** Retrieves a specific body-to-local matrix element.
266       @param r matrix row index.
267       @param c matrix column index.
268       @return the matrix element described by the row and column supplied.
269       */
270   double GetTb2l(int i, int j) { return mTb2l(i,j);}
271   
272   /** Prints a summary of simulator state (speed, altitude, 
273       configuration, etc.)
274   */
275   void ReportState(void);
276   
277   inline string GetPropertyName(string prm) { return ParamNameToProp[prm]; }
278   //inline string GetPropertyName(eParam prm) { return ParamIdxToProp[prm]; }
279   //inline eParam GetParam(string property) { return PropToParam[property]; }
280   
281   void bind();
282   void unbind();
283
284 private:
285   double a;                          // speed of sound
286   double sim_time, dt;
287   double saved_dt;
288
289   FGFDMExec* FDMExec;
290   FGMatrix33 mTb2l;
291   FGMatrix33 mTl2b;
292   FGMatrix33 mTs2b;
293   FGMatrix33 mTb2s;
294   FGColumnVector4 vQtrn;
295   FGColumnVector4 vlastQdot;
296   FGColumnVector4 vQdot;
297   FGColumnVector3 vUVW;
298   FGColumnVector3 vLocalVelNED;
299   FGColumnVector3 vLocalEuler;
300   
301   FGColumnVector4 vTmp;
302   FGColumnVector3 vEuler;
303
304   FGAircraft* Aircraft;
305   FGPosition* Position;
306   FGTranslation* Translation;
307   FGRotation* Rotation;
308   FGOutput* Output;
309   FGAtmosphere* Atmosphere;
310   FGFCS* FCS;
311   FGAerodynamics* Aerodynamics;
312   FGGroundReactions* GroundReactions;
313   FGPropulsion* Propulsion;
314   FGPropertyManager* PropertyManager;
315
316  /*  typedef map<string, eParam> CoeffMap;
317   CoeffMap coeffdef;
318
319   typedef map<eParam, string> ParamMap;
320   //ParamMap paramdef; */
321
322   
323   typedef map<string,string> ParamNameMap;
324   ParamNameMap ParamNameToProp;
325   
326   typedef map<eParam,string> ParamIdxMap;
327   ParamIdxMap ParamIdxToProp;
328   //CoeffMap PropToParam;
329
330   int ActiveEngine;
331   
332   void InitPropertyMaps(void);
333   
334   void Debug(int from);
335 };
336
337 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338
339 #include "FGFDMExec.h"
340 #include "FGAtmosphere.h"
341 #include "FGFCS.h"
342 #include "FGTranslation.h"
343 #include "FGRotation.h"
344 #include "FGPosition.h"
345 #include "FGAerodynamics.h"
346 #include "FGOutput.h"
347 #include "FGAircraft.h"
348 #include "FGGroundReactions.h"
349 #include "FGPropulsion.h"
350
351 #endif
352