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__)
61 #include "FGJSBBase.h"
62 #include "FGInitialCondition.h"
63 #include "FGMatrix33.h"
64 #include "FGColumnVector3.h"
65 #include "FGColumnVector4.h"
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
71 #define ID_STATE "$Id$"
73 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
84 class FGGroundReactions;
87 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
91 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
95 /** Encapsulates the calculation of aircraft state.
98 @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGState.h?rev=HEAD&content-type=text/vnd.viewcvs-markup">
100 @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGState.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">
104 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
108 class FGState : public FGJSBBase
112 @param Executive a pointer to the parent executive object */
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:
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>
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.
138 bool Reset(string path, string aircraft, string filename);
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
154 void Initialize(double U,
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.
171 void Initialize(FGInitialCondition *FGIC);
173 /// returns the speed of sound in feet per second.
174 inline double Geta(void) { return a; }
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; }
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;}
186 /** Sets the speed of sound.
187 @param speed the speed of sound in feet per second.
189 inline void Seta(double speed) { a = speed; }
191 /** Sets the current sim time.
192 @param cur_time the current time
193 @return the current time.
195 inline double Setsim_time(double cur_time) {
200 /** Sets the integration time step for the simulation executive.
201 @param delta_t the time step in seconds.
203 inline void Setdt(double delta_t) { dt = delta_t; }
205 /** Increments the simulation time.
206 @return the new simulation time.
208 inline double IncrTime(void) {
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
218 void InitMatrices(double phi, double tht, double psi);
220 /** Calculates the local-to-body and body-to-local conversion matrices.
222 void CalcMatrices(void);
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
228 @param vPQR the body rotational rate column vector.
229 @param rate the integration rate in seconds.
231 void IntegrateQuat(FGColumnVector3 vPQR, int rate);
233 // ======================================= General Purpose INTEGRATOR
235 enum iType {AB4, AB3, AB2, AM3, EULER, TRAPZ};
237 /** Multi-method integrator.
238 @param type Type of intergation scheme to use. Can be one of:
240 <li>AB4 - Adams-Bashforth, fourth order</li>
241 <li>AB3 - Adams-Bashforth, third order</li>
242 <li>AB2 - Adams-Bashforth, second order</li>
243 <li>AM3 - Adams Moulton, third order</li>
244 <li>EULER - Euler</li>
245 <li>TRAPZ - Trapezoidal</li>
247 @param delta_t the integration time step in seconds
248 @param vTDeriv a reference to the current value of the time derivative of
249 the quantity being integrated (i.e. if vUVW is being integrated
250 vTDeriv is the current value of vUVWdot)
251 @param vLastArray an array of previously calculated and saved values of
252 the quantity being integrated (i.e. if vUVW is being integrated
253 vLastArray[0] is the past value of vUVWdot, vLastArray[1] is the value of
254 vUVWdot prior to that, etc.)
255 @return the current, incremental value of the item integrated to add to the
258 template <class T> T Integrate(iType type, double delta_t, T& vTDeriv, T *vLastArray)
264 vResult = (delta_t/24.0)*( 55.0 * vTDeriv
265 - 59.0 * vLastArray[0]
266 + 37.0 * vLastArray[1]
267 - 9.0 * vLastArray[2] );
268 vLastArray[2] = vLastArray[1];
269 vLastArray[1] = vLastArray[0];
270 vLastArray[0] = vTDeriv;
273 vResult = (delta_t/12.0)*( 23.0 * vTDeriv
274 - 16.0 * vLastArray[0]
275 + 5.0 * vLastArray[1] );
276 vLastArray[1] = vLastArray[0];
277 vLastArray[0] = vTDeriv;
280 vResult = (delta_t/2.0)*( 3.0 * vTDeriv - vLastArray[0] );
281 vLastArray[0] = vTDeriv;
284 vResult = (delta_t/12.0)*( 5.0 * vTDeriv
285 + 8.0 * vLastArray[0]
286 - 1.0 * vLastArray[1] );
287 vLastArray[1] = vLastArray[0];
288 vLastArray[0] = vTDeriv;
291 vResult = delta_t * vTDeriv;
294 vResult = (delta_t*0.5) * (vTDeriv + vLastArray[0]);
295 vLastArray[0] = vTDeriv;
302 // =======================================
304 /** Calculates Euler angles from the local-to-body matrix.
305 @return a reference to the vEuler column vector.
307 FGColumnVector3& CalcEuler(void);
309 /** Calculates and returns the stability-to-body axis transformation matrix.
310 @return a reference to the stability-to-body transformation matrix.
312 FGMatrix33& GetTs2b(void);
314 /** Calculates and returns the body-to-stability axis transformation matrix.
315 @return a reference to the stability-to-body transformation matrix.
317 FGMatrix33& GetTb2s(void);
319 /** Retrieves the local-to-body transformation matrix.
320 @return a reference to the local-to-body transformation matrix.
322 FGMatrix33& GetTl2b(void) { return mTl2b; }
324 /** Retrieves a specific local-to-body matrix element.
325 @param r matrix row index.
326 @param c matrix column index.
327 @return the matrix element described by the row and column supplied.
329 double GetTl2b(int r, int c) { return mTl2b(r,c);}
331 /** Retrieves the body-to-local transformation matrix.
332 @return a reference to the body-to-local matrix.
334 FGMatrix33& GetTb2l(void) { return mTb2l; }
336 /** Retrieves a specific body-to-local matrix element.
337 @param r matrix row index.
338 @param c matrix column index.
339 @return the matrix element described by the row and column supplied.
341 double GetTb2l(int i, int j) { return mTb2l(i,j);}
343 /** Prints a summary of simulator state (speed, altitude,
346 void ReportState(void);
348 inline string GetPropertyName(string prm) { return ParamNameToProp[prm]; }
354 double a; // speed of sound
363 FGColumnVector4 vQtrn;
364 FGColumnVector4 vQdot_prev[3];
365 FGColumnVector4 vQdot;
366 FGColumnVector3 vUVW;
367 FGColumnVector3 vLocalVelNED;
368 FGColumnVector3 vLocalEuler;
370 FGColumnVector4 vTmp;
371 FGColumnVector3 vEuler;
373 FGAircraft* Aircraft;
374 FGPosition* Position;
375 FGTranslation* Translation;
376 FGRotation* Rotation;
378 FGAtmosphere* Atmosphere;
380 FGAerodynamics* Aerodynamics;
381 FGGroundReactions* GroundReactions;
382 FGPropulsion* Propulsion;
383 FGPropertyManager* PropertyManager;
385 typedef map<string,string> ParamNameMap;
386 ParamNameMap ParamNameToProp;
388 void InitPropertyMaps(void);
390 void Debug(int from);
393 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
395 #include "FGFDMExec.h"
396 #include "FGAtmosphere.h"
398 #include "FGTranslation.h"
399 #include "FGRotation.h"
400 #include "FGPosition.h"
401 #include "FGAerodynamics.h"
402 #include "FGOutput.h"
403 #include "FGAircraft.h"
404 #include "FGGroundReactions.h"
405 #include "FGPropulsion.h"