]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGState.h
Synced with latest JSBSim cvs.
[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 */
99
100 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 CLASS DECLARATION
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
103
104 class FGState : public FGJSBBase
105 {
106 public:
107   /** Constructor
108       @param Executive a pointer to the parent executive object */
109   FGState(FGFDMExec*);
110   /// Destructor
111   ~FGState();
112
113   /** Specifies the Reset file to use.
114       The reset file normally resides in the same directory as an aircraft config file.
115       it includes the following information:
116       <ul>
117       <li>U, the body X-Axis velocity</li>
118       <li>V, the body Y-Axis velocity</li>
119       <li>W, the body Z-Axis velocity</li>
120       <li>Latitude measured in radians from the equator, negative values are south.</li>
121       <li>Longitude, measured in radians from the Greenwich meridian, negative values are west.</li>
122       <li>Phi, the roll angle in radians.</li>
123       <li>Theta, the pitch attitude in radians.</li>
124       <li>Psi, the heading angle in radians.</li>
125       <li>H, the altitude in feet</li>
126       <li>Wind Direction, the direction the wind is coming <u>from</u>.</li>
127       <li>Wind magnitude, the wind speed in fps.</li>
128       </ul>
129       @param path the path string leading to the specific aircraft file, i.e. "aircraft".
130       @param aircraft the name of the aircraft, i.e. "c172".
131       @param filename the name of the reset file without an extension, i.e. "reset00".
132       @return true if successful, false if the file could not be opened.
133       */
134   bool Reset(string path, string aircraft, string filename);
135
136   /** Initializes the simulation state based on the passed-in parameters.
137       @param U the body X-Axis velocity in fps.
138       @param V the body Y-Axis velocity in fps.
139       @param W the body Z-Axis velocity in fps.
140       @param lat latitude measured in radians from the equator, negative values are south.
141       @param lon longitude, measured in radians from the Greenwich meridian, negative values are west.
142       @param phi the roll angle in radians.
143       @param tht the pitch angle in radians.
144       @param psi the heading angle in radians measured clockwise from north.
145       @param h altitude in feet.
146       @param wnorth north velocity in feet per second
147       @param weast eastward velocity in feet per second
148       @param wdown downward velocity in feet per second
149       */
150   void Initialize(double U,
151                   double V,
152                   double W,
153                   double lat,
154                   double lon,
155                   double phi,
156                   double tht,
157                   double psi,
158                   double h,
159                   double wnorth,
160                   double weast,
161                   double wdown);
162
163   /** Initializes the simulation state based on parameters from an Initial Conditions object.
164       @param FGIC pointer to an initial conditions object.
165       @see FGInitialConditions.
166       */
167   void Initialize(FGInitialCondition *FGIC);
168
169   /** Stores state data in the supplied file name.
170       @param filename the file to store the data in.
171       @return true if successful.
172       */
173   bool StoreData(string filename);
174
175   /// returns the speed of sound in feet per second.
176   inline double Geta(void) { return a; }
177
178   /// Returns the simulation time in seconds.
179   inline double Getsim_time(void) { return sim_time; }
180   /// Returns the simulation delta T.
181   inline double Getdt(void) { return dt; }
182
183   /// Suspends the simulation and sets the delta T to zero.
184   inline void Suspend(void) {saved_dt = dt; dt = 0.0;}
185   /// Resumes the simulation by resetting delta T to the correct value.
186   inline void Resume(void)  {dt = saved_dt;}
187
188   /** Retrieves a parameter.
189       The parameters that can be retrieved are enumerated in FGJSBBase.h.
190       @param val_idx one of the enumerated JSBSim parameters.
191       @return the value of the parameter.
192       */
193   double GetParameter(eParam val_idx);
194
195   /** Retrieves a parameter.
196       The parameters that can be retrieved are enumerated in FGJSBBase.h.
197       @param val_string a string representing one of the enumerated JSBSim parameters,
198              i.e. "FG_QBAR".
199       @return the value of the parameter.
200       */
201   double GetParameter(string val_string);
202
203   /** Retrieves the JSBSim parameter enumerated item given the text string.
204       @param val_string the parameter string, i.e. "FG_QBAR".
205       @return the JSBSim parameter index (an enumerated type) for the supplied string.
206       */
207   eParam GetParameterIndex(string val_string);
208
209   /** Sets the speed of sound.
210       @param speed the speed of sound in feet per second.
211       */
212   inline void Seta(double speed) { a = speed; }
213
214   /** Sets the current sim time.
215       @param cur_time the current time
216       @return the current time.
217       */
218   inline double Setsim_time(double cur_time) {
219     sim_time = cur_time;
220     return sim_time;
221   }
222   
223   /** Sets the integration time step for the simulation executive.
224       @param delta_t the time step in seconds.
225       */
226   inline void  Setdt(double delta_t) { dt = delta_t; }
227
228   /** Sets the JSBSim parameter to the supplied value.
229       @param prm the JSBSim parameter to set, i.e. FG_RUDDER_POS.
230       @param val the value to give the parameter.
231       */
232   void SetParameter(eParam prm, double val);
233
234   /** Increments the simulation time.
235       @return the new simulation time.
236       */
237   inline double IncrTime(void) {
238     sim_time+=dt;
239     return sim_time;
240   }
241
242   /** Initializes the transformation matrices.
243       @param phi the roll angle in radians.
244       @param tht the pitch angle in radians.
245       @param psi the heading angle in radians
246       */
247   void InitMatrices(double phi, double tht, double psi);
248
249   /** Calculates the local-to-body and body-to-local conversion matrices.
250       */
251   void CalcMatrices(void);
252
253   /** Integrates the quaternion.
254       Given the supplied rotational rate vector and integration rate, the quaternion
255       is integrated. The quaternion is later used to update the transformation
256       matrices.
257       @param vPQR the body rotational rate column vector.
258       @param rate the integration rate in seconds.
259       */
260   void IntegrateQuat(FGColumnVector3 vPQR, int rate);
261
262   /** Calculates Euler angles from the local-to-body matrix.
263       @return a reference to the vEuler column vector.
264       */
265   FGColumnVector3& CalcEuler(void);
266
267   /** Calculates and returns the stability-to-body axis transformation matrix.
268       @return a reference to the stability-to-body transformation matrix.
269       */
270   FGMatrix33& GetTs2b(void);
271
272   /** Retrieves the local-to-body transformation matrix.
273       @return a reference to the local-to-body transformation matrix.
274       */
275   FGMatrix33& GetTl2b(void) { return mTl2b; }
276
277   /** Retrieves a specific local-to-body matrix element.
278       @param r matrix row index.
279       @param c matrix column index.
280       @return the matrix element described by the row and column supplied.
281       */
282   double GetTl2b(int r, int c) { return mTl2b(r,c);}
283
284   /** Retrieves the body-to-local transformation matrix.
285       @return a reference to the body-to-local matrix.
286       */
287   FGMatrix33& GetTb2l(void) { return mTb2l; }
288
289   /** Retrieves a specific body-to-local matrix element.
290       @param r matrix row index.
291       @param c matrix column index.
292       @return the matrix element described by the row and column supplied.
293       */
294   double GetTb2l(int i, int j) { return mTb2l(i,j);}
295   
296   /** Prints a summary of simulator state (speed, altitude, 
297       configuration, etc.)
298   */
299   void ReportState(void);
300
301
302   typedef map<eParam, string> ParamMap;
303   ParamMap paramdef;
304
305 private:
306   double a;                          // speed of sound
307   double sim_time, dt;
308   double saved_dt;
309
310   FGFDMExec* FDMExec;
311   FGMatrix33 mTb2l;
312   FGMatrix33 mTl2b;
313   FGMatrix33 mTs2b;
314   FGColumnVector4 vQtrn;
315   FGColumnVector4 vlastQdot;
316   FGColumnVector3 vUVW;
317   FGColumnVector3 vLocalVelNED;
318   FGColumnVector3 vLocalEuler;
319   FGColumnVector4 vQdot;
320   FGColumnVector4 vTmp;
321   FGColumnVector3 vEuler;
322
323   FGAircraft* Aircraft;
324   FGPosition* Position;
325   FGTranslation* Translation;
326   FGRotation* Rotation;
327   FGOutput* Output;
328   FGAtmosphere* Atmosphere;
329   FGFCS* FCS;
330   FGAerodynamics* Aerodynamics;
331   FGGroundReactions* GroundReactions;
332   FGPropulsion* Propulsion;
333
334   typedef map<string, eParam> CoeffMap;
335   CoeffMap coeffdef;
336   void Debug(void);
337   int ActiveEngine;
338 };
339
340 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341
342 #include "FGFDMExec.h"
343 #include "FGAtmosphere.h"
344 #include "FGFCS.h"
345 #include "FGTranslation.h"
346 #include "FGRotation.h"
347 #include "FGPosition.h"
348 #include "FGAerodynamics.h"
349 #include "FGOutput.h"
350 #include "FGAircraft.h"
351 #include "FGGroundReactions.h"
352 #include "FGPropulsion.h"
353
354 #endif
355