]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGTranslation.cpp
Member variable initialization fixes from Cameron Moore
[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 static const char *IdSrc = "$Id$";
74 static const char *IdHdr = ID_TRANSLATION;
75
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 CLASS IMPLEMENTATION
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
79
80
81 FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex)
82 {
83   Name = "FGTranslation";
84   qbar = 0;
85   qbarUW = 0.0;
86   qbarUV = 0.0;
87   Vt = 0.0;
88   Mach = 0.0;
89   alpha = beta = 0.0;
90   adot = bdot = 0.0;
91   bind();
92   Debug(0);
93 }
94
95 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96
97 FGTranslation::~FGTranslation(void)
98 {
99   unbind();
100   Debug(1);
101 }
102
103 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104
105 bool FGTranslation::Run(void)
106 {
107   double Tc = 0.5*State->Getdt()*rate;
108
109   if (!FGModel::Run()) {
110
111     mVel(1,1) =  0.0;
112     mVel(1,2) = -vUVW(eW);
113     mVel(1,3) =  vUVW(eV);
114     mVel(2,1) =  vUVW(eW);
115     mVel(2,2) =  0.0;
116     mVel(2,3) = -vUVW(eU);
117     mVel(3,1) = -vUVW(eV);
118     mVel(3,2) =  vUVW(eU);
119     mVel(3,3) =  0.0;
120
121     vUVWdot = mVel*Rotation->GetPQR() + Aircraft->GetBodyAccel();
122
123     vUVW += Tc*(vUVWdot + vlastUVWdot);
124
125     vAeroUVW = vUVW + State->GetTl2b()*Atmosphere->GetWindNED();
126
127     Vt = vAeroUVW.Magnitude();
128     if ( Vt > 1) {
129       if (vAeroUVW(eW) != 0.0)
130         alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
131       if (vAeroUVW(eV) != 0.0)
132         beta = vAeroUVW(eU)*vAeroUVW(eU)+vAeroUVW(eW)*vAeroUVW(eW) > 0.0 ? atan2(vAeroUVW(eV),
133                sqrt(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW))) : 0.0;
134
135       // stolen, quite shamelessly, from LaRCsim
136       double mUW = (vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW));
137       double signU=1;
138       if (vAeroUVW(eU) != 0.0)
139         signU = vAeroUVW(eU)/fabs(vAeroUVW(eU));
140
141       if ( (mUW == 0.0) || (Vt == 0.0) ) {
142         adot = 0.0;
143         bdot = 0.0;
144       } else {
145         adot = (vAeroUVW(eU)*vAeroUVW(eW) - vAeroUVW(eW)*vUVWdot(eU))/mUW;
146         bdot = (signU*mUW*vUVWdot(eV) - vAeroUVW(eV)*(vAeroUVW(eU)*vUVWdot(eU)
147                 + vAeroUVW(eW)*vUVWdot(eW)))/(Vt*Vt*sqrt(mUW));
148       }
149     } else {
150       alpha = beta = adot = bdot = 0;
151     }
152
153     qbar = 0.5*Atmosphere->GetDensity()*Vt*Vt;
154     qbarUW = 0.5*Atmosphere->GetDensity()*(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW));
155     qbarUV = 0.5*Atmosphere->GetDensity()*(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eV)*vAeroUVW(eV));
156     Mach = Vt / State->Geta();
157
158     vlastUVWdot = vUVWdot;
159
160     if (debug_lvl > 1) Debug(1);
161
162     return false;
163   } else {
164     return true;
165   }
166 }
167
168 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169
170 void FGTranslation::bind(void)
171 {
172   typedef double (FGTranslation::*PMF)(int) const;
173   PropertyManager->Tie("velocities/u-fps", this,1,
174                        (PMF)&FGTranslation::GetUVW /*,
175                        &FGTranslation::SetUVW,
176                        true */);
177   PropertyManager->Tie("velocities/v-fps", this,2,
178                        (PMF)&FGTranslation::GetUVW /*,
179                        &FGTranslation::SetUVW,
180                        true*/);
181   PropertyManager->Tie("velocities/w-fps", this,3,
182                        (PMF)&FGTranslation::GetUVW /*,
183                        &FGTranslation::SetUVW,
184                        true*/);
185   PropertyManager->Tie("accelerations/udot-fps", this,1,
186                        (PMF)&FGTranslation::GetUVWdot);
187   PropertyManager->Tie("accelerations/vdot-fps", this,2,
188                        (PMF)&FGTranslation::GetUVWdot);
189   PropertyManager->Tie("accelerations/wdot-fps", this,3,
190                        (PMF)&FGTranslation::GetUVWdot);
191   PropertyManager->Tie("velocities/u-aero-fps", this,1,
192                        (PMF)&FGTranslation::GetAeroUVW);
193   PropertyManager->Tie("velocities/v-aero-fps", this,2,
194                        (PMF)&FGTranslation::GetAeroUVW);
195   PropertyManager->Tie("velocities/w-aero-fps", this,3,
196                        (PMF)&FGTranslation::GetAeroUVW);
197   PropertyManager->Tie("aero/alpha-rad", this,
198                        &FGTranslation::Getalpha,
199                        &FGTranslation::Setalpha,
200                        true);
201   PropertyManager->Tie("aero/beta-rad", this,
202                        &FGTranslation::Getbeta,
203                        &FGTranslation::Setbeta,
204                        true);
205   PropertyManager->Tie("aero/mag-beta-rad", this,
206                        &FGTranslation::GetMagBeta);
207   PropertyManager->Tie("aero/qbar-psf", this,
208                        &FGTranslation::Getqbar,
209                        &FGTranslation::Setqbar,
210                        true);
211   PropertyManager->Tie("aero/qbarUW-psf", this,
212                        &FGTranslation::GetqbarUW,
213                        &FGTranslation::SetqbarUW,
214                        true);
215   PropertyManager->Tie("aero/qbarUV-psf", this,
216                        &FGTranslation::GetqbarUV,
217                        &FGTranslation::SetqbarUV,
218                        true);
219   PropertyManager->Tie("velocities/vt-fps", this,
220                        &FGTranslation::GetVt,
221                        &FGTranslation::SetVt,
222                        true);
223   PropertyManager->Tie("velocities/mach-norm", this,
224                        &FGTranslation::GetMach,
225                        &FGTranslation::SetMach,
226                        true);
227   PropertyManager->Tie("aero/alphadot-rad_sec", this,
228                        &FGTranslation::Getadot,
229                        &FGTranslation::Setadot,
230                        true);
231   PropertyManager->Tie("aero/betadot-rad_sec", this,
232                        &FGTranslation::Getbdot,
233                        &FGTranslation::Setbdot,
234                        true);
235 }
236
237 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238
239 void FGTranslation::unbind(void)
240 {
241   PropertyManager->Untie("velocities/u-fps");
242   PropertyManager->Untie("velocities/v-fps");
243   PropertyManager->Untie("velocities/w-fps");
244   PropertyManager->Untie("accelerations/udot-fps");
245   PropertyManager->Untie("accelerations/vdot-fps");
246   PropertyManager->Untie("accelerations/wdot-fps");
247   PropertyManager->Untie("velocities/u-aero-fps");
248   PropertyManager->Untie("velocities/v-aero-fps");
249   PropertyManager->Untie("velocities/w-aero-fps");
250   PropertyManager->Untie("aero/alpha-rad");
251   PropertyManager->Untie("aero/beta-rad");
252   PropertyManager->Untie("aero/qbar-psf");
253   PropertyManager->Untie("aero/qbarUW-psf");
254   PropertyManager->Untie("aero/qbarUV-psf");
255   PropertyManager->Untie("velocities/vt-fps");
256   PropertyManager->Untie("velocities/mach-norm");
257   PropertyManager->Untie("aero/alphadot-rad_sec");
258   PropertyManager->Untie("aero/betadot-rad_sec");
259 }
260
261 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 //    The bitmasked value choices are as follows:
263 //    unset: In this case (the default) JSBSim would only print
264 //       out the normally expected messages, essentially echoing
265 //       the config files as they are read. If the environment
266 //       variable is not set, debug_lvl is set to 1 internally
267 //    0: This requests JSBSim not to output any messages
268 //       whatsoever.
269 //    1: This value explicity requests the normal JSBSim
270 //       startup messages
271 //    2: This value asks for a message to be printed out when
272 //       a class is instantiated
273 //    4: When this value is set, a message is displayed when a
274 //       FGModel object executes its Run() method
275 //    8: When this value is set, various runtime state variables
276 //       are printed out periodically
277 //    16: When set various parameters are sanity checked and
278 //       a message is printed out when they go out of bounds
279
280 void FGTranslation::Debug(int from)
281 {
282   if (debug_lvl <= 0) return;
283
284   if (debug_lvl & 1) { // Standard console startup message output
285     if (from == 0) { // Constructor
286
287     }
288   }
289   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
290     if (from == 0) cout << "Instantiated: FGTranslation" << endl;
291     if (from == 1) cout << "Destroyed:    FGTranslation" << endl;
292   }
293   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
294   }
295   if (debug_lvl & 8 ) { // Runtime state variables
296   }
297   if (debug_lvl & 16) { // Sanity checking
298     if (fabs(vUVW(eU)) > 1e6)
299       cout << "FGTranslation::U velocity out of bounds: " << vUVW(eU) << endl;
300     if (fabs(vUVW(eV)) > 1e6)
301       cout << "FGTranslation::V velocity out of bounds: " << vUVW(eV) << endl;
302     if (fabs(vUVW(eW)) > 1e6)
303       cout << "FGTranslation::W velocity out of bounds: " << vUVW(eW) << endl;
304     if (fabs(vUVWdot(eU)) > 1e4)
305       cout << "FGTranslation::U acceleration out of bounds: " << vUVWdot(eU) << endl;
306     if (fabs(vUVWdot(eV)) > 1e4)
307       cout << "FGTranslation::V acceleration out of bounds: " << vUVWdot(eV) << endl;
308     if (fabs(vUVWdot(eW)) > 1e4)
309       cout << "FGTranslation::W acceleration out of bounds: " << vUVWdot(eW) << endl;
310     if (Mach > 100 || Mach < 0.00)
311       cout << "FGTranslation::Mach is out of bounds: " << Mach << endl;
312     if (qbar > 1e6 || qbar < 0.00)
313       cout << "FGTranslation::qbar is out of bounds: " << qbar << endl;
314   }
315   if (debug_lvl & 64) {
316     if (from == 0) { // Constructor
317       cout << IdSrc << endl;
318       cout << IdHdr << endl;
319     }
320   }
321 }
322