1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
30 --------------------------------------------------------------------------------
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 # include <simgear/compiler.h>
46 # ifdef SG_HAVE_STD_INCLUDES
52 # if defined(sgi) && !defined(__GNUC__)
62 #include "FGJSBBase.h"
63 #include "FGInitialCondition.h"
64 #include "FGMatrix33.h"
65 #include "FGColumnVector3.h"
66 #include "FGColumnVector4.h"
68 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
72 #define ID_STATE "$Id$"
74 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
85 class FGGroundReactions;
88 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
96 /** Encapsulates the calculation of aircraft state.
101 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
105 class FGState : public FGJSBBase
109 @param Executive a pointer to the parent executive object */
114 /** Specifies the Reset file to use.
115 The reset file normally resides in the same directory as an aircraft config file.
116 it includes the following information:
118 <li>U, the body X-Axis velocity</li>
119 <li>V, the body Y-Axis velocity</li>
120 <li>W, the body Z-Axis velocity</li>
121 <li>Latitude measured in radians from the equator, negative values are south.</li>
122 <li>Longitude, measured in radians from the Greenwich meridian, negative values are west.</li>
123 <li>Phi, the roll angle in radians.</li>
124 <li>Theta, the pitch attitude in radians.</li>
125 <li>Psi, the heading angle in radians.</li>
126 <li>H, the altitude in feet</li>
127 <li>Wind Direction, the direction the wind is coming <u>from</u>.</li>
128 <li>Wind magnitude, the wind speed in fps.</li>
130 @param path the path string leading to the specific aircraft file, i.e. "aircraft".
131 @param aircraft the name of the aircraft, i.e. "c172".
132 @param filename the name of the reset file without an extension, i.e. "reset00".
133 @return true if successful, false if the file could not be opened.
135 bool Reset(string path, string aircraft, string filename);
137 /** Initializes the simulation state based on the passed-in parameters.
138 @param U the body X-Axis velocity in fps.
139 @param V the body Y-Axis velocity in fps.
140 @param W the body Z-Axis velocity in fps.
141 @param lat latitude measured in radians from the equator, negative values are south.
142 @param lon longitude, measured in radians from the Greenwich meridian, negative values are west.
143 @param phi the roll angle in radians.
144 @param tht the pitch angle in radians.
145 @param psi the heading angle in radians measured clockwise from north.
146 @param h altitude in feet.
147 @param wnorth north velocity in feet per second
148 @param weast eastward velocity in feet per second
149 @param wdown downward velocity in feet per second
151 void Initialize(float U,
164 /** Initializes the simulation state based on parameters from an Initial Conditions object.
165 @param FGIC pointer to an initial conditions object.
166 @see FGInitialConditions.
168 void Initialize(FGInitialCondition *FGIC);
170 /** Stores state data in the supplied file name.
171 @param filename the file to store the data in.
172 @return true if successful.
174 bool StoreData(string filename);
176 /// returns the speed of sound in feet per second.
177 inline float Geta(void) { return a; }
179 /// Returns the simulation time in seconds.
180 inline float Getsim_time(void) { return sim_time; }
181 /// Returns the simulation delta T.
182 inline float Getdt(void) { return dt; }
184 /// Suspends the simulation and sets the delta T to zero.
185 inline void Suspend(void) {saved_dt = dt; dt = 0.0;}
186 /// Resumes the simulation by resetting delta T to the correct value.
187 inline void Resume(void) {dt = saved_dt;}
189 /** Retrieves a parameter.
190 The parameters that can be retrieved are enumerated in FGDefs.h.
191 @param val_idx one of the enumerated JSBSim parameters.
192 @return the value of the parameter.
194 float GetParameter(eParam val_idx);
196 /** Retrieves a parameter.
197 The parameters that can be retrieved are enumerated in FGDefs.h.
198 @param val_string a string representing one of the enumerated JSBSim parameters,
200 @return the value of the parameter.
202 float GetParameter(string val_string);
204 /** Retrieves the JSBSim parameter enumerated item given the text string.
205 @param val_string the parameter string, i.e. "FG_QBAR".
206 @return the JSBSim parameter index (an enumerated type) for the supplied string.
208 eParam GetParameterIndex(string val_string);
210 /** Sets the speed of sound.
211 @param speed the speed of sound in feet per second.
213 inline void Seta(float speed) { a = speed; }
215 /** Sets the current sim time.
216 @param cur_time the current time
217 @return the current time.
219 inline float Setsim_time(float cur_time) {
224 /** Sets the integration time step for the simulation executive.
225 @param delta_t the time step in seconds.
227 inline void Setdt(float delta_t) { dt = delta_t; }
229 /** Sets the JSBSim parameter to the supplied value.
230 @param prm the JSBSim parameter to set, i.e. FG_RUDDER_POS.
231 @param val the value to give the parameter.
233 void SetParameter(eParam prm, float val);
235 /** Increments the simulation time.
236 @return the new simulation time.
238 inline float IncrTime(void) {
243 /** Initializes the transformation matrices.
244 @param phi the roll angle in radians.
245 @param tht the pitch angle in radians.
246 @param psi the heading angle in radians
248 void InitMatrices(float phi, float tht, float psi);
250 /** Calculates the local-to-body and body-to-local conversion matrices.
252 void CalcMatrices(void);
254 /** Integrates the quaternion.
255 Given the supplied rotational rate vector and integration rate, the quaternion
256 is integrated. The quaternion is later used to update the transformation
258 @param vPQR the body rotational rate column vector.
259 @param rate the integration rate in seconds.
261 void IntegrateQuat(FGColumnVector3 vPQR, int rate);
263 /** Calculates Euler angles from the local-to-body matrix.
264 @return a reference to the vEuler column vector.
266 FGColumnVector3& CalcEuler(void);
268 /** Calculates and returns the stability-to-body axis transformation matrix.
269 @param alpha angle of attack in radians.
270 @param beta angle of sideslip in radians.
271 @return a reference to the stability-to-body transformation matrix.
273 FGMatrix33& GetTs2b(float alpha, float beta);
275 /** Retrieves the local-to-body transformation matrix.
276 @return a reference to the local-to-body transformation matrix.
278 FGMatrix33& GetTl2b(void) { return mTl2b; }
280 /** Retrieves a specific local-to-body matrix element.
281 @param r matrix row index.
282 @param c matrix column index.
283 @return the matrix element described by the row and column supplied.
285 float GetTl2b(int r, int c) { return mTl2b(r,c);}
287 /** Retrieves the body-to-local transformation matrix.
288 @return a reference to the body-to-local matrix.
290 FGMatrix33& GetTb2l(void) { return mTb2l; }
292 /** Retrieves a specific body-to-local matrix element.
293 @param r matrix row index.
294 @param c matrix column index.
295 @return the matrix element described by the row and column supplied.
297 float GetTb2l(int i, int j) { return mTb2l(i,j);}
299 /** Prints a summary of simulator state (speed, altitude,
302 void ReportState(void);
305 typedef map<eParam, string> ParamMap;
309 float a; // speed of sound
317 FGColumnVector4 vQtrn;
318 FGColumnVector4 vlastQdot;
319 FGColumnVector3 vUVW;
320 FGColumnVector3 vLocalVelNED;
321 FGColumnVector3 vLocalEuler;
322 FGColumnVector4 vQdot;
323 FGColumnVector4 vTmp;
324 FGColumnVector3 vEuler;
326 FGAircraft* Aircraft;
327 FGPosition* Position;
328 FGTranslation* Translation;
329 FGRotation* Rotation;
331 FGAtmosphere* Atmosphere;
333 FGAerodynamics* Aerodynamics;
334 FGGroundReactions* GroundReactions;
335 FGPropulsion* Propulsion;
337 typedef map<string, eParam> CoeffMap;
343 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345 #include "FGFDMExec.h"
346 #include "FGAtmosphere.h"
348 #include "FGTranslation.h"
349 #include "FGRotation.h"
350 #include "FGPosition.h"
351 #include "FGAerodynamics.h"
352 #include "FGOutput.h"
353 #include "FGAircraft.h"
354 #include "FGGroundReactions.h"
355 #include "FGPropulsion.h"