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
70 #include "FGPosition.h"
71 #include "FGAtmosphere.h"
73 #include "FGFDMExec.h"
75 #include "FGAircraft.h"
76 #include "FGTranslation.h"
77 #include "FGRotation.h"
78 #include "FGAuxiliary.h"
81 /*******************************************************************************
82 ************************************ CODE **************************************
83 *******************************************************************************/
85 extern float globalTriNormal[3];
86 extern double globalSceneryAltitude;
87 extern double globalSeaLevelRadius;
89 FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex),
94 LongitudeDot = LatitudeDot = RadiusDot = 0.0;
95 lastLongitudeDot = lastLatitudeDot = lastRadiusDot = 0.0;
96 Longitude = Latitude = 0.0;
98 h = 3.0; // Est. height of aircraft cg off runway
99 SeaLevelRadius = EARTHRAD; // For initialization ONLY
100 Radius = SeaLevelRadius + h;
101 RunwayRadius = SeaLevelRadius;
102 DistanceAGL = Radius - RunwayRadius; // Geocentric
105 /******************************************************************************/
107 FGPosition::~FGPosition(void) {}
109 /*************************************************************************** Run
110 Purpose: Called on a schedule to perform Positioning algorithms
111 Notes: [TP] Make sure that -Vt <= hdot <= Vt, which, of course, should always
113 [JB] Run in standalone mode, SeaLevelRadius will be EARTHRAD. In FGFS,
114 SeaLevelRadius is stuffed from FGJSBSim in JSBSim.cxx each pass.
117 bool FGPosition:: Run(void) {
121 if (!FGModel::Run()) {
124 invMass = 1.0 / Aircraft->GetMass();
125 Radius = h + SeaLevelRadius;
126 invRadius = 1.0 / Radius;
128 cosLat = cos(Latitude);
129 if (cosLat != 0) LongitudeDot = vVel(eEast) / (Radius * cosLat);
131 LatitudeDot = vVel(eNorth) * invRadius;
132 RadiusDot = -vVel(eDown);
134 Longitude += 0.5*dt*rate*(LongitudeDot + lastLongitudeDot);
135 Latitude += 0.5*dt*rate*(LatitudeDot + lastLatitudeDot);
136 Radius += 0.5*dt*rate*(RadiusDot + lastRadiusDot);
138 h = Radius - SeaLevelRadius; // Geocentric
140 DistanceAGL = Radius - RunwayRadius; // Geocentric
142 hoverb = DistanceAGL/b;
145 hdot_Vt = RadiusDot/Vt;
146 if (fabs(hdot_Vt) <= 1) gamma = asin(hdot_Vt);
151 lastLatitudeDot = LatitudeDot;
152 lastLongitudeDot = LongitudeDot;
153 lastRadiusDot = RadiusDot;
162 /******************************************************************************/
164 void FGPosition::GetState(void) {
167 vUVW = Translation->GetUVW();
168 Vt = Translation->GetVt();
169 vVel = State->GetTb2l()*vUVW;
171 b = Aircraft->GetWingSpan();