1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGAuxiliary.cpp
6 Purpose: Calculates additional parameters needed by the visual system, etc.
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This class calculates various auxiliary parameters.
33 Anderson, John D. "Introduction to Flight", 3rd Edition, McGraw-Hill, 1989
36 --------------------------------------------------------------------------------
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43 #include "FGAuxiliary.h"
44 #include "FGTranslation.h"
45 #include "FGRotation.h"
46 #include "FGAtmosphere.h"
48 #include "FGFDMExec.h"
50 #include "FGAircraft.h"
51 #include "FGPosition.h"
55 static const char *IdSrc = "$Id$";
56 static const char *IdHdr = ID_AUXILIARY;
58 extern short debug_lvl;
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex) {
67 vcas = veas = mach = qbar = pt = 0;
71 if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
74 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 FGAuxiliary::~FGAuxiliary()
78 if (debug_lvl & 2) cout << "Destroyed: FGAuxiliary" << endl;
81 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 bool FGAuxiliary::Run() {
86 if (!FGModel::Run()) {
88 if(mach < 1) //calculate total pressure assuming isentropic flow
89 pt=p*pow((1 + 0.2*mach*mach),3.5);
91 // shock in front of pitot tube, we'll assume its normal and use
92 // the Rayleigh Pitot Tube Formula, i.e. the ratio of total
93 // pressure behind the shock to the static pressure in front
95 B = 5.76*mach*mach/(5.6*mach*mach - 0.8);
97 // The denominator above is zero for Mach ~ 0.38, for which
98 // we'll never be here, so we're safe
100 D = (2.8*mach*mach-0.4)*0.4167;
104 A = pow(((pt-p)/psl+1),0.28571);
105 vcas = sqrt(7*psl/rhosl*(A-1));
106 veas = sqrt(2*qbar/rhosl);
108 vPilotAccel = Translation->GetUVWdot() + Aircraft->GetXYZep() * Rotation->GetPQRdot();
110 earthPosAngle += State->Getdt()*OMEGA_EARTH;
118 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 float FGAuxiliary::GetHeadWind(void) {
124 psiw = Atmosphere->GetWindPsi();
125 psi = Rotation->Getpsi();
126 vw = Atmosphere->GetWindNED().Magnitude();
127 return -vw*cos(psiw - psi);
130 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 float FGAuxiliary::GetCrossWind(void) {
136 psiw = Atmosphere->GetWindPsi();
137 psi = Rotation->Getpsi();
138 vw = Atmosphere->GetWindNED().Magnitude();
139 return vw*sin(psiw - psi);
142 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 void FGAuxiliary::GetState(void) {
145 qbar = Translation->Getqbar();
146 mach = Translation->GetMach();
147 p = Atmosphere->GetPressure();
148 rhosl = Atmosphere->GetDensitySL();
149 psl = Atmosphere->GetPressureSL();
153 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 void FGAuxiliary::Debug(void)
157 //TODO: Add your source code here