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