1 /*******************************************************************************
7 ------------- Copyright (C) 2000 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.
26 #ifndef _LARCSIMIC_HXX
27 #define _LARCSIMIC_HXX
29 /*******************************************************************************
31 *******************************************************************************/
33 #include <FDM/LaRCsim/ls_constants.h>
34 #include <FDM/LaRCsim/ls_types.h>
36 /*******************************************************************************
38 *******************************************************************************/
40 #define KTS_TO_FPS 1.6889
41 #define M_TO_FT 3.2808399
42 #define DEFAULT_AGL_ALT 3.758099
43 #define DEFAULT_PITCH_ON_GROUND 0.0074002
45 typedef enum lsspeedset { lssetvt, lssetvc, lssetve, lssetmach, lssetuvw, lssetned };
46 typedef enum lsaltset { lssetasl, lssetagl };
55 void SetVcalibratedKtsIC(SCALAR tt);
56 void SetMachIC(SCALAR tt);
58 void SetVtrueFpsIC(SCALAR tt);
60 void SetVequivalentKtsIC(SCALAR tt);
62 void SetUBodyFpsIC(SCALAR tt);
63 void SetVBodyFpsIC(SCALAR tt);
64 void SetWBodyFpsIC(SCALAR tt);
66 void SetVnorthFpsIC(SCALAR tt);
67 void SetVeastFpsIC(SCALAR tt);
68 void SetVdownFpsIC(SCALAR tt);
70 void SetVNorthAirmassFpsIC(SCALAR tt);
71 void SetVEastAirmassFpsIC(SCALAR tt);
72 void SetVDownAirmassFpsIC(SCALAR tt);
74 void SetAltitudeFtIC(SCALAR tt);
75 void SetAltitudeAGLFtIC(SCALAR tt);
77 //"vertical" flight path, recalculate theta
78 inline void SetFlightPathAngleDegIC(SCALAR tt) { SetFlightPathAngleRadIC(tt*DEG_TO_RAD); }
79 void SetFlightPathAngleRadIC(SCALAR tt);
82 void SetClimbRateFpmIC(SCALAR tt);
83 void SetClimbRateFpsIC(SCALAR tt);
85 //use currently stored gamma, recalcualte theta
86 inline void SetAlphaDegIC(SCALAR tt) { alpha=tt*DEG_TO_RAD; getTheta(); }
87 inline void SetAlphaRadIC(SCALAR tt) { alpha=tt; getTheta(); }
89 //use currently stored gamma, recalcualte alpha
90 inline void SetPitchAngleDegIC(SCALAR tt) { SetPitchAngleRadIC(tt*DEG_TO_RAD); }
91 void SetPitchAngleRadIC(SCALAR tt);
93 inline void SetBetaDegIC(SCALAR tt) { beta=tt*DEG_TO_RAD; getTheta();}
94 inline void SetBetaRadIC(SCALAR tt) { beta=tt; getTheta(); }
96 inline void SetRollAngleDegIC(SCALAR tt) { phi=tt*DEG_TO_RAD; getTheta(); }
97 inline void SetRollAngleRadIC(SCALAR tt) { phi=tt; getTheta(); }
99 inline void SetHeadingDegIC(SCALAR tt) { psi=tt*DEG_TO_RAD; }
100 inline void SetHeadingRadIC(SCALAR tt) { psi=tt; }
102 inline void SetLatitudeGDDegIC(SCALAR tt) { SetLatitudeGDRadIC(tt*DEG_TO_RAD); }
103 void SetLatitudeGDRadIC(SCALAR tt);
105 inline void SetLongitudeDegIC(SCALAR tt) { longitude=tt*DEG_TO_RAD; }
106 inline void SetLongitudeRadIC(SCALAR tt) { longitude=tt; }
108 void SetRunwayAltitudeFtIC(SCALAR tt);
110 inline SCALAR GetVcalibratedKtsIC(void) { return sqrt(density_ratio*vt*vt)*V_TO_KNOTS; }
111 inline SCALAR GetVequivalentKtsIC(void) { return sqrt(density_ratio)*vt*V_TO_KNOTS; }
112 inline SCALAR GetVtrueKtsIC(void) { return vt*V_TO_KNOTS; }
113 inline SCALAR GetVtrueFpsIC(void) { return vt; }
114 inline SCALAR GetMachIC(void) { return vt/soundspeed; }
116 inline SCALAR GetAltitudeFtIC(void) { return altitude; }
117 inline SCALAR GetAltitudeAGLFtIC(void) { return alt_agl; }
119 inline SCALAR GetRunwayAltitudeFtIC(void) { return runway_altitude; }
121 inline SCALAR GetFlightPathAngleDegIC(void) { return gamma*RAD_TO_DEG; }
122 inline SCALAR GetFlightPathAngleRadIC(void) { return gamma; }
124 inline SCALAR GetClimbRateFpmIC(void) { return hdot*60; }
125 inline SCALAR GetClimbRateFpsIC(void) { return hdot; }
127 inline SCALAR GetAlphaDegIC(void) { return alpha*RAD_TO_DEG; }
128 inline SCALAR GetAlphaRadIC(void) { return alpha; }
130 inline SCALAR GetPitchAngleDegIC(void) { return theta*RAD_TO_DEG; }
131 inline SCALAR GetPitchAngleRadIC(void) { return theta; }
134 inline SCALAR GetBetaDegIC(void) { return beta*RAD_TO_DEG; }
135 inline SCALAR GetBetaRadIC(void) { return beta*RAD_TO_DEG; }
137 inline SCALAR GetRollAngleDegIC(void) { return phi*RAD_TO_DEG; }
138 inline SCALAR GetRollAngleRadIC(void) { return phi; }
140 inline SCALAR GetHeadingDegIC(void) { return psi*RAD_TO_DEG; }
141 inline SCALAR GetHeadingRadIC(void) { return psi; }
143 inline SCALAR GetLatitudeGDDegIC(void) { return latitude_gd*RAD_TO_DEG; }
144 inline SCALAR GetLatitudeGDRadIC(void) { return latitude_gd; }
146 inline SCALAR GetLongitudeDegIC(void) { return longitude*RAD_TO_DEG; }
147 inline SCALAR GetLongitudeRadIC(void) { return longitude; }
149 inline SCALAR GetUBodyFpsIC(void) { return vt*cos(alpha)*cos(beta); }
150 inline SCALAR GetVBodyFpsIC(void) { return vt*sin(beta); }
151 inline SCALAR GetWBodyFpsIC(void) { return vt*sin(alpha)*cos(beta); }
153 inline SCALAR GetVnorthFpsIC(void) { calcNEDfromVt();return vnorth; }
154 inline SCALAR GetVeastFpsIC(void) { calcNEDfromVt();return veast; }
155 inline SCALAR GetVdownFpsIC(void) { calcNEDfromVt();return vdown; }
157 inline SCALAR GetVnorthAirmassFpsIC(void) { return vnorthwind; }
158 inline SCALAR GetVeastAirmassFpsIC(void) { return veastwind; }
159 inline SCALAR GetVdownAirmassFpsIC(void) { return vdownwind; }
161 inline SCALAR GetThetaRadIC(void) { return theta; }
162 inline SCALAR GetPhiRadIC(void) { return phi; }
163 inline SCALAR GetPsiRadIC(void) { return psi; }
168 SCALAR vt,vtg,vw,vc,ve;
169 SCALAR alpha,beta,gamma,theta,phi,psi;
171 SCALAR altitude,runway_altitude,hdot,alt_agl,sea_level_radius;
172 SCALAR latitude_gd,latitude_gc,longitude;
174 SCALAR vnorth,veast,vdown;
175 SCALAR vnorthwind, veastwind, vdownwind;
176 SCALAR p,T,soundspeed,density_ratio,rho;
178 SCALAR xlo, xhi,xmin,xmax;
180 typedef SCALAR (LaRCsimIC::*fp)(SCALAR x);
183 lsspeedset lastSpeedSet;
187 void calcVtfromNED(void);
188 void calcNEDfromVt(void);
189 void calcSpeeds(void);
194 SCALAR GammaEqOfTheta(SCALAR tt);
195 SCALAR GammaEqOfAlpha(SCALAR tt);
196 void get_atmosphere(void);
199 bool findInterval(SCALAR x,SCALAR guess);
200 bool solve(SCALAR *y, SCALAR x);