]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGInitialCondition.cpp
Updates to help work the kinks out of JSBsim.
[flightgear.git] / src / FDM / JSBSim / FGInitialCondition.cpp
1 /*******************************************************************************
2
3  Header:       FGInitialCondition.cpp
4  Author:       Tony Peden
5  Date started: 7/1/99
6
7  ------------- Copyright (C) 1999  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
27  HISTORY
28 --------------------------------------------------------------------------------
29 7/1/99   TP   Created
30
31
32 FUNCTIONAL DESCRIPTION
33 --------------------------------------------------------------------------------
34
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.
40
41 CAVEAT: This class makes use of alpha=theta-gamma. This means that setting
42         any of the three with this class is only valid for steady state
43         (all accels zero) and zero pitch rate.  One example where this
44         would produce invalid results is setting up for a trim in a pull-up
45         or pushover (both have nonzero pitch rate).  Maybe someday...
46
47 ********************************************************************************
48 INCLUDES
49 *******************************************************************************/
50
51 #include "FGInitialCondition.h"
52 #include "FGFDMExec.h"
53 #include "FGState.h"
54 #include "FGAtmosphere.h"
55 #include "FGFCS.h"
56 #include "FGAircraft.h"
57 #include "FGTranslation.h"
58 #include "FGRotation.h"
59 #include "FGPosition.h"
60 #include "FGAuxiliary.h"
61 #include "FGOutput.h"
62 #include "FGDefs.h"
63
64
65 FGInitialCondition::FGInitialCondition(FGFDMExec *fdmex)
66 {
67   vt=vc=0;
68   mach=0;
69   alpha=beta=gamma=0;
70   theta=phi=psi=0;
71   altitude=hdot=0;
72   latitude=longitude=0;
73   
74   atm=fdmex->GetAtmosphere();
75 }
76
77
78 FGInitialCondition::~FGInitialCondition(void) {};
79
80
81 void FGInitialCondition::SetVcalibratedKtsIC(float tt)
82 {
83   vc=tt*KTSTOFPS;
84   cout << "ic.vc: " << vc << endl;
85   cout << "ic.rhosl: " << atm->GetDensity(0) << endl;
86   cout << "ic.rho: "   << atm->GetDensity(altitude) << endl;
87   vt=sqrt(atm->GetDensity(0)/atm->GetDensity(altitude)*vc*vc);
88   cout << "ic.vt: "   << vt << endl;
89   //mach=vt*sqrt(SHRATIO*Reng*atm->GetTemperature(altitude));
90 }
91
92
93 void FGInitialCondition::SetVtrueKtsIC(float tt)
94 {
95   vt=tt*KTSTOFPS;
96   //vc=sqrt(atm->GetDensity(altitude)/atm->GetDensity(0)*vt*vt);
97   //mach=vt*sqrt(SHRATIO*Reng*atm->GetTemperature(altitude));
98 }
99
100
101 void FGInitialCondition::SetMachIC(float tt)
102 {
103   mach=tt;
104   vt=mach*sqrt(SHRATIO*Reng*atm->GetTemperature(altitude));
105   //vc=sqrt(atm->GetDensity(altitude)/atm->GetDensity(0)*vt*vt);
106 }
107
108
109 void FGInitialCondition::SetAltitudeFtIC(float tt)
110 {
111   altitude=tt;
112   //mach=vt/sqrt(SHRATIO*Reng*atm->GetTemperature(altitude));
113   //vc=sqrt(atm->GetDensity(altitude)/atm->GetDensity(0)*vt*vt);
114 }
115
116
117 void FGInitialCondition::SetFlightPathAngleDegIC(float tt)
118 {
119   gamma=tt*DEGTORAD;
120   theta=alpha+gamma;
121 }
122
123
124 void FGInitialCondition::SetAlphaDegIC(float tt)
125 {
126   alpha=tt*DEGTORAD;
127   theta=alpha+gamma;
128 }
129
130
131 void FGInitialCondition::SetBetaDegIC(float tt)
132 {
133   beta=tt*DEGTORAD;
134 }
135
136
137 void FGInitialCondition::SetRollAngleDegIC(float tt)
138 {
139   phi=tt*DEGTORAD;
140 }
141
142
143 void FGInitialCondition::SetPitchAngleDegIC(float tt)
144 {
145   theta=tt*DEGTORAD;
146   alpha=theta-gamma;
147 }
148
149
150 void FGInitialCondition::SetHeadingDegIC(float tt)
151 {
152   psi=tt*DEGTORAD;
153 }
154
155
156 void FGInitialCondition::SetLatitudeDegIC(float tt)
157 {
158   latitude=tt*DEGTORAD;
159 }
160
161
162 void FGInitialCondition::SetLongitudeDegIC(float tt)
163 {
164   longitude=tt*DEGTORAD;
165 }
166
167
168 float FGInitialCondition::GetUBodyFpsIC(void)
169 {
170   return vt*cos(alpha)*cos(beta);
171 }
172
173
174 float FGInitialCondition::GetVBodyFpsIC(void)
175 {
176   return vt*sin(beta);
177 }
178
179
180 float FGInitialCondition::GetWBodyFpsIC(void)
181 {
182   return vt*sin(alpha)*cos(beta);
183 }
184
185
186 float FGInitialCondition::GetThetaRadIC(void)
187 {
188   return theta;
189 }
190
191
192 float FGInitialCondition::GetPhiRadIC(void)
193 {
194   return phi;
195 }
196
197
198 float FGInitialCondition::GetPsiRadIC(void)
199 {
200   return psi;
201 }
202
203
204 float FGInitialCondition::GetLatitudeRadIC(void)
205 {
206   return latitude;
207 }
208
209
210 float FGInitialCondition::GetLongitudeRadIC(void)
211 {
212   return longitude;
213 }
214
215
216 float FGInitialCondition::GetAltitudeFtIC(void)
217 {
218   return altitude;
219 }
220