]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGTranslation.cpp
First steps in a weather reorganization. Note especially that
[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
72 static const char *IdSrc = "$Id$";
73 static const char *IdHdr = ID_TRANSLATION;
74
75 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 CLASS IMPLEMENTATION
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
78
79
80 FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex)
81 {
82   Name = "FGTranslation";
83   qbar = 0;
84   Vt = 0.0;
85   Mach = 0.0;
86   alpha = beta = 0.0;
87   adot = bdot = 0.0;
88
89   Debug(0);
90 }
91
92 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93
94 FGTranslation::~FGTranslation(void)
95 {
96   Debug(1);
97 }
98
99 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100
101 bool FGTranslation::Run(void)
102 {
103   double Tc = 0.5*State->Getdt()*rate;
104
105   if (!FGModel::Run()) {
106
107     mVel(1,1) =  0.0;
108     mVel(1,2) = -vUVW(eW);
109     mVel(1,3) =  vUVW(eV);
110     mVel(2,1) =  vUVW(eW);
111     mVel(2,2) =  0.0;
112     mVel(2,3) = -vUVW(eU);
113     mVel(3,1) = -vUVW(eV);
114     mVel(3,2) =  vUVW(eU);
115     mVel(3,3) =  0.0;
116
117     vUVWdot = mVel*Rotation->GetPQR() + Aircraft->GetBodyAccel();
118
119     vUVW += Tc*(vUVWdot + vlastUVWdot);
120
121     vAeroUVW = vUVW + State->GetTl2b()*Atmosphere->GetWindNED();
122
123     Vt = vAeroUVW.Magnitude();
124     if ( Vt > 1) {
125       if (vAeroUVW(eW) != 0.0)
126         alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
127       if (vAeroUVW(eV) != 0.0)
128         beta = vAeroUVW(eU)*vAeroUVW(eU)+vAeroUVW(eW)*vAeroUVW(eW) > 0.0 ? atan2(vAeroUVW(eV),
129                sqrt(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW))) : 0.0;
130
131       // stolen, quite shamelessly, from LaRCsim
132       double mUW = (vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW));
133       double signU=1;
134       if (vAeroUVW(eU) != 0.0)
135         signU = vAeroUVW(eU)/fabs(vAeroUVW(eU));
136
137       if ( (mUW == 0.0) || (Vt == 0.0) ) {
138         adot = 0.0;
139         bdot = 0.0;
140       } else {
141         adot = (vAeroUVW(eU)*vAeroUVW(eW) - vAeroUVW(eW)*vUVWdot(eU))/mUW;
142         bdot = (signU*mUW*vUVWdot(eV) - vAeroUVW(eV)*(vAeroUVW(eU)*vUVWdot(eU)
143                 + vAeroUVW(eW)*vUVWdot(eW)))/(Vt*Vt*sqrt(mUW));
144       }
145     } else {
146       alpha = beta = adot = bdot = 0;
147     }
148
149     qbar = 0.5*Atmosphere->GetDensity()*Vt*Vt;
150     Mach = Vt / State->Geta();
151
152     vlastUVWdot = vUVWdot;
153
154     if (debug_lvl > 1) Debug(1);
155
156     return false;
157   } else {
158     return true;
159   }
160 }
161
162 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 //    The bitmasked value choices are as follows:
164 //    unset: In this case (the default) JSBSim would only print
165 //       out the normally expected messages, essentially echoing
166 //       the config files as they are read. If the environment
167 //       variable is not set, debug_lvl is set to 1 internally
168 //    0: This requests JSBSim not to output any messages
169 //       whatsoever.
170 //    1: This value explicity requests the normal JSBSim
171 //       startup messages
172 //    2: This value asks for a message to be printed out when
173 //       a class is instantiated
174 //    4: When this value is set, a message is displayed when a
175 //       FGModel object executes its Run() method
176 //    8: When this value is set, various runtime state variables
177 //       are printed out periodically
178 //    16: When set various parameters are sanity checked and
179 //       a message is printed out when they go out of bounds
180
181 void FGTranslation::Debug(int from)
182 {
183   if (debug_lvl <= 0) return;
184
185   if (debug_lvl & 1) { // Standard console startup message output
186     if (from == 0) { // Constructor
187
188     }
189   }
190   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
191     if (from == 0) cout << "Instantiated: FGTranslation" << endl;
192     if (from == 1) cout << "Destroyed:    FGTranslation" << endl;
193   }
194   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
195   }
196   if (debug_lvl & 8 ) { // Runtime state variables
197   }
198   if (debug_lvl & 16) { // Sanity checking
199     if (fabs(vUVW(eU)) > 1e6)
200       cout << "FGTranslation::U velocity out of bounds: " << vUVW(eU) << endl;
201     if (fabs(vUVW(eV)) > 1e6)
202       cout << "FGTranslation::V velocity out of bounds: " << vUVW(eV) << endl;
203     if (fabs(vUVW(eW)) > 1e6)
204       cout << "FGTranslation::W velocity out of bounds: " << vUVW(eW) << endl;
205     if (fabs(vUVWdot(eU)) > 1e4)
206       cout << "FGTranslation::U acceleration out of bounds: " << vUVWdot(eU) << endl;
207     if (fabs(vUVWdot(eV)) > 1e4)
208       cout << "FGTranslation::V acceleration out of bounds: " << vUVWdot(eV) << endl;
209     if (fabs(vUVWdot(eW)) > 1e4)
210       cout << "FGTranslation::W acceleration out of bounds: " << vUVWdot(eW) << endl;
211     if (Mach > 100 || Mach < 0.00)
212       cout << "FGTranslation::Mach is out of bounds: " << Mach << endl;
213     if (qbar > 1e6 || qbar < 0.00)
214       cout << "FGTranslation::qbar is out of bounds: " << qbar << endl;
215   }
216   if (debug_lvl & 64) {
217     if (from == 0) { // Constructor
218       cout << IdSrc << endl;
219       cout << IdHdr << endl;
220     }
221   }
222 }
223