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) { 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 /** Sets the current sim time.
215 @param cur_time the current time
216 @return the current time.
218 inline double Setsim_time(double cur_time) {
223 /** Sets the integration time step for the simulation executive.
224 @param delta_t the time step in seconds.
226 inline void Setdt(double delta_t) { dt = delta_t; }
228 /** Sets the JSBSim parameter to the supplied value.
229 @param prm the JSBSim parameter to set, i.e. FG_RUDDER_POS.
230 @param val the value to give the parameter.
232 void SetParameter(eParam prm, double val);
234 /** Increments the simulation time.
235 @return the new simulation time.
237 inline double IncrTime(void) {
242 /** Initializes the transformation matrices.
243 @param phi the roll angle in radians.
244 @param tht the pitch angle in radians.
245 @param psi the heading angle in radians
247 void InitMatrices(double phi, double tht, double psi);
249 /** Calculates the local-to-body and body-to-local conversion matrices.
251 void CalcMatrices(void);
253 /** Integrates the quaternion.
254 Given the supplied rotational rate vector and integration rate, the quaternion
255 is integrated. The quaternion is later used to update the transformation
257 @param vPQR the body rotational rate column vector.
258 @param rate the integration rate in seconds.
260 void IntegrateQuat(FGColumnVector3 vPQR, int rate);
262 /** Calculates Euler angles from the local-to-body matrix.
263 @return a reference to the vEuler column vector.
265 FGColumnVector3& CalcEuler(void);
267 /** Calculates and returns the stability-to-body axis transformation matrix.
268 @return a reference to the stability-to-body transformation matrix.
270 FGMatrix33& GetTs2b(void);
272 /** Calculates and returns the body-to-stability axis transformation matrix.
273 @return a reference to the stability-to-body transformation matrix.
275 FGMatrix33& GetTb2s(void);
277 /** Retrieves the local-to-body transformation matrix.
278 @return a reference to the local-to-body transformation matrix.
280 FGMatrix33& GetTl2b(void) { return mTl2b; }
282 /** Retrieves a specific local-to-body matrix element.
283 @param r matrix row index.
284 @param c matrix column index.
285 @return the matrix element described by the row and column supplied.
287 double GetTl2b(int r, int c) { return mTl2b(r,c);}
289 /** Retrieves the body-to-local transformation matrix.
290 @return a reference to the body-to-local matrix.
292 FGMatrix33& GetTb2l(void) { return mTb2l; }
294 /** Retrieves a specific body-to-local matrix element.
295 @param r matrix row index.
296 @param c matrix column index.
297 @return the matrix element described by the row and column supplied.
299 double GetTb2l(int i, int j) { return mTb2l(i,j);}
301 /** Prints a summary of simulator state (speed, altitude,
304 void ReportState(void);
307 typedef map<eParam, string> ParamMap;
311 double a; // speed of sound
320 FGColumnVector4 vQtrn;
321 FGColumnVector4 vlastQdot;
322 FGColumnVector4 vQdot;
323 FGColumnVector3 vUVW;
324 FGColumnVector3 vLocalVelNED;
325 FGColumnVector3 vLocalEuler;
327 FGColumnVector4 vTmp;
328 FGColumnVector3 vEuler;
330 FGAircraft* Aircraft;
331 FGPosition* Position;
332 FGTranslation* Translation;
333 FGRotation* Rotation;
335 FGAtmosphere* Atmosphere;
337 FGAerodynamics* Aerodynamics;
338 FGGroundReactions* GroundReactions;
339 FGPropulsion* Propulsion;
341 typedef map<string, eParam> CoeffMap;
344 void Debug(int from);
347 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
349 #include "FGFDMExec.h"
350 #include "FGAtmosphere.h"
352 #include "FGTranslation.h"
353 #include "FGRotation.h"
354 #include "FGPosition.h"
355 #include "FGAerodynamics.h"
356 #include "FGOutput.h"
357 #include "FGAircraft.h"
358 #include "FGGroundReactions.h"
359 #include "FGPropulsion.h"