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 "FGAircraft.h"
67 #include "FGPosition.h"
68 #include "FGAuxiliary.h"
71 static const char *IdSrc = "$Id$";
72 static const char *IdHdr = ID_TRANSLATION;
74 extern short debug_lvl;
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
81 FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex),
91 Name = "FGTranslation";
99 if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
102 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 FGTranslation::~FGTranslation()
106 if (debug_lvl & 2) cout << "Destroyed: FGTranslation" << endl;
109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 bool FGTranslation::Run(void) {
113 if (!FGModel::Run()) {
118 mVel(1,2) = -vUVW(eW);
119 mVel(1,3) = vUVW(eV);
120 mVel(2,1) = vUVW(eW);
122 mVel(2,3) = -vUVW(eU);
123 mVel(3,1) = -vUVW(eV);
124 mVel(3,2) = vUVW(eU);
127 vUVWdot = mVel*vPQR + vForces/Mass;
129 vNcg = vUVWdot*INVGRAVITY;
131 vUVW += 0.5*dt*rate*(vlastUVWdot + vUVWdot);
133 Vt = vUVW.Magnitude();
136 alpha = vUVW(eU)*vUVW(eU) > 0.0 ? atan2(vUVW(eW), vUVW(eU)) : 0.0;
138 beta = vUVW(eU)*vUVW(eU)+vUVW(eW)*vUVW(eW) > 0.0 ? atan2(vUVW(eV),
139 sqrt(vUVW(eU)*vUVW(eU) + vUVW(eW)*vUVW(eW))) : 0.0;
141 // stolen, quite shamelessly, from LaRCsim
142 float mUW = (vUVW(eU)*vUVW(eU) + vUVW(eW)*vUVW(eW));
145 signU = vUVW(eU)/fabs(vUVW(eU));
147 if ( (mUW == 0.0) || (Vt == 0.0) ) {
151 adot = (vUVW(eU)*vUVWdot(eW) - vUVW(eW)*vUVWdot(eU))/mUW;
152 bdot = (signU*mUW*vUVWdot(eV) - vUVW(eV)*(vUVW(eU)*vUVWdot(eU)
153 + vUVW(eW)*vUVWdot(eW)))/(Vt*Vt*sqrt(mUW));
156 qbar = 0.5*rho*Vt*Vt;
157 Mach = Vt / State->Geta();
159 vlastUVWdot = vUVWdot;
166 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 void FGTranslation::GetState(void) {
171 vPQR = Rotation->GetPQR();
172 vForces = Aircraft->GetForces();
174 Mass = Aircraft->GetMass();
175 rho = Atmosphere->GetDensity();
177 vEuler = Rotation->GetEuler();
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 void FGTranslation::Debug(void)
184 //TODO: Add your source code here