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 /** Calculates Euler angles from the local-to-body matrix.
234 @return a reference to the vEuler column vector.
236 FGColumnVector3& CalcEuler(void);
238 /** Calculates and returns the stability-to-body axis transformation matrix.
239 @return a reference to the stability-to-body transformation matrix.
241 FGMatrix33& GetTs2b(void);
243 /** Calculates and returns the body-to-stability axis transformation matrix.
244 @return a reference to the stability-to-body transformation matrix.
246 FGMatrix33& GetTb2s(void);
248 /** Retrieves the local-to-body transformation matrix.
249 @return a reference to the local-to-body transformation matrix.
251 FGMatrix33& GetTl2b(void) { return mTl2b; }
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.
258 double GetTl2b(int r, int c) { return mTl2b(r,c);}
260 /** Retrieves the body-to-local transformation matrix.
261 @return a reference to the body-to-local matrix.
263 FGMatrix33& GetTb2l(void) { return mTb2l; }
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.
270 double GetTb2l(int i, int j) { return mTb2l(i,j);}
272 /** Prints a summary of simulator state (speed, altitude,
275 void ReportState(void);
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]; }
285 double a; // speed of sound
294 FGColumnVector4 vQtrn;
295 FGColumnVector4 vlastQdot;
296 FGColumnVector4 vQdot;
297 FGColumnVector3 vUVW;
298 FGColumnVector3 vLocalVelNED;
299 FGColumnVector3 vLocalEuler;
301 FGColumnVector4 vTmp;
302 FGColumnVector3 vEuler;
304 FGAircraft* Aircraft;
305 FGPosition* Position;
306 FGTranslation* Translation;
307 FGRotation* Rotation;
309 FGAtmosphere* Atmosphere;
311 FGAerodynamics* Aerodynamics;
312 FGGroundReactions* GroundReactions;
313 FGPropulsion* Propulsion;
314 FGPropertyManager* PropertyManager;
316 /* typedef map<string, eParam> CoeffMap;
319 typedef map<eParam, string> ParamMap;
320 //ParamMap paramdef; */
323 typedef map<string,string> ParamNameMap;
324 ParamNameMap ParamNameToProp;
326 typedef map<eParam,string> ParamIdxMap;
327 ParamIdxMap ParamIdxToProp;
328 //CoeffMap PropToParam;
332 void InitPropertyMaps(void);
334 void Debug(int from);
337 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339 #include "FGFDMExec.h"
340 #include "FGAtmosphere.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"