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__)
68 # if (_COMPILER_VERSION < 740)
79 #include "FGPosition.h"
81 #include "FGFDMExec.h"
82 #include "FGAircraft.h"
83 #include "FGMassBalance.h"
84 #include "FGTranslation.h"
85 #include "FGRotation.h"
86 #include "FGInertial.h"
87 #include "FGPropertyManager.h"
91 static const char *IdSrc = "$Id$";
92 static const char *IdHdr = ID_POSITION;
94 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
98 FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex)
101 LongitudeDot = LatitudeDot = RadiusDot = 0.0;
103 for (int i=0;i<4;i++) {
104 LatitudeDot_prev[i] = 0.0;
105 LongitudeDot_prev[i] = 0.0;
106 RadiusDot_prev[i] = 0.0;
109 vVRPoffset.InitMatrix();
111 Longitude = Latitude = 0.0;
112 LongitudeVRP = LatitudeVRP = 0.0;
113 gamma = Vt = Vground = 0.0;
114 hoverbmac = hoverbcg = 0.0;
120 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 FGPosition::~FGPosition(void)
128 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 bool FGPosition::InitModel(void)
132 FGModel::InitModel();
134 h = 3.0; // Est. height of aircraft cg off runway
135 SeaLevelRadius = Inertial->RefRadius(); // For initialization ONLY
136 Radius = SeaLevelRadius + h;
137 RunwayRadius = SeaLevelRadius;
138 DistanceAGL = Radius - RunwayRadius; // Geocentric
139 vRunwayNormal(3) = -1.0; // Initialized for standalone mode
144 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 Purpose: Called on a schedule to perform Positioning algorithms
147 Notes: [TP] Make sure that -Vt <= hdot <= Vt, which, of course, should always
149 [JB] Run in standalone mode, SeaLevelRadius will be reference radius.
150 In FGFS, SeaLevelRadius is stuffed from FGJSBSim in JSBSim.cxx each pass.
153 bool FGPosition::Run(void)
158 if (!FGModel::Run()) {
161 Vground = sqrt( vVel(eNorth)*vVel(eNorth) + vVel(eEast)*vVel(eEast) );
163 if (vVel(eNorth) == 0) psigt = 0;
164 else psigt = atan2(vVel(eEast), vVel(eNorth));
166 if (psigt < 0.0) psigt += 2*M_PI;
168 Radius = h + SeaLevelRadius;
170 cosLat = cos(Latitude);
171 if (cosLat != 0) LongitudeDot = vVel(eEast) / (Radius * cosLat);
172 LatitudeDot = vVel(eNorth) / Radius;
173 RadiusDot = -vVel(eDown);
175 Longitude += State->Integrate(FGState::TRAPZ, dt*rate, LongitudeDot, LongitudeDot_prev);
176 Latitude += State->Integrate(FGState::TRAPZ, dt*rate, LatitudeDot, LatitudeDot_prev);
177 Radius += State->Integrate(FGState::TRAPZ, dt*rate, RadiusDot, RadiusDot_prev);
179 h = Radius - SeaLevelRadius; // Geocentric
181 vVRPoffset = State->GetTb2l() * MassBalance->StructuralToBody(Aircraft->GetXYZvrp());
183 // vVRP - the vector to the Visual Reference Point - now contains the
184 // offset from the CG to the VRP, in units of feet, in the Local coordinate
185 // frame, where X points north, Y points East, and Z points down. This needs
186 // to be converted to Lat/Lon/Alt, now.
189 LongitudeVRP = vVRPoffset(eEast) / (Radius * cosLat) + Longitude;
191 LatitudeVRP = vVRPoffset(eNorth) / Radius + Latitude;
192 hVRP = h - vVRPoffset(eDown);
194 cout << "Lat/Lon/Alt : " << Latitude << " / " << Longitude << " / " << h << endl;
195 cout << "Lat/Lon/Alt VRP: " << LatitudeVRP << " / " << LongitudeVRP << " / " << hVRP << endl << endl;
197 DistanceAGL = Radius - RunwayRadius; // Geocentric
199 hoverbcg = DistanceAGL/b;
201 vMac = State->GetTb2l()*MassBalance->StructuralToBody(Aircraft->GetXYZrp());
202 hoverbmac = (DistanceAGL + vMac(3)) / b;
205 hdot_Vt = RadiusDot/Vt;
206 if (fabs(hdot_Vt) <= 1) gamma = asin(hdot_Vt);
218 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 void FGPosition::GetState(void)
224 Vt = Translation->GetVt();
225 vVel = State->GetTb2l() * Translation->GetUVW();
226 vVelDot = State->GetTb2l() * Translation->GetUVWdot();
228 b = Aircraft->GetWingSpan();
231 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 void FGPosition::Seth(double tt)
236 Radius = h + SeaLevelRadius;
237 DistanceAGL = Radius - RunwayRadius; // Geocentric
238 hoverbcg = DistanceAGL/b;
241 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 void FGPosition::SetDistanceAGL(double tt)
246 Radius = RunwayRadius + DistanceAGL;
247 h = Radius - SeaLevelRadius;
248 hoverbcg = DistanceAGL/b;
251 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 void FGPosition::bind(void)
255 PropertyManager->Tie("velocities/v-north-fps", this,
257 PropertyManager->Tie("velocities/v-east-fps", this,
259 PropertyManager->Tie("velocities/v-down-fps", this,
261 PropertyManager->Tie("velocities/vg-fps", this,
262 &FGPosition::GetVground);
263 PropertyManager->Tie("flight-path/psi-gt-rad", this,
264 &FGPosition::GetGroundTrack);
265 PropertyManager->Tie("position/h-sl-ft", this,
269 PropertyManager->Tie("velocities/h-dot-fps", this,
270 &FGPosition::Gethdot);
271 PropertyManager->Tie("position/lat-gc-rad", this,
272 &FGPosition::GetLatitude,
273 &FGPosition::SetLatitude);
274 PropertyManager->Tie("position/lat-dot-gc-rad", this,
275 &FGPosition::GetLatitudeDot);
276 PropertyManager->Tie("position/long-gc-rad", this,
277 &FGPosition::GetLongitude,
278 &FGPosition::SetLongitude,
280 PropertyManager->Tie("position/long-dot-gc-rad", this,
281 &FGPosition::GetLongitudeDot);
282 PropertyManager->Tie("metrics/runway-radius", this,
283 &FGPosition::GetRunwayRadius,
284 &FGPosition::SetRunwayRadius);
285 PropertyManager->Tie("position/h-agl-ft", this,
286 &FGPosition::GetDistanceAGL,
287 &FGPosition::SetDistanceAGL);
288 PropertyManager->Tie("position/radius-to-vehicle-ft", this,
289 &FGPosition::GetRadius);
290 PropertyManager->Tie("flight-path/gamma-rad", this,
291 &FGPosition::GetGamma,
292 &FGPosition::SetGamma);
293 PropertyManager->Tie("aero/h_b-cg-ft", this,
294 &FGPosition::GetHOverBCG);
295 PropertyManager->Tie("aero/h_b-mac-ft", this,
296 &FGPosition::GetHOverBMAC);
299 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301 void FGPosition::unbind(void)
303 PropertyManager->Untie("velocities/v-north-fps");
304 PropertyManager->Untie("velocities/v-east-fps");
305 PropertyManager->Untie("velocities/v-down-fps");
306 PropertyManager->Untie("velocities/vg-fps");
307 PropertyManager->Untie("flight-path/psi-gt-rad");
308 PropertyManager->Untie("position/h-sl-ft");
309 PropertyManager->Untie("velocities/h-dot-fps");
310 PropertyManager->Untie("position/lat-gc-rad");
311 PropertyManager->Untie("position/lat-dot-gc-rad");
312 PropertyManager->Untie("position/long-gc-rad");
313 PropertyManager->Untie("position/long-dot-gc-rad");
314 PropertyManager->Untie("metrics/runway-radius");
315 PropertyManager->Untie("position/h-agl-ft");
316 PropertyManager->Untie("position/radius-to-vehicle-ft");
317 PropertyManager->Untie("flight-path/gamma-rad");
318 PropertyManager->Untie("aero/h_b-cg-ft");
319 PropertyManager->Untie("aero/h_b-mac-ft");
322 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323 // The bitmasked value choices are as follows:
324 // unset: In this case (the default) JSBSim would only print
325 // out the normally expected messages, essentially echoing
326 // the config files as they are read. If the environment
327 // variable is not set, debug_lvl is set to 1 internally
328 // 0: This requests JSBSim not to output any messages
330 // 1: This value explicity requests the normal JSBSim
332 // 2: This value asks for a message to be printed out when
333 // a class is instantiated
334 // 4: When this value is set, a message is displayed when a
335 // FGModel object executes its Run() method
336 // 8: When this value is set, various runtime state variables
337 // are printed out periodically
338 // 16: When set various parameters are sanity checked and
339 // a message is printed out when they go out of bounds
341 void FGPosition::Debug(int from)
343 if (debug_lvl <= 0) return;
345 if (debug_lvl & 1) { // Standard console startup message output
346 if (from == 0) { // Constructor
350 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
351 if (from == 0) cout << "Instantiated: FGPosition" << endl;
352 if (from == 1) cout << "Destroyed: FGPosition" << endl;
354 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
356 if (debug_lvl & 8 ) { // Runtime state variables
358 if (debug_lvl & 16) { // Sanity checking
360 if (debug_lvl & 64) {
361 if (from == 0) { // Constructor
362 cout << IdSrc << endl;
363 cout << IdHdr << endl;