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