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