]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAircraft.h
Synced with latest JSBSim. X15 works for me, but C172 segfaults.
[flightgear.git] / src / FDM / JSBSim / FGAircraft.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2  
3  Header:       FGAircraft.h
4  Author:       Jon S. Berndt
5  Date started: 12/12/98
6  
7  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
8  
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
12  version.
13  
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
17  details.
18  
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.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25  
26 HISTORY
27 --------------------------------------------------------------------------------
28 12/12/98   JSB   Created
29  
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGAIRCRAFT_H
35 #define FGAIRCRAFT_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #ifdef FGFS
42 #  include <simgear/compiler.h>
43 #  ifdef FG_HAVE_STD_INCLUDES
44 #    include <vector>
45 #    include <iterator>
46 #    include <map>
47 #  else
48 #    include <vector.h>
49 #    include <iterator.h>
50 #    include <map.h>
51 #  endif
52 #else
53 #  include <vector>
54 #  include <iterator>
55 #  include <map>
56 #endif
57
58 #include "FGModel.h"
59 #include "FGCoefficient.h"
60 #include "FGPropulsion.h"
61 #include "FGConfigFile.h"
62 #include "FGMatrix.h"
63 #include "FGLGear.h"
64
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 DEFINITIONS
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68
69 #define ID_AIRCRAFT "$Id$"
70
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 FORWARD DECLARATIONS
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74
75 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
78
79 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 CLASS DOCUMENTATION
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
82
83 /** Encapsulates an Aircraft and its systems.
84     Owns all the parts (other classes) which make up this aircraft. This includes
85     the Engines, Tanks, Propellers, Nozzles, Aerodynamic and Mass properties,
86     landing gear, etc. These constituent parts may actually run as separate
87     JSBSim models themselves, but the responsibility for initializing them and
88     for retrieving their force and moment contributions falls to FGAircraft.<br>
89     When an aircraft model is loaded the config file is parsed and for each of the
90     sections of the config file (propulsion, flight control, etc.) the
91     corresponding "ReadXXX()" method is called. From within this method the 
92     "Load()" method of that system is called (e.g. LoadFCS).
93     @author Jon S. Berndt
94     @version $Id$
95     @see
96      <ol><li>Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
97            Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420  Naval Postgraduate
98            School, January 1994</li>
99      <li>D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
100      JSC 12960, July 1977</li>
101      <li>Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
102      NASA-Ames", NASA CR-2497, January 1975</li>
103      <li>Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
104      Wiley & Sons, 1979 ISBN 0-471-03032-5</li>
105      <li>Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
106      1982 ISBN 0-471-08936-2</li></ol>
107 */
108
109 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110 CLASS DECLARATION
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
112
113 class FGAircraft : public FGModel {
114   enum {eL=1, eM, eN};
115   enum {eX=1, eY, eZ};
116   enum {eP=1, eQ, eR};
117   enum {ePhi=1, eTht, ePsi};
118
119 public:
120   /** Constructor
121       @param Executive a pointer to the parent executive object */
122   FGAircraft(FGFDMExec *Executive);
123   
124   /// Destructor
125   ~FGAircraft();
126
127   /** Runs the Aircraft model; called by the Executive
128       @see JSBSim.cpp documentation
129       @return false if no error */
130   bool Run(void);
131   
132   /** Loads the aircraft.
133       The executive calls this method to load the aircraft into JSBSim.
134       @param apath path to the aircraft files (e.g. "aircraft/X15/")
135       @param epath path to engine files (e.g. "engine/")
136       @param acname name of aircraft (e.g. "X15")
137       @return true if succesful */
138   bool LoadAircraft(string apath, string epath, string acname);
139   
140   /** Gets the aircraft name
141       @return the name of the aircraft as a string type */
142   inline string GetAircraftName(void) { return AircraftName; }
143   
144   /** Gets the gear status
145       @return true if gear is not deployed */
146   inline bool GetGearUp(void) { return GearUp; }
147   /** Gets the number of gear units defined for the aircraft
148       @return number of gear units defined */
149   inline int GetNumGearUnits(void) { return lGear.size(); }
150   /** Gets a gear instance
151       @param gear index of gear instance
152       @return a pointer to the FGLGear instance of the gear unit requested */
153   inline FGLGear* GetGearUnit(int gear) { return &(lGear[gear]); }
154   /// Gets the wing area
155   inline float GetWingArea(void) { return WingArea; }
156   /// Gets the wing span
157   inline float GetWingSpan(void) { return WingSpan; }
158   /// Gets the average wing chord
159   inline float Getcbar(void) { return cbar; }
160   inline float GetWeight(void) { return Weight; }
161   inline float GetMass(void) { return Mass; }
162   inline FGColumnVector GetMoments(void) { return vMoments; }
163   inline FGColumnVector GetForces(void) { return vForces; }
164   inline FGColumnVector GetAeroBodyForces(void) { return vAeroBodyForces; }
165   inline float GetAeroBodyForces(int axis) { return vAeroBodyForces(axis); }
166   inline FGColumnVector GetvFs(void) { return vFs; }
167   inline float GetvFs(int axis) { return vFs(axis); }
168   inline FGColumnVector GetvLastFs(void) { return vLastFs; }
169   inline float GetvLastFs(int axis) { return vLastFs(axis); }
170   inline float GetIxx(void) { return Ixx; }
171   inline float GetIyy(void) { return Iyy; }
172   inline float GetIzz(void) { return Izz; }
173   inline float GetIxz(void) { return Ixz; }
174   inline FGColumnVector GetXYZcg(void) { return vXYZcg; }
175   inline FGColumnVector GetXYZrp(void) { return vXYZrp; }
176   inline FGColumnVector GetXYZep(void) { return vXYZep; }
177   inline float GetXYZcg(int idx) { return vXYZcg(idx); }
178   inline float GetXYZrp(int idx) { return vXYZrp(idx); }
179   inline float GetXYZep(int idx) { return vXYZep(idx); }
180   inline float GetNlf(void) { return nlf; }
181   inline float GetAlphaCLMax(void) { return alphaclmax; }
182   inline float GetAlphaCLMin(void) { return alphaclmin; }
183
184   inline void SetGearUp(bool tt) { GearUp = tt; }
185   inline void SetAlphaCLMax(float tt) { alphaclmax=tt; }
186   inline void SetAlphaCLMin(float tt) { alphaclmin=tt; }
187
188   inline FGCoefficient* GetCoeff(int axis, int idx) { return Coeff[axis][idx]; }
189   string GetCoefficientStrings(void);
190   string GetCoefficientValues(void);
191   string GetGroundReactionStrings(void);
192   string GetGroundReactionValues(void);
193
194   float GetLoD(void);
195
196   /// Subsystem types for specifying which will be output in the FDM data logging
197   enum  SubSystems {
198     /** Subsystem: Simulation (= 1)          */ ssSimulation      = 1,
199     /** Subsystem: Aerosurfaces (= 2)        */ ssAerosurfaces    = 2,
200     /** Subsystem: Body rates (= 4)          */ ssRates           = 4,
201     /** Subsystem: Velocities (= 8)          */ ssVelocities      = 8,
202     /** Subsystem: Forces (= 16)             */ ssForces          = 16,
203     /** Subsystem: Moments (= 32)            */ ssMoments         = 32,
204     /** Subsystem: Atmosphere (= 64)         */ ssAtmosphere      = 64,
205     /** Subsystem: Mass Properties (= 128)   */ ssMassProps       = 128,
206     /** Subsystem: Coefficients (= 256)      */ ssCoefficients    = 256,
207     /** Subsystem: Position (= 512)          */ ssPosition        = 512,
208     /** Subsystem: Ground Reactions (= 1024) */ ssGroundReactions = 1024,
209     /** Subsystem: FCS (= 2048)              */ ssFCS             = 2048,
210     /** Subsystem: Propulsion (= 4096)       */ ssPropulsion      = 4096
211   } subsystems;
212
213 private:
214   void GetState(void);
215   void FMAero(void);
216   void FMGear(void);
217   void FMMass(void);
218   void FMProp(void);
219   void MassChange(void);
220   FGColumnVector vMoments;
221   FGColumnVector vForces;
222   FGColumnVector vFs;
223   FGColumnVector vLastFs;
224   FGColumnVector vXYZrp;
225   FGColumnVector vbaseXYZcg;
226   FGColumnVector vXYZcg;
227   FGColumnVector vXYZep;
228   FGColumnVector vEuler;
229   FGColumnVector vXYZtank;
230   FGColumnVector vDXYZcg;
231   FGColumnVector vAeroBodyForces;
232   float baseIxx, baseIyy, baseIzz, baseIxz, EmptyMass, Mass;
233   float Ixx, Iyy, Izz, Ixz;
234   float alpha, beta;
235   float WingArea, WingSpan, cbar;
236   float Weight, EmptyWeight;
237   float nlf,alphaclmax,alphaclmin;
238   float dt;
239   string CFGVersion;
240   string AircraftName;
241
242   typedef map<string,int> AxisIndex;
243   AxisIndex AxisIdx;
244
245   typedef vector<FGCoefficient*> CoeffArray;
246
247   CoeffArray* Coeff;
248
249   void DisplayCoeffFactors(vector <eParam> multipliers);
250
251   bool GearUp;
252
253   string Axis[6];
254   vector <FGLGear> lGear;
255
256   string AircraftPath;
257   string EnginePath;
258   void ReadMetrics(FGConfigFile*);
259   void ReadPropulsion(FGConfigFile*);
260   void ReadFlightControls(FGConfigFile*);
261   void ReadAerodynamics(FGConfigFile*);
262   void ReadUndercarriage(FGConfigFile*);
263   void ReadPrologue(FGConfigFile*);
264   void ReadOutput(FGConfigFile*);
265   void Debug(void);
266 };
267
268 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 #endif
270