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