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