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$"
65 typedef enum { setvt, setvc, setve, setmach, setuvw, setned, setvg } speedset;
66 typedef enum { setwned, setwmd, setwhc } windset;
68 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
80 /** Takes a set of initial conditions and provide a kinematically consistent set
81 of body axis velocity components, euler angles, and altitude. This class
82 does not attempt to trim the model i.e. the sim will most likely start in a
83 very dynamic state (unless, of course, you have chosen your IC's wisely)
84 even after setting it up with this class.
88 With a valid object of FGFDMExec and an aircraft model loaded
89 FGInitialCondition fgic=new FGInitialCondition(FDMExec);
90 fgic->SetVcalibratedKtsIC()
91 fgic->SetAltitudeFtIC();
95 //to directly into Run
96 FDMExec->GetState()->Initialize(fgic)
100 //or to loop the sim w/o integrating
105 Since vc, ve, vt, and mach all represent speed, the remaining
106 three are recalculated each time one of them is set (using the
107 current altitude). The most recent speed set is remembered so
108 that if and when altitude is reset, the last set speed is used
109 to recalculate the remaining three. Setting any of the body
110 components forces a recalculation of vt and vt then becomes the
111 most recent speed set.
113 Alpha,Gamma, and Theta:
115 This class assumes that it will be used to set up the sim for a
116 steady, zero pitch rate condition. Since any two of those angles
117 specifies the third gamma (flight path angle) is favored when setting
118 alpha and theta and alpha is favored when setting gamma. i.e.
120 set alpha : recalculate theta using gamma as currently set
121 set theta : recalculate alpha using gamma as currently set
122 set gamma : recalculate theta using alpha as currently set
124 The idea being that gamma is most interesting to pilots (since it
125 is indicative of climb rate).
127 Setting climb rate is, for the purpose of this discussion,
128 considered equivalent to setting gamma.
129 @author Anthony K. Peden
131 @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGInitialCondition.h?rev=HEAD&content-type=text/vnd.viewcvs-markup">
133 @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGInitialCondition.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">
137 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
141 class FGInitialCondition : public FGJSBBase
145 FGInitialCondition(FGFDMExec *fdmex);
147 ~FGInitialCondition();
149 void SetVcalibratedKtsIC(double tt);
150 void SetVequivalentKtsIC(double tt);
151 inline void SetVtrueKtsIC(double tt) { SetVtrueFpsIC(tt*ktstofps); }
152 inline void SetVgroundKtsIC(double tt) { SetVgroundFpsIC(tt*ktstofps); }
153 void SetMachIC(double tt);
155 inline void SetAlphaDegIC(double tt) { SetAlphaRadIC(tt*degtorad); }
156 inline void SetBetaDegIC(double tt) { SetBetaRadIC(tt*degtorad);}
158 inline void SetPitchAngleDegIC(double tt) { SetPitchAngleRadIC(tt*degtorad); }
159 inline void SetRollAngleDegIC(double tt) { SetRollAngleRadIC(tt*degtorad);}
160 inline void SetTrueHeadingDegIC(double tt){ SetTrueHeadingRadIC(tt*degtorad); }
162 void SetClimbRateFpmIC(double tt);
163 inline void SetFlightPathAngleDegIC(double tt) { SetFlightPathAngleRadIC(tt*degtorad); }
165 void SetAltitudeFtIC(double tt);
166 void SetAltitudeAGLFtIC(double tt);
168 void SetSeaLevelRadiusFtIC(double tt);
169 void SetTerrainAltitudeFtIC(double tt);
171 inline void SetLatitudeDegIC(double tt) { latitude=tt*degtorad; }
172 inline void SetLongitudeDegIC(double tt) { longitude=tt*degtorad; }
175 inline double GetVcalibratedKtsIC(void) const { return vc*fpstokts; }
176 inline double GetVequivalentKtsIC(void) const { return ve*fpstokts; }
177 inline double GetVgroundKtsIC(void) const { return vg*fpstokts; }
178 inline double GetVtrueKtsIC(void) const { return vt*fpstokts; }
179 inline double GetMachIC(void) const { return mach; }
181 inline double GetClimbRateFpmIC(void) const { return hdot*60; }
182 inline double GetFlightPathAngleDegIC(void)const { return gamma*radtodeg; }
184 inline double GetAlphaDegIC(void) const { return alpha*radtodeg; }
185 inline double GetBetaDegIC(void) const { return beta*radtodeg; }
187 inline double GetPitchAngleDegIC(void) const { return theta*radtodeg; }
188 inline double GetRollAngleDegIC(void) const { return phi*radtodeg; }
189 inline double GetHeadingDegIC(void) const { return psi*radtodeg; }
191 inline double GetLatitudeDegIC(void) const { return latitude*radtodeg; }
192 inline double GetLongitudeDegIC(void) const { return longitude*radtodeg; }
194 inline double GetAltitudeFtIC(void) const { return altitude; }
195 inline double GetAltitudeAGLFtIC(void) const { return altitude - terrain_altitude; }
197 inline double GetSeaLevelRadiusFtIC(void) const { return sea_level_radius; }
198 inline double GetTerrainAltitudeFtIC(void) const { return terrain_altitude; }
200 void SetVgroundFpsIC(double tt);
201 void SetVtrueFpsIC(double tt);
202 void SetUBodyFpsIC(double tt);
203 void SetVBodyFpsIC(double tt);
204 void SetWBodyFpsIC(double tt);
205 void SetVnorthFpsIC(double tt);
206 void SetVeastFpsIC(double tt);
207 void SetVdownFpsIC(double tt);
209 void SetWindNEDFpsIC(double wN, double wE, double wD);
211 void SetWindMagKtsIC(double mag);
212 void SetWindDirDegIC(double dir);
214 void SetHeadWindKtsIC(double head);
215 void SetCrossWindKtsIC(double cross);// positive from left
217 void SetWindDownKtsIC(double wD);
219 void SetClimbRateFpsIC(double tt);
220 inline double GetVgroundFpsIC(void) const { return vg; }
221 inline double GetVtrueFpsIC(void) const { return vt; }
222 inline double GetWindUFpsIC(void) const { return uw; }
223 inline double GetWindVFpsIC(void) const { return vw; }
224 inline double GetWindWFpsIC(void) const { return ww; }
225 inline double GetWindNFpsIC(void) const { return wnorth; }
226 inline double GetWindEFpsIC(void) const { return weast; }
227 inline double GetWindDFpsIC(void) const { return wdown; }
228 inline double GetWindFpsIC(void) const { return sqrt(wnorth*wnorth + weast*weast); }
229 double GetWindDirDegIC(void);
230 inline double GetClimbRateFpsIC(void) const { return hdot; }
231 double GetUBodyFpsIC(void);
232 double GetVBodyFpsIC(void);
233 double GetWBodyFpsIC(void);
234 void SetFlightPathAngleRadIC(double tt);
235 void SetAlphaRadIC(double tt);
236 void SetPitchAngleRadIC(double tt);
237 void SetBetaRadIC(double tt);
238 void SetRollAngleRadIC(double tt);
239 void SetTrueHeadingRadIC(double tt);
240 inline void SetLatitudeRadIC(double tt) { latitude=tt; }
241 inline void SetLongitudeRadIC(double tt) { longitude=tt; }
242 inline double GetFlightPathAngleRadIC(void) const { return gamma; }
243 inline double GetAlphaRadIC(void) const { return alpha; }
244 inline double GetPitchAngleRadIC(void) const { return theta; }
245 inline double GetBetaRadIC(void) const { return beta; }
246 inline double GetRollAngleRadIC(void) const { return phi; }
247 inline double GetHeadingRadIC(void) const { return psi; }
248 inline double GetLatitudeRadIC(void) const { return latitude; }
249 inline double GetLongitudeRadIC(void) const { return longitude; }
250 inline double GetThetaRadIC(void) const { return theta; }
251 inline double GetPhiRadIC(void) const { return phi; }
252 inline double GetPsiRadIC(void) const { return psi; }
254 inline speedset GetSpeedSet(void) { return lastSpeedSet; }
255 inline windset GetWindSet(void) { return lastWindSet; }
257 bool Load(string rstname, bool useStoredPath = true );
266 double altitude,hdot;
267 double latitude,longitude;
270 double vnorth,veast,vdown;
271 double wnorth,weast,wdown;
272 double whead, wcross, wdir, wmag;
273 double sea_level_radius;
274 double terrain_altitude;
275 double radius_to_vehicle;
277 double alpha, beta, theta, phi, psi, gamma;
278 double salpha,sbeta,stheta,sphi,spsi,sgamma;
279 double calpha,cbeta,ctheta,cphi,cpsi,cgamma;
281 double xlo, xhi,xmin,xmax;
283 typedef double (FGInitialCondition::*fp)(double x);
286 speedset lastSpeedSet;
290 FGPropertyManager *PropertyManager;
294 bool getMachFromVcas(double *Mach,double vcas);
296 double GammaEqOfTheta(double Theta);
297 double GammaEqOfAlpha(double Alpha);
298 double calcVcas(double Mach);
299 void calcUVWfromNED(void);
300 void calcWindUVW(void);
302 bool findInterval(double x,double guess);
303 bool solve(double *y, double x);
304 void Debug(int from);