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 SetUVWFpsIC(SCALAR vu, SCALAR vv, SCALAR vw);
64 void SetVNEDFpsIC(SCALAR north, SCALAR east, SCALAR down);
66 void SetVNEDAirmassFpsIC(SCALAR north, SCALAR east, SCALAR down );
68 void SetAltitudeFtIC(SCALAR tt);
69 void SetAltitudeAGLFtIC(SCALAR tt);
71 //"vertical" flight path, recalculate theta
72 inline void SetFlightPathAngleDegIC(SCALAR tt) { SetFlightPathAngleRadIC(tt*DEG_TO_RAD); }
73 void SetFlightPathAngleRadIC(SCALAR tt);
76 void SetClimbRateFpmIC(SCALAR tt);
77 void SetClimbRateFpsIC(SCALAR tt);
79 //use currently stored gamma, recalcualte theta
80 inline void SetAlphaDegIC(SCALAR tt) { alpha=tt*DEG_TO_RAD; getTheta(); }
81 inline void SetAlphaRadIC(SCALAR tt) { alpha=tt; getTheta(); }
83 //use currently stored gamma, recalcualte alpha
84 inline void SetPitchAngleDegIC(SCALAR tt) { SetPitchAngleRadIC(tt*DEG_TO_RAD); }
85 void SetPitchAngleRadIC(SCALAR tt);
87 inline void SetBetaDegIC(SCALAR tt) { beta=tt*DEG_TO_RAD; getTheta();}
88 inline void SetBetaRadIC(SCALAR tt) { beta=tt; getTheta(); }
90 inline void SetRollAngleDegIC(SCALAR tt) { phi=tt*DEG_TO_RAD; getTheta(); }
91 inline void SetRollAngleRadIC(SCALAR tt) { phi=tt; getTheta(); }
93 inline void SetHeadingDegIC(SCALAR tt) { psi=tt*DEG_TO_RAD; }
94 inline void SetHeadingRadIC(SCALAR tt) { psi=tt; }
96 inline void SetLatitudeGDDegIC(SCALAR tt) { SetLatitudeGDRadIC(tt*DEG_TO_RAD); }
97 void SetLatitudeGDRadIC(SCALAR tt);
99 inline void SetLongitudeDegIC(SCALAR tt) { longitude=tt*DEG_TO_RAD; }
100 inline void SetLongitudeRadIC(SCALAR tt) { longitude=tt; }
102 void SetRunwayAltitudeFtIC(SCALAR tt);
104 inline SCALAR GetVcalibratedKtsIC(void) { return sqrt(density_ratio*vt*vt)*V_TO_KNOTS; }
105 inline SCALAR GetVequivalentKtsIC(void) { return sqrt(density_ratio)*vt*V_TO_KNOTS; }
106 inline SCALAR GetVtrueKtsIC(void) { return vt*V_TO_KNOTS; }
107 inline SCALAR GetVtrueFpsIC(void) { return vt; }
108 inline SCALAR GetMachIC(void) { return vt/soundspeed; }
110 inline SCALAR GetAltitudeFtIC(void) { return altitude; }
111 inline SCALAR GetAltitudeAGLFtIC(void) { return alt_agl; }
113 inline SCALAR GetRunwayAltitudeFtIC(void) { return runway_altitude; }
115 inline SCALAR GetFlightPathAngleDegIC(void) { return gamma*RAD_TO_DEG; }
116 inline SCALAR GetFlightPathAngleRadIC(void) { return gamma; }
118 inline SCALAR GetClimbRateFpmIC(void) { return hdot*60; }
119 inline SCALAR GetClimbRateFpsIC(void) { return hdot; }
121 inline SCALAR GetAlphaDegIC(void) { return alpha*RAD_TO_DEG; }
122 inline SCALAR GetAlphaRadIC(void) { return alpha; }
124 inline SCALAR GetPitchAngleDegIC(void) { return theta*RAD_TO_DEG; }
125 inline SCALAR GetPitchAngleRadIC(void) { return theta; }
128 inline SCALAR GetBetaDegIC(void) { return beta*RAD_TO_DEG; }
129 inline SCALAR GetBetaRadIC(void) { return beta*RAD_TO_DEG; }
131 inline SCALAR GetRollAngleDegIC(void) { return phi*RAD_TO_DEG; }
132 inline SCALAR GetRollAngleRadIC(void) { return phi; }
134 inline SCALAR GetHeadingDegIC(void) { return psi*RAD_TO_DEG; }
135 inline SCALAR GetHeadingRadIC(void) { return psi; }
137 inline SCALAR GetLatitudeGDDegIC(void) { return latitude_gd*RAD_TO_DEG; }
138 inline SCALAR GetLatitudeGDRadIC(void) { return latitude_gd; }
140 inline SCALAR GetLongitudeDegIC(void) { return longitude*RAD_TO_DEG; }
141 inline SCALAR GetLongitudeRadIC(void) { return longitude; }
143 inline SCALAR GetUBodyFpsIC(void) { return vt*cos(alpha)*cos(beta); }
144 inline SCALAR GetVBodyFpsIC(void) { return vt*sin(beta); }
145 inline SCALAR GetWBodyFpsIC(void) { return vt*sin(alpha)*cos(beta); }
147 inline SCALAR GetVnorthFpsIC(void) { calcNEDfromVt();return vnorth; }
148 inline SCALAR GetVeastFpsIC(void) { calcNEDfromVt();return veast; }
149 inline SCALAR GetVdownFpsIC(void) { calcNEDfromVt();return vdown; }
151 inline SCALAR GetVnorthAirmassFpsIC(void) { return vnorthwind; }
152 inline SCALAR GetVeastAirmassFpsIC(void) { return veastwind; }
153 inline SCALAR GetVdownAirmassFpsIC(void) { return vdownwind; }
155 inline SCALAR GetThetaRadIC(void) { return theta; }
156 inline SCALAR GetPhiRadIC(void) { return phi; }
157 inline SCALAR GetPsiRadIC(void) { return psi; }
162 SCALAR vt,vtg,vw,vc,ve;
163 SCALAR alpha,beta,gamma,theta,phi,psi;
165 SCALAR altitude,runway_altitude,hdot,alt_agl,sea_level_radius;
166 SCALAR latitude_gd,latitude_gc,longitude;
168 SCALAR vnorth,veast,vdown;
169 SCALAR vnorthwind, veastwind, vdownwind;
170 SCALAR p,T,soundspeed,density_ratio,rho;
172 SCALAR xlo, xhi,xmin,xmax;
174 typedef SCALAR (LaRCsimIC::*fp)(SCALAR x);
177 lsspeedset lastSpeedSet;
181 void calcVtfromNED(void);
182 void calcNEDfromVt(void);
183 void calcSpeeds(void);
188 SCALAR GammaEqOfTheta(SCALAR tt);
189 SCALAR GammaEqOfAlpha(SCALAR tt);
190 void get_atmosphere(void);
193 bool findInterval(SCALAR x,SCALAR guess);
194 bool solve(SCALAR *y, SCALAR x);