]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAuxiliary.cpp
09b2aefc74dc08993f3dc40adb88e43302d18545
[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 "FGAerodynamics.h"
45 #include "FGTranslation.h"
46 #include "FGRotation.h"
47 #include "FGAtmosphere.h"
48 #include "FGState.h"
49 #include "FGFDMExec.h"
50 #include "FGAircraft.h"
51 #include "FGInertial.h"
52 #include "FGPropertyManager.h"
53
54 namespace JSBSim {
55
56 static const char *IdSrc = "$Id$";
57 static const char *IdHdr = ID_AUXILIARY;
58
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 CLASS IMPLEMENTATION
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62
63
64 FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex)
65 {
66   Name = "FGAuxiliary";
67   vcas = veas = mach = qbar = pt = tat = 0;
68   psl = rhosl = 1;
69   earthPosAngle = 0.0;
70   
71   vPilotAccelN.InitMatrix();
72   
73   bind();
74   
75   Debug(0);
76 }
77
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80 FGAuxiliary::~FGAuxiliary()
81 {
82   unbind();
83   Debug(1);
84 }
85
86 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87
88 bool FGAuxiliary::Run()
89 {
90   double A,B,D;
91
92   if (!FGModel::Run()) {
93     GetState();
94     
95     //calculate total temperature assuming isentropic flow
96     tat=sat*(1 + 0.2*mach*mach);
97     tatc=RankineToCelsius(tat);
98     
99     if (mach < 1) {   //calculate total pressure assuming isentropic flow
100       pt = p*pow((1 + 0.2*machU*machU),3.5);
101     } else {
102       // shock in front of pitot tube, we'll assume its normal and use
103       // the Rayleigh Pitot Tube Formula, i.e. the ratio of total
104       // pressure behind the shock to the static pressure in front
105
106       B = 5.76*machU*machU/(5.6*machU*machU - 0.8);
107
108       // The denominator above is zero for Mach ~ 0.38, for which
109       // we'll never be here, so we're safe
110
111       D = (2.8*machU*machU-0.4)*0.4167;
112       pt = p*pow(B,3.5)*D;
113     }
114
115     A = pow(((pt-p)/psl+1),0.28571);
116     if (machU > 0.0) {
117       vcas = sqrt(7*psl/rhosl*(A-1));
118       veas = sqrt(2*qbar/rhosl);
119     } else {
120       vcas = veas = 0.0;
121     }
122
123     // Pilot sensed accelerations are calculated here. This is used
124     // for the coordinated turn ball instrument. Motion base platforms sometimes
125     // use the derivative of pilot sensed accelerations as the driving parameter,
126     // rather than straight accelerations.
127     //
128     // The theory behind pilot-sensed calculations is presented:
129     //
130     // For purposes of discussion and calculation, assume for a minute that the
131     // pilot is in space and motionless in inertial space. She will feel
132     // no accelerations. If the aircraft begins to accelerate along any axis or
133     // axes (without rotating), the pilot will sense those accelerations. If
134     // any rotational moment is applied, the pilot will sense an acceleration
135     // due to that motion in the amount:
136     //
137     // [wdot X R]  +  [w X (w X R)]
138     //   Term I          Term II
139     //
140     // where:
141     //
142     // wdot = omegadot, the rotational acceleration rate vector
143     // w    = omega, the rotational rate vector
144     // R    = the vector from the aircraft CG to the pilot eyepoint
145     //
146     // The sum total of these two terms plus the acceleration of the aircraft
147     // body axis gives the acceleration the pilot senses in inertial space.
148     // In the presence of a large body such as a planet, a gravity field also
149     // provides an accelerating attraction. This acceleration can be transformed
150     // from the reference frame of the planet so as to be expressed in the frame
151     // of reference of the aircraft. This gravity field accelerating attraction
152     // is felt by the pilot as a force on her tushie as she sits in her aircraft
153     // on the runway awaiting takeoff clearance.
154     //
155     // In JSBSim the acceleration of the body frame in inertial space is given
156     // by the F = ma relation. If the vForces vector is divided by the aircraft
157     // mass, the acceleration vector is calculated. The term wdot is equivalent
158     // to the JSBSim vPQRdot vector, and the w parameter is equivalent to vPQR.
159     // The radius R is calculated below in the vector vToEyePt.
160     
161     vPilotAccel.InitMatrix();   
162     if ( Translation->GetVt() > 1 ) {
163        vPilotAccel =  Aerodynamics->GetForces() 
164                       +  Propulsion->GetForces()
165                       +  GroundReactions->GetForces();
166        vPilotAccel /= MassBalance->GetMass();
167        vToEyePt = MassBalance->StructuralToBody(Aircraft->GetXYZep());
168        vPilotAccel += Rotation->GetPQRdot() * vToEyePt;
169        vPilotAccel += Rotation->GetPQR() * (Rotation->GetPQR() * vToEyePt);
170     } else {
171        vPilotAccel = -1*( State->GetTl2b() * Inertial->GetGravity() );
172     }   
173
174     vPilotAccelN = vPilotAccel/Inertial->gravity();
175
176     earthPosAngle += State->Getdt()*Inertial->omega();
177     return false;
178   } else {
179     return true;
180   }
181 }
182
183 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184
185 double FGAuxiliary::GetHeadWind(void)
186 {
187   double psiw,vw,psi;
188
189   psiw = Atmosphere->GetWindPsi();
190   psi = Rotation->Getpsi();
191   vw = Atmosphere->GetWindNED().Magnitude();
192
193   return vw*cos(psiw - psi);
194 }
195
196 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197
198 double FGAuxiliary::GetCrossWind(void)
199 {
200   double psiw,vw,psi;
201
202   psiw = Atmosphere->GetWindPsi();
203   psi = Rotation->Getpsi();
204   vw = Atmosphere->GetWindNED().Magnitude();
205
206   return  vw*sin(psiw - psi);
207 }
208
209 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210
211 void FGAuxiliary::bind(void)
212 {
213   typedef double (FGAuxiliary::*PMF)(int) const;
214   PropertyManager->Tie("velocities/vc-fps", this,
215                        &FGAuxiliary::GetVcalibratedFPS);
216   PropertyManager->Tie("velocities/vc-kts", this,
217                        &FGAuxiliary::GetVcalibratedKTS);
218   PropertyManager->Tie("velocities/ve-fps", this,
219                        &FGAuxiliary::GetVequivalentFPS);
220   PropertyManager->Tie("velocities/ve-kts", this,
221                        &FGAuxiliary::GetVequivalentKTS);
222   PropertyManager->Tie("velocities/machU", this,
223                        &FGAuxiliary::GetMachU);
224   PropertyManager->Tie("velocities/tat-r", this,
225                        &FGAuxiliary::GetTotalTemperature);
226   PropertyManager->Tie("velocities/tat-c", this,
227                        &FGAuxiliary::GetTAT_C);
228   PropertyManager->Tie("velocities/pt-lbs_sqft", this,
229                        &FGAuxiliary::GetTotalPressure);
230                      
231   PropertyManager->Tie("accelerations/a-pilot-x-ft_sec2", this,1,
232                        (PMF)&FGAuxiliary::GetPilotAccel);
233   PropertyManager->Tie("accelerations/a-pilot-y-ft_sec2", this,2,
234                        (PMF)&FGAuxiliary::GetPilotAccel);
235   PropertyManager->Tie("accelerations/a-pilot-z-ft_sec2", this,3,
236                        (PMF)&FGAuxiliary::GetPilotAccel);
237   PropertyManager->Tie("accelerations/n-pilot-x-norm", this,1,
238                        (PMF)&FGAuxiliary::GetNpilot);
239   PropertyManager->Tie("accelerations/n-pilot-y-norm", this,2,
240                        (PMF)&FGAuxiliary::GetNpilot);
241   PropertyManager->Tie("accelerations/n-pilot-z-norm", this,3,
242                        (PMF)&FGAuxiliary::GetNpilot);
243   PropertyManager->Tie("position/epa-rad", this,
244                        &FGAuxiliary::GetEarthPositionAngle);
245   /* PropertyManager->Tie("atmosphere/headwind-fps", this,
246                        &FGAuxiliary::GetHeadWind,
247                        true);
248   PropertyManager->Tie("atmosphere/crosswind-fps", this,
249                        &FGAuxiliary::GetCrossWind,
250                        true); */
251 }
252
253 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254
255 void FGAuxiliary::unbind(void)
256 {
257   PropertyManager->Untie("velocities/vc-fps");
258   PropertyManager->Untie("velocities/vc-kts");
259   PropertyManager->Untie("velocities/ve-fps");
260   PropertyManager->Untie("velocities/ve-kts");
261   PropertyManager->Untie("velocities/machU");
262   PropertyManager->Untie("velocities/tat-r");
263   PropertyManager->Untie("velocities/tat-c");
264   PropertyManager->Untie("accelerations/a-pilot-x-ft_sec2");
265   PropertyManager->Untie("accelerations/a-pilot-y-ft_sec2");
266   PropertyManager->Untie("accelerations/a-pilot-z-ft_sec2");
267   PropertyManager->Untie("accelerations/n-pilot-x-norm");
268   PropertyManager->Untie("accelerations/n-pilot-y-norm");
269   PropertyManager->Untie("accelerations/n-pilot-z-norm");
270   PropertyManager->Untie("position/epa-rad");
271   /* PropertyManager->Untie("atmosphere/headwind-fps");
272   PropertyManager->Untie("atmosphere/crosswind-fps"); */
273
274 }
275
276 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277
278 void FGAuxiliary::GetState(void)
279 {
280   qbar = Translation->Getqbar();
281   mach = Translation->GetMach();
282   machU= Translation->GetMachU();
283   p = Atmosphere->GetPressure();
284   rhosl = Atmosphere->GetDensitySL();
285   psl = Atmosphere->GetPressureSL();
286   sat = Atmosphere->GetTemperature();
287 }
288
289 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290 //    The bitmasked value choices are as follows:
291 //    unset: In this case (the default) JSBSim would only print
292 //       out the normally expected messages, essentially echoing
293 //       the config files as they are read. If the environment
294 //       variable is not set, debug_lvl is set to 1 internally
295 //    0: This requests JSBSim not to output any messages
296 //       whatsoever.
297 //    1: This value explicity requests the normal JSBSim
298 //       startup messages
299 //    2: This value asks for a message to be printed out when
300 //       a class is instantiated
301 //    4: When this value is set, a message is displayed when a
302 //       FGModel object executes its Run() method
303 //    8: When this value is set, various runtime state variables
304 //       are printed out periodically
305 //    16: When set various parameters are sanity checked and
306 //       a message is printed out when they go out of bounds
307
308 void FGAuxiliary::Debug(int from)
309 {
310   if (debug_lvl <= 0) return;
311
312   if (debug_lvl & 1) { // Standard console startup message output
313     if (from == 0) { // Constructor
314
315     }
316   }
317   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
318     if (from == 0) cout << "Instantiated: FGAuxiliary" << endl;
319     if (from == 1) cout << "Destroyed:    FGAuxiliary" << endl;
320   }
321   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
322   }
323   if (debug_lvl & 8 ) { // Runtime state variables
324   }
325   if (debug_lvl & 16) { // Sanity checking
326   }
327   if (debug_lvl & 64) {
328     if (from == 0) { // Constructor
329       cout << IdSrc << endl;
330       cout << IdHdr << endl;
331     }
332   }
333 }
334
335 } // namespace JSBSim