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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
86 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
90 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
94 /** Encapsulates the calculation of aircraft state.
99 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
103 class FGState : public FGJSBBase
107 @param Executive a pointer to the parent executive object */
112 /** Specifies the Reset file to use.
113 The reset file normally resides in the same directory as an aircraft config file.
114 it includes the following information:
116 <li>U, the body X-Axis velocity</li>
117 <li>V, the body Y-Axis velocity</li>
118 <li>W, the body Z-Axis velocity</li>
119 <li>Latitude measured in radians from the equator, negative values are south.</li>
120 <li>Longitude, measured in radians from the Greenwich meridian, negative values are west.</li>
121 <li>Phi, the roll angle in radians.</li>
122 <li>Theta, the pitch attitude in radians.</li>
123 <li>Psi, the heading angle in radians.</li>
124 <li>H, the altitude in feet</li>
125 <li>Wind Direction, the direction the wind is coming <u>from</u>.</li>
126 <li>Wind magnitude, the wind speed in fps.</li>
128 @param path the path string leading to the specific aircraft file, i.e. "aircraft".
129 @param aircraft the name of the aircraft, i.e. "c172".
130 @param filename the name of the reset file without an extension, i.e. "reset00".
131 @return true if successful, false if the file could not be opened.
133 bool Reset(string path, string aircraft, string filename);
135 /** Initializes the simulation state based on the passed-in parameters.
136 @param U the body X-Axis velocity in fps.
137 @param V the body Y-Axis velocity in fps.
138 @param W the body Z-Axis velocity in fps.
139 @param lat latitude measured in radians from the equator, negative values are south.
140 @param lon longitude, measured in radians from the Greenwich meridian, negative values are west.
141 @param phi the roll angle in radians.
142 @param tht the pitch angle in radians.
143 @param psi the heading angle in radians measured clockwise from north.
144 @param h altitude in feet.
145 @param wnorth north velocity in feet per second
146 @param weast eastward velocity in feet per second
147 @param wdown downward velocity in feet per second
149 void Initialize(float U,
162 /** Initializes the simulation state based on parameters from an Initial Conditions object.
163 @param FGIC pointer to an initial conditions object.
164 @see FGInitialConditions.
166 void Initialize(FGInitialCondition *FGIC);
168 /** Stores state data in the supplied file name.
169 @param filename the file to store the data in.
170 @return true if successful.
172 bool StoreData(string filename);
174 /// returns the speed of sound in feet per second.
175 inline float Geta(void) { return a; }
177 /// Returns the simulation time in seconds.
178 inline float Getsim_time(void) { return sim_time; }
179 /// Returns the simulation delta T.
180 inline float Getdt(void) { return dt; }
182 /// Suspends the simulation and sets the delta T to zero.
183 inline void Suspend(void) {saved_dt = dt; dt = 0.0;}
184 /// Resumes the simulation by resetting delta T to the correct value.
185 inline void Resume(void) {dt = saved_dt;}
187 /** Retrieves a parameter.
188 The parameters that can be retrieved are enumerated in FGDefs.h.
189 @param val_idx one of the enumerated JSBSim parameters.
190 @return the value of the parameter.
192 float GetParameter(eParam val_idx);
194 /** Retrieves a parameter.
195 The parameters that can be retrieved are enumerated in FGDefs.h.
196 @param val_string a string representing one of the enumerated JSBSim parameters,
198 @return the value of the parameter.
200 float GetParameter(string val_string);
202 /** Retrieves the JSBSim parameter enumerated item given the text string.
203 @param val_string the parameter string, i.e. "FG_QBAR".
204 @return the JSBSim parameter index (an enumerated type) for the supplied string.
206 eParam GetParameterIndex(string val_string);
208 /** Sets the speed of sound.
209 @param speed the speed of sound in feet per second.
211 inline void Seta(float speed) { a = speed; }
213 /** Sets the current sim time.
214 @param cur_time the current time
215 @return the current time.
217 inline float Setsim_time(float cur_time) {
222 /** Sets the integration time step for the simulation executive.
223 @param delta_t the time step in seconds.
225 inline void Setdt(float delta_t) { dt = delta_t; }
227 /** Sets the JSBSim parameter to the supplied value.
228 @param prm the JSBSim parameter to set, i.e. FG_RUDDER_POS.
229 @param val the value to give the parameter.
231 void SetParameter(eParam prm, float val);
233 /** Increments the simulation time.
234 @return the new simulation time.
236 inline float IncrTime(void) {
241 /** Initializes the transformation matrices.
242 @param phi the roll angle in radians.
243 @param tht the pitch angle in radians.
244 @param psi the heading angle in radians
246 void InitMatrices(float phi, float tht, float psi);
248 /** Calculates the local-to-body and body-to-local conversion matrices.
250 void CalcMatrices(void);
252 /** Integrates the quaternion.
253 Given the supplied rotational rate vector and integration rate, the quaternion
254 is integrated. The quaternion is later used to update the transformation
256 @param vPQR the body rotational rate column vector.
257 @param rate the integration rate in seconds.
259 void IntegrateQuat(FGColumnVector3 vPQR, int rate);
261 /** Calculates Euler angles from the local-to-body matrix.
262 @return a reference to the vEuler column vector.
264 FGColumnVector3& CalcEuler(void);
266 /** Calculates and returns the stability-to-body axis transformation matrix.
267 @param alpha angle of attack in radians.
268 @param beta angle of sideslip in radians.
269 @return a reference to the stability-to-body transformation matrix.
271 FGMatrix33& GetTs2b(float alpha, float beta);
273 /** Retrieves the local-to-body transformation matrix.
274 @return a reference to the local-to-body transformation matrix.
276 FGMatrix33& GetTl2b(void) { return mTl2b; }
278 /** Retrieves a specific local-to-body matrix element.
279 @param r matrix row index.
280 @param c matrix column index.
281 @return the matrix element described by the row and column supplied.
283 float GetTl2b(int r, int c) { return mTl2b(r,c);}
285 /** Retrieves the body-to-local transformation matrix.
286 @return a reference to the body-to-local matrix.
288 FGMatrix33& GetTb2l(void) { return mTb2l; }
290 /** Retrieves a specific body-to-local matrix element.
291 @param r matrix row index.
292 @param c matrix column index.
293 @return the matrix element described by the row and column supplied.
295 float GetTb2l(int i, int j) { return mTb2l(i,j);}
297 /** Prints a summary of simulator state (speed, altitude,
300 void ReportState(void);
303 typedef map<eParam, string> ParamMap;
307 float a; // speed of sound
315 FGColumnVector4 vQtrn;
316 FGColumnVector4 vlastQdot;
317 FGColumnVector3 vUVW;
318 FGColumnVector3 vLocalVelNED;
319 FGColumnVector3 vLocalEuler;
320 FGColumnVector4 vQdot;
321 FGColumnVector4 vTmp;
322 FGColumnVector3 vEuler;
324 FGAircraft* Aircraft;
325 FGPosition* Position;
326 FGTranslation* Translation;
327 FGRotation* Rotation;
329 FGAtmosphere* Atmosphere;
331 FGAerodynamics* Aerodynamics;
333 typedef map<string, eParam> CoeffMap;
339 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341 #include "FGFDMExec.h"
342 #include "FGAtmosphere.h"
344 #include "FGTranslation.h"
345 #include "FGRotation.h"
346 #include "FGPosition.h"
347 #include "FGAerodynamics.h"
348 #include "FGOutput.h"
349 #include "FGAircraft.h"