1 /*******************************************************************************
6 Purpose: Integrate the EOM to determine instantaneous position
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This class encapsulates the integration of rates and accelerations to get the
31 current position of the aircraft.
34 --------------------------------------------------------------------------------
37 ********************************************************************************
38 COMMENTS, REFERENCES, and NOTES
39 ********************************************************************************
40 [1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
41 Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
43 [2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
45 [3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
46 NASA-Ames", NASA CR-2497, January 1975
47 [4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
48 Wiley & Sons, 1979 ISBN 0-471-03032-5
49 [5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
50 1982 ISBN 0-471-08936-2
52 ********************************************************************************
54 *******************************************************************************/
57 #include "FGPosition.h"
58 #include "FGAtmosphere.h"
60 #include "FGFDMExec.h"
62 #include "FGAircraft.h"
63 #include "FGTranslation.h"
64 #include "FGRotation.h"
65 #include "FGAuxiliary.h"
68 /*******************************************************************************
69 ************************************ CODE **************************************
70 *******************************************************************************/
73 FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex)
75 strcpy(Name, "FGPosition");
76 AccelN = AccelE = AccelD = 0.0;
77 LongitudeDot = LatitudeDot = RadiusDot = 0.0;
81 FGPosition::~FGPosition(void)
86 bool FGPosition:: Run(void)
90 if (!FGModel::Run()) {
92 T[1][1] = Q0*Q0 + Q1*Q1 - Q2*Q2 - Q3*Q3; // Page A-11
93 T[1][2] = 2*(Q1*Q2 + Q0*Q3); // From
94 T[1][3] = 2*(Q1*Q3 - Q0*Q2); // Reference [2]
95 T[2][1] = 2*(Q1*Q2 - Q0*Q3);
96 T[2][2] = Q0*Q0 - Q1*Q1 + Q2*Q2 - Q3*Q3;
97 T[2][3] = 2*(Q2*Q3 + Q0*Q1);
98 T[3][1] = 2*(Q1*Q3 + Q0*Q2);
99 T[3][2] = 2*(Q2*Q3 - Q0*Q1);
100 T[3][3] = Q0*Q0 - Q1*Q1 - Q2*Q2 + Q3*Q3;
102 Fn = T[1][1]*Fx + T[2][1]*Fy + T[3][1]*Fz; // Eqn. 3.5
103 Fe = T[1][2]*Fx + T[2][2]*Fy + T[3][2]*Fz; // From
104 Fd = T[1][3]*Fx + T[2][3]*Fy + T[3][3]*Fz; // Reference [3]
106 tanLat = tan(Latitude); // I made this up
107 cosLat = cos(Latitude);
113 Vn = T[1][1]*U + T[2][1]*V + T[3][1]*W;
114 Ve = T[1][2]*U + T[2][2]*V + T[3][2]*W;
115 Vd = T[1][3]*U + T[2][3]*V + T[3][3]*W;
117 AccelN = invMass * Fn + invRadius * (Vn*Vd - Ve*Ve*tanLat); // Eqn. 3.6
118 AccelE = invMass * Fe + invRadius * (Ve*Vd + Vn*Ve*tanLat); // From
119 AccelD = invMass * Fd - invRadius * (Vn*Vn + Ve*Ve); // Reference [3]
121 Vn += 0.5*dt*rate*(3.0*AccelN - lastAccelN); // Eqn. 3.7
122 Ve += 0.5*dt*rate*(3.0*AccelE - lastAccelE); // From
123 Vd += 0.5*dt*rate*(3.0*AccelD - lastAccelD); // Reference [3]
125 Vee = Ve - OMEGAEARTH * (Radius) * cosLat; // From Eq. 3.8
127 lastLatitudeDot = LatitudeDot;
128 lastLongitudeDot = LongitudeDot;
129 lastRadiusDot = RadiusDot;
131 if (cosLat != 0) LongitudeDot = Ve / (Radius * cosLat);
132 LatitudeDot = Vn * invRadius;
135 Longitude += 0.5*dt*rate*(LongitudeDot + lastLongitudeDot);
136 Latitude += 0.5*dt*rate*(LatitudeDot + lastLatitudeDot);
137 Radius += 0.5*dt*rate*(RadiusDot + lastRadiusDot);
147 void FGPosition::GetState(void)
151 Q0 = Rotation->GetQ0();
152 Q1 = Rotation->GetQ1();
153 Q2 = Rotation->GetQ2();
154 Q3 = Rotation->GetQ3();
156 Fx = Aircraft->GetFx();
157 Fy = Aircraft->GetFy();
158 Fz = Aircraft->GetFz();
160 U = Translation->GetU();
161 V = Translation->GetV();
162 W = Translation->GetW();
164 Latitude = State->Getlatitude();
165 Longitude = State->Getlongitude();
167 invMass = 1.0 / Aircraft->GetMass();
168 invRadius = 1.0 / (State->Geth() + EARTHRAD);
169 Radius = State->Geth() + EARTHRAD;
173 void FGPosition::PutState(void)
175 State->Setlatitude(Latitude);
176 State->Setlongitude(Longitude);
177 State->Seth(Radius - EARTHRAD);