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 <simgear/compiler.h>
58 # ifdef FG_HAVE_STD_INCLUDES
67 #include "FGPosition.h"
68 #include "FGAtmosphere.h"
70 #include "FGFDMExec.h"
72 #include "FGAircraft.h"
73 #include "FGTranslation.h"
74 #include "FGRotation.h"
75 #include "FGAuxiliary.h"
78 /*******************************************************************************
79 ************************************ CODE **************************************
80 *******************************************************************************/
82 extern float globalTriNormal[3];
83 extern double globalSceneryAltitude;
84 extern double globalSeaLevelRadius;
86 FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex),
91 LongitudeDot = LatitudeDot = RadiusDot = 0.0;
92 lastLongitudeDot = lastLatitudeDot = lastRadiusDot = 0.0;
93 Longitude = Latitude = 0.0;
95 Radius = EARTHRAD + h;
97 RunwayRadius = EARTHRAD;
100 /******************************************************************************/
102 FGPosition::~FGPosition(void) {}
104 /******************************************************************************/
106 bool FGPosition:: Run(void) {
110 if (!FGModel::Run()) {
113 vVel = State->GetTl2b()*vUVW;
115 cosLat = cos(Latitude);
116 if (cosLat != 0) LongitudeDot = vVel(eEast) / (Radius * cosLat);
118 LatitudeDot = vVel(eNorth) * invRadius;
119 RadiusDot = -vVel(eDown);
121 Longitude += 0.5*dt*rate*(LongitudeDot + lastLongitudeDot);
122 Latitude += 0.5*dt*rate*(LatitudeDot + lastLatitudeDot);
123 Radius += 0.5*dt*rate*(RadiusDot + lastRadiusDot);
125 h = Radius - EARTHRAD; // Geocentric
127 DistanceAGL = Radius - RunwayRadius; // Geocentric
132 hdot_Vt=RadiusDot/Vt;
133 //make sure that -Vt <= hdot <= Vt, which, of course, should always be the case
134 if(fabs(hdot_Vt) <= 1) gamma= asin(hdot_Vt);
138 lastLatitudeDot = LatitudeDot;
139 lastLongitudeDot = LongitudeDot;
140 lastRadiusDot = RadiusDot;
149 /******************************************************************************/
151 void FGPosition::GetState(void) {
154 vUVW = Translation->GetUVW();
155 Vt = Translation->GetVt();
156 invMass = 1.0 / Aircraft->GetMass();
157 invRadius = 1.0 / (h + EARTHRAD);
158 Radius = h + EARTHRAD;
159 b = Aircraft->GetWingSpan();