]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGPosition.cpp
Updates to JSBSim.
[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 #    include <iomanip>
61 #  else
62 #    include <math.h>
63 #    include <iomanip.h>
64 #  endif
65 #else
66 #  include <cmath>
67 #  include <iomanip>
68 #endif
69
70 #include "FGPosition.h"
71 #include "FGAtmosphere.h"
72 #include "FGState.h"
73 #include "FGFDMExec.h"
74 #include "FGFCS.h"
75 #include "FGAircraft.h"
76 #include "FGTranslation.h"
77 #include "FGRotation.h"
78 #include "FGAuxiliary.h"
79 #include "FGOutput.h"
80
81 /*******************************************************************************
82 ************************************ CODE **************************************
83 *******************************************************************************/
84
85 extern float globalTriNormal[3];
86 extern double globalSceneryAltitude;
87 extern double globalSeaLevelRadius;
88
89 FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex),
90     vUVW(3),
91     vVel(3),
92     vVelDot(3)
93 {
94   Name = "FGPosition";
95   LongitudeDot = LatitudeDot = RadiusDot = 0.0;
96   lastLongitudeDot = lastLatitudeDot = lastRadiusDot = 0.0;
97   Longitude = Latitude = 0.0;
98   gamma = Vt = Vground = 0.0;
99   h = 3.0;                                 // Est. height of aircraft cg off runway
100   SeaLevelRadius = EARTHRAD;               // For initialization ONLY
101   Radius         = SeaLevelRadius + h;
102   RunwayRadius   = SeaLevelRadius;
103   DistanceAGL    = Radius - RunwayRadius;  // Geocentric
104 }
105
106 /******************************************************************************/
107
108 FGPosition::~FGPosition(void) {}
109
110 /*************************************************************************** Run
111 Purpose: Called on a schedule to perform Positioning algorithms
112 Notes:   [TP] Make sure that -Vt <= hdot <= Vt, which, of course, should always
113          be the case
114          [JB] Run in standalone mode, SeaLevelRadius will be EARTHRAD. In FGFS,
115          SeaLevelRadius is stuffed from FGJSBSim in JSBSim.cxx each pass.
116 */
117
118 bool FGPosition:: Run(void) {
119   double cosLat;
120   double hdot_Vt;
121
122   if (!FGModel::Run()) {
123     GetState();
124
125     Vground = sqrt( vVel(eNorth)*vVel(eNorth) + vVel(eEast)*vVel(eEast) );
126     
127     invMass   = 1.0 / Aircraft->GetMass();
128     Radius    = h + SeaLevelRadius;
129     invRadius = 1.0 / Radius;
130
131     cosLat = cos(Latitude);
132     if (cosLat != 0) LongitudeDot = vVel(eEast) / (Radius * cosLat);
133
134     LatitudeDot = vVel(eNorth) * invRadius;
135     RadiusDot   = -vVel(eDown);
136
137     Longitude += 0.5*dt*rate*(LongitudeDot + lastLongitudeDot);
138     Latitude  += 0.5*dt*rate*(LatitudeDot + lastLatitudeDot);
139     Radius    += 0.5*dt*rate*(RadiusDot + lastRadiusDot);
140
141     h = Radius - SeaLevelRadius;           // Geocentric
142
143     DistanceAGL = Radius - RunwayRadius;   // Geocentric
144
145     hoverb = DistanceAGL/b;
146
147     if (Vt > 0) {
148       hdot_Vt = RadiusDot/Vt;
149       if (fabs(hdot_Vt) <= 1) gamma = asin(hdot_Vt);
150     } else {
151       gamma = 0.0;
152     }
153
154     lastLatitudeDot  = LatitudeDot;
155     lastLongitudeDot = LongitudeDot;
156     lastRadiusDot    = RadiusDot;
157
158     return false;
159
160   } else {
161     return true;
162   }
163 }
164
165 /******************************************************************************/
166
167 void FGPosition::GetState(void) {
168   dt = State->Getdt();
169
170   vUVW      = Translation->GetUVW();
171   Vt        = Translation->GetVt();
172   vVel      = State->GetTb2l()*vUVW;
173   vVelDot   = State->GetTb2l() * Translation->GetUVWdot();
174
175   b = Aircraft->GetWingSpan();
176   
177 }
178
179 void FGPosition::Seth(double tt) { 
180  h=tt;
181  Radius    = h + SeaLevelRadius;
182  DistanceAGL = Radius - RunwayRadius;   // Geocentric 
183 }  
184
185 void FGPosition::SetDistanceAGL(double tt) {
186   DistanceAGL=tt;
187   Radius = RunwayRadius + DistanceAGL;
188   h = Radius - SeaLevelRadius;
189 }