]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAuxiliary.cpp
First steps in a weather reorganization. Note especially that
[flightgear.git] / src / FDM / JSBSim / FGAuxiliary.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2  
3  Module:       FGAuxiliary.cpp
4  Author:       Tony Peden, Jon Berndt
5  Date started: 01/26/99
6  Purpose:      Calculates additional parameters needed by the visual system, etc.
7  Called by:    FGSimExec
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 calculates various auxiliary parameters.
31
32 REFERENCES
33   Anderson, John D. "Introduction to Flight", 3rd Edition, McGraw-Hill, 1989
34                     pgs. 112-126
35 HISTORY
36 --------------------------------------------------------------------------------
37 01/26/99   JSB   Created
38
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 INCLUDES
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42
43 #include "FGAuxiliary.h"
44 #include "FGTranslation.h"
45 #include "FGRotation.h"
46 #include "FGAtmosphere.h"
47 #include "FGState.h"
48 #include "FGFDMExec.h"
49 #include "FGFCS.h"
50 #include "FGAircraft.h"
51 #include "FGPosition.h"
52 #include "FGOutput.h"
53 #include "FGInertial.h"
54 #include "FGMatrix33.h"
55 #include "FGColumnVector3.h"
56 #include "FGColumnVector4.h"
57
58 static const char *IdSrc = "$Id$";
59 static const char *IdHdr = ID_AUXILIARY;
60
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 CLASS IMPLEMENTATION
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64
65
66 FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex)
67 {
68   Name = "FGAuxiliary";
69   vcas = veas = mach = qbar = pt = 0;
70   psl = rhosl = 1;
71   earthPosAngle = 0.0;
72   
73   Debug(0);
74 }
75
76 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77
78 FGAuxiliary::~FGAuxiliary()
79 {
80   Debug(1);
81 }
82
83 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84
85 bool FGAuxiliary::Run()
86 {
87   double A,B,D;
88
89   if (!FGModel::Run()) {
90     GetState();
91     if (mach < 1) {   //calculate total pressure assuming isentropic flow
92       pt=p*pow((1 + 0.2*mach*mach),3.5);
93     } else {
94       // shock in front of pitot tube, we'll assume its normal and use
95       // the Rayleigh Pitot Tube Formula, i.e. the ratio of total
96       // pressure behind the shock to the static pressure in front
97
98       B = 5.76*mach*mach/(5.6*mach*mach - 0.8);
99
100       // The denominator above is zero for Mach ~ 0.38, for which
101       // we'll never be here, so we're safe
102
103       D = (2.8*mach*mach-0.4)*0.4167;
104       pt = p*pow(B,3.5)*D;
105     }
106
107     A = pow(((pt-p)/psl+1),0.28571);
108     vcas = sqrt(7*psl/rhosl*(A-1));
109     veas = sqrt(2*qbar/rhosl);
110
111     // Pilot sensed accelerations are calculated here. This is used
112     // for the coordinated turn ball instrument. Motion base platforms sometimes
113     // use the derivative of pilot sensed accelerations as the driving parameter,
114     // rather than straight accelerations.
115     //
116     // The theory behind pilot-sensed calculations is presented:
117     //
118     // For purposes of discussion and calculation, assume for a minute that the
119     // pilot is in space and motionless in inertial space. She will feel
120     // no accelerations. If the aircraft begins to accelerate along any axis or
121     // axes (without rotating), the pilot will sense those accelerations. If
122     // any rotational moment is applied, the pilot will sense an acceleration
123     // due to that motion in the amount:
124     //
125     // [wdot X R]  +  [w X (w X R)]
126     //   Term I          Term II
127     //
128     // where:
129     //
130     // wdot = omegadot, the rotational acceleration rate vector
131     // w    = omega, the rotational rate vector
132     // R    = the vector from the aircraft CG to the pilot eyepoint
133     //
134     // The sum total of these two terms plus the acceleration of the aircraft
135     // body axis gives the acceleration the pilot senses in inertial space.
136     // In the presence of a large body such as a planet, a gravity field also
137     // provides an accelerating attraction. This acceleration can be transformed
138     // from the reference frame of the planet so as to be expressed in the frame
139     // of reference of the aircraft. This gravity field accelerating attraction
140     // is felt by the pilot as a force on her tushie as she sits in her aircraft
141     // on the runway awaiting takeoff clearance.
142     //
143     // In JSBSim the acceleration of the body frame in inertial space is given
144     // by the F = ma relation. If the vForces vector is divided by the aircraft
145     // mass, the acceleration vector is calculated. The term wdot is equivalent
146     // to the JSBSim vPQRdot vector, and the w parameter is equivalent to vPQR.
147     // The radius R is calculated below in the vector vToEyePt.
148     
149     vPilotAccel.InitMatrix();   
150     if( Translation->GetVt() > 1 ) {
151       vToEyePt = Aircraft->GetXYZep() - MassBalance->GetXYZcg();
152       vToEyePt *= inchtoft;
153       vPilotAccel =  Aerodynamics->GetForces() 
154                   +  Propulsion->GetForces()
155                   +  GroundReactions->GetForces();
156       vPilotAccel /= MassBalance->GetMass();
157       vPilotAccel += Rotation->GetPQRdot() * vToEyePt;
158       vPilotAccel += Rotation->GetPQR() * (Rotation->GetPQR() * vToEyePt);
159       //vPilotAccel(2)*=-1;
160     }
161     earthPosAngle += State->Getdt()*Inertial->omega();
162     return false;
163   } else {
164     return true;
165   }
166 }
167
168 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169
170 double FGAuxiliary::GetHeadWind(void)
171 {
172   double psiw,vw,psi;
173
174   psiw = Atmosphere->GetWindPsi();
175   psi = Rotation->Getpsi();
176   vw = Atmosphere->GetWindNED().Magnitude();
177
178   return vw*cos(psiw - psi);
179 }
180
181 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182
183 double FGAuxiliary::GetCrossWind(void)
184 {
185   double psiw,vw,psi;
186
187   psiw = Atmosphere->GetWindPsi();
188   psi = Rotation->Getpsi();
189   vw = Atmosphere->GetWindNED().Magnitude();
190
191   return  vw*sin(psiw - psi);
192 }
193
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195
196 FGColumnVector3 FGAuxiliary::GetNpilot(void)
197 {
198   return vPilotAccel/Inertial->gravity();
199 }
200
201 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202
203 double FGAuxiliary::GetNpilot(int idx)
204 {
205   return (vPilotAccel/Inertial->gravity())(idx);
206 }
207
208 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209
210 void FGAuxiliary::GetState(void)
211 {
212   qbar = Translation->Getqbar();
213   mach = Translation->GetMach();
214   p = Atmosphere->GetPressure();
215   rhosl = Atmosphere->GetDensitySL();
216   psl = Atmosphere->GetPressureSL();
217 }
218
219 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 //    The bitmasked value choices are as follows:
221 //    unset: In this case (the default) JSBSim would only print
222 //       out the normally expected messages, essentially echoing
223 //       the config files as they are read. If the environment
224 //       variable is not set, debug_lvl is set to 1 internally
225 //    0: This requests JSBSim not to output any messages
226 //       whatsoever.
227 //    1: This value explicity requests the normal JSBSim
228 //       startup messages
229 //    2: This value asks for a message to be printed out when
230 //       a class is instantiated
231 //    4: When this value is set, a message is displayed when a
232 //       FGModel object executes its Run() method
233 //    8: When this value is set, various runtime state variables
234 //       are printed out periodically
235 //    16: When set various parameters are sanity checked and
236 //       a message is printed out when they go out of bounds
237
238 void FGAuxiliary::Debug(int from)
239 {
240   if (debug_lvl <= 0) return;
241
242   if (debug_lvl & 1) { // Standard console startup message output
243     if (from == 0) { // Constructor
244
245     }
246   }
247   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
248     if (from == 0) cout << "Instantiated: FGAuxiliary" << endl;
249     if (from == 1) cout << "Destroyed:    FGAuxiliary" << endl;
250   }
251   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
252   }
253   if (debug_lvl & 8 ) { // Runtime state variables
254   }
255   if (debug_lvl & 16) { // Sanity checking
256   }
257   if (debug_lvl & 64) {
258     if (from == 0) { // Constructor
259       cout << IdSrc << endl;
260       cout << IdHdr << endl;
261     }
262   }
263 }
264