]> git.mxchange.org Git - flightgear.git/blob - src/FDM/LaRCsimIC.hxx
Moved FDM/LaRCsim.[ch]xx to FDM/LaRCsim/LaRCsim.[ch]xx
[flightgear.git] / src / FDM / LaRCsimIC.hxx
1 /*******************************************************************************
2  
3  Header:       LaRCsimIC.hxx
4  Author:       Tony Peden
5  Date started: 10/9/00
6  
7  ------------- Copyright (C) 2000 Anthony K. Peden (apeden@earthlink.net) -------------
8  
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
12  version.
13  
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
17  details.
18  
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.
22  
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25 */ 
26 #ifndef _LARCSIMIC_HXX
27 #define _LARCSIMIC_HXX
28
29 /*******************************************************************************
30 INCLUDES
31 *******************************************************************************/
32
33 #include <plib/sg.h>
34
35 #include <FDM/LaRCsim/ls_constants.h>
36 #include <FDM/LaRCsim/ls_types.h>
37
38 /*******************************************************************************
39 CLASS DECLARATION
40 *******************************************************************************/
41
42 #define KTS_TO_FPS 1.6889
43 #define M_TO_FT 3.2808399
44 #define DEFAULT_AGL_ALT 3.758099
45 #define DEFAULT_PITCH_ON_GROUND 0.0074002
46
47 enum lsspeedset { lssetvt, lssetvc, lssetve, lssetmach, lssetuvw, lssetned };
48 enum lsaltset { lssetasl, lssetagl };
49
50
51 class LaRCsimIC {
52 public:
53
54   LaRCsimIC(void);
55   ~LaRCsimIC(void);
56
57   void SetVcalibratedKtsIC(SCALAR tt);
58   void SetMachIC(SCALAR tt);
59   
60   void SetVtrueFpsIC(SCALAR tt);
61   
62   void SetVequivalentKtsIC(SCALAR tt);
63
64   void SetUVWFpsIC(SCALAR vu, SCALAR vv, SCALAR vw);
65  
66   void SetVNEDFpsIC(SCALAR north, SCALAR east, SCALAR down);
67   
68   void SetVNEDAirmassFpsIC(SCALAR north, SCALAR east, SCALAR down );
69   
70   void SetAltitudeFtIC(SCALAR tt);
71   void SetAltitudeAGLFtIC(SCALAR tt);
72   
73   //"vertical" flight path, recalculate theta
74   inline void SetFlightPathAngleDegIC(SCALAR tt) { SetFlightPathAngleRadIC(tt*SGD_DEGREES_TO_RADIANS); }
75   void SetFlightPathAngleRadIC(SCALAR tt);
76   
77   //set speed first
78   void SetClimbRateFpmIC(SCALAR tt);
79   void SetClimbRateFpsIC(SCALAR tt);
80   
81   //use currently stored gamma, recalcualte theta
82   inline void SetAlphaDegIC(SCALAR tt)      { alpha=tt*SGD_DEGREES_TO_RADIANS; getTheta(); }
83   inline void SetAlphaRadIC(SCALAR tt)      { alpha=tt; getTheta(); }
84   
85   //use currently stored gamma, recalcualte alpha
86   inline void SetPitchAngleDegIC(SCALAR tt) { SetPitchAngleRadIC(tt*SGD_DEGREES_TO_RADIANS); }
87          void SetPitchAngleRadIC(SCALAR tt);
88
89   inline void SetBetaDegIC(SCALAR tt)       { beta=tt*SGD_DEGREES_TO_RADIANS; getTheta();}
90   inline void SetBetaRadIC(SCALAR tt)       { beta=tt; getTheta(); }
91   
92   inline void SetRollAngleDegIC(SCALAR tt) { phi=tt*SGD_DEGREES_TO_RADIANS; getTheta(); }
93   inline void SetRollAngleRadIC(SCALAR tt) { phi=tt; getTheta(); }
94
95   inline void SetHeadingDegIC(SCALAR tt)   { psi=tt*SGD_DEGREES_TO_RADIANS; }
96   inline void SetHeadingRadIC(SCALAR tt)   { psi=tt; }
97
98   inline void SetLatitudeGDDegIC(SCALAR tt)  { SetLatitudeGDRadIC(tt*SGD_DEGREES_TO_RADIANS); }
99          void SetLatitudeGDRadIC(SCALAR tt);
100
101   inline void SetLongitudeDegIC(SCALAR tt) { longitude=tt*SGD_DEGREES_TO_RADIANS; }
102   inline void SetLongitudeRadIC(SCALAR tt) { longitude=tt; }
103   
104   void SetRunwayAltitudeFtIC(SCALAR tt);
105
106   inline SCALAR GetVcalibratedKtsIC(void) { return sqrt(density_ratio*vt*vt)*V_TO_KNOTS; }
107   inline SCALAR GetVequivalentKtsIC(void) { return sqrt(density_ratio)*vt*V_TO_KNOTS; }
108   inline SCALAR GetVtrueKtsIC(void) { return vt*V_TO_KNOTS; }
109   inline SCALAR GetVtrueFpsIC(void) { return vt; }
110   inline SCALAR GetMachIC(void) { return vt/soundspeed; }
111
112   inline SCALAR GetAltitudeFtIC(void)    { return altitude; }
113   inline SCALAR GetAltitudeAGLFtIC(void) { return alt_agl; }
114   
115   inline SCALAR GetRunwayAltitudeFtIC(void) { return runway_altitude; }
116
117   inline SCALAR GetFlightPathAngleDegIC(void) { return gamma*SGD_RADIANS_TO_DEGREES; }
118   inline SCALAR GetFlightPathAngleRadIC(void) { return gamma; }
119
120   inline SCALAR GetClimbRateFpmIC(void) { return hdot*60; }
121   inline SCALAR GetClimbRateFpsIC(void) { return hdot; }
122
123   inline SCALAR GetAlphaDegIC(void)      { return alpha*SGD_RADIANS_TO_DEGREES; }
124   inline SCALAR GetAlphaRadIC(void)      { return alpha; }
125
126   inline SCALAR GetPitchAngleDegIC(void) { return theta*SGD_RADIANS_TO_DEGREES; }
127   inline SCALAR GetPitchAngleRadIC(void) { return theta; }
128
129
130   inline SCALAR GetBetaDegIC(void)       { return beta*SGD_RADIANS_TO_DEGREES; }
131   inline SCALAR GetBetaRadIC(void)       { return beta*SGD_RADIANS_TO_DEGREES; }
132
133   inline SCALAR GetRollAngleDegIC(void) { return phi*SGD_RADIANS_TO_DEGREES; }
134   inline SCALAR GetRollAngleRadIC(void) { return phi; }
135
136   inline SCALAR GetHeadingDegIC(void)   { return psi*SGD_RADIANS_TO_DEGREES; }
137   inline SCALAR GetHeadingRadIC(void)   { return psi; }
138
139   inline SCALAR GetLatitudeGDDegIC(void)  { return latitude_gd*SGD_RADIANS_TO_DEGREES; }
140   inline SCALAR GetLatitudeGDRadIC(void) { return latitude_gd; }
141
142   inline SCALAR GetLongitudeDegIC(void) { return longitude*SGD_RADIANS_TO_DEGREES; }
143   inline SCALAR GetLongitudeRadIC(void) { return longitude; }
144
145   inline SCALAR GetUBodyFpsIC(void) { return vt*cos(alpha)*cos(beta); }
146   inline SCALAR GetVBodyFpsIC(void) { return vt*sin(beta); }
147   inline SCALAR GetWBodyFpsIC(void) { return vt*sin(alpha)*cos(beta); }
148   
149   inline SCALAR GetVnorthFpsIC(void) { calcNEDfromVt();return vnorth; }
150   inline SCALAR GetVeastFpsIC(void)  { calcNEDfromVt();return veast; }
151   inline SCALAR GetVdownFpsIC(void)  { calcNEDfromVt();return vdown; }
152   
153   inline SCALAR GetVnorthAirmassFpsIC(void) { return vnorthwind; }
154   inline SCALAR GetVeastAirmassFpsIC(void)  { return veastwind; }
155   inline SCALAR GetVdownAirmassFpsIC(void)  { return vdownwind; }
156   
157   inline SCALAR GetThetaRadIC(void) { return theta; }
158   inline SCALAR GetPhiRadIC(void)   { return phi; }
159   inline SCALAR GetPsiRadIC(void)   { return psi; }
160
161
162
163 private:
164   SCALAR vt,vtg,vw,vc,ve;
165   SCALAR alpha,beta,gamma,theta,phi,psi;
166   SCALAR mach;
167   SCALAR altitude,runway_altitude,hdot,alt_agl,sea_level_radius;
168   SCALAR latitude_gd,latitude_gc,longitude;
169   SCALAR u,v,w;
170   SCALAR vnorth,veast,vdown;
171   SCALAR vnorthwind, veastwind, vdownwind;
172   SCALAR p,T,soundspeed,density_ratio,rho;
173   
174   SCALAR xlo, xhi,xmin,xmax;
175   
176   typedef SCALAR (LaRCsimIC::*fp)(SCALAR x);
177   fp sfunc;
178
179   lsspeedset lastSpeedSet;
180   lsaltset lastAltSet;
181   
182   
183   void calcVtfromNED(void);
184   void calcNEDfromVt(void);
185   void calcSpeeds(void);
186   
187   
188   bool getAlpha(void);
189   bool getTheta(void);
190   SCALAR GammaEqOfTheta(SCALAR tt);
191   SCALAR GammaEqOfAlpha(SCALAR tt);
192   void get_atmosphere(void);
193   
194   
195   bool findInterval(SCALAR x,SCALAR guess);
196   bool solve(SCALAR *y, SCALAR x);
197 };
198
199 #endif