]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGInitialCondition.h
b) FDM - ada.cxx, ada.hxx have been updated with the faux, daux and iaux arrays that...
[flightgear.git] / src / FDM / JSBSim / FGInitialCondition.h
1 /*******************************************************************************
2  
3  Header:       FGInitialCondition.h
4  Author:       Tony Peden
5  Date started: 7/1/99
6  
7  ------------- Copyright (C) 1999  Anthony K. Peden (apeden@earthlink.net) -------------
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  
27  HISTORY
28 --------------------------------------------------------------------------------
29 7/1/99   TP   Created
30  
31  
32 FUNCTIONAL DESCRIPTION
33 --------------------------------------------------------------------------------
34  
35 The purpose of this class is to take a set of initial conditions and provide
36 a kinematically consistent set of body axis velocity components, euler
37 angles, and altitude.  This class does not attempt to trim the model i.e.
38 the sim will most likely start in a very dynamic state (unless, of course,
39 you have chosen your IC's wisely) even after setting it up with this class.
40  
41 ********************************************************************************
42 SENTRY
43 *******************************************************************************/
44
45 #ifndef FGINITIALCONDITION_H
46 #define FGINITIALCONDITION_H
47
48 /*******************************************************************************
49 INCLUDES
50 *******************************************************************************/
51
52 #include "FGFDMExec.h"
53 #include "FGAtmosphere.h"
54 #include "FGMatrix.h"
55
56 #define ID_INITIALCONDITION "$Id$"
57
58 /*******************************************************************************
59 CLASS DECLARATION
60 *******************************************************************************/
61
62 typedef enum { setvt, setvc, setve, setmach, setuvw, setned, setvg } speedset;
63
64 #define jsbFPSTOKTS 0.5924838
65 #define jsbKTSTOFPS 1.6878099
66
67
68 /* USAGE NOTES
69    With a valid object of FGFDMExec and an aircraft model loaded
70    FGInitialCondition fgic=new FGInitialCondition(FDMExec);
71    fgic->SetVcalibratedKtsIC()
72    fgic->SetAltitudeFtIC();
73    .
74    .
75    .
76    //to directly into Run
77    FDMExec->GetState()->Initialize(fgic)
78    delete fgic;
79    FDMExec->Run()
80    
81    //or to loop the sim w/o integrating
82    FDMExec->RunIC(fgic)
83    
84    Speed:
85          Since vc, ve, vt, and mach all represent speed, the remaining
86          three are recalculated each time one of them is set (using the
87          current altitude).  The most recent speed set is remembered so 
88          that if and when altitude is reset, the last set speed is used 
89          to recalculate the remaining three. Setting any of the body 
90          components forces a recalculation of vt and vt then becomes the
91          most recent speed set.
92    
93    Alpha,Gamma, and Theta:
94      This class assumes that it will be used to set up the sim for a
95          steady, zero pitch rate condition. Since any two of those angles 
96    specifies the third gamma (flight path angle) is favored when setting
97    alpha and theta and alpha is favored when setting gamma. i.e.
98         set alpha : recalculate theta using gamma as currently set
99                   set theta : recalculate alpha using gamma as currently set
100                   set gamma : recalculate theta using alpha as currently set
101  
102          The idea being that gamma is most interesting to pilots (since it 
103          is indicative of climb rate). 
104          
105          Setting climb rate is, for the purpose of this discussion, 
106          considered equivalent to setting gamma.
107  
108 */
109 class FGInitialCondition {
110 public:
111
112   FGInitialCondition(FGFDMExec *fdmex);
113   ~FGInitialCondition();
114
115   void SetVcalibratedKtsIC(float tt);
116   void SetVequivalentKtsIC(float tt);
117   inline void SetVtrueKtsIC(float tt)   { SetVtrueFpsIC(tt*jsbKTSTOFPS);   }
118   inline void SetVgroundKtsIC(float tt) { SetVgroundFpsIC(tt*jsbKTSTOFPS); }
119   void SetMachIC(float tt);
120   
121   inline void SetAlphaDegIC(float tt)      { SetAlphaRadIC(tt*DEGTORAD); }
122   inline void SetBetaDegIC(float tt)       { SetBetaRadIC(tt*DEGTORAD);}
123   
124   inline void SetPitchAngleDegIC(float tt) { SetPitchAngleRadIC(tt*DEGTORAD); }
125   inline void SetRollAngleDegIC(float tt)  { SetRollAngleRadIC(tt*DEGTORAD);}
126   inline void SetTrueHeadingDegIC(float tt){ SetTrueHeadingRadIC(tt*DEGTORAD); }
127   
128   void SetClimbRateFpmIC(float tt);
129   inline void SetFlightPathAngleDegIC(float tt) { SetFlightPathAngleRadIC(tt*DEGTORAD); }
130
131   void SetAltitudeFtIC(float tt);
132   void SetAltitudeAGLFtIC(float tt);
133   
134   void SetSeaLevelRadiusFtIC(double tt);
135   void SetTerrainAltitudeFtIC(double tt);
136
137   inline void SetLatitudeDegIC(float tt)  { latitude=tt*DEGTORAD; }
138   inline void SetLongitudeDegIC(float tt) { longitude=tt*DEGTORAD; }
139
140   
141   inline float GetVcalibratedKtsIC(void) { return vc*jsbFPSTOKTS; }
142   inline float GetVequivalentKtsIC(void) { return ve*jsbFPSTOKTS; }
143   inline float GetVgroundKtsIC(void) { return vg*jsbFPSTOKTS; }
144   inline float GetVtrueKtsIC(void) { return vt*jsbFPSTOKTS; }
145   inline float GetMachIC(void) { return mach; }
146   
147   inline float GetClimbRateFpmIC(void) { return hdot*60; }
148   inline float GetFlightPathAngleDegIC(void) { return gamma*RADTODEG; }
149   
150   inline float GetAlphaDegIC(void)      { return alpha*RADTODEG; }
151   inline float GetBetaDegIC(void)       { return beta*RADTODEG; }
152   
153   inline float GetPitchAngleDegIC(void) { return theta*RADTODEG; }
154   inline float GetRollAngleDegIC(void) { return phi*RADTODEG; }
155   inline float GetHeadingDegIC(void)   { return psi*RADTODEG; }
156
157   inline float GetLatitudeDegIC(void)  { return latitude*RADTODEG; }
158   inline float GetLongitudeDegIC(void) { return longitude*RADTODEG; }
159   
160   inline float GetAltitudeFtIC(void) { return altitude; }
161   inline float GetAltitudeAGLFtIC(void) { return altitude - terrain_altitude; }
162   
163   inline float GetSeaLevelRadiusFtIC(void)  { return sea_level_radius; }
164   inline float GetTerrainAltitudeFtIC(void) { return terrain_altitude; }
165
166   void SetVgroundFpsIC(float tt);
167   void SetVtrueFpsIC(float tt);
168   void SetUBodyFpsIC(float tt);
169   void SetVBodyFpsIC(float tt);
170   void SetWBodyFpsIC(float tt);
171   void SetVnorthFpsIC(float tt);
172   void SetVeastFpsIC(float tt);
173   void SetVdownFpsIC(float tt);
174   void SetWindNEDFpsIC(float wN, float wE, float wD);
175   void SetClimbRateFpsIC(float tt);
176   inline float GetVgroundFpsIC(void) { return vg; }
177   inline float GetVtrueFpsIC(void) { return vt; }
178   inline float GetWindUFpsIC(void) { return uw; }
179   inline float GetWindVFpsIC(void) { return vw; }
180   inline float GetWindWFpsIC(void) { return ww; }
181   inline float GetWindNFpsIC(void) { return wnorth; }
182   inline float GetWindEFpsIC(void) { return weast; }
183   inline float GetWindDFpsIC(void) { return wdown; }
184   inline float GetClimbRateFpsIC(void) { return hdot; }
185   float GetUBodyFpsIC(void);
186   float GetVBodyFpsIC(void);
187   float GetWBodyFpsIC(void);
188   void SetFlightPathAngleRadIC(float tt);
189   void SetAlphaRadIC(float tt);
190   void SetPitchAngleRadIC(float tt);
191   void SetBetaRadIC(float tt);
192   void SetRollAngleRadIC(float tt);
193   void SetTrueHeadingRadIC(float tt);
194   inline void SetLatitudeRadIC(float tt)  { latitude=tt; }
195   inline void SetLongitudeRadIC(float tt) { longitude=tt; }
196   inline float GetFlightPathAngleRadIC(void) { return gamma; }
197   inline float GetAlphaRadIC(void)      { return alpha; }
198   inline float GetPitchAngleRadIC(void) { return theta; }
199   inline float GetBetaRadIC(void)       { return beta; }
200   inline float GetRollAngleRadIC(void) { return phi; }
201   inline float GetHeadingRadIC(void)   { return psi; }
202   inline float GetLatitudeRadIC(void) { return latitude; }
203   inline float GetLongitudeRadIC(void) { return longitude; }
204   inline float GetThetaRadIC(void) { return theta; }
205   inline float GetPhiRadIC(void)   { return phi; }
206   inline float GetPsiRadIC(void)   { return psi; }
207
208   inline speedset GetSpeedSet(void) { return lastSpeedSet; }
209
210 private:
211   float vt,vc,ve,vg;
212   float mach;
213   float altitude,hdot;
214   float latitude,longitude;
215   float u,v,w;
216   float uw,vw,ww;
217   float vnorth,veast,vdown;
218   float wnorth,weast,wdown;
219   double sea_level_radius;
220   double terrain_altitude;
221   double radius_to_vehicle;
222
223   float  alpha, beta, theta, phi, psi, gamma;
224   float salpha,sbeta,stheta,sphi,spsi,sgamma;
225   float calpha,cbeta,ctheta,cphi,cpsi,cgamma;
226
227   float xlo, xhi,xmin,xmax;
228
229   typedef float (FGInitialCondition::*fp)(float x);
230   fp sfunc;
231
232   speedset lastSpeedSet;
233
234   FGFDMExec *fdmex;
235
236   bool getAlpha(void);
237   bool getTheta(void);
238   bool getMachFromVcas(float *Mach,float vcas);
239
240   float GammaEqOfTheta(float Theta);
241   float GammaEqOfAlpha(float Alpha);
242   float calcVcas(float Mach);
243   void calcUVWfromNED(void);
244   void calcWindUVW(void);
245
246   bool findInterval(float x,float guess);
247   bool solve(float *y, float x);
248   void Debug(void);
249 };
250
251 #endif
252