]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGInitialCondition.h
Updated to match changes in radiostack.[ch]xx
[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     @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGInitialCondition.h?rev=HEAD&content-type=text/vnd.viewcvs-markup">
130          Header File </a>
131     @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGInitialCondition.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">
132          Source File </a>
133 */
134
135 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 CLASS DECLARATION
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
138
139 class FGInitialCondition : public FGJSBBase
140 {
141 public:
142   /// Constructor
143   FGInitialCondition(FGFDMExec *fdmex);
144   /// Destructor
145   ~FGInitialCondition();
146
147   void SetVcalibratedKtsIC(double tt);
148   void SetVequivalentKtsIC(double tt);
149   inline void SetVtrueKtsIC(double tt)   { SetVtrueFpsIC(tt*ktstofps);   }
150   inline void SetVgroundKtsIC(double tt) { SetVgroundFpsIC(tt*ktstofps); }
151   void SetMachIC(double tt);
152   
153   inline void SetAlphaDegIC(double tt)      { SetAlphaRadIC(tt*degtorad); }
154   inline void SetBetaDegIC(double tt)       { SetBetaRadIC(tt*degtorad);}
155   
156   inline void SetPitchAngleDegIC(double tt) { SetPitchAngleRadIC(tt*degtorad); }
157   inline void SetRollAngleDegIC(double tt)  { SetRollAngleRadIC(tt*degtorad);}
158   inline void SetTrueHeadingDegIC(double tt){ SetTrueHeadingRadIC(tt*degtorad); }
159   
160   void SetClimbRateFpmIC(double tt);
161   inline void SetFlightPathAngleDegIC(double tt) { SetFlightPathAngleRadIC(tt*degtorad); }
162
163   void SetAltitudeFtIC(double tt);
164   void SetAltitudeAGLFtIC(double tt);
165   
166   void SetSeaLevelRadiusFtIC(double tt);
167   void SetTerrainAltitudeFtIC(double tt);
168
169   inline void SetLatitudeDegIC(double tt)  { latitude=tt*degtorad; }
170   inline void SetLongitudeDegIC(double tt) { longitude=tt*degtorad; }
171
172   
173   inline double GetVcalibratedKtsIC(void) const { return vc*fpstokts; }
174   inline double GetVequivalentKtsIC(void) const { return ve*fpstokts; }
175   inline double GetVgroundKtsIC(void) const { return vg*fpstokts; }
176   inline double GetVtrueKtsIC(void) const { return vt*fpstokts; }
177   inline double GetMachIC(void) const { return mach; }
178   
179   inline double GetClimbRateFpmIC(void) const { return hdot*60; }
180   inline double GetFlightPathAngleDegIC(void)const  { return gamma*radtodeg; }
181   
182   inline double GetAlphaDegIC(void) const { return alpha*radtodeg; }
183   inline double GetBetaDegIC(void) const  { return beta*radtodeg; }
184   
185   inline double GetPitchAngleDegIC(void) const { return theta*radtodeg; }
186   inline double GetRollAngleDegIC(void) const { return phi*radtodeg; }
187   inline double GetHeadingDegIC(void) const { return psi*radtodeg; }
188
189   inline double GetLatitudeDegIC(void) const { return latitude*radtodeg; }
190   inline double GetLongitudeDegIC(void) const { return longitude*radtodeg; }
191   
192   inline double GetAltitudeFtIC(void) const { return altitude; }
193   inline double GetAltitudeAGLFtIC(void) const { return altitude - terrain_altitude; }
194   
195   inline double GetSeaLevelRadiusFtIC(void) const { return sea_level_radius; }
196   inline double GetTerrainAltitudeFtIC(void) const { return terrain_altitude; }
197
198   void SetVgroundFpsIC(double tt);
199   void SetVtrueFpsIC(double tt);
200   void SetUBodyFpsIC(double tt);
201   void SetVBodyFpsIC(double tt);
202   void SetWBodyFpsIC(double tt);
203   void SetVnorthFpsIC(double tt);
204   void SetVeastFpsIC(double tt);
205   void SetVdownFpsIC(double tt);
206   
207   void SetWindNEDFpsIC(double wN, double wE, double wD);
208  
209   void SetWindMagKtsIC(double mag);
210   void SetWindDirDegIC(double dir);
211  
212   void SetHeadWindKtsIC(double head);
213   void SetCrossWindKtsIC(double cross);// positive from left
214  
215   void SetWindDownKtsIC(double wD);                                          
216   
217   void SetClimbRateFpsIC(double tt);
218   inline double GetVgroundFpsIC(void) const  { return vg; }
219   inline double GetVtrueFpsIC(void) const { return vt; }
220   inline double GetWindUFpsIC(void) const { return uw; }
221   inline double GetWindVFpsIC(void) const { return vw; }
222   inline double GetWindWFpsIC(void) const { return ww; }
223   inline double GetWindNFpsIC(void) const { return wnorth; }
224   inline double GetWindEFpsIC(void) const { return weast; }
225   inline double GetWindDFpsIC(void) const { return wdown; }
226   inline double GetWindFpsIC(void)  const { return sqrt(wnorth*wnorth + weast*weast); }
227   double GetWindDirDegIC(void); 
228   inline double GetClimbRateFpsIC(void) const { return hdot; }
229   double GetUBodyFpsIC(void);
230   double GetVBodyFpsIC(void);
231   double GetWBodyFpsIC(void);
232   void SetFlightPathAngleRadIC(double tt);
233   void SetAlphaRadIC(double tt);
234   void SetPitchAngleRadIC(double tt);
235   void SetBetaRadIC(double tt);
236   void SetRollAngleRadIC(double tt);
237   void SetTrueHeadingRadIC(double tt);
238   inline void SetLatitudeRadIC(double tt) { latitude=tt; }
239   inline void SetLongitudeRadIC(double tt) { longitude=tt; }
240   inline double GetFlightPathAngleRadIC(void) const { return gamma; }
241   inline double GetAlphaRadIC(void) const      { return alpha; }
242   inline double GetPitchAngleRadIC(void) const { return theta; }
243   inline double GetBetaRadIC(void) const       { return beta; }
244   inline double GetRollAngleRadIC(void) const  { return phi; }
245   inline double GetHeadingRadIC(void) const   { return psi; }
246   inline double GetLatitudeRadIC(void) const { return latitude; }
247   inline double GetLongitudeRadIC(void) const { return longitude; }
248   inline double GetThetaRadIC(void) const { return theta; }
249   inline double GetPhiRadIC(void)  const  { return phi; }
250   inline double GetPsiRadIC(void) const   { return psi; }
251
252   inline speedset GetSpeedSet(void) { return lastSpeedSet; }
253   inline windset GetWindSet(void) { return lastWindSet; }
254   
255   bool Load(string acpath, string acname, string rstname);
256   
257   void bind(void);
258   void unbind(void);
259
260   
261 private:
262   double vt,vc,ve,vg;
263   double mach;
264   double altitude,hdot;
265   double latitude,longitude;
266   double u,v,w;
267   double uw,vw,ww;
268   double vnorth,veast,vdown;
269   double wnorth,weast,wdown;
270   double whead, wcross, wdir, wmag;
271   double sea_level_radius;
272   double terrain_altitude;
273   double radius_to_vehicle;
274
275   double  alpha, beta, theta, phi, psi, gamma;
276   double salpha,sbeta,stheta,sphi,spsi,sgamma;
277   double calpha,cbeta,ctheta,cphi,cpsi,cgamma;
278
279   double xlo, xhi,xmin,xmax;
280
281   typedef double (FGInitialCondition::*fp)(double x);
282   fp sfunc;
283
284   speedset lastSpeedSet;
285   windset lastWindSet;
286
287   FGFDMExec *fdmex;
288   FGPropertyManager *PropertyManager;
289
290   bool getAlpha(void);
291   bool getTheta(void);
292   bool getMachFromVcas(double *Mach,double vcas);
293
294   double GammaEqOfTheta(double Theta);
295   double GammaEqOfAlpha(double Alpha);
296   double calcVcas(double Mach);
297   void calcUVWfromNED(void);
298   void calcWindUVW(void);
299
300   bool findInterval(double x,double guess);
301   bool solve(double *y, double x);
302   void Debug(int from);
303 };
304
305 #endif
306