1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGTranslation.cpp
6 Purpose: Integrates the translational EOM
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This class integrates the translational EOM.
33 --------------------------------------------------------------------------------
35 7/23/99 TP Added data member and modified Run and PutState to calcuate
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
44 [2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
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
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.
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60 #include "FGTranslation.h"
61 #include "FGRotation.h"
62 #include "FGAtmosphere.h"
64 #include "FGFDMExec.h"
66 #include "FGMassBalance.h"
67 #include "FGAircraft.h"
68 #include "FGPosition.h"
69 #include "FGAuxiliary.h"
72 static const char *IdSrc = "$Id$";
73 static const char *IdHdr = ID_TRANSLATION;
75 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
80 FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex)
82 Name = "FGTranslation";
89 if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
92 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 FGTranslation::~FGTranslation()
96 if (debug_lvl & 2) cout << "Destroyed: FGTranslation" << endl;
99 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 bool FGTranslation::Run(void)
103 double Tc = 0.5*State->Getdt()*rate;
105 if (!FGModel::Run()) {
108 mVel(1,2) = -vUVW(eW);
109 mVel(1,3) = vUVW(eV);
110 mVel(2,1) = vUVW(eW);
112 mVel(2,3) = -vUVW(eU);
113 mVel(3,1) = -vUVW(eV);
114 mVel(3,2) = vUVW(eU);
117 vUVWdot = mVel*Rotation->GetPQR() + Aircraft->GetBodyAccel();
119 vUVW += Tc * (vlastUVWdot + vUVWdot);
120 vAeroUVW = vUVW + State->GetTl2b()*Atmosphere->GetWindNED();
122 Vt = vAeroUVW.Magnitude();
124 if (vAeroUVW(eW) != 0.0)
125 alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
126 if (vAeroUVW(eV) != 0.0)
127 beta = vAeroUVW(eU)*vAeroUVW(eU)+vAeroUVW(eW)*vAeroUVW(eW) > 0.0 ? atan2(vAeroUVW(eV),
128 sqrt(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW))) : 0.0;
130 // stolen, quite shamelessly, from LaRCsim
131 double mUW = (vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW));
133 if (vAeroUVW(eU) != 0.0)
134 signU = vAeroUVW(eU)/fabs(vAeroUVW(eU));
136 if ( (mUW == 0.0) || (Vt == 0.0) ) {
140 adot = (vAeroUVW(eU)*vAeroUVW(eW) - vAeroUVW(eW)*vUVWdot(eU))/mUW;
141 bdot = (signU*mUW*vUVWdot(eV) - vAeroUVW(eV)*(vAeroUVW(eU)*vUVWdot(eU)
142 + vAeroUVW(eW)*vUVWdot(eW)))/(Vt*Vt*sqrt(mUW));
145 alpha = beta = adot = bdot = 0;
148 qbar = 0.5*Atmosphere->GetDensity()*Vt*Vt;
149 Mach = Vt / State->Geta();
151 vlastUVWdot = vUVWdot;
153 if (debug_lvl > 1) Debug();
161 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 void FGTranslation::Debug(void)
165 if (debug_lvl & 16) { // Sanity check variables
166 if (fabs(vUVW(eU)) > 1e6)
167 cout << "FGTranslation::U velocity out of bounds: " << vUVW(eU) << endl;
168 if (fabs(vUVW(eV)) > 1e6)
169 cout << "FGTranslation::V velocity out of bounds: " << vUVW(eV) << endl;
170 if (fabs(vUVW(eW)) > 1e6)
171 cout << "FGTranslation::W velocity out of bounds: " << vUVW(eW) << endl;
172 if (fabs(vUVWdot(eU)) > 1e4)
173 cout << "FGTranslation::U acceleration out of bounds: " << vUVWdot(eU) << endl;
174 if (fabs(vUVWdot(eV)) > 1e4)
175 cout << "FGTranslation::V acceleration out of bounds: " << vUVWdot(eV) << endl;
176 if (fabs(vUVWdot(eW)) > 1e4)
177 cout << "FGTranslation::W acceleration out of bounds: " << vUVWdot(eW) << endl;
178 if (Mach > 100 || Mach < 0.00)
179 cout << "FGTranslation::Mach is out of bounds: " << Mach << endl;
180 if (qbar > 1e6 || qbar < 0.00)
181 cout << "FGTranslation::qbar is out of bounds: " << qbar << endl;