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.
28 --------------------------------------------------------------------------------
32 FUNCTIONAL DESCRIPTION
33 --------------------------------------------------------------------------------
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.
41 ********************************************************************************
43 *******************************************************************************/
45 #ifndef FGINITIALCONDITION_H
46 #define FGINITIALCONDITION_H
48 /*******************************************************************************
50 *******************************************************************************/
52 #include "FGFDMExec.h"
53 #include "FGAtmosphere.h"
56 #define ID_INITIALCONDITION "$Id$"
58 /*******************************************************************************
60 *******************************************************************************/
62 typedef enum { setvt, setvc, setve, setmach, setuvw, setned, setvg } speedset;
64 #define jsbFPSTOKTS 0.5924838
65 #define jsbKTSTOFPS 1.6878099
69 With a valid object of FGFDMExec and an aircraft model loaded
70 FGInitialCondition fgic=new FGInitialCondition(FDMExec);
71 fgic->SetVcalibratedKtsIC()
72 fgic->SetAltitudeFtIC();
76 //to directly into Run
77 FDMExec->GetState()->Initialize(fgic)
81 //or to loop the sim w/o integrating
85 Since vc, ve, vt, and mach all represent speed, the remaining
86 three are recalculated each time one of them is set (using the
87 current altitude). The most recent speed set is remembered so
88 that if and when altitude is reset, the last set speed is used
89 to recalculate the remaining three. Setting any of the body
90 components forces a recalculation of vt and vt then becomes the
91 most recent speed set.
93 Alpha,Gamma, and Theta:
94 This class assumes that it will be used to set up the sim for a
95 steady, zero pitch rate condition. Since any two of those angles
96 specifies the third gamma (flight path angle) is favored when setting
97 alpha and theta and alpha is favored when setting gamma. i.e.
98 set alpha : recalculate theta using gamma as currently set
99 set theta : recalculate alpha using gamma as currently set
100 set gamma : recalculate theta using alpha as currently set
102 The idea being that gamma is most interesting to pilots (since it
103 is indicative of climb rate).
105 Setting climb rate is, for the purpose of this discussion,
106 considered equivalent to setting gamma.
109 class FGInitialCondition {
112 FGInitialCondition(FGFDMExec *fdmex);
113 ~FGInitialCondition();
115 void SetVcalibratedKtsIC(float tt);
116 void SetVequivalentKtsIC(float tt);
117 inline void SetVtrueKtsIC(float tt) { SetVtrueFpsIC(tt*jsbKTSTOFPS); }
118 inline void SetVgroundKtsIC(float tt) { SetVgroundFpsIC(tt*jsbKTSTOFPS); }
119 void SetMachIC(float tt);
121 inline void SetAlphaDegIC(float tt) { SetAlphaRadIC(tt*DEGTORAD); }
122 inline void SetBetaDegIC(float tt) { SetBetaRadIC(tt*DEGTORAD);}
124 inline void SetPitchAngleDegIC(float tt) { SetPitchAngleRadIC(tt*DEGTORAD); }
125 inline void SetRollAngleDegIC(float tt) { SetRollAngleRadIC(tt*DEGTORAD);}
126 inline void SetTrueHeadingDegIC(float tt){ SetTrueHeadingRadIC(tt*DEGTORAD); }
128 void SetClimbRateFpmIC(float tt);
129 inline void SetFlightPathAngleDegIC(float tt) { SetFlightPathAngleRadIC(tt*DEGTORAD); }
131 void SetAltitudeFtIC(float tt);
132 void SetAltitudeAGLFtIC(float tt);
134 void SetSeaLevelRadiusFtIC(double tt);
135 void SetTerrainAltitudeFtIC(double tt);
137 inline void SetLatitudeDegIC(float tt) { latitude=tt*DEGTORAD; }
138 inline void SetLongitudeDegIC(float tt) { longitude=tt*DEGTORAD; }
141 inline float GetVcalibratedKtsIC(void) { return vc*jsbFPSTOKTS; }
142 inline float GetVequivalentKtsIC(void) { return ve*jsbFPSTOKTS; }
143 inline float GetVgroundKtsIC(void) { return vg*jsbFPSTOKTS; }
144 inline float GetVtrueKtsIC(void) { return vt*jsbFPSTOKTS; }
145 inline float GetMachIC(void) { return mach; }
147 inline float GetClimbRateFpmIC(void) { return hdot*60; }
148 inline float GetFlightPathAngleDegIC(void) { return gamma*RADTODEG; }
150 inline float GetAlphaDegIC(void) { return alpha*RADTODEG; }
151 inline float GetBetaDegIC(void) { return beta*RADTODEG; }
153 inline float GetPitchAngleDegIC(void) { return theta*RADTODEG; }
154 inline float GetRollAngleDegIC(void) { return phi*RADTODEG; }
155 inline float GetHeadingDegIC(void) { return psi*RADTODEG; }
157 inline float GetLatitudeDegIC(void) { return latitude*RADTODEG; }
158 inline float GetLongitudeDegIC(void) { return longitude*RADTODEG; }
160 inline float GetAltitudeFtIC(void) { return altitude; }
161 inline float GetAltitudeAGLFtIC(void) { return altitude - terrain_altitude; }
163 inline float GetSeaLevelRadiusFtIC(void) { return sea_level_radius; }
164 inline float GetTerrainAltitudeFtIC(void) { return terrain_altitude; }
166 void SetVgroundFpsIC(float tt);
167 void SetVtrueFpsIC(float tt);
168 void SetUBodyFpsIC(float tt);
169 void SetVBodyFpsIC(float tt);
170 void SetWBodyFpsIC(float tt);
171 void SetVnorthFpsIC(float tt);
172 void SetVeastFpsIC(float tt);
173 void SetVdownFpsIC(float tt);
174 void SetWindNEDFpsIC(float wN, float wE, float wD);
175 void SetClimbRateFpsIC(float tt);
176 inline float GetVgroundFpsIC(void) { return vg; }
177 inline float GetVtrueFpsIC(void) { return vt; }
178 inline float GetWindUFpsIC(void) { return uw; }
179 inline float GetWindVFpsIC(void) { return vw; }
180 inline float GetWindWFpsIC(void) { return ww; }
181 inline float GetWindNFpsIC(void) { return wnorth; }
182 inline float GetWindEFpsIC(void) { return weast; }
183 inline float GetWindDFpsIC(void) { return wdown; }
184 inline float GetClimbRateFpsIC(void) { return hdot; }
185 float GetUBodyFpsIC(void);
186 float GetVBodyFpsIC(void);
187 float GetWBodyFpsIC(void);
188 void SetFlightPathAngleRadIC(float tt);
189 void SetAlphaRadIC(float tt);
190 void SetPitchAngleRadIC(float tt);
191 void SetBetaRadIC(float tt);
192 void SetRollAngleRadIC(float tt);
193 void SetTrueHeadingRadIC(float tt);
194 inline void SetLatitudeRadIC(float tt) { latitude=tt; }
195 inline void SetLongitudeRadIC(float tt) { longitude=tt; }
196 inline float GetFlightPathAngleRadIC(void) { return gamma; }
197 inline float GetAlphaRadIC(void) { return alpha; }
198 inline float GetPitchAngleRadIC(void) { return theta; }
199 inline float GetBetaRadIC(void) { return beta; }
200 inline float GetRollAngleRadIC(void) { return phi; }
201 inline float GetHeadingRadIC(void) { return psi; }
202 inline float GetLatitudeRadIC(void) { return latitude; }
203 inline float GetLongitudeRadIC(void) { return longitude; }
204 inline float GetThetaRadIC(void) { return theta; }
205 inline float GetPhiRadIC(void) { return phi; }
206 inline float GetPsiRadIC(void) { return psi; }
208 inline speedset GetSpeedSet(void) { return lastSpeedSet; }
214 float latitude,longitude;
217 float vnorth,veast,vdown;
218 float wnorth,weast,wdown;
219 double sea_level_radius;
220 double terrain_altitude;
221 double radius_to_vehicle;
223 float alpha, beta, theta, phi, psi, gamma;
224 float salpha,sbeta,stheta,sphi,spsi,sgamma;
225 float calpha,cbeta,ctheta,cphi,cpsi,cgamma;
227 float xlo, xhi,xmin,xmax;
229 typedef float (FGInitialCondition::*fp)(float x);
232 speedset lastSpeedSet;
238 bool getMachFromVcas(float *Mach,float vcas);
240 float GammaEqOfTheta(float Theta);
241 float GammaEqOfAlpha(float Alpha);
242 float calcVcas(float Mach);
243 void calcUVWfromNED(void);
244 void calcWindUVW(void);
246 bool findInterval(float x,float guess);
247 bool solve(float *y, float x);