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)
101 LongitudeDot = LatitudeDot = RadiusDot = 0.0;
102 lastLongitudeDot = lastLatitudeDot = lastRadiusDot = 0.0;
103 Longitude = Latitude = 0.0;
104 gamma = Vt = Vground = 0.0;
105 hoverbmac = hoverbcg = 0.0;
111 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 FGPosition::~FGPosition(void)
118 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 bool FGPosition::InitModel(void)
122 FGModel::InitModel();
124 h = 3.0; // Est. height of aircraft cg off runway
125 SeaLevelRadius = Inertial->RefRadius(); // For initialization ONLY
126 Radius = SeaLevelRadius + h;
127 RunwayRadius = SeaLevelRadius;
128 DistanceAGL = Radius - RunwayRadius; // Geocentric
129 vRunwayNormal(3) = -1.0; // Initialized for standalone mode
134 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 Purpose: Called on a schedule to perform Positioning algorithms
137 Notes: [TP] Make sure that -Vt <= hdot <= Vt, which, of course, should always
139 [JB] Run in standalone mode, SeaLevelRadius will be reference radius.
140 In FGFS, SeaLevelRadius is stuffed from FGJSBSim in JSBSim.cxx each pass.
143 bool FGPosition::Run(void) {
146 FGColumnVector3 vMac;
148 if (!FGModel::Run()) {
151 Vground = sqrt( vVel(eNorth)*vVel(eNorth) + vVel(eEast)*vVel(eEast) );
152 psigt = atan2(vVel(eEast), vVel(eNorth));
156 Radius = h + SeaLevelRadius;
158 cosLat = cos(Latitude);
159 if (cosLat != 0) LongitudeDot = vVel(eEast) / (Radius * cosLat);
161 LatitudeDot = vVel(eNorth) / Radius;
162 RadiusDot = -vVel(eDown);
164 Longitude += 0.5*dt*rate*(LongitudeDot + lastLongitudeDot);
165 Latitude += 0.5*dt*rate*(LatitudeDot + lastLatitudeDot);
166 Radius += 0.5*dt*rate*(RadiusDot + lastRadiusDot);
168 h = Radius - SeaLevelRadius; // Geocentric
170 DistanceAGL = Radius - RunwayRadius; // Geocentric
173 hoverbcg = DistanceAGL/b;
175 vMac=State->GetTb2l()*Aircraft->GetXYZrp();
178 hoverbmac = (DistanceAGL + vMac(3))/b;
181 hdot_Vt = RadiusDot/Vt;
182 if (fabs(hdot_Vt) <= 1) gamma = asin(hdot_Vt);
187 lastLatitudeDot = LatitudeDot;
188 lastLongitudeDot = LongitudeDot;
189 lastRadiusDot = RadiusDot;
198 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200 void FGPosition::GetState(void) {
203 Vt = Translation->GetVt();
204 vVel = State->GetTb2l() * Translation->GetUVW();
205 vVelDot = State->GetTb2l() * Translation->GetUVWdot();
207 b = Aircraft->GetWingSpan();
210 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 void FGPosition::Seth(double tt) {
214 Radius = h + SeaLevelRadius;
215 DistanceAGL = Radius - RunwayRadius; // Geocentric
216 hoverbcg = DistanceAGL/b;
219 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 void FGPosition::SetDistanceAGL(double tt) {
223 Radius = RunwayRadius + DistanceAGL;
224 h = Radius - SeaLevelRadius;
225 hoverbcg = DistanceAGL/b;
228 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229 // The bitmasked value choices are as follows:
230 // unset: In this case (the default) JSBSim would only print
231 // out the normally expected messages, essentially echoing
232 // the config files as they are read. If the environment
233 // variable is not set, debug_lvl is set to 1 internally
234 // 0: This requests JSBSim not to output any messages
236 // 1: This value explicity requests the normal JSBSim
238 // 2: This value asks for a message to be printed out when
239 // a class is instantiated
240 // 4: When this value is set, a message is displayed when a
241 // FGModel object executes its Run() method
242 // 8: When this value is set, various runtime state variables
243 // are printed out periodically
244 // 16: When set various parameters are sanity checked and
245 // a message is printed out when they go out of bounds
247 void FGPosition::Debug(int from)
249 if (debug_lvl <= 0) return;
251 if (debug_lvl & 1) { // Standard console startup message output
252 if (from == 0) { // Constructor
256 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
257 if (from == 0) cout << "Instantiated: FGPosition" << endl;
258 if (from == 1) cout << "Destroyed: FGPosition" << endl;
260 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
262 if (debug_lvl & 8 ) { // Runtime state variables
264 if (debug_lvl & 16) { // Sanity checking