]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGTranslation.cpp
JSBSim tweaks.
[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 extern short debug_lvl;
76
77 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 CLASS IMPLEMENTATION
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
80
81
82 FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex),
83     vUVW(3),
84     vUVWdot(3),
85     vNcg(3),
86     vPQR(3),
87     vForces(3),
88     vEuler(3),
89     vlastUVWdot(3),
90     mVel(3,3)
91 {
92   Name = "FGTranslation";
93   qbar = 0;
94   Vt = 0.0;
95   Mach = 0.0;
96   alpha = beta = 0.0;
97   adot = bdot = 0.0;
98   rho = 0.002378;
99
100   if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
101 }
102
103 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104
105 FGTranslation::~FGTranslation()
106 {
107   if (debug_lvl & 2) cout << "Destroyed:    FGTranslation" << endl;
108 }
109
110 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111
112 bool FGTranslation::Run(void) {
113
114   if (!FGModel::Run()) {
115
116     GetState();
117
118     mVel(1,1) =  0.0;
119     mVel(1,2) = -vUVW(eW);
120     mVel(1,3) =  vUVW(eV);
121     mVel(2,1) =  vUVW(eW);
122     mVel(2,2) =  0.0;
123     mVel(2,3) = -vUVW(eU);
124     mVel(3,1) = -vUVW(eV);
125     mVel(3,2) =  vUVW(eU);
126     mVel(3,3) =  0.0;
127
128     vUVWdot = mVel*vPQR + vForces/Mass;
129
130     vNcg = vUVWdot*INVGRAVITY;
131
132     vUVW += 0.5*dt*rate*(vlastUVWdot + vUVWdot);
133
134     Vt = vUVW.Magnitude();
135
136     if (vUVW(eW) != 0.0)
137       alpha = vUVW(eU)*vUVW(eU) > 0.0 ? atan2(vUVW(eW), vUVW(eU)) : 0.0;
138     if (vUVW(eV) != 0.0)
139       beta = vUVW(eU)*vUVW(eU)+vUVW(eW)*vUVW(eW) > 0.0 ? atan2(vUVW(eV),
140              sqrt(vUVW(eU)*vUVW(eU) + vUVW(eW)*vUVW(eW))) : 0.0;
141
142     // stolen, quite shamelessly, from LaRCsim
143     float mUW = (vUVW(eU)*vUVW(eU) + vUVW(eW)*vUVW(eW));
144     float signU=1;
145     if (vUVW(eU) != 0.0)
146       signU = vUVW(eU)/fabs(vUVW(eU));
147
148     if ( (mUW == 0.0) || (Vt == 0.0) ) {
149       adot = 0.0;
150       bdot = 0.0;
151     } else {
152       adot = (vUVW(eU)*vUVWdot(eW) - vUVW(eW)*vUVWdot(eU))/mUW;
153       bdot = (signU*mUW*vUVWdot(eV) - vUVW(eV)*(vUVW(eU)*vUVWdot(eU)
154               + vUVW(eW)*vUVWdot(eW)))/(Vt*Vt*sqrt(mUW));
155     }
156
157     qbar = 0.5*rho*Vt*Vt;
158     Mach = Vt / State->Geta();
159
160     vlastUVWdot = vUVWdot;
161
162     if (debug_lvl > 1) Debug();
163
164     return false;
165   } else {
166     return true;
167   }
168 }
169
170 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171
172 void FGTranslation::GetState(void) {
173   dt = State->Getdt();
174
175   vPQR = Rotation->GetPQR();
176   vForces = Aircraft->GetForces();
177
178   Mass = MassBalance->GetMass();
179   rho = Atmosphere->GetDensity();
180
181   vEuler = Rotation->GetEuler();
182 }
183
184 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185
186 void FGTranslation::Debug(void)
187 {
188   if (debug_lvl & 16) { // Sanity check variables
189     if (fabs(vUVW(eU)) > 1e6)
190       cout << "FGTranslation::U velocity out of bounds: " << vUVW(eU) << endl;
191     if (fabs(vUVW(eV)) > 1e6)
192       cout << "FGTranslation::V velocity out of bounds: " << vUVW(eV) << endl;
193     if (fabs(vUVW(eW)) > 1e6)
194       cout << "FGTranslation::W velocity out of bounds: " << vUVW(eW) << endl;
195     if (fabs(vUVWdot(eU)) > 1e4)
196       cout << "FGTranslation::U acceleration out of bounds: " << vUVWdot(eU) << endl;
197     if (fabs(vUVWdot(eV)) > 1e4)
198       cout << "FGTranslation::V acceleration out of bounds: " << vUVWdot(eV) << endl;
199     if (fabs(vUVWdot(eW)) > 1e4)
200       cout << "FGTranslation::W acceleration out of bounds: " << vUVWdot(eW) << endl;
201     if (Mach > 100 || Mach < 0.00)
202       cout << "FGTranslation::Mach is out of bounds: " << Mach << endl;
203     if (qbar > 1e6 || qbar < 0.00)
204       cout << "FGTranslation::qbar is out of bounds: " << qbar << endl;
205   }
206 }
207