]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGTranslation.cpp
Adjust the turbine names for N1, N2 and EGT_degC to match those already specified...
[flightgear.git] / src / FDM / JSBSim / FGTranslation.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGTranslation.cpp
4  Author:       Jon Berndt
5  Date started: 12/02/98
6  Purpose:      Integrates the translational EOM
7  Called by:    FDMExec
8
9  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
10
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  details.
20
21  You should have received a copy of the GNU General Public License along with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA  02111-1307, USA.
24
25  Further information about the GNU General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This class integrates the translational EOM.
31
32 HISTORY
33 --------------------------------------------------------------------------------
34 12/02/98   JSB   Created
35  7/23/99   TP    Added data member and modified Run and PutState to calcuate
36                  Mach number
37
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 COMMENTS, REFERENCES,  and NOTES
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 [1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
42     Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420  Naval Postgraduate
43     School, January 1994
44 [2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
45     JSC 12960, July 1977
46 [3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
47     NASA-Ames", NASA CR-2497, January 1975
48 [4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
49     Wiley & Sons, 1979 ISBN 0-471-03032-5
50 [5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
51     1982 ISBN 0-471-08936-2
52
53   The order of rotations used in this class corresponds to a 3-2-1 sequence,
54   or Y-P-R, or Z-Y-X, if you prefer.
55
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 INCLUDES
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59
60 #include "FGTranslation.h"
61 #include "FGRotation.h"
62 #include "FGAtmosphere.h"
63 #include "FGState.h"
64 #include "FGFDMExec.h"
65 #include "FGFCS.h"
66 #include "FGMassBalance.h"
67 #include "FGAircraft.h"
68 #include "FGPosition.h"
69 #include "FGAuxiliary.h"
70 #include "FGOutput.h"
71 #include "FGPropertyManager.h"
72
73 namespace JSBSim {
74
75 static const char *IdSrc = "$Id$";
76 static const char *IdHdr = ID_TRANSLATION;
77
78 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 CLASS IMPLEMENTATION
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
81
82
83 FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex)
84 {
85   Name = "FGTranslation";
86   qbar = 0;
87   qbarUW = 0.0;
88   qbarUV = 0.0;
89   Vt = 0.0;
90   Mach = 0.0;
91   alpha = beta = 0.0;
92   adot = bdot = 0.0;
93
94   vUVWdot.InitMatrix();
95   vUVWdot_prev[0].InitMatrix();
96   vUVWdot_prev[1].InitMatrix();
97   vUVWdot_prev[2].InitMatrix();
98   vUVWdot_prev[3].InitMatrix();
99
100   bind();
101   Debug(0);
102 }
103
104 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105
106 FGTranslation::~FGTranslation(void)
107 {
108   unbind();
109   Debug(1);
110 }
111
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113
114 bool FGTranslation::Run(void)
115 {
116   if (!FGModel::Run()) {
117
118     mVel(1,1) =  0.0;
119     mVel(1,2) = -vUVW(eW);
120     mVel(1,3) =  vUVW(eV);
121     mVel(2,1) =  vUVW(eW);
122     mVel(2,2) =  0.0;
123     mVel(2,3) = -vUVW(eU);
124     mVel(3,1) = -vUVW(eV);
125     mVel(3,2) =  vUVW(eU);
126     mVel(3,3) =  0.0;
127
128     vUVWdot = mVel*Rotation->GetPQR() + Aircraft->GetBodyAccel();
129
130     vUVW += State->Integrate(FGState::TRAPZ, State->Getdt()*rate, vUVWdot, vUVWdot_prev);
131
132     vAeroUVW = vUVW + State->GetTl2b()*Atmosphere->GetWindNED();
133
134     Vt = vAeroUVW.Magnitude();
135     if ( Vt > 1) {
136       if (vAeroUVW(eW) != 0.0)
137         alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
138       if (vAeroUVW(eV) != 0.0)
139         beta = vAeroUVW(eU)*vAeroUVW(eU)+vAeroUVW(eW)*vAeroUVW(eW) > 0.0 ? atan2(vAeroUVW(eV),
140                sqrt(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW))) : 0.0;
141
142       // stolen, quite shamelessly, from LaRCsim
143       double mUW = (vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW));
144       double signU=1;
145       if (vAeroUVW(eU) != 0.0)
146         signU = vAeroUVW(eU)/fabs(vAeroUVW(eU));
147
148       if ( (mUW == 0.0) || (Vt == 0.0) ) {
149         adot = 0.0;
150         bdot = 0.0;
151       } else {
152         adot = (vAeroUVW(eU)*vAeroUVW(eW) - vAeroUVW(eW)*vUVWdot(eU))/mUW;
153         bdot = (signU*mUW*vUVWdot(eV) - vAeroUVW(eV)*(vAeroUVW(eU)*vUVWdot(eU)
154                 + vAeroUVW(eW)*vUVWdot(eW)))/(Vt*Vt*sqrt(mUW));
155       }
156     } else {
157       alpha = beta = adot = bdot = 0;
158     }
159
160     qbar = 0.5*Atmosphere->GetDensity()*Vt*Vt;
161     qbarUW = 0.5*Atmosphere->GetDensity()*(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW));
162     qbarUV = 0.5*Atmosphere->GetDensity()*(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eV)*vAeroUVW(eV));
163     Mach = Vt / State->Geta();
164     vMachUVW(eU) = vAeroUVW(eU) / State->Geta();
165     vMachUVW(eV) = vAeroUVW(eV) / State->Geta();
166     vMachUVW(eW) = vAeroUVW(eW) / State->Geta();
167
168     if (debug_lvl > 1) Debug(1);
169
170     return false;
171   } else {
172     return true;
173   }
174 }
175
176 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177
178 void FGTranslation::bind(void)
179 {
180   typedef double (FGTranslation::*PMF)(int) const;
181   PropertyManager->Tie("velocities/u-fps", this,1,
182                        (PMF)&FGTranslation::GetUVW /*,
183                        &FGTranslation::SetUVW,
184                        true */);
185   PropertyManager->Tie("velocities/v-fps", this,2,
186                        (PMF)&FGTranslation::GetUVW /*,
187                        &FGTranslation::SetUVW,
188                        true*/);
189   PropertyManager->Tie("velocities/w-fps", this,3,
190                        (PMF)&FGTranslation::GetUVW /*,
191                        &FGTranslation::SetUVW,
192                        true*/);
193   PropertyManager->Tie("accelerations/udot-fps", this,1,
194                        (PMF)&FGTranslation::GetUVWdot);
195   PropertyManager->Tie("accelerations/vdot-fps", this,2,
196                        (PMF)&FGTranslation::GetUVWdot);
197   PropertyManager->Tie("accelerations/wdot-fps", this,3,
198                        (PMF)&FGTranslation::GetUVWdot);
199   PropertyManager->Tie("velocities/u-aero-fps", this,1,
200                        (PMF)&FGTranslation::GetAeroUVW);
201   PropertyManager->Tie("velocities/v-aero-fps", this,2,
202                        (PMF)&FGTranslation::GetAeroUVW);
203   PropertyManager->Tie("velocities/w-aero-fps", this,3,
204                        (PMF)&FGTranslation::GetAeroUVW);
205   PropertyManager->Tie("aero/alpha-rad", this,
206                        &FGTranslation::Getalpha,
207                        &FGTranslation::Setalpha,
208                        true);
209   PropertyManager->Tie("aero/beta-rad", this,
210                        &FGTranslation::Getbeta,
211                        &FGTranslation::Setbeta,
212                        true);
213   PropertyManager->Tie("aero/mag-beta-rad", this,
214                        &FGTranslation::GetMagBeta);
215   PropertyManager->Tie("aero/qbar-psf", this,
216                        &FGTranslation::Getqbar,
217                        &FGTranslation::Setqbar,
218                        true);
219   PropertyManager->Tie("aero/qbarUW-psf", this,
220                        &FGTranslation::GetqbarUW,
221                        &FGTranslation::SetqbarUW,
222                        true);
223   PropertyManager->Tie("aero/qbarUV-psf", this,
224                        &FGTranslation::GetqbarUV,
225                        &FGTranslation::SetqbarUV,
226                        true);
227   PropertyManager->Tie("velocities/vt-fps", this,
228                        &FGTranslation::GetVt,
229                        &FGTranslation::SetVt,
230                        true);
231   PropertyManager->Tie("velocities/mach-norm", this,
232                        &FGTranslation::GetMach,
233                        &FGTranslation::SetMach,
234                        true);
235   PropertyManager->Tie("aero/alphadot-rad_sec", this,
236                        &FGTranslation::Getadot,
237                        &FGTranslation::Setadot,
238                        true);
239   PropertyManager->Tie("aero/betadot-rad_sec", this,
240                        &FGTranslation::Getbdot,
241                        &FGTranslation::Setbdot,
242                        true);
243 }
244
245 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246
247 void FGTranslation::unbind(void)
248 {
249   PropertyManager->Untie("velocities/u-fps");
250   PropertyManager->Untie("velocities/v-fps");
251   PropertyManager->Untie("velocities/w-fps");
252   PropertyManager->Untie("accelerations/udot-fps");
253   PropertyManager->Untie("accelerations/vdot-fps");
254   PropertyManager->Untie("accelerations/wdot-fps");
255   PropertyManager->Untie("velocities/u-aero-fps");
256   PropertyManager->Untie("velocities/v-aero-fps");
257   PropertyManager->Untie("velocities/w-aero-fps");
258   PropertyManager->Untie("aero/alpha-rad");
259   PropertyManager->Untie("aero/beta-rad");
260   PropertyManager->Untie("aero/qbar-psf");
261   PropertyManager->Untie("aero/qbarUW-psf");
262   PropertyManager->Untie("aero/qbarUV-psf");
263   PropertyManager->Untie("velocities/vt-fps");
264   PropertyManager->Untie("velocities/mach-norm");
265   PropertyManager->Untie("aero/alphadot-rad_sec");
266   PropertyManager->Untie("aero/betadot-rad_sec");
267   PropertyManager->Untie("aero/mag-beta-rad");
268 }
269
270 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271 //    The bitmasked value choices are as follows:
272 //    unset: In this case (the default) JSBSim would only print
273 //       out the normally expected messages, essentially echoing
274 //       the config files as they are read. If the environment
275 //       variable is not set, debug_lvl is set to 1 internally
276 //    0: This requests JSBSim not to output any messages
277 //       whatsoever.
278 //    1: This value explicity requests the normal JSBSim
279 //       startup messages
280 //    2: This value asks for a message to be printed out when
281 //       a class is instantiated
282 //    4: When this value is set, a message is displayed when a
283 //       FGModel object executes its Run() method
284 //    8: When this value is set, various runtime state variables
285 //       are printed out periodically
286 //    16: When set various parameters are sanity checked and
287 //       a message is printed out when they go out of bounds
288
289 void FGTranslation::Debug(int from)
290 {
291   if (debug_lvl <= 0) return;
292
293   if (debug_lvl & 1) { // Standard console startup message output
294     if (from == 0) { // Constructor
295
296     }
297   }
298   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
299     if (from == 0) cout << "Instantiated: FGTranslation" << endl;
300     if (from == 1) cout << "Destroyed:    FGTranslation" << endl;
301   }
302   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
303   }
304   if (debug_lvl & 8 ) { // Runtime state variables
305   }
306   if (debug_lvl & 16) { // Sanity checking
307     if (fabs(vUVW(eU)) > 1e6)
308       cout << "FGTranslation::U velocity out of bounds: " << vUVW(eU) << endl;
309     if (fabs(vUVW(eV)) > 1e6)
310       cout << "FGTranslation::V velocity out of bounds: " << vUVW(eV) << endl;
311     if (fabs(vUVW(eW)) > 1e6)
312       cout << "FGTranslation::W velocity out of bounds: " << vUVW(eW) << endl;
313     if (fabs(vUVWdot(eU)) > 1e4)
314       cout << "FGTranslation::U acceleration out of bounds: " << vUVWdot(eU) << endl;
315     if (fabs(vUVWdot(eV)) > 1e4)
316       cout << "FGTranslation::V acceleration out of bounds: " << vUVWdot(eV) << endl;
317     if (fabs(vUVWdot(eW)) > 1e4)
318       cout << "FGTranslation::W acceleration out of bounds: " << vUVWdot(eW) << endl;
319     if (Mach > 100 || Mach < 0.00)
320       cout << "FGTranslation::Mach is out of bounds: " << Mach << endl;
321     if (qbar > 1e6 || qbar < 0.00)
322       cout << "FGTranslation::qbar is out of bounds: " << qbar << endl;
323   }
324   if (debug_lvl & 64) {
325     if (from == 0) { // Constructor
326       cout << IdSrc << endl;
327       cout << IdHdr << endl;
328     }
329   }
330 }
331 }