]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGInitialCondition.h
Friday the 13th JSBSim update ... :-0 !!!
[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 "$Header"
57
58 /*******************************************************************************
59 CLASS DECLARATION
60 *******************************************************************************/
61
62 typedef enum { setvt, setvc, setve, setmach } speedset;
63
64
65 /* USAGE NOTES
66    With a valid object of FGFDMExec and an aircraft model loaded
67    FGInitialCondition fgic=new FGInitialCondition(FDMExec);
68    fgic->SetVcalibratedKtsIC()
69    fgic->SetAltitudeFtIC();
70    .
71    .
72    .
73    //to directly into Run
74    FDMExec->GetState()->Initialize(fgic)
75    delete fgic;
76    FDMExec->Run()
77    
78    //or to loop the sim w/o integrating
79    FDMExec->RunIC(fgic)
80    
81    
82    
83    Speed:
84          Since vc, ve, vt, and mach all represent speed, the remaining
85          three are recalculated each time one of them is set (using the
86          current altitude).  The most recent speed set is remembered so 
87          that if and when altitude is reset, the last set speed is used 
88          to recalculate the remaining three. Setting any of the body 
89          components forces a recalculation of vt and vt then becomes the
90          most recent speed set.
91    
92    Alpha,Gamma, and Theta:
93      This class assumes that it will be used to set up the sim for a
94          steady, zero pitch rate condition. Since any two of those angles 
95    specifies the third gamma (flight path angle) is favored when setting
96    alpha and theta and alpha is favored when setting gamma. i.e.
97         set alpha : recalculate theta using gamma as currently set
98                   set theta : recalculate alpha using gamma as currently set
99                   set gamma : recalculate theta using alpha as currently set
100  
101          The idea being that gamma is most interesting to pilots (since it 
102          is indicative of climb rate). 
103          
104          Setting climb rate is, for the purpose of this discussion, 
105          considered equivalent to setting gamma.
106  
107 */
108
109 class FGInitialCondition {
110 public:
111
112   FGInitialCondition(FGFDMExec *fdmex);
113   ~FGInitialCondition(void);
114
115   void SetVcalibratedKtsIC(float tt);
116   void SetVequivalentKtsIC(float tt);
117   void SetVtrueKtsIC(float tt);
118   void SetMachIC(float tt);
119
120   void SetUBodyFpsIC(float tt);
121   void SetVBodyFpsIC(float tt);
122   void SetWBodyFpsIC(float tt);
123   
124   void SetVnorthFpsIC(float tt);
125   void SetVeastFpsIC(float tt);
126   void SetVdownFpsIC(float tt);
127   
128   void SetAltitudeFtIC(float tt);
129   void SetAltitudeAGLFtIC(float tt);
130
131   //"vertical" flight path, recalculate theta
132   inline void SetFlightPathAngleDegIC(float tt) { SetFlightPathAngleRadIC(tt*DEGTORAD); }
133   void SetFlightPathAngleRadIC(float tt);
134   //set speed first
135   void SetClimbRateFpmIC(float tt);
136   void SetClimbRateFpsIC(float tt);
137   //use currently stored gamma, recalcualte theta
138   inline void SetAlphaDegIC(float tt)      { alpha=tt*DEGTORAD; getTheta(); }
139   inline void SetAlphaRadIC(float tt)      { alpha=tt; getTheta(); }
140   //use currently stored gamma, recalcualte alpha
141   inline void SetPitchAngleDegIC(float tt) { theta=tt*DEGTORAD; getAlpha(); }
142   inline void SetPitchAngleRadIC(float tt) { theta=tt; getAlpha(); }
143
144   inline void SetBetaDegIC(float tt)       { beta=tt*DEGTORAD; getTheta();}
145   inline void SetBetaRadIC(float tt)       { beta=tt; getTheta(); }
146   
147   inline void SetRollAngleDegIC(float tt) { phi=tt*DEGTORAD; getTheta(); }
148   inline void SetRollAngleRadIC(float tt) { phi=tt; getTheta(); }
149
150   inline void SetHeadingDegIC(float tt)   { psi=tt*DEGTORAD; }
151   inline void SetHeadingRadIC(float tt)   { psi=tt; }
152
153   inline void SetLatitudeDegIC(float tt)  { latitude=tt*DEGTORAD; }
154   inline void SetLatitudeRadIC(float tt)  { latitude=tt; }
155
156   inline void SetLongitudeDegIC(float tt) { longitude=tt*DEGTORAD; }
157   inline void SetLongitudeRadIC(float tt) { longitude=tt; }
158
159   inline float GetVcalibratedKtsIC(void) { return vc*FPSTOKTS; }
160   inline float GetVequivalentKtsIC(void) { return ve*FPSTOKTS; }
161   inline float GetVtrueKtsIC(void) { return vt*FPSTOKTS; }
162   inline float GetVtrueFpsIC(void) { return vt; }
163   inline float GetMachIC(void) { return mach; }
164
165   inline float GetAltitudeFtIC(void) { return altitude; }
166
167   inline float GetFlightPathAngleDegIC(void) { return gamma*RADTODEG; }
168   inline float GetFlightPathAngleRadIC(void) { return gamma; }
169
170   inline float GetClimbRateFpmIC(void) { return hdot*60; }
171   inline float GetClimbRateFpsIC(void) { return hdot; }
172
173   inline float GetAlphaDegIC(void)      { return alpha*RADTODEG; }
174   inline float GetAlphaRadIC(void)      { return alpha; }
175
176   inline float GetPitchAngleDegIC(void) { return theta*RADTODEG; }
177   inline float GetPitchAngleRadIC(void) { return theta; }
178
179
180   inline float GetBetaDegIC(void)       { return beta*RADTODEG; }
181   inline float GetBetaRadIC(void)       { return beta*RADTODEG; }
182
183   inline float GetRollAngleDegIC(void) { return phi*RADTODEG; }
184   inline float GetRollAngleRadIC(void) { return phi; }
185
186   inline float GetHeadingDegIC(void)   { return psi*RADTODEG; }
187   inline float GetHeadingRadIC(void)   { return psi; }
188
189   inline float GetLatitudeDegIC(void)  { return latitude*RADTODEG; }
190   inline float GetLatitudeRadIC(void) { return latitude; }
191
192   inline float GetLongitudeDegIC(void) { return longitude*RADTODEG; }
193   inline float GetLongitudeRadIC(void) { return longitude; }
194
195   inline float GetUBodyFpsIC(void) { return vt*cos(alpha)*cos(beta); }
196   inline float GetVBodyFpsIC(void) { return vt*sin(beta); }
197   inline float GetWBodyFpsIC(void) { return vt*sin(alpha)*cos(beta); }
198
199   inline float GetThetaRadIC(void) { return theta; }
200   inline float GetPhiRadIC(void)   { return phi; }
201   inline float GetPsiRadIC(void)   { return psi; }
202
203
204
205 private:
206   float vt,vc,ve;
207   float alpha,beta,gamma,theta,phi,psi;
208   float mach;
209   float altitude,hdot;
210   float latitude,longitude;
211   float u,v,w;
212   float vnorth,veast,vdown;
213   
214   float xlo, xhi,xmin,xmax;
215   
216   typedef float (FGInitialCondition::*fp)(float x);
217   fp sfunc;
218
219   speedset lastSpeedSet;
220
221   FGFDMExec *fdmex;
222   
223   
224   bool getAlpha(void);
225   bool getTheta(void);
226   bool getMachFromVcas(float *Mach,float vcas);
227   
228   float GammaEqOfTheta(float Theta);
229   float GammaEqOfAlpha(float Alpha);
230   float calcVcas(float Mach);
231   void calcUVWfromNED(void);
232   
233   bool findInterval(float x,float guess);
234   bool solve(float *y, float x);
235 };
236
237 #endif