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"
71 #include "FGPropertyManager.h"
73 static const char *IdSrc = "$Id$";
74 static const char *IdHdr = ID_TRANSLATION;
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
81 FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex)
83 Name = "FGTranslation";
93 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 FGTranslation::~FGTranslation(void)
101 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 bool FGTranslation::Run(void)
105 double Tc = 0.5*State->Getdt()*rate;
107 if (!FGModel::Run()) {
110 mVel(1,2) = -vUVW(eW);
111 mVel(1,3) = vUVW(eV);
112 mVel(2,1) = vUVW(eW);
114 mVel(2,3) = -vUVW(eU);
115 mVel(3,1) = -vUVW(eV);
116 mVel(3,2) = vUVW(eU);
119 vUVWdot = mVel*Rotation->GetPQR() + Aircraft->GetBodyAccel();
121 vUVW += Tc*(vUVWdot + vlastUVWdot);
123 vAeroUVW = vUVW + State->GetTl2b()*Atmosphere->GetWindNED();
125 Vt = vAeroUVW.Magnitude();
127 if (vAeroUVW(eW) != 0.0)
128 alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
129 if (vAeroUVW(eV) != 0.0)
130 beta = vAeroUVW(eU)*vAeroUVW(eU)+vAeroUVW(eW)*vAeroUVW(eW) > 0.0 ? atan2(vAeroUVW(eV),
131 sqrt(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW))) : 0.0;
133 // stolen, quite shamelessly, from LaRCsim
134 double mUW = (vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW));
136 if (vAeroUVW(eU) != 0.0)
137 signU = vAeroUVW(eU)/fabs(vAeroUVW(eU));
139 if ( (mUW == 0.0) || (Vt == 0.0) ) {
143 adot = (vAeroUVW(eU)*vAeroUVW(eW) - vAeroUVW(eW)*vUVWdot(eU))/mUW;
144 bdot = (signU*mUW*vUVWdot(eV) - vAeroUVW(eV)*(vAeroUVW(eU)*vUVWdot(eU)
145 + vAeroUVW(eW)*vUVWdot(eW)))/(Vt*Vt*sqrt(mUW));
148 alpha = beta = adot = bdot = 0;
151 qbar = 0.5*Atmosphere->GetDensity()*Vt*Vt;
152 Mach = Vt / State->Geta();
154 vlastUVWdot = vUVWdot;
156 if (debug_lvl > 1) Debug(1);
164 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 void FGTranslation::bind(void)
168 typedef double (FGTranslation::*PMF)(int) const;
169 PropertyManager->Tie("velocities/u-fps", this,1,
170 (PMF)&FGTranslation::GetUVW /*,
171 &FGTranslation::SetUVW,
173 PropertyManager->Tie("velocities/v-fps", this,2,
174 (PMF)&FGTranslation::GetUVW /*,
175 &FGTranslation::SetUVW,
177 PropertyManager->Tie("velocities/w-fps", this,3,
178 (PMF)&FGTranslation::GetUVW /*,
179 &FGTranslation::SetUVW,
181 PropertyManager->Tie("accelerations/udot-fps", this,1,
182 (PMF)&FGTranslation::GetUVWdot);
183 PropertyManager->Tie("accelerations/vdot-fps", this,2,
184 (PMF)&FGTranslation::GetUVWdot);
185 PropertyManager->Tie("accelerations/wdot-fps", this,3,
186 (PMF)&FGTranslation::GetUVWdot);
187 PropertyManager->Tie("velocities/u-aero-fps", this,1,
188 (PMF)&FGTranslation::GetAeroUVW);
189 PropertyManager->Tie("velocities/v-aero-fps", this,2,
190 (PMF)&FGTranslation::GetAeroUVW);
191 PropertyManager->Tie("velocities/w-aero-fps", this,3,
192 (PMF)&FGTranslation::GetAeroUVW);
193 PropertyManager->Tie("aero/alpha-rad", this,
194 &FGTranslation::Getalpha,
195 &FGTranslation::Setalpha,
197 PropertyManager->Tie("aero/beta-rad", this,
198 &FGTranslation::Getbeta,
199 &FGTranslation::Setbeta,
201 PropertyManager->Tie("aero/mag-beta-rad", this,
202 &FGTranslation::GetMagBeta);
203 PropertyManager->Tie("aero/qbar-psf", this,
204 &FGTranslation::Getqbar,
205 &FGTranslation::Setqbar,
207 PropertyManager->Tie("velocities/vt-fps", this,
208 &FGTranslation::GetVt,
209 &FGTranslation::SetVt,
211 PropertyManager->Tie("velocities/mach-norm", this,
212 &FGTranslation::GetMach,
213 &FGTranslation::SetMach,
215 PropertyManager->Tie("aero/alphadot-rad_sec", this,
216 &FGTranslation::Getadot,
217 &FGTranslation::Setadot,
219 PropertyManager->Tie("aero/betadot-rad_sec", this,
220 &FGTranslation::Getbdot,
221 &FGTranslation::Setbdot,
225 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227 void FGTranslation::unbind(void)
229 PropertyManager->Untie("velocities/u-fps");
230 PropertyManager->Untie("velocities/v-fps");
231 PropertyManager->Untie("velocities/w-fps");
232 PropertyManager->Untie("accelerations/udot-fps");
233 PropertyManager->Untie("accelerations/vdot-fps");
234 PropertyManager->Untie("accelerations/wdot-fps");
235 PropertyManager->Untie("velocities/u-aero-fps");
236 PropertyManager->Untie("velocities/v-aero-fps");
237 PropertyManager->Untie("velocities/w-aero-fps");
238 PropertyManager->Untie("aero/alpha-rad");
239 PropertyManager->Untie("aero/beta-rad");
240 PropertyManager->Untie("aero/qbar-psf");
241 PropertyManager->Untie("velocities/vt-fps");
242 PropertyManager->Untie("velocities/mach-norm");
243 PropertyManager->Untie("aero/alphadot-rad_sec");
244 PropertyManager->Untie("aero/betadot-rad_sec");
247 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 // The bitmasked value choices are as follows:
249 // unset: In this case (the default) JSBSim would only print
250 // out the normally expected messages, essentially echoing
251 // the config files as they are read. If the environment
252 // variable is not set, debug_lvl is set to 1 internally
253 // 0: This requests JSBSim not to output any messages
255 // 1: This value explicity requests the normal JSBSim
257 // 2: This value asks for a message to be printed out when
258 // a class is instantiated
259 // 4: When this value is set, a message is displayed when a
260 // FGModel object executes its Run() method
261 // 8: When this value is set, various runtime state variables
262 // are printed out periodically
263 // 16: When set various parameters are sanity checked and
264 // a message is printed out when they go out of bounds
266 void FGTranslation::Debug(int from)
268 if (debug_lvl <= 0) return;
270 if (debug_lvl & 1) { // Standard console startup message output
271 if (from == 0) { // Constructor
275 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
276 if (from == 0) cout << "Instantiated: FGTranslation" << endl;
277 if (from == 1) cout << "Destroyed: FGTranslation" << endl;
279 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
281 if (debug_lvl & 8 ) { // Runtime state variables
283 if (debug_lvl & 16) { // Sanity checking
284 if (fabs(vUVW(eU)) > 1e6)
285 cout << "FGTranslation::U velocity out of bounds: " << vUVW(eU) << endl;
286 if (fabs(vUVW(eV)) > 1e6)
287 cout << "FGTranslation::V velocity out of bounds: " << vUVW(eV) << endl;
288 if (fabs(vUVW(eW)) > 1e6)
289 cout << "FGTranslation::W velocity out of bounds: " << vUVW(eW) << endl;
290 if (fabs(vUVWdot(eU)) > 1e4)
291 cout << "FGTranslation::U acceleration out of bounds: " << vUVWdot(eU) << endl;
292 if (fabs(vUVWdot(eV)) > 1e4)
293 cout << "FGTranslation::V acceleration out of bounds: " << vUVWdot(eV) << endl;
294 if (fabs(vUVWdot(eW)) > 1e4)
295 cout << "FGTranslation::W acceleration out of bounds: " << vUVWdot(eW) << endl;
296 if (Mach > 100 || Mach < 0.00)
297 cout << "FGTranslation::Mach is out of bounds: " << Mach << endl;
298 if (qbar > 1e6 || qbar < 0.00)
299 cout << "FGTranslation::qbar is out of bounds: " << qbar << endl;
301 if (debug_lvl & 64) {
302 if (from == 0) { // Constructor
303 cout << IdSrc << endl;
304 cout << IdHdr << endl;