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"
86 #include "FGPropertyManager.h"
89 static const char *IdSrc = "$Id$";
90 static const char *IdHdr = ID_POSITION;
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
96 extern double globalTriNormal[3];
97 extern double globalSceneryAltitude;
98 extern double globalSeaLevelRadius;
100 FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex)
103 LongitudeDot = LatitudeDot = RadiusDot = 0.0;
104 lastLongitudeDot = lastLatitudeDot = lastRadiusDot = 0.0;
105 Longitude = Latitude = 0.0;
106 gamma = Vt = Vground = 0.0;
107 hoverbmac = hoverbcg = 0.0;
113 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 FGPosition::~FGPosition(void)
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 bool FGPosition::InitModel(void)
125 FGModel::InitModel();
127 h = 3.0; // Est. height of aircraft cg off runway
128 SeaLevelRadius = Inertial->RefRadius(); // For initialization ONLY
129 Radius = SeaLevelRadius + h;
130 RunwayRadius = SeaLevelRadius;
131 DistanceAGL = Radius - RunwayRadius; // Geocentric
132 vRunwayNormal(3) = -1.0; // Initialized for standalone mode
137 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 Purpose: Called on a schedule to perform Positioning algorithms
140 Notes: [TP] Make sure that -Vt <= hdot <= Vt, which, of course, should always
142 [JB] Run in standalone mode, SeaLevelRadius will be reference radius.
143 In FGFS, SeaLevelRadius is stuffed from FGJSBSim in JSBSim.cxx each pass.
146 bool FGPosition::Run(void) {
149 FGColumnVector3 vMac;
151 if (!FGModel::Run()) {
154 Vground = sqrt( vVel(eNorth)*vVel(eNorth) + vVel(eEast)*vVel(eEast) );
155 psigt = atan2(vVel(eEast), vVel(eNorth));
159 Radius = h + SeaLevelRadius;
161 cosLat = cos(Latitude);
162 if (cosLat != 0) LongitudeDot = vVel(eEast) / (Radius * cosLat);
164 LatitudeDot = vVel(eNorth) / Radius;
165 RadiusDot = -vVel(eDown);
167 Longitude += 0.5*dt*rate*(LongitudeDot + lastLongitudeDot);
168 Latitude += 0.5*dt*rate*(LatitudeDot + lastLatitudeDot);
169 Radius += 0.5*dt*rate*(RadiusDot + lastRadiusDot);
171 h = Radius - SeaLevelRadius; // Geocentric
173 DistanceAGL = Radius - RunwayRadius; // Geocentric
176 hoverbcg = DistanceAGL/b;
178 vMac=State->GetTb2l()*Aircraft->GetXYZrp();
181 hoverbmac = (DistanceAGL + vMac(3))/b;
184 hdot_Vt = RadiusDot/Vt;
185 if (fabs(hdot_Vt) <= 1) gamma = asin(hdot_Vt);
190 lastLatitudeDot = LatitudeDot;
191 lastLongitudeDot = LongitudeDot;
192 lastRadiusDot = RadiusDot;
201 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 void FGPosition::GetState(void) {
206 Vt = Translation->GetVt();
207 vVel = State->GetTb2l() * Translation->GetUVW();
208 vVelDot = State->GetTb2l() * Translation->GetUVWdot();
210 b = Aircraft->GetWingSpan();
213 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215 void FGPosition::Seth(double tt) {
217 Radius = h + SeaLevelRadius;
218 DistanceAGL = Radius - RunwayRadius; // Geocentric
219 hoverbcg = DistanceAGL/b;
222 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 void FGPosition::SetDistanceAGL(double tt) {
226 Radius = RunwayRadius + DistanceAGL;
227 h = Radius - SeaLevelRadius;
228 hoverbcg = DistanceAGL/b;
231 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 void FGPosition::bind(void)
235 PropertyManager->Tie("velocities/v-north-fps", this,
237 PropertyManager->Tie("velocities/v-east-fps", this,
239 PropertyManager->Tie("velocities/v-down-fps", this,
241 PropertyManager->Tie("velocities/vg-fps", this,
242 &FGPosition::GetVground);
243 PropertyManager->Tie("flight-path/psi-gt-rad", this,
244 &FGPosition::GetGroundTrack);
245 PropertyManager->Tie("position/h-sl-ft", this,
249 PropertyManager->Tie("velocities/h-dot-fps", this,
250 &FGPosition::Gethdot);
251 PropertyManager->Tie("position/lat-gc-rad", this,
252 &FGPosition::GetLatitude,
253 &FGPosition::SetLatitude);
254 PropertyManager->Tie("position/lat-dot-gc-rad", this,
255 &FGPosition::GetLatitudeDot);
256 PropertyManager->Tie("position/long-gc-rad", this,
257 &FGPosition::GetLongitude,
258 &FGPosition::SetLongitude,
260 PropertyManager->Tie("position/long-dot-gc-rad", this,
261 &FGPosition::GetLongitudeDot);
262 PropertyManager->Tie("metrics/runway-radius", this,
263 &FGPosition::GetRunwayRadius,
264 &FGPosition::SetRunwayRadius);
265 PropertyManager->Tie("position/h-agl-ft", this,
266 &FGPosition::GetDistanceAGL,
267 &FGPosition::SetDistanceAGL);
268 PropertyManager->Tie("position/radius-to-vehicle-ft", this,
269 &FGPosition::GetRadius);
270 PropertyManager->Tie("flight-path/gamma-rad", this,
271 &FGPosition::GetGamma,
272 &FGPosition::SetGamma);
273 PropertyManager->Tie("aero/h_b-cg-ft", this,
274 &FGPosition::GetHOverBCG);
275 PropertyManager->Tie("aero/h_b-mac-ft", this,
276 &FGPosition::GetHOverBMAC);
279 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
281 void FGPosition::unbind(void)
283 PropertyManager->Untie("velocities/v-north-fps");
284 PropertyManager->Untie("velocities/v-east-fps");
285 PropertyManager->Untie("velocities/v-down-fps");
286 PropertyManager->Untie("velocities/vg-fps");
287 PropertyManager->Untie("flight-path/psi-gt-rad");
288 PropertyManager->Untie("position/h-sl-ft");
289 PropertyManager->Untie("velocities/h-dot-fps");
290 PropertyManager->Untie("position/lat-gc-rad");
291 PropertyManager->Untie("position/lat-dot-gc-rad");
292 PropertyManager->Untie("position/long-gc-rad");
293 PropertyManager->Untie("position/long-dot-gc-rad");
294 PropertyManager->Untie("metrics/runway-radius");
295 PropertyManager->Untie("position/h-agl-ft");
296 PropertyManager->Untie("position/radius-to-vehicle-ft");
297 PropertyManager->Untie("flight-path/gamma-rad");
298 PropertyManager->Untie("aero/h_b-cg-ft");
299 PropertyManager->Untie("aero/h_b-mac-ft");
302 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 // The bitmasked value choices are as follows:
304 // unset: In this case (the default) JSBSim would only print
305 // out the normally expected messages, essentially echoing
306 // the config files as they are read. If the environment
307 // variable is not set, debug_lvl is set to 1 internally
308 // 0: This requests JSBSim not to output any messages
310 // 1: This value explicity requests the normal JSBSim
312 // 2: This value asks for a message to be printed out when
313 // a class is instantiated
314 // 4: When this value is set, a message is displayed when a
315 // FGModel object executes its Run() method
316 // 8: When this value is set, various runtime state variables
317 // are printed out periodically
318 // 16: When set various parameters are sanity checked and
319 // a message is printed out when they go out of bounds
321 void FGPosition::Debug(int from)
323 if (debug_lvl <= 0) return;
325 if (debug_lvl & 1) { // Standard console startup message output
326 if (from == 0) { // Constructor
330 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
331 if (from == 0) cout << "Instantiated: FGPosition" << endl;
332 if (from == 1) cout << "Destroyed: FGPosition" << endl;
334 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
336 if (debug_lvl & 8 ) { // Runtime state variables
338 if (debug_lvl & 16) { // Sanity checking
340 if (debug_lvl & 64) {
341 if (from == 0) { // Constructor
342 cout << IdSrc << endl;
343 cout << IdHdr << endl;