]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGPosition.cpp
078f495b8a9a4336aa0fb33bde582cdc0f4b2e70
[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 SG_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 "FGMassBalance.h"
77 #include "FGTranslation.h"
78 #include "FGRotation.h"
79 #include "FGAuxiliary.h"
80 #include "FGOutput.h"
81
82 static const char *IdSrc = "$Id$";
83 static const char *IdHdr = ID_POSITION;
84
85 extern short debug_lvl;
86
87 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 CLASS IMPLEMENTATION
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
90
91 extern float globalTriNormal[3];
92 extern double globalSceneryAltitude;
93 extern double globalSeaLevelRadius;
94
95 FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex),
96     vVel(3),
97     vVelDot(3),
98     vRunwayNormal(3)
99 {
100   Name = "FGPosition";
101   LongitudeDot = LatitudeDot = RadiusDot = 0.0;
102   lastLongitudeDot = lastLatitudeDot = lastRadiusDot = 0.0;
103   Longitude = Latitude = 0.0;
104   gamma = Vt = Vground = 0.0;
105   h = 3.0;                                 // Est. height of aircraft cg off runway
106   SeaLevelRadius = EARTHRAD;               // For initialization ONLY
107   Radius         = SeaLevelRadius + h;
108   RunwayRadius   = SeaLevelRadius;
109   DistanceAGL    = Radius - RunwayRadius;  // Geocentric
110   vRunwayNormal(3) = -1.0;                 // Initialized for standalone mode
111
112   if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
113 }
114
115 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116
117 FGPosition::~FGPosition()
118 {
119   if (debug_lvl & 2) cout << "Destroyed:    FGPosition" << endl;
120 }
121
122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 /*
124 Purpose: Called on a schedule to perform Positioning algorithms
125 Notes:   [TP] Make sure that -Vt <= hdot <= Vt, which, of course, should always
126          be the case
127          [JB] Run in standalone mode, SeaLevelRadius will be EARTHRAD. In FGFS,
128          SeaLevelRadius is stuffed from FGJSBSim in JSBSim.cxx each pass.
129 */
130
131 bool FGPosition:: Run(void) {
132   double cosLat;
133   double hdot_Vt;
134
135   if (!FGModel::Run()) {
136     GetState();
137
138     Vground = sqrt( vVel(eNorth)*vVel(eNorth) + vVel(eEast)*vVel(eEast) );
139     psigt =  atan2(vVel(eEast), vVel(eNorth));
140     if(psigt < 0.0)
141       psigt += 2*M_PI;
142
143     invMass   = 1.0 / MassBalance->GetMass();
144     Radius    = h + SeaLevelRadius;
145     invRadius = 1.0 / Radius;
146
147     cosLat = cos(Latitude);
148     if (cosLat != 0) LongitudeDot = vVel(eEast) / (Radius * cosLat);
149
150     LatitudeDot = vVel(eNorth) * invRadius;
151     RadiusDot   = -vVel(eDown);
152
153     Longitude += 0.5*dt*rate*(LongitudeDot + lastLongitudeDot);
154     Latitude  += 0.5*dt*rate*(LatitudeDot + lastLatitudeDot);
155     Radius    += 0.5*dt*rate*(RadiusDot + lastRadiusDot);
156
157     h = Radius - SeaLevelRadius;           // Geocentric
158
159     DistanceAGL = Radius - RunwayRadius;   // Geocentric
160
161     hoverb = DistanceAGL/b;
162
163     if (Vt > 0) {
164       hdot_Vt = RadiusDot/Vt;
165       if (fabs(hdot_Vt) <= 1) gamma = asin(hdot_Vt);
166     } else {
167       gamma = 0.0;
168     }
169
170     lastLatitudeDot  = LatitudeDot;
171     lastLongitudeDot = LongitudeDot;
172     lastRadiusDot    = RadiusDot;
173
174     return false;
175
176   } else {
177     return true;
178   }
179 }
180
181 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182
183 void FGPosition::GetState(void) {
184   dt = State->Getdt();
185
186   Vt        = Translation->GetVt();
187   vVel      = State->GetTb2l() * Translation->GetUVW();
188   vVelDot   = State->GetTb2l() * Translation->GetUVWdot();
189
190   b = Aircraft->GetWingSpan();
191 }
192
193 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194
195 void FGPosition::Seth(double tt) {
196  h = tt;
197  Radius    = h + SeaLevelRadius;
198  DistanceAGL = Radius - RunwayRadius;   // Geocentric
199 }
200
201 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202
203 void FGPosition::SetDistanceAGL(double tt) {
204   DistanceAGL=tt;
205   Radius = RunwayRadius + DistanceAGL;
206   h = Radius - SeaLevelRadius;
207 }
208
209 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210
211 void FGPosition::Debug(void)
212 {
213     //TODO: Add your source code here
214 }
215