]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGPosition.cpp
Updates from the Jon and Tony show.
[flightgear.git] / src / FDM / JSBSim / FGPosition.cpp
1 /*******************************************************************************
2  
3  Module:       FGPosition.cpp
4  Author:       Jon S. Berndt
5  Date started: 01/05/99
6  Purpose:      Integrate the EOM to determine instantaneous position
7  Called by:    FGFDMExec
8  
9  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
10  
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
14  version.
15  
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
19  details.
20  
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.
24  
25  Further information about the GNU General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27  
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This class encapsulates the integration of rates and accelerations to get the
31 current position of the aircraft.
32  
33 HISTORY
34 --------------------------------------------------------------------------------
35 01/05/99   JSB   Created
36  
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
42     School, January 1994
43 [2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
44     JSC 12960, July 1977
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
51  
52 ********************************************************************************
53 INCLUDES
54 *******************************************************************************/
55
56 #ifdef FGFS
57 #  include <simgear/compiler.h>
58 #  ifdef FG_HAVE_STD_INCLUDES
59 #    include <cmath>
60 #  else
61 #    include <math.h>
62 #  endif
63 #else
64 #  include <cmath>
65 #endif
66
67 #include "FGPosition.h"
68 #include "FGAtmosphere.h"
69 #include "FGState.h"
70 #include "FGFDMExec.h"
71 #include "FGFCS.h"
72 #include "FGAircraft.h"
73 #include "FGTranslation.h"
74 #include "FGRotation.h"
75 #include "FGAuxiliary.h"
76 #include "FGOutput.h"
77
78 /*******************************************************************************
79 ************************************ CODE **************************************
80 *******************************************************************************/
81
82 extern float globalTriNormal[3];
83 extern double globalSceneryAltitude;
84 extern double globalSeaLevelRadius;
85
86 FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex),
87     vUVW(3),
88     vVel(3)
89 {
90   Name = "FGPosition";
91   LongitudeDot = LatitudeDot = RadiusDot = 0.0;
92   lastLongitudeDot = lastLatitudeDot = lastRadiusDot = 0.0;
93   Longitude = Latitude = 0.0;
94   h = 0.0;
95   Radius = EARTHRAD + h;
96   gamma=Vt=0.0;
97   RunwayRadius = EARTHRAD;
98 }
99
100 /******************************************************************************/
101
102 FGPosition::~FGPosition(void) {}
103
104 /******************************************************************************/
105
106 bool FGPosition:: Run(void) {
107   double cosLat;
108   double hdot_Vt;
109
110   if (!FGModel::Run()) {
111     GetState();
112
113     vVel = State->GetTl2b()*vUVW;
114
115     cosLat = cos(Latitude);
116     if (cosLat != 0) LongitudeDot = vVel(eEast) / (Radius * cosLat);
117
118     LatitudeDot = vVel(eNorth) * invRadius;
119     RadiusDot   = -vVel(eDown);
120
121     Longitude += 0.5*dt*rate*(LongitudeDot + lastLongitudeDot);
122     Latitude  += 0.5*dt*rate*(LatitudeDot + lastLatitudeDot);
123     Radius    += 0.5*dt*rate*(RadiusDot + lastRadiusDot);
124
125     h = Radius - EARTHRAD;                 // Geocentric
126
127     DistanceAGL = Radius - RunwayRadius;   // Geocentric
128
129     cout << "h: " << h << "  DistanceAGL: " << DistanceAGL << endl;
130
131     hoverb = h/b;
132
133     if(Vt > 0) {
134       hdot_Vt=RadiusDot/Vt;
135       //make sure that -Vt <= hdot <= Vt, which, of course, should always be the case
136       if(fabs(hdot_Vt) <= 1) gamma= asin(hdot_Vt);
137     } else
138       gamma=0.0;
139
140     lastLatitudeDot = LatitudeDot;
141     lastLongitudeDot = LongitudeDot;
142     lastRadiusDot = RadiusDot;
143
144     return false;
145
146   } else {
147     return true;
148   }
149 }
150
151 /******************************************************************************/
152
153 void FGPosition::GetState(void) {
154   dt = State->Getdt();
155
156   vUVW = Translation->GetUVW();
157   Vt = Translation->GetVt();
158   invMass = 1.0 / Aircraft->GetMass();
159   invRadius = 1.0 / (h + EARTHRAD);
160   Radius = h + EARTHRAD;
161   b = Aircraft->GetWingSpan();
162 }
163