]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAuxiliary.cpp
Synced with latest JSBSim as of June 5, 2001.
[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 "FGMatrix.h"
54
55 static const char *IdSrc = "$Id$";
56 static const char *IdHdr = ID_AUXILIARY;
57
58 extern short debug_lvl;
59
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 CLASS IMPLEMENTATION
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63
64
65 FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex),
66   vPilotAccel(3),
67   vToEyePt(3)
68 {
69   Name = "FGAuxiliary";
70   vcas = veas = mach = qbar = pt = 0;
71   psl = rhosl = 1;
72   earthPosAngle = 0.0;
73   
74   if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
75 }
76
77 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78
79 FGAuxiliary::~FGAuxiliary()
80 {
81   if (debug_lvl & 2) cout << "Destroyed:    FGAuxiliary" << endl;
82 }
83
84 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85
86 bool FGAuxiliary::Run()
87 {
88   float A,B,D;
89
90   if (!FGModel::Run()) {
91     GetState();
92     if (mach < 1) {   //calculate total pressure assuming isentropic flow
93       pt=p*pow((1 + 0.2*mach*mach),3.5);
94     } else {
95       // shock in front of pitot tube, we'll assume its normal and use
96       // the Rayleigh Pitot Tube Formula, i.e. the ratio of total
97       // pressure behind the shock to the static pressure in front
98
99       B = 5.76*mach*mach/(5.6*mach*mach - 0.8);
100
101       // The denominator above is zero for Mach ~ 0.38, for which
102       // we'll never be here, so we're safe
103
104       D = (2.8*mach*mach-0.4)*0.4167;
105       pt = p*pow(B,3.5)*D;
106     }
107
108     A = pow(((pt-p)/psl+1),0.28571);
109     vcas = sqrt(7*psl/rhosl*(A-1));
110     veas = sqrt(2*qbar/rhosl);
111
112     // vPilotAccel = Translation->GetUVWdot() + Aircraft->GetXYZep() * Rotation->GetPQRdot();
113     
114     vToEyePt = Aircraft->GetXYZep() - MassBalance->GetXYZcg();
115     vPilotAccel = Translation->GetUVWdot()
116                     + Rotation->GetPQRdot() * vToEyePt
117                     + Rotation->GetPQR() * (Rotation->GetPQR() * vToEyePt);
118
119     earthPosAngle += State->Getdt()*OMEGA_EARTH;
120     return false;
121   } else {
122     return true;
123   }
124 }
125
126 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127
128 float FGAuxiliary::GetHeadWind(void)
129 {
130   float psiw,vw,psi;
131
132   psiw = Atmosphere->GetWindPsi();
133   psi = Rotation->Getpsi();
134   vw = Atmosphere->GetWindNED().Magnitude();
135
136   return -vw*cos(psiw - psi);
137 }
138
139 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140
141 float FGAuxiliary::GetCrossWind(void)
142 {
143   float psiw,vw,psi;
144
145   psiw = Atmosphere->GetWindPsi();
146   psi = Rotation->Getpsi();
147   vw = Atmosphere->GetWindNED().Magnitude();
148
149   return  vw*sin(psiw - psi);
150 }
151
152 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153
154 void FGAuxiliary::GetState(void)
155 {
156   qbar = Translation->Getqbar();
157   mach = Translation->GetMach();
158   p = Atmosphere->GetPressure();
159   rhosl = Atmosphere->GetDensitySL();
160   psl = Atmosphere->GetPressureSL();
161 }
162
163 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164
165 void FGAuxiliary::Debug(void)
166 {
167     //TODO: Add your source code here
168 }
169