]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAuxiliary.cpp
Synced with latest JSBSim cvs.
[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   vPilotAccel(3),
68   vToEyePt(3)
69 {
70   Name = "FGAuxiliary";
71   vcas = veas = mach = qbar = pt = 0;
72   psl = rhosl = 1;
73   earthPosAngle = 0.0;
74   
75   if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
76 }
77
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80 FGAuxiliary::~FGAuxiliary()
81 {
82   if (debug_lvl & 2) cout << "Destroyed:    FGAuxiliary" << endl;
83 }
84
85 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86
87 bool FGAuxiliary::Run()
88 {
89   double A,B,D;
90
91   if (!FGModel::Run()) {
92     GetState();
93     if (mach < 1) {   //calculate total pressure assuming isentropic flow
94       pt=p*pow((1 + 0.2*mach*mach),3.5);
95     } else {
96       // shock in front of pitot tube, we'll assume its normal and use
97       // the Rayleigh Pitot Tube Formula, i.e. the ratio of total
98       // pressure behind the shock to the static pressure in front
99
100       B = 5.76*mach*mach/(5.6*mach*mach - 0.8);
101
102       // The denominator above is zero for Mach ~ 0.38, for which
103       // we'll never be here, so we're safe
104
105       D = (2.8*mach*mach-0.4)*0.4167;
106       pt = p*pow(B,3.5)*D;
107     }
108
109     A = pow(((pt-p)/psl+1),0.28571);
110     vcas = sqrt(7*psl/rhosl*(A-1));
111     veas = sqrt(2*qbar/rhosl);
112
113     // Pilot sensed accelerations are calculated here. This is used
114     // for the coordinated turn ball instrument. Motion base platforms sometimes
115     // use the derivative of pilot sensed accelerations as the driving parameter,
116     // rather than straight accelerations.
117     //
118     // The theory behind pilot-sensed calculations is presented:
119     //
120     // For purposes of discussion and calculation, assume for a minute that the
121     // pilot is in space and motionless in inertial space. She will feel
122     // no accelerations. If the aircraft begins to accelerate along any axis or
123     // axes (without rotating), the pilot will sense those accelerations. If
124     // any rotational moment is applied, the pilot will sense an acceleration
125     // due to that motion in the amount:
126     //
127     // [wdot X R]  +  [w X (w X R)]
128     //   Term I          Term II
129     //
130     // where:
131     //
132     // wdot = omegadot, the rotational acceleration rate vector
133     // w    = omega, the rotational rate vector
134     // R    = the vector from the aircraft CG to the pilot eyepoint
135     //
136     // The sum total of these two terms plus the acceleration of the aircraft
137     // body axis gives the acceleration the pilot senses in inertial space.
138     // In the presence of a large body such as a planet, a gravity field also
139     // provides an accelerating attraction. This acceleration can be transformed
140     // from the reference frame of the planet so as to be expressed in the frame
141     // of reference of the aircraft. This gravity field accelerating attraction
142     // is felt by the pilot as a force on her tushie as she sits in her aircraft
143     // on the runway awaiting takeoff clearance.
144     //
145     // In JSBSim the acceleration of the body frame in inertial space is given
146     // by the F = ma relation. If the vForces vector is divided by the aircraft
147     // mass, the acceleration vector is calculated. The term wdot is equivalent
148     // to the JSBSim vPQRdot vector, and the w parameter is equivalent to vPQR.
149     // The radius R is calculated below in the vector vToEyePt.
150         
151     vToEyePt = Aircraft->GetXYZep() - MassBalance->GetXYZcg();
152
153     vPilotAccel = Aircraft->GetBodyAccel()
154                   + Rotation->GetPQRdot() * vToEyePt
155                   + Rotation->GetPQR() * (Rotation->GetPQR() * vToEyePt)
156                   + Inertial->GetGravity();
157
158     earthPosAngle += State->Getdt()*Inertial->omega();
159     return false;
160   } else {
161     return true;
162   }
163 }
164
165 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166
167 double FGAuxiliary::GetHeadWind(void)
168 {
169   double psiw,vw,psi;
170
171   psiw = Atmosphere->GetWindPsi();
172   psi = Rotation->Getpsi();
173   vw = Atmosphere->GetWindNED().Magnitude();
174
175   return vw*cos(psiw - psi);
176 }
177
178 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179
180 double FGAuxiliary::GetCrossWind(void)
181 {
182   double psiw,vw,psi;
183
184   psiw = Atmosphere->GetWindPsi();
185   psi = Rotation->Getpsi();
186   vw = Atmosphere->GetWindNED().Magnitude();
187
188   return  vw*sin(psiw - psi);
189 }
190
191 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192
193 FGColumnVector3 FGAuxiliary::GetNpilot(void)
194 {
195   return vPilotAccel/Inertial->gravity();
196 }
197
198 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199
200 double FGAuxiliary::GetNpilot(int idx)
201 {
202   return (vPilotAccel/Inertial->gravity())(idx);
203 }
204
205 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206
207 void FGAuxiliary::GetState(void)
208 {
209   qbar = Translation->Getqbar();
210   mach = Translation->GetMach();
211   p = Atmosphere->GetPressure();
212   rhosl = Atmosphere->GetDensitySL();
213   psl = Atmosphere->GetPressureSL();
214 }
215
216 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217
218 void FGAuxiliary::Debug(void)
219 {
220     //TODO: Add your source code here
221 }
222