]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBsim/FGTranslation.cpp
source tree reorganization prior to flightgear 0.7
[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
36 ********************************************************************************
37 COMMENTS, REFERENCES,  and NOTES
38 ********************************************************************************
39 [1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
40     Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420  Naval Postgraduate
41     School, January 1994
42 [2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
43     JSC 12960, July 1977
44 [3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
45     NASA-Ames", NASA CR-2497, January 1975
46 [4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
47     Wiley & Sons, 1979 ISBN 0-471-03032-5
48 [5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
49     1982 ISBN 0-471-08936-2
50
51   The order of rotations used in this class corresponds to a 3-2-1 sequence,
52   or Y-P-R, or Z-Y-X, if you prefer.
53
54 ********************************************************************************
55 INCLUDES
56 *******************************************************************************/
57
58 #include "FGTranslation.h"
59 #include "FGRotation.h"
60 #include "FGAtmosphere.h"
61 #include "FGState.h"
62 #include "FGFDMExec.h"
63 #include "FGFCS.h"
64 #include "FGAircraft.h"
65 #include "FGPosition.h"
66 #include "FGAuxiliary.h"
67 #include "FGOutput.h"
68
69 /*******************************************************************************
70 ************************************ CODE **************************************
71 *******************************************************************************/
72
73
74 FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex)
75 {
76   Name = "FGTranslation";
77   Udot = Vdot = Wdot = 0.0;
78 }
79
80
81 FGTranslation::~FGTranslation(void)
82 {
83 }
84
85
86 bool FGTranslation::Run(void)
87 {
88   if (!FGModel::Run()) {
89
90     GetState();
91
92     lastUdot = Udot;
93     lastVdot = Vdot;
94     lastWdot = Wdot;
95
96     Udot = V*R - W*Q + Fx/Mass;
97     Vdot = W*P - U*R + Fy/Mass;
98     Wdot = U*Q - V*P + Fz/Mass;
99
100     U += 0.5*dt*rate*(lastUdot + Udot);
101     V += 0.5*dt*rate*(lastVdot + Vdot);
102     W += 0.5*dt*rate*(lastWdot + Wdot);
103
104     Vt = U*U+V*V+W*W > 0.0 ? sqrt(U*U + V*V + W*W) : 0.0;
105
106     if (W != 0.0)
107       alpha = U*U > 0.0 ? atan2(W, U) : 0.0;
108     if (V != 0.0)
109       beta = U*U+W*W > 0.0 ? atan2(V, (fabs(U)/U)*sqrt(U*U + W*W)) : 0.0;
110
111     qbar = 0.5*rho*Vt*Vt;
112
113     PutState();
114   } else {
115   }
116   return false;
117 }
118
119
120 void FGTranslation::GetState(void)
121 {
122   dt = State->Getdt();
123
124   P = Rotation->GetP();
125   Q = Rotation->GetQ();
126   R = Rotation->GetR();
127
128   Fx = Aircraft->GetFx();
129   Fy = Aircraft->GetFy();
130   Fz = Aircraft->GetFz();
131
132   Mass = Aircraft->GetMass();
133   rho = Atmosphere->Getrho();
134
135   phi = Rotation->Getphi();
136   tht = Rotation->Gettht();
137   psi = Rotation->Getpsi();
138 }
139
140
141 void FGTranslation::PutState(void)
142 {
143   State->SetVt(Vt);
144   State->Setqbar(qbar);
145 }
146