]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBsim/FGRotation.cpp
source tree reorganization prior to flightgear 0.7
[flightgear.git] / src / FDM / JSBsim / FGRotation.cpp
1 /*******************************************************************************
2
3  Module:       FGRotation.cpp
4  Author:       Jon Berndt
5  Date started: 12/02/98
6  Purpose:      Integrates the rotational EOM
7  Called by:    FGFDMExec
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 rotational 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 "FGRotation.h"
59 #include "FGAtmosphere.h"
60 #include "FGState.h"
61 #include "FGFDMExec.h"
62 #include "FGFCS.h"
63 #include "FGAircraft.h"
64 #include "FGTranslation.h"
65 #include "FGPosition.h"
66 #include "FGAuxiliary.h"
67 #include "FGOutput.h"
68
69 /*******************************************************************************
70 ************************************ CODE **************************************
71 *******************************************************************************/
72
73
74 FGRotation::FGRotation(FGFDMExec* fdmex) : FGModel(fdmex)
75 {
76   Name = "FGRotation";
77   Q0dot = Q1dot = Q2dot = Q3dot = 0.0;
78   Pdot = Qdot = Rdot = 0.0;
79 }
80
81
82 FGRotation::~FGRotation(void)
83 {
84 }
85
86
87 bool FGRotation::Run(void)
88 {
89   float L2, N1, iQtot, sum;
90
91   if (!FGModel::Run()) {
92     GetState();
93
94     lastPdot = Pdot;
95     lastQdot = Qdot;
96     lastRdot = Rdot;
97
98     L2 = L + Ixz*P*Q - (Izz-Iyy)*R*Q;
99     N1 = N - (Iyy-Ixx)*P*Q - Ixz*R*Q;
100
101     Pdot = (L2*Izz - N1*Ixz) / (Ixx*Izz - Ixz*Ixz);
102     Qdot = (M - (Ixx-Izz)*P*R - Ixz*(P*P - R*R))/Iyy;
103     Rdot = (N1*Ixx + L2*Ixz) / (Ixx*Izz - Ixz*Ixz);
104
105     P += dt*rate*(lastPdot + Pdot)/2.0;
106     Q += dt*rate*(lastQdot + Qdot)/2.0;
107     R += dt*rate*(lastRdot + Rdot)/2.0;
108
109     lastQ0dot = Q0dot;
110     lastQ1dot = Q1dot;
111     lastQ2dot = Q2dot;
112     lastQ3dot = Q3dot;
113
114     Q0dot = -0.5*(Q1*P + Q2*Q + Q3*R);
115     Q1dot =  0.5*(Q0*P + Q2*R - Q3*Q);
116     Q2dot =  0.5*(Q0*Q + Q3*P - Q1*R);
117     Q3dot =  0.5*(Q0*R + Q1*Q - Q2*P);
118
119     Q0 += 0.5*dt*rate*(lastQ0dot + Q0dot);
120     Q1 += 0.5*dt*rate*(lastQ1dot + Q1dot);
121     Q2 += 0.5*dt*rate*(lastQ2dot + Q2dot);
122     Q3 += 0.5*dt*rate*(lastQ3dot + Q3dot);
123
124     sum = Q0*Q0 + Q1*Q1 + Q2*Q2 + Q3*Q3;
125
126     iQtot = 1.0 / sqrt(sum);
127
128     Q0 *= iQtot;
129     Q1 *= iQtot;
130     Q2 *= iQtot;
131     Q3 *= iQtot;
132
133     if (T[3][3] == 0)
134       phi = 0.0;
135     else
136       phi = atan2(T[2][3], T[3][3]);
137
138     tht = asin(-T[1][3]);
139
140     if (T[1][1] == 0.0)
141       psi = 0.0;
142     else
143       psi = atan2(T[1][2], T[1][1]);
144
145     if (psi < 0.0) psi += 2*M_PI;
146
147     PutState();
148   } else {
149   }
150   return false;
151 }
152
153
154 void FGRotation::GetState(void)
155 {
156   dt = State->Getdt();
157
158   L = Aircraft->GetL();
159   M = Aircraft->GetM();
160   N = Aircraft->GetN();
161
162   Ixx = Aircraft->GetIxx();
163   Iyy = Aircraft->GetIyy();
164   Izz = Aircraft->GetIzz();
165   Ixz = Aircraft->GetIxz();
166
167   for (int r=1;r<=3;r++)
168     for (int c=1;c<=3;c++)
169       T[r][c] = Position->GetT(r,c);
170 }
171
172
173 void FGRotation::PutState(void)
174 {
175 }
176