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.
100 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
104 class FGState : public FGJSBBase
108 @param Executive a pointer to the parent executive object */
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:
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>
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.
134 bool Reset(string path, string aircraft, string filename);
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
150 void Initialize(double U,
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.
167 void Initialize(FGInitialCondition *FGIC);
169 /** Stores state data in the supplied file name.
170 @param filename the file to store the data in.
171 @return true if successful.
173 bool StoreData(string filename);
175 /// returns the speed of sound in feet per second.
176 inline double Geta(void) { return a; }
178 /// Returns the simulation time in seconds.
179 inline double Getsim_time(void) const { return sim_time; }
180 /// Returns the simulation delta T.
181 inline double Getdt(void) { return dt; }
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;}
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.
193 double GetParameter(eParam val_idx);
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,
199 @return the value of the parameter.
201 double GetParameter(string val_string);
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.
207 eParam GetParameterIndex(string val_string);
209 /** Sets the speed of sound.
210 @param speed the speed of sound in feet per second.
212 inline void Seta(double speed) { a = speed; }
214 /** Gets the name of the parameter given the index.
215 @param val_idx one of the enumerated JSBSim parameters.
216 @return the name of the parameter pointed to by the index.
218 string GetParameterName(eParam val_idx) {return paramdef[val_idx];}
220 /** Sets the current sim time.
221 @param cur_time the current time
222 @return the current time.
224 inline double Setsim_time(double cur_time) {
229 /** Sets the integration time step for the simulation executive.
230 @param delta_t the time step in seconds.
232 inline void Setdt(double delta_t) { dt = delta_t; }
234 /** Sets the JSBSim parameter to the supplied value.
235 @param prm the JSBSim parameter to set, i.e. FG_RUDDER_POS.
236 @param val the value to give the parameter.
238 void SetParameter(eParam prm, double val);
240 /** Increments the simulation time.
241 @return the new simulation time.
243 inline double IncrTime(void) {
248 /** Initializes the transformation matrices.
249 @param phi the roll angle in radians.
250 @param tht the pitch angle in radians.
251 @param psi the heading angle in radians
253 void InitMatrices(double phi, double tht, double psi);
255 /** Calculates the local-to-body and body-to-local conversion matrices.
257 void CalcMatrices(void);
259 /** Integrates the quaternion.
260 Given the supplied rotational rate vector and integration rate, the quaternion
261 is integrated. The quaternion is later used to update the transformation
263 @param vPQR the body rotational rate column vector.
264 @param rate the integration rate in seconds.
266 void IntegrateQuat(FGColumnVector3 vPQR, int rate);
268 /** Calculates Euler angles from the local-to-body matrix.
269 @return a reference to the vEuler column vector.
271 FGColumnVector3& CalcEuler(void);
273 /** Calculates and returns the stability-to-body axis transformation matrix.
274 @return a reference to the stability-to-body transformation matrix.
276 FGMatrix33& GetTs2b(void);
278 /** Calculates and returns the body-to-stability axis transformation matrix.
279 @return a reference to the stability-to-body transformation matrix.
281 FGMatrix33& GetTb2s(void);
283 /** Retrieves the local-to-body transformation matrix.
284 @return a reference to the local-to-body transformation matrix.
286 FGMatrix33& GetTl2b(void) { return mTl2b; }
288 /** Retrieves a specific local-to-body matrix element.
289 @param r matrix row index.
290 @param c matrix column index.
291 @return the matrix element described by the row and column supplied.
293 double GetTl2b(int r, int c) { return mTl2b(r,c);}
295 /** Retrieves the body-to-local transformation matrix.
296 @return a reference to the body-to-local matrix.
298 FGMatrix33& GetTb2l(void) { return mTb2l; }
300 /** Retrieves a specific body-to-local matrix element.
301 @param r matrix row index.
302 @param c matrix column index.
303 @return the matrix element described by the row and column supplied.
305 double GetTb2l(int i, int j) { return mTb2l(i,j);}
307 /** Prints a summary of simulator state (speed, altitude,
310 void ReportState(void);
312 inline string GetPropertyName(eParam prm) { return ParamToProp[prm]; }
313 inline eParam GetParam(string property) { return PropToParam[property]; }
319 double a; // speed of sound
328 FGColumnVector4 vQtrn;
329 FGColumnVector4 vlastQdot;
330 FGColumnVector4 vQdot;
331 FGColumnVector3 vUVW;
332 FGColumnVector3 vLocalVelNED;
333 FGColumnVector3 vLocalEuler;
335 FGColumnVector4 vTmp;
336 FGColumnVector3 vEuler;
338 FGAircraft* Aircraft;
339 FGPosition* Position;
340 FGTranslation* Translation;
341 FGRotation* Rotation;
343 FGAtmosphere* Atmosphere;
345 FGAerodynamics* Aerodynamics;
346 FGGroundReactions* GroundReactions;
347 FGPropulsion* Propulsion;
348 FGPropertyManager* PropertyManager;
350 typedef map<string, eParam> CoeffMap;
353 typedef map<eParam, string> ParamMap;
356 ParamMap ParamToProp;
357 CoeffMap PropToParam;
361 void InitPropertyMaps(void);
363 void Debug(int from);
366 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
368 #include "FGFDMExec.h"
369 #include "FGAtmosphere.h"
371 #include "FGTranslation.h"
372 #include "FGRotation.h"
373 #include "FGPosition.h"
374 #include "FGAerodynamics.h"
375 #include "FGOutput.h"
376 #include "FGAircraft.h"
377 #include "FGGroundReactions.h"
378 #include "FGPropulsion.h"