1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGAuxiliary.cpp
4 Author: Tony Peden, Jon Berndt
6 Purpose: Calculates additional parameters needed by the visual system, etc.
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This class calculates various auxiliary parameters.
33 Anderson, John D. "Introduction to Flight", 3rd Edition, McGraw-Hill, 1989
36 --------------------------------------------------------------------------------
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43 #include "FGAuxiliary.h"
44 #include "FGAerodynamics.h"
45 #include "FGTranslation.h"
46 #include "FGRotation.h"
47 #include "FGAtmosphere.h"
49 #include "FGFDMExec.h"
51 #include "FGAircraft.h"
52 #include "FGPosition.h"
54 #include "FGInertial.h"
55 #include "FGMatrix33.h"
56 #include "FGColumnVector3.h"
57 #include "FGColumnVector4.h"
58 #include "FGPropertyManager.h"
60 static const char *IdSrc = "$Id$";
61 static const char *IdHdr = ID_AUXILIARY;
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68 FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex)
71 vcas = veas = mach = qbar = pt = 0;
75 vPilotAccelN.InitMatrix();
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 FGAuxiliary::~FGAuxiliary()
90 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 bool FGAuxiliary::Run()
96 if (!FGModel::Run()) {
98 if (mach < 1) { //calculate total pressure assuming isentropic flow
99 pt=p*pow((1 + 0.2*mach*mach),3.5);
101 // shock in front of pitot tube, we'll assume its normal and use
102 // the Rayleigh Pitot Tube Formula, i.e. the ratio of total
103 // pressure behind the shock to the static pressure in front
105 B = 5.76*mach*mach/(5.6*mach*mach - 0.8);
107 // The denominator above is zero for Mach ~ 0.38, for which
108 // we'll never be here, so we're safe
110 D = (2.8*mach*mach-0.4)*0.4167;
114 A = pow(((pt-p)/psl+1),0.28571);
115 vcas = sqrt(7*psl/rhosl*(A-1));
116 veas = sqrt(2*qbar/rhosl);
118 // Pilot sensed accelerations are calculated here. This is used
119 // for the coordinated turn ball instrument. Motion base platforms sometimes
120 // use the derivative of pilot sensed accelerations as the driving parameter,
121 // rather than straight accelerations.
123 // The theory behind pilot-sensed calculations is presented:
125 // For purposes of discussion and calculation, assume for a minute that the
126 // pilot is in space and motionless in inertial space. She will feel
127 // no accelerations. If the aircraft begins to accelerate along any axis or
128 // axes (without rotating), the pilot will sense those accelerations. If
129 // any rotational moment is applied, the pilot will sense an acceleration
130 // due to that motion in the amount:
132 // [wdot X R] + [w X (w X R)]
137 // wdot = omegadot, the rotational acceleration rate vector
138 // w = omega, the rotational rate vector
139 // R = the vector from the aircraft CG to the pilot eyepoint
141 // The sum total of these two terms plus the acceleration of the aircraft
142 // body axis gives the acceleration the pilot senses in inertial space.
143 // In the presence of a large body such as a planet, a gravity field also
144 // provides an accelerating attraction. This acceleration can be transformed
145 // from the reference frame of the planet so as to be expressed in the frame
146 // of reference of the aircraft. This gravity field accelerating attraction
147 // is felt by the pilot as a force on her tushie as she sits in her aircraft
148 // on the runway awaiting takeoff clearance.
150 // In JSBSim the acceleration of the body frame in inertial space is given
151 // by the F = ma relation. If the vForces vector is divided by the aircraft
152 // mass, the acceleration vector is calculated. The term wdot is equivalent
153 // to the JSBSim vPQRdot vector, and the w parameter is equivalent to vPQR.
154 // The radius R is calculated below in the vector vToEyePt.
156 vPilotAccel.InitMatrix();
157 if ( Translation->GetVt() > 1 ) {
158 vPilotAccel = Aerodynamics->GetForces()
159 + Propulsion->GetForces()
160 + GroundReactions->GetForces();
161 vPilotAccel /= MassBalance->GetMass();
162 vToEyePt = Aircraft->GetXYZep() - MassBalance->GetXYZcg();
163 vToEyePt *= inchtoft;
164 vPilotAccel += Rotation->GetPQRdot() * vToEyePt;
165 vPilotAccel += Rotation->GetPQR() * (Rotation->GetPQR() * vToEyePt);
167 vPilotAccel = -1*( State->GetTl2b() * Inertial->GetGravity() );
170 vPilotAccelN = vPilotAccel/Inertial->gravity();
173 earthPosAngle += State->Getdt()*Inertial->omega();
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 double FGAuxiliary::GetHeadWind(void)
186 psiw = Atmosphere->GetWindPsi();
187 psi = Rotation->Getpsi();
188 vw = Atmosphere->GetWindNED().Magnitude();
190 return vw*cos(psiw - psi);
193 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 double FGAuxiliary::GetCrossWind(void)
199 psiw = Atmosphere->GetWindPsi();
200 psi = Rotation->Getpsi();
201 vw = Atmosphere->GetWindNED().Magnitude();
203 return vw*sin(psiw - psi);
206 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 void FGAuxiliary::bind(void)
210 typedef double (FGAuxiliary::*PMF)(int) const;
211 PropertyManager->Tie("velocities/vc-fps", this,
212 &FGAuxiliary::GetVcalibratedFPS);
213 PropertyManager->Tie("velocities/vc-kts", this,
214 &FGAuxiliary::GetVcalibratedKTS);
215 PropertyManager->Tie("velocities/ve-fps", this,
216 &FGAuxiliary::GetVequivalentFPS);
217 PropertyManager->Tie("velocities/ve-kts", this,
218 &FGAuxiliary::GetVequivalentKTS);
219 PropertyManager->Tie("accelerations/a-pilot-x-ft_sec2", this,1,
220 (PMF)&FGAuxiliary::GetPilotAccel);
221 PropertyManager->Tie("accelerations/a-pilot-y-ft_sec2", this,2,
222 (PMF)&FGAuxiliary::GetPilotAccel);
223 PropertyManager->Tie("accelerations/a-pilot-z-ft_sec2", this,3,
224 (PMF)&FGAuxiliary::GetPilotAccel);
225 PropertyManager->Tie("accelerations/n-pilot-x-norm", this,1,
226 (PMF)&FGAuxiliary::GetNpilot);
227 PropertyManager->Tie("accelerations/n-pilot-y-norm", this,2,
228 (PMF)&FGAuxiliary::GetNpilot);
229 PropertyManager->Tie("accelerations/n-pilot-z-norm", this,3,
230 (PMF)&FGAuxiliary::GetNpilot);
231 PropertyManager->Tie("position/epa-rad", this,
232 &FGAuxiliary::GetEarthPositionAngle);
233 /* PropertyManager->Tie("atmosphere/headwind-fps", this,
234 &FGAuxiliary::GetHeadWind,
236 PropertyManager->Tie("atmosphere/crosswind-fps", this,
237 &FGAuxiliary::GetCrossWind,
241 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 void FGAuxiliary::unbind(void)
245 PropertyManager->Untie("velocities/vc-fps");
246 PropertyManager->Untie("velocities/vc-kts");
247 PropertyManager->Untie("velocities/ve-fps");
248 PropertyManager->Untie("velocities/ve-kts");
249 PropertyManager->Untie("accelerations/a-pilot-x-ft_sec2");
250 PropertyManager->Untie("accelerations/a-pilot-y-ft_sec2");
251 PropertyManager->Untie("accelerations/a-pilot-z-ft_sec2");
252 PropertyManager->Untie("accelerations/n-pilot-x-norm");
253 PropertyManager->Untie("accelerations/n-pilot-y-norm");
254 PropertyManager->Untie("accelerations/n-pilot-z-norm");
255 PropertyManager->Untie("position/epa-rad");
256 /* PropertyManager->Untie("atmosphere/headwind-fps");
257 PropertyManager->Untie("atmosphere/crosswind-fps"); */
261 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 void FGAuxiliary::GetState(void)
265 qbar = Translation->Getqbar();
266 mach = Translation->GetMach();
267 p = Atmosphere->GetPressure();
268 rhosl = Atmosphere->GetDensitySL();
269 psl = Atmosphere->GetPressureSL();
272 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273 // The bitmasked value choices are as follows:
274 // unset: In this case (the default) JSBSim would only print
275 // out the normally expected messages, essentially echoing
276 // the config files as they are read. If the environment
277 // variable is not set, debug_lvl is set to 1 internally
278 // 0: This requests JSBSim not to output any messages
280 // 1: This value explicity requests the normal JSBSim
282 // 2: This value asks for a message to be printed out when
283 // a class is instantiated
284 // 4: When this value is set, a message is displayed when a
285 // FGModel object executes its Run() method
286 // 8: When this value is set, various runtime state variables
287 // are printed out periodically
288 // 16: When set various parameters are sanity checked and
289 // a message is printed out when they go out of bounds
291 void FGAuxiliary::Debug(int from)
293 if (debug_lvl <= 0) return;
295 if (debug_lvl & 1) { // Standard console startup message output
296 if (from == 0) { // Constructor
300 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
301 if (from == 0) cout << "Instantiated: FGAuxiliary" << endl;
302 if (from == 1) cout << "Destroyed: FGAuxiliary" << endl;
304 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
306 if (debug_lvl & 8 ) { // Runtime state variables
308 if (debug_lvl & 16) { // Sanity checking
310 if (debug_lvl & 64) {
311 if (from == 0) { // Constructor
312 cout << IdSrc << endl;
313 cout << IdHdr << endl;