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 vUVWdot_prev[0].InitMatrix();
94 vUVWdot_prev[1].InitMatrix();
95 vUVWdot_prev[2].InitMatrix();
101 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 FGTranslation::~FGTranslation(void)
109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 bool FGTranslation::Run(void)
113 if (!FGModel::Run()) {
116 mVel(1,2) = -vUVW(eW);
117 mVel(1,3) = vUVW(eV);
118 mVel(2,1) = vUVW(eW);
120 mVel(2,3) = -vUVW(eU);
121 mVel(3,1) = -vUVW(eV);
122 mVel(3,2) = vUVW(eU);
125 vUVWdot = mVel*Rotation->GetPQR() + Aircraft->GetBodyAccel();
127 vUVW += State->Integrate(FGState::TRAPZ, State->Getdt()*rate, vUVWdot, vUVWdot_prev);
129 vAeroUVW = vUVW + State->GetTl2b()*Atmosphere->GetWindNED();
131 Vt = vAeroUVW.Magnitude();
133 if (vAeroUVW(eW) != 0.0)
134 alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
135 if (vAeroUVW(eV) != 0.0)
136 beta = vAeroUVW(eU)*vAeroUVW(eU)+vAeroUVW(eW)*vAeroUVW(eW) > 0.0 ? atan2(vAeroUVW(eV),
137 sqrt(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW))) : 0.0;
139 // stolen, quite shamelessly, from LaRCsim
140 double mUW = (vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW));
142 if (vAeroUVW(eU) != 0.0)
143 signU = vAeroUVW(eU)/fabs(vAeroUVW(eU));
145 if ( (mUW == 0.0) || (Vt == 0.0) ) {
149 adot = (vAeroUVW(eU)*vAeroUVW(eW) - vAeroUVW(eW)*vUVWdot(eU))/mUW;
150 bdot = (signU*mUW*vUVWdot(eV) - vAeroUVW(eV)*(vAeroUVW(eU)*vUVWdot(eU)
151 + vAeroUVW(eW)*vUVWdot(eW)))/(Vt*Vt*sqrt(mUW));
154 alpha = beta = adot = bdot = 0;
157 qbar = 0.5*Atmosphere->GetDensity()*Vt*Vt;
158 qbarUW = 0.5*Atmosphere->GetDensity()*(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW));
159 qbarUV = 0.5*Atmosphere->GetDensity()*(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eV)*vAeroUVW(eV));
160 Mach = Vt / State->Geta();
162 if (debug_lvl > 1) Debug(1);
170 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 void FGTranslation::bind(void)
174 typedef double (FGTranslation::*PMF)(int) const;
175 PropertyManager->Tie("velocities/u-fps", this,1,
176 (PMF)&FGTranslation::GetUVW /*,
177 &FGTranslation::SetUVW,
179 PropertyManager->Tie("velocities/v-fps", this,2,
180 (PMF)&FGTranslation::GetUVW /*,
181 &FGTranslation::SetUVW,
183 PropertyManager->Tie("velocities/w-fps", this,3,
184 (PMF)&FGTranslation::GetUVW /*,
185 &FGTranslation::SetUVW,
187 PropertyManager->Tie("accelerations/udot-fps", this,1,
188 (PMF)&FGTranslation::GetUVWdot);
189 PropertyManager->Tie("accelerations/vdot-fps", this,2,
190 (PMF)&FGTranslation::GetUVWdot);
191 PropertyManager->Tie("accelerations/wdot-fps", this,3,
192 (PMF)&FGTranslation::GetUVWdot);
193 PropertyManager->Tie("velocities/u-aero-fps", this,1,
194 (PMF)&FGTranslation::GetAeroUVW);
195 PropertyManager->Tie("velocities/v-aero-fps", this,2,
196 (PMF)&FGTranslation::GetAeroUVW);
197 PropertyManager->Tie("velocities/w-aero-fps", this,3,
198 (PMF)&FGTranslation::GetAeroUVW);
199 PropertyManager->Tie("aero/alpha-rad", this,
200 &FGTranslation::Getalpha,
201 &FGTranslation::Setalpha,
203 PropertyManager->Tie("aero/beta-rad", this,
204 &FGTranslation::Getbeta,
205 &FGTranslation::Setbeta,
207 PropertyManager->Tie("aero/mag-beta-rad", this,
208 &FGTranslation::GetMagBeta);
209 PropertyManager->Tie("aero/qbar-psf", this,
210 &FGTranslation::Getqbar,
211 &FGTranslation::Setqbar,
213 PropertyManager->Tie("aero/qbarUW-psf", this,
214 &FGTranslation::GetqbarUW,
215 &FGTranslation::SetqbarUW,
217 PropertyManager->Tie("aero/qbarUV-psf", this,
218 &FGTranslation::GetqbarUV,
219 &FGTranslation::SetqbarUV,
221 PropertyManager->Tie("velocities/vt-fps", this,
222 &FGTranslation::GetVt,
223 &FGTranslation::SetVt,
225 PropertyManager->Tie("velocities/mach-norm", this,
226 &FGTranslation::GetMach,
227 &FGTranslation::SetMach,
229 PropertyManager->Tie("aero/alphadot-rad_sec", this,
230 &FGTranslation::Getadot,
231 &FGTranslation::Setadot,
233 PropertyManager->Tie("aero/betadot-rad_sec", this,
234 &FGTranslation::Getbdot,
235 &FGTranslation::Setbdot,
239 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241 void FGTranslation::unbind(void)
243 PropertyManager->Untie("velocities/u-fps");
244 PropertyManager->Untie("velocities/v-fps");
245 PropertyManager->Untie("velocities/w-fps");
246 PropertyManager->Untie("accelerations/udot-fps");
247 PropertyManager->Untie("accelerations/vdot-fps");
248 PropertyManager->Untie("accelerations/wdot-fps");
249 PropertyManager->Untie("velocities/u-aero-fps");
250 PropertyManager->Untie("velocities/v-aero-fps");
251 PropertyManager->Untie("velocities/w-aero-fps");
252 PropertyManager->Untie("aero/alpha-rad");
253 PropertyManager->Untie("aero/beta-rad");
254 PropertyManager->Untie("aero/qbar-psf");
255 PropertyManager->Untie("aero/qbarUW-psf");
256 PropertyManager->Untie("aero/qbarUV-psf");
257 PropertyManager->Untie("velocities/vt-fps");
258 PropertyManager->Untie("velocities/mach-norm");
259 PropertyManager->Untie("aero/alphadot-rad_sec");
260 PropertyManager->Untie("aero/betadot-rad_sec");
263 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 // The bitmasked value choices are as follows:
265 // unset: In this case (the default) JSBSim would only print
266 // out the normally expected messages, essentially echoing
267 // the config files as they are read. If the environment
268 // variable is not set, debug_lvl is set to 1 internally
269 // 0: This requests JSBSim not to output any messages
271 // 1: This value explicity requests the normal JSBSim
273 // 2: This value asks for a message to be printed out when
274 // a class is instantiated
275 // 4: When this value is set, a message is displayed when a
276 // FGModel object executes its Run() method
277 // 8: When this value is set, various runtime state variables
278 // are printed out periodically
279 // 16: When set various parameters are sanity checked and
280 // a message is printed out when they go out of bounds
282 void FGTranslation::Debug(int from)
284 if (debug_lvl <= 0) return;
286 if (debug_lvl & 1) { // Standard console startup message output
287 if (from == 0) { // Constructor
291 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
292 if (from == 0) cout << "Instantiated: FGTranslation" << endl;
293 if (from == 1) cout << "Destroyed: FGTranslation" << endl;
295 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
297 if (debug_lvl & 8 ) { // Runtime state variables
299 if (debug_lvl & 16) { // Sanity checking
300 if (fabs(vUVW(eU)) > 1e6)
301 cout << "FGTranslation::U velocity out of bounds: " << vUVW(eU) << endl;
302 if (fabs(vUVW(eV)) > 1e6)
303 cout << "FGTranslation::V velocity out of bounds: " << vUVW(eV) << endl;
304 if (fabs(vUVW(eW)) > 1e6)
305 cout << "FGTranslation::W velocity out of bounds: " << vUVW(eW) << endl;
306 if (fabs(vUVWdot(eU)) > 1e4)
307 cout << "FGTranslation::U acceleration out of bounds: " << vUVWdot(eU) << endl;
308 if (fabs(vUVWdot(eV)) > 1e4)
309 cout << "FGTranslation::V acceleration out of bounds: " << vUVWdot(eV) << endl;
310 if (fabs(vUVWdot(eW)) > 1e4)
311 cout << "FGTranslation::W acceleration out of bounds: " << vUVWdot(eW) << endl;
312 if (Mach > 100 || Mach < 0.00)
313 cout << "FGTranslation::Mach is out of bounds: " << Mach << endl;
314 if (qbar > 1e6 || qbar < 0.00)
315 cout << "FGTranslation::qbar is out of bounds: " << qbar << endl;
317 if (debug_lvl & 64) {
318 if (from == 0) { // Constructor
319 cout << IdSrc << endl;
320 cout << IdHdr << endl;