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