]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGTranslation.cpp
Oct. 10, 2000 sync with JSBSim master repository.
[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 "FGAircraft.h"
67 #include "FGPosition.h"
68 #include "FGAuxiliary.h"
69 #include "FGOutput.h"
70
71 /*******************************************************************************
72 ************************************ CODE **************************************
73 *******************************************************************************/
74
75
76 FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex),
77     vUVW(3),
78     vWindUVW(3),
79     vUVWdot(3),
80     vNcg(3),
81     vPQR(3),
82     vForces(3),
83     vEuler(3)
84 {
85   Name = "FGTranslation";
86   qbar = 0;
87   Vt = 0.0;
88   Mach = 0.0;
89   alpha = beta = 0.0;
90   adot = bdot = 0.0;
91   rho = 0.002378;
92 }
93
94 /******************************************************************************/
95
96 FGTranslation::~FGTranslation(void) {}
97
98 /******************************************************************************/
99
100 bool FGTranslation::Run(void) {
101   static FGColumnVector vlastUVWdot(3);
102   static FGMatrix       mVel(3,3);
103
104   if (!FGModel::Run()) {
105
106     GetState();
107
108     mVel(1,1) =  0.0;
109     mVel(1,2) = -vUVW(eW);
110     mVel(1,3) =  vUVW(eV);
111     mVel(2,1) =  vUVW(eW);
112     mVel(2,2) =  0.0;
113     mVel(2,3) = -vUVW(eU);
114     mVel(3,1) = -vUVW(eV);
115     mVel(3,2) =  vUVW(eU);
116     mVel(3,3) =  0.0;
117
118     vUVWdot = mVel*vPQR + vForces/Mass;
119     
120     vNcg=vUVWdot*INVGRAVITY;
121
122     vUVW += 0.5*dt*rate*(vlastUVWdot + vUVWdot) + vWindUVW;
123     
124     Vt = vUVW.Magnitude();
125
126     if (vUVW(eW) != 0.0)
127       alpha = vUVW(eU)*vUVW(eU) > 0.0 ? atan2(vUVW(eW), vUVW(eU)) : 0.0;
128     if (vUVW(eV) != 0.0)
129       beta = vUVW(eU)*vUVW(eU)+vUVW(eW)*vUVW(eW) > 0.0 ? atan2(vUVW(eV),
130              sqrt(vUVW(eU)*vUVW(eU) + vUVW(eW)*vUVW(eW))) : 0.0;
131     
132      
133         
134           // stolen, quite shamelessly, from LaRCsim
135     float mUW = (vUVW(eU)*vUVW(eU) + vUVW(eW)*vUVW(eW));
136     float signU=1;
137     if (vUVW(eU) != 0.0)
138                   signU = vUVW(eU)/fabs(vUVW(eU));
139
140           if( (mUW == 0.0) || (Vt == 0.0) ) {
141                   adot = 0.0;
142                   bdot = 0.0;
143           } else {
144                   adot = (vUVW(eU)*vUVWdot(eW) - vUVW(eW)*vUVWdot(eU))/mUW;
145                   bdot = (signU*mUW*vUVWdot(eV) - vUVW(eV)*(vUVW(eU)*vUVWdot(eU) 
146               + vUVW(eW)*vUVWdot(eW)))/(Vt*Vt*sqrt(mUW));
147           }
148     //
149     
150     qbar = 0.5*rho*Vt*Vt;
151
152     Mach = Vt / State->Geta();
153
154     vlastUVWdot = vUVWdot;
155
156   } else {}
157
158   return false;
159 }
160
161 /******************************************************************************/
162
163 void FGTranslation::GetState(void) {
164   dt = State->Getdt();
165
166   vPQR = Rotation->GetPQR();
167   vForces = Aircraft->GetForces();
168
169   Mass = Aircraft->GetMass();
170   rho = Atmosphere->GetDensity();
171
172   vEuler = Rotation->GetEuler();
173
174   vWindUVW = Atmosphere->GetWindUVW();
175 }
176