1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
3 Module: FGPosition.cpp
\r
4 Author: Jon S. Berndt
\r
5 Date started: 01/05/99
\r
6 Purpose: Integrate the EOM to determine instantaneous position
\r
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
\r
11 This program is free software; you can redistribute it and/or modify it under
\r
12 the terms of the GNU General Public License as published by the Free Software
\r
13 Foundation; either version 2 of the License, or (at your option) any later
\r
16 This program is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
21 You should have received a copy of the GNU General Public License along with
\r
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
\r
23 Place - Suite 330, Boston, MA 02111-1307, USA.
\r
25 Further information about the GNU General Public License can also be found on
\r
26 the world wide web at http://www.gnu.org.
\r
28 FUNCTIONAL DESCRIPTION
\r
29 --------------------------------------------------------------------------------
\r
30 This class encapsulates the integration of rates and accelerations to get the
\r
31 current position of the aircraft.
\r
34 --------------------------------------------------------------------------------
\r
35 01/05/99 JSB Created
\r
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
38 COMMENTS, REFERENCES, and NOTES
\r
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
40 [1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
\r
41 Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
\r
42 School, January 1994
\r
43 [2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
\r
44 JSC 12960, July 1977
\r
45 [3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
\r
46 NASA-Ames", NASA CR-2497, January 1975
\r
47 [4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
\r
48 Wiley & Sons, 1979 ISBN 0-471-03032-5
\r
49 [5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
\r
50 1982 ISBN 0-471-08936-2
\r
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
57 # include <simgear/compiler.h>
\r
58 # ifdef SG_HAVE_STD_INCLUDES
\r
63 # include <iomanip.h>
\r
66 # if defined(sgi) && !defined(__GNUC__)
\r
68 # if (_COMPILER_VERSION < 740)
\r
69 # include <iomanip.h>
\r
79 #include "FGPosition.h"
\r
80 #include "FGState.h"
\r
81 #include "FGFDMExec.h"
\r
82 #include "FGAircraft.h"
\r
83 #include "FGMassBalance.h"
\r
84 #include "FGTranslation.h"
\r
85 #include "FGRotation.h"
\r
86 #include "FGInertial.h"
\r
87 #include "FGPropertyManager.h"
\r
91 static const char *IdSrc = "$Id$";
\r
92 static const char *IdHdr = ID_POSITION;
\r
94 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
95 CLASS IMPLEMENTATION
\r
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
98 FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex)
\r
100 Name = "FGPosition";
\r
101 LongitudeDot = LatitudeDot = RadiusDot = 0.0;
\r
103 for (int i=0;i<4;i++) {
\r
104 LatitudeDot_prev[i] = 0.0;
\r
105 LongitudeDot_prev[i] = 0.0;
\r
106 RadiusDot_prev[i] = 0.0;
\r
109 vVRPoffset.InitMatrix();
\r
111 Longitude = Latitude = 0.0;
\r
112 LongitudeVRP = LatitudeVRP = 0.0;
\r
113 gamma = Vt = Vground = 0.0;
\r
114 hoverbmac = hoverbcg = 0.0;
\r
120 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
122 FGPosition::~FGPosition(void)
\r
128 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
130 bool FGPosition::InitModel(void)
\r
132 FGModel::InitModel();
\r
134 h = 3.0; // Est. height of aircraft cg off runway
\r
135 SeaLevelRadius = Inertial->RefRadius(); // For initialization ONLY
\r
136 Radius = SeaLevelRadius + h;
\r
137 RunwayRadius = SeaLevelRadius;
\r
138 DistanceAGL = Radius - RunwayRadius; // Geocentric
\r
139 vRunwayNormal(3) = -1.0; // Initialized for standalone mode
\r
144 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
146 Purpose: Called on a schedule to perform Positioning algorithms
\r
147 Notes: [TP] Make sure that -Vt <= hdot <= Vt, which, of course, should always
\r
149 [JB] Run in standalone mode, SeaLevelRadius will be reference radius.
\r
150 In FGFS, SeaLevelRadius is stuffed from FGJSBSim in JSBSim.cxx each pass.
\r
153 bool FGPosition::Run(void)
\r
158 if (!FGModel::Run()) {
\r
161 Vground = sqrt( vVel(eNorth)*vVel(eNorth) + vVel(eEast)*vVel(eEast) );
\r
163 if (vVel(eNorth) == 0) psigt = 0;
\r
164 else psigt = atan2(vVel(eEast), vVel(eNorth));
\r
166 if (psigt < 0.0) psigt += 2*M_PI;
\r
168 Radius = h + SeaLevelRadius;
\r
170 cosLat = cos(Latitude);
\r
171 if (cosLat != 0) LongitudeDot = vVel(eEast) / (Radius * cosLat);
\r
172 LatitudeDot = vVel(eNorth) / Radius;
\r
173 RadiusDot = -vVel(eDown);
\r
175 Longitude += State->Integrate(FGState::TRAPZ, dt*rate, LongitudeDot, LongitudeDot_prev);
\r
176 Latitude += State->Integrate(FGState::TRAPZ, dt*rate, LatitudeDot, LatitudeDot_prev);
\r
177 Radius += State->Integrate(FGState::TRAPZ, dt*rate, RadiusDot, RadiusDot_prev);
\r
179 h = Radius - SeaLevelRadius; // Geocentric
\r
181 vVRPoffset = State->GetTb2l() * MassBalance->StructuralToBody(Aircraft->GetXYZvrp());
\r
183 // vVRP - the vector to the Visual Reference Point - now contains the
\r
184 // offset from the CG to the VRP, in units of feet, in the Local coordinate
\r
185 // frame, where X points north, Y points East, and Z points down. This needs
\r
186 // to be converted to Lat/Lon/Alt, now.
\r
189 LongitudeVRP = vVRPoffset(eEast) / (Radius * cosLat) + Longitude;
\r
191 LatitudeVRP = vVRPoffset(eNorth) / Radius + Latitude;
\r
192 hVRP = h - vVRPoffset(eDown);
\r
194 cout << "Lat/Lon/Alt : " << Latitude << " / " << Longitude << " / " << h << endl;
\r
195 cout << "Lat/Lon/Alt VRP: " << LatitudeVRP << " / " << LongitudeVRP << " / " << hVRP << endl << endl;
\r
197 DistanceAGL = Radius - RunwayRadius; // Geocentric
\r
199 hoverbcg = DistanceAGL/b;
\r
201 vMac = State->GetTb2l()*MassBalance->StructuralToBody(Aircraft->GetXYZrp());
\r
202 hoverbmac = (DistanceAGL + vMac(3)) / b;
\r
205 hdot_Vt = RadiusDot/Vt;
\r
206 if (fabs(hdot_Vt) <= 1) gamma = asin(hdot_Vt);
\r
218 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
220 void FGPosition::GetState(void)
\r
222 dt = State->Getdt();
\r
224 Vt = Translation->GetVt();
\r
225 vVel = State->GetTb2l() * Translation->GetUVW();
\r
226 vVelDot = State->GetTb2l() * Translation->GetUVWdot();
\r
228 b = Aircraft->GetWingSpan();
\r
231 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
233 void FGPosition::Seth(double tt)
\r
236 Radius = h + SeaLevelRadius;
\r
237 DistanceAGL = Radius - RunwayRadius; // Geocentric
\r
238 hoverbcg = DistanceAGL/b;
\r
241 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
243 void FGPosition::SetDistanceAGL(double tt)
\r
246 Radius = RunwayRadius + DistanceAGL;
\r
247 h = Radius - SeaLevelRadius;
\r
248 hoverbcg = DistanceAGL/b;
\r
251 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
253 void FGPosition::bind(void)
\r
255 PropertyManager->Tie("velocities/v-north-fps", this,
\r
256 &FGPosition::GetVn);
\r
257 PropertyManager->Tie("velocities/v-east-fps", this,
\r
258 &FGPosition::GetVe);
\r
259 PropertyManager->Tie("velocities/v-down-fps", this,
\r
260 &FGPosition::GetVd);
\r
261 PropertyManager->Tie("velocities/vg-fps", this,
\r
262 &FGPosition::GetVground);
\r
263 PropertyManager->Tie("flight-path/psi-gt-rad", this,
\r
264 &FGPosition::GetGroundTrack);
\r
265 PropertyManager->Tie("position/h-sl-ft", this,
\r
269 PropertyManager->Tie("velocities/h-dot-fps", this,
\r
270 &FGPosition::Gethdot);
\r
271 PropertyManager->Tie("position/lat-gc-rad", this,
\r
272 &FGPosition::GetLatitude,
\r
273 &FGPosition::SetLatitude);
\r
274 PropertyManager->Tie("position/lat-dot-gc-rad", this,
\r
275 &FGPosition::GetLatitudeDot);
\r
276 PropertyManager->Tie("position/long-gc-rad", this,
\r
277 &FGPosition::GetLongitude,
\r
278 &FGPosition::SetLongitude,
\r
280 PropertyManager->Tie("position/long-dot-gc-rad", this,
\r
281 &FGPosition::GetLongitudeDot);
\r
282 PropertyManager->Tie("metrics/runway-radius", this,
\r
283 &FGPosition::GetRunwayRadius,
\r
284 &FGPosition::SetRunwayRadius);
\r
285 PropertyManager->Tie("position/h-agl-ft", this,
\r
286 &FGPosition::GetDistanceAGL,
\r
287 &FGPosition::SetDistanceAGL);
\r
288 PropertyManager->Tie("position/radius-to-vehicle-ft", this,
\r
289 &FGPosition::GetRadius);
\r
290 PropertyManager->Tie("flight-path/gamma-rad", this,
\r
291 &FGPosition::GetGamma,
\r
292 &FGPosition::SetGamma);
\r
293 PropertyManager->Tie("aero/h_b-cg-ft", this,
\r
294 &FGPosition::GetHOverBCG);
\r
295 PropertyManager->Tie("aero/h_b-mac-ft", this,
\r
296 &FGPosition::GetHOverBMAC);
\r
299 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
301 void FGPosition::unbind(void)
\r
303 PropertyManager->Untie("velocities/v-north-fps");
\r
304 PropertyManager->Untie("velocities/v-east-fps");
\r
305 PropertyManager->Untie("velocities/v-down-fps");
\r
306 PropertyManager->Untie("velocities/vg-fps");
\r
307 PropertyManager->Untie("flight-path/psi-gt-rad");
\r
308 PropertyManager->Untie("position/h-sl-ft");
\r
309 PropertyManager->Untie("velocities/h-dot-fps");
\r
310 PropertyManager->Untie("position/lat-gc-rad");
\r
311 PropertyManager->Untie("position/lat-dot-gc-rad");
\r
312 PropertyManager->Untie("position/long-gc-rad");
\r
313 PropertyManager->Untie("position/long-dot-gc-rad");
\r
314 PropertyManager->Untie("metrics/runway-radius");
\r
315 PropertyManager->Untie("position/h-agl-ft");
\r
316 PropertyManager->Untie("position/radius-to-vehicle-ft");
\r
317 PropertyManager->Untie("flight-path/gamma-rad");
\r
318 PropertyManager->Untie("aero/h_b-cg-ft");
\r
319 PropertyManager->Untie("aero/h_b-mac-ft");
\r
322 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
323 // The bitmasked value choices are as follows:
\r
324 // unset: In this case (the default) JSBSim would only print
\r
325 // out the normally expected messages, essentially echoing
\r
326 // the config files as they are read. If the environment
\r
327 // variable is not set, debug_lvl is set to 1 internally
\r
328 // 0: This requests JSBSim not to output any messages
\r
330 // 1: This value explicity requests the normal JSBSim
\r
331 // startup messages
\r
332 // 2: This value asks for a message to be printed out when
\r
333 // a class is instantiated
\r
334 // 4: When this value is set, a message is displayed when a
\r
335 // FGModel object executes its Run() method
\r
336 // 8: When this value is set, various runtime state variables
\r
337 // are printed out periodically
\r
338 // 16: When set various parameters are sanity checked and
\r
339 // a message is printed out when they go out of bounds
\r
341 void FGPosition::Debug(int from)
\r
343 if (debug_lvl <= 0) return;
\r
345 if (debug_lvl & 1) { // Standard console startup message output
\r
346 if (from == 0) { // Constructor
\r
350 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
\r
351 if (from == 0) cout << "Instantiated: FGPosition" << endl;
\r
352 if (from == 1) cout << "Destroyed: FGPosition" << endl;
\r
354 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
\r
356 if (debug_lvl & 8 ) { // Runtime state variables
\r
358 if (debug_lvl & 16) { // Sanity checking
\r
360 if (debug_lvl & 64) {
\r
361 if (from == 0) { // Constructor
\r
362 cout << IdSrc << endl;
\r
363 cout << IdHdr << endl;
\r