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