1 /*******************************************************************************
3 Header: FGInitialCondition.h
7 ------------- Copyright (C) 1999 Anthony K. Peden (apeden@earthlink.net) -------------
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
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
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.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
27 --------------------------------------------------------------------------------
30 FUNCTIONAL DESCRIPTION
31 --------------------------------------------------------------------------------
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.
39 ********************************************************************************
41 *******************************************************************************/
43 #ifndef FGINITIALCONDITION_H
44 #define FGINITIALCONDITION_H
46 /*******************************************************************************
48 *******************************************************************************/
50 #include "FGFDMExec.h"
51 #include "FGJSBBase.h"
52 #include "FGAtmosphere.h"
53 #include "FGMatrix33.h"
54 #include "FGColumnVector3.h"
55 #include "FGColumnVector4.h"
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 #define ID_INITIALCONDITION "$Id$"
63 typedef enum { setvt, setvc, setve, setmach, setuvw, setned, setvg } speedset;
64 typedef enum { setwned, setwmd, setwhc } windset;
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
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.
86 With a valid object of FGFDMExec and an aircraft model loaded
87 FGInitialCondition fgic=new FGInitialCondition(FDMExec);
88 fgic->SetVcalibratedKtsIC()
89 fgic->SetAltitudeFtIC();
93 //to directly into Run
94 FDMExec->GetState()->Initialize(fgic)
98 //or to loop the sim w/o integrating
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.
111 Alpha,Gamma, and Theta:
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.
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
122 The idea being that gamma is most interesting to pilots (since it
123 is indicative of climb rate).
125 Setting climb rate is, for the purpose of this discussion,
126 considered equivalent to setting gamma.
127 @author Anthony K. Peden
131 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
135 class FGInitialCondition : public FGJSBBase
139 FGInitialCondition(FGFDMExec *fdmex);
141 ~FGInitialCondition();
143 void SetVcalibratedKtsIC(double tt);
144 void SetVequivalentKtsIC(double tt);
145 inline void SetVtrueKtsIC(double tt) { SetVtrueFpsIC(tt*ktstofps); }
146 inline void SetVgroundKtsIC(double tt) { SetVgroundFpsIC(tt*ktstofps); }
147 void SetMachIC(double tt);
149 inline void SetAlphaDegIC(double tt) { SetAlphaRadIC(tt*degtorad); }
150 inline void SetBetaDegIC(double tt) { SetBetaRadIC(tt*degtorad);}
152 inline void SetPitchAngleDegIC(double tt) { SetPitchAngleRadIC(tt*degtorad); }
153 inline void SetRollAngleDegIC(double tt) { SetRollAngleRadIC(tt*degtorad);}
154 inline void SetTrueHeadingDegIC(double tt){ SetTrueHeadingRadIC(tt*degtorad); }
156 void SetClimbRateFpmIC(double tt);
157 inline void SetFlightPathAngleDegIC(double tt) { SetFlightPathAngleRadIC(tt*degtorad); }
159 void SetAltitudeFtIC(double tt);
160 void SetAltitudeAGLFtIC(double tt);
162 void SetSeaLevelRadiusFtIC(double tt);
163 void SetTerrainAltitudeFtIC(double tt);
165 inline void SetLatitudeDegIC(double tt) { latitude=tt*degtorad; }
166 inline void SetLongitudeDegIC(double tt) { longitude=tt*degtorad; }
169 inline double GetVcalibratedKtsIC(void) { return vc*fpstokts; }
170 inline double GetVequivalentKtsIC(void) { return ve*fpstokts; }
171 inline double GetVgroundKtsIC(void) { return vg*fpstokts; }
172 inline double GetVtrueKtsIC(void) { return vt*fpstokts; }
173 inline double GetMachIC(void) { return mach; }
175 inline double GetClimbRateFpmIC(void) { return hdot*60; }
176 inline double GetFlightPathAngleDegIC(void) { return gamma*radtodeg; }
178 inline double GetAlphaDegIC(void) { return alpha*radtodeg; }
179 inline double GetBetaDegIC(void) { return beta*radtodeg; }
181 inline double GetPitchAngleDegIC(void) { return theta*radtodeg; }
182 inline double GetRollAngleDegIC(void) { return phi*radtodeg; }
183 inline double GetHeadingDegIC(void) { return psi*radtodeg; }
185 inline double GetLatitudeDegIC(void) { return latitude*radtodeg; }
186 inline double GetLongitudeDegIC(void) { return longitude*radtodeg; }
188 inline double GetAltitudeFtIC(void) { return altitude; }
189 inline double GetAltitudeAGLFtIC(void) { return altitude - terrain_altitude; }
191 inline double GetSeaLevelRadiusFtIC(void) { return sea_level_radius; }
192 inline double GetTerrainAltitudeFtIC(void) { return terrain_altitude; }
194 void SetVgroundFpsIC(double tt);
195 void SetVtrueFpsIC(double tt);
196 void SetUBodyFpsIC(double tt);
197 void SetVBodyFpsIC(double tt);
198 void SetWBodyFpsIC(double tt);
199 void SetVnorthFpsIC(double tt);
200 void SetVeastFpsIC(double tt);
201 void SetVdownFpsIC(double tt);
203 void SetWindNEDFpsIC(double wN, double wE, double wD);
205 void SetWindMagKtsIC(double mag);
206 void SetWindDirDegIC(double dir);
208 void SetHeadWindKtsIC(double head);
209 void SetCrossWindKtsIC(double cross);// positive from left
211 void SetWindDownKtsIC(double wD);
213 void SetClimbRateFpsIC(double tt);
214 inline double GetVgroundFpsIC(void) { return vg; }
215 inline double GetVtrueFpsIC(void) { return vt; }
216 inline double GetWindUFpsIC(void) { return uw; }
217 inline double GetWindVFpsIC(void) { return vw; }
218 inline double GetWindWFpsIC(void) { return ww; }
219 inline double GetWindNFpsIC(void) { return wnorth; }
220 inline double GetWindEFpsIC(void) { return weast; }
221 inline double GetWindDFpsIC(void) { return wdown; }
222 inline double GetWindFpsIC(void) { return sqrt(wnorth*wnorth + weast*weast); }
223 double GetWindDirDegIC(void);
224 inline double GetClimbRateFpsIC(void) { return hdot; }
225 double GetUBodyFpsIC(void);
226 double GetVBodyFpsIC(void);
227 double GetWBodyFpsIC(void);
228 void SetFlightPathAngleRadIC(double tt);
229 void SetAlphaRadIC(double tt);
230 void SetPitchAngleRadIC(double tt);
231 void SetBetaRadIC(double tt);
232 void SetRollAngleRadIC(double tt);
233 void SetTrueHeadingRadIC(double tt);
234 inline void SetLatitudeRadIC(double tt) { latitude=tt; }
235 inline void SetLongitudeRadIC(double tt) { longitude=tt; }
236 inline double GetFlightPathAngleRadIC(void) { return gamma; }
237 inline double GetAlphaRadIC(void) { return alpha; }
238 inline double GetPitchAngleRadIC(void) { return theta; }
239 inline double GetBetaRadIC(void) { return beta; }
240 inline double GetRollAngleRadIC(void) { return phi; }
241 inline double GetHeadingRadIC(void) { return psi; }
242 inline double GetLatitudeRadIC(void) { return latitude; }
243 inline double GetLongitudeRadIC(void) { return longitude; }
244 inline double GetThetaRadIC(void) { return theta; }
245 inline double GetPhiRadIC(void) { return phi; }
246 inline double GetPsiRadIC(void) { return psi; }
248 inline speedset GetSpeedSet(void) { return lastSpeedSet; }
249 inline windset GetWindSet(void) { return lastWindSet; }
251 bool Load(string acpath, string acname, string rstname);
256 double altitude,hdot;
257 double latitude,longitude;
260 double vnorth,veast,vdown;
261 double wnorth,weast,wdown;
262 double whead, wcross, wdir, wmag;
263 double sea_level_radius;
264 double terrain_altitude;
265 double radius_to_vehicle;
267 double alpha, beta, theta, phi, psi, gamma;
268 double salpha,sbeta,stheta,sphi,spsi,sgamma;
269 double calpha,cbeta,ctheta,cphi,cpsi,cgamma;
271 double xlo, xhi,xmin,xmax;
273 typedef double (FGInitialCondition::*fp)(double x);
276 speedset lastSpeedSet;
283 bool getMachFromVcas(double *Mach,double vcas);
285 double GammaEqOfTheta(double Theta);
286 double GammaEqOfAlpha(double Alpha);
287 double calcVcas(double Mach);
288 void calcUVWfromNED(void);
289 void calcWindUVW(void);
291 bool findInterval(double x,double guess);
292 bool solve(double *y, double x);
293 void Debug(int from);