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 SG_HAVE_STD_INCLUDES
66 # if defined(sgi) && !defined(__GNUC__)
75 #include "FGPosition.h"
76 #include "FGAtmosphere.h"
78 #include "FGFDMExec.h"
80 #include "FGAircraft.h"
81 #include "FGMassBalance.h"
82 #include "FGTranslation.h"
83 #include "FGRotation.h"
84 #include "FGAuxiliary.h"
87 static const char *IdSrc = "$Id$";
88 static const char *IdHdr = ID_POSITION;
90 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
94 extern double globalTriNormal[3];
95 extern double globalSceneryAltitude;
96 extern double globalSeaLevelRadius;
98 FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex),
104 LongitudeDot = LatitudeDot = RadiusDot = 0.0;
105 lastLongitudeDot = lastLatitudeDot = lastRadiusDot = 0.0;
106 Longitude = Latitude = 0.0;
107 gamma = Vt = Vground = 0.0;
109 if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 FGPosition::~FGPosition()
116 if (debug_lvl & 2) cout << "Destroyed: FGPosition" << endl;
119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 bool FGPosition::InitModel(void)
123 FGModel::InitModel();
125 h = 3.0; // Est. height of aircraft cg off runway
126 SeaLevelRadius = Inertial->RefRadius(); // For initialization ONLY
127 Radius = SeaLevelRadius + h;
128 RunwayRadius = SeaLevelRadius;
129 DistanceAGL = Radius - RunwayRadius; // Geocentric
130 vRunwayNormal(3) = -1.0; // Initialized for standalone mode
135 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 Purpose: Called on a schedule to perform Positioning algorithms
138 Notes: [TP] Make sure that -Vt <= hdot <= Vt, which, of course, should always
140 [JB] Run in standalone mode, SeaLevelRadius will be reference radius.
141 In FGFS, SeaLevelRadius is stuffed from FGJSBSim in JSBSim.cxx each pass.
144 bool FGPosition::Run(void) {
148 if (!FGModel::Run()) {
151 Vground = sqrt( vVel(eNorth)*vVel(eNorth) + vVel(eEast)*vVel(eEast) );
152 psigt = atan2(vVel(eEast), vVel(eNorth));
156 invMass = 1.0 / MassBalance->GetMass();
157 Radius = h + SeaLevelRadius;
158 invRadius = 1.0 / Radius;
160 cosLat = cos(Latitude);
161 if (cosLat != 0) LongitudeDot = vVel(eEast) / (Radius * cosLat);
163 LatitudeDot = vVel(eNorth) * invRadius;
164 RadiusDot = -vVel(eDown);
166 Longitude += 0.5*dt*rate*(LongitudeDot + lastLongitudeDot);
167 Latitude += 0.5*dt*rate*(LatitudeDot + lastLatitudeDot);
168 Radius += 0.5*dt*rate*(RadiusDot + lastRadiusDot);
170 h = Radius - SeaLevelRadius; // Geocentric
172 DistanceAGL = Radius - RunwayRadius; // Geocentric
174 hoverb = DistanceAGL/b;
177 hdot_Vt = RadiusDot/Vt;
178 if (fabs(hdot_Vt) <= 1) gamma = asin(hdot_Vt);
183 lastLatitudeDot = LatitudeDot;
184 lastLongitudeDot = LongitudeDot;
185 lastRadiusDot = RadiusDot;
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 void FGPosition::GetState(void) {
199 Vt = Translation->GetVt();
200 vVel = State->GetTb2l() * Translation->GetUVW();
201 vVelDot = State->GetTb2l() * Translation->GetUVWdot();
203 b = Aircraft->GetWingSpan();
206 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 void FGPosition::Seth(double tt) {
210 Radius = h + SeaLevelRadius;
211 DistanceAGL = Radius - RunwayRadius; // Geocentric
212 hoverb = DistanceAGL/b;
215 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 void FGPosition::SetDistanceAGL(double tt) {
219 Radius = RunwayRadius + DistanceAGL;
220 h = Radius - SeaLevelRadius;
221 hoverb = DistanceAGL/b;
224 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 void FGPosition::Debug(void)
228 //TODO: Add your source code here