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 Lesser 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 Lesser General Public License for more
21 You should have received a copy of the GNU Lesser 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 Lesser 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 "FGPropagate.h"
46 #include "FGAtmosphere.h"
48 #include <FGFDMExec.h>
49 #include "FGAircraft.h"
50 #include "FGInertial.h"
51 #include <input_output/FGPropertyManager.h>
55 static const char *IdSrc = "$Id$";
56 static const char *IdHdr = ID_AUXILIARY;
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex)
66 vcas = veas = pt = tat = 0;
75 gamma = Vt = Vground = 0.0;
79 hoverbmac = hoverbcg = 0.0;
81 vPilotAccel.InitMatrix();
82 vPilotAccelN.InitMatrix();
83 vToEyePt.InitMatrix();
84 vAeroPQR.InitMatrix();
85 vEulerRates.InitMatrix();
92 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 FGAuxiliary::~FGAuxiliary()
100 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 bool FGAuxiliary::Run()
106 if (FGModel::Run()) return true; // return true if error returned from base class
107 if (FDMExec->Holding()) return false;
109 const FGColumnVector3& vPQR = Propagate->GetPQR();
110 const FGColumnVector3& vUVW = Propagate->GetUVW();
111 const FGColumnVector3& vUVWdot = Propagate->GetUVWdot();
112 const FGColumnVector3& vVel = Propagate->GetVel();
114 p = Atmosphere->GetPressure();
115 rhosl = Atmosphere->GetDensitySL();
116 psl = Atmosphere->GetPressureSL();
117 sat = Atmosphere->GetTemperature();
121 double cTht = Propagate->GetCosEuler(eTht);
122 double sTht = Propagate->GetSinEuler(eTht);
123 double cPhi = Propagate->GetCosEuler(ePhi);
124 double sPhi = Propagate->GetSinEuler(ePhi);
126 vEulerRates(eTht) = vPQR(eQ)*cPhi - vPQR(eR)*sPhi;
128 vEulerRates(ePsi) = (vPQR(eQ)*sPhi + vPQR(eR)*cPhi)/cTht;
129 vEulerRates(ePhi) = vPQR(eP) + vEulerRates(ePsi)*sTht;
132 // 12/16/2005, JSB: For ground handling purposes, at this time, let's ramp
133 // in the effects of wind from 10 fps to 30 fps when there is weight on the
134 // landing gear wheels.
136 if (GroundReactions->GetWOW() && vUVW(eU) < 10) {
139 } else if (GroundReactions->GetWOW() && vUVW(eU) < 30) {
140 double factor = (vUVW(eU) - 10.0)/20.0;
141 vAeroPQR = vPQR + factor*Atmosphere->GetTurbPQR();
142 vAeroUVW = vUVW + factor*Propagate->GetTl2b()*Atmosphere->GetWindNED();
144 vAeroPQR = vPQR + Atmosphere->GetTurbPQR();
145 vAeroUVW = vUVW + Propagate->GetTl2b()*Atmosphere->GetWindNED();
148 Vt = vAeroUVW.Magnitude();
150 if (vAeroUVW(eW) != 0.0)
151 alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
152 if (vAeroUVW(eV) != 0.0)
153 beta = vAeroUVW(eU)*vAeroUVW(eU)+vAeroUVW(eW)*vAeroUVW(eW) > 0.0 ? atan2(vAeroUVW(eV),
154 sqrt(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW))) : 0.0;
156 double mUW = (vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW));
158 if (vAeroUVW(eU) != 0.0)
159 signU = vAeroUVW(eU)/fabs(vAeroUVW(eU));
161 if ( (mUW == 0.0) || (Vt == 0.0) ) {
165 adot = (vAeroUVW(eU)*vUVWdot(eW) - vAeroUVW(eW)*vUVWdot(eU))/mUW;
166 bdot = (signU*mUW*vUVWdot(eV) - vAeroUVW(eV)*(vAeroUVW(eU)*vUVWdot(eU)
167 + vAeroUVW(eW)*vUVWdot(eW)))/(Vt*Vt*sqrt(mUW));
170 alpha = beta = adot = bdot = 0;
173 qbar = 0.5*Atmosphere->GetDensity()*Vt*Vt;
174 qbarUW = 0.5*Atmosphere->GetDensity()*(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW));
175 qbarUV = 0.5*Atmosphere->GetDensity()*(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eV)*vAeroUVW(eV));
176 Mach = Vt / Atmosphere->GetSoundSpeed();
177 MachU = vMachUVW(eU) = vAeroUVW(eU) / Atmosphere->GetSoundSpeed();
178 vMachUVW(eV) = vAeroUVW(eV) / Atmosphere->GetSoundSpeed();
179 vMachUVW(eW) = vAeroUVW(eW) / Atmosphere->GetSoundSpeed();
183 Vground = sqrt( vVel(eNorth)*vVel(eNorth) + vVel(eEast)*vVel(eEast) );
185 psigt = atan2(vVel(eEast), vVel(eNorth));
186 if (psigt < 0.0) psigt += 2*M_PI;
187 gamma = atan2(-vVel(eDown), Vground);
189 tat = sat*(1 + 0.2*Mach*Mach); // Total Temperature, isentropic flow
190 tatc = RankineToCelsius(tat);
192 if (MachU < 1) { // Calculate total pressure assuming isentropic flow
193 pt = p*pow((1 + 0.2*MachU*MachU),3.5);
195 // Use Rayleigh pitot tube formula for normal shock in front of pitot tube
196 B = 5.76*MachU*MachU/(5.6*MachU*MachU - 0.8);
197 D = (2.8*MachU*MachU-0.4)*0.4167;
201 A = pow(((pt-p)/psl+1),0.28571);
203 vcas = sqrt(7*psl/rhosl*(A-1));
204 veas = sqrt(2*qbar/rhosl);
209 vPilotAccel.InitMatrix();
211 vPilotAccel = Aerodynamics->GetForces()
212 + Propulsion->GetForces()
213 + GroundReactions->GetForces();
214 vPilotAccel /= MassBalance->GetMass();
215 vToEyePt = MassBalance->StructuralToBody(Aircraft->GetXYZep());
216 vPilotAccel += Propagate->GetPQRdot() * vToEyePt;
217 vPilotAccel += vPQR * (vPQR * vToEyePt);
219 // The line below handles low velocity (and on-ground) cases, basically
220 // representing the opposite of the force that the landing gear would
221 // exert on the ground (which is just the total weight). This eliminates
222 // any jitter that could be introduced by the landing gear. Theoretically,
223 // this branch could be eliminated, with a penalty of having a short
224 // transient at startup (lasting only a fraction of a second).
225 vPilotAccel = Propagate->GetTl2b() * FGColumnVector3( 0.0, 0.0, -Inertial->gravity() );
228 vPilotAccelN = vPilotAccel/Inertial->gravity();
230 earthPosAngle += State->Getdt()*Inertial->omega();
233 const FGLocation& vLocation = Propagate->GetLocation();
234 FGColumnVector3 vrpStructural = Aircraft->GetXYZvrp();
235 FGColumnVector3 vrpBody = MassBalance->StructuralToBody( vrpStructural );
236 FGColumnVector3 vrpLocal = Propagate->GetTb2l() * vrpBody;
237 vLocationVRP = vLocation.LocalToLocation( vrpLocal );
239 // Recompute some derived values now that we know the dependent parameters values ...
240 hoverbcg = Propagate->GetDistanceAGL() / Aircraft->GetWingSpan();
242 FGColumnVector3 vMac = Propagate->GetTb2l()*MassBalance->StructuralToBody(Aircraft->GetXYZrp());
243 hoverbmac = (Propagate->GetDistanceAGL() + vMac(3)) / Aircraft->GetWingSpan();
248 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 double FGAuxiliary::GetHeadWind(void)
254 psiw = Atmosphere->GetWindPsi();
255 vw = Atmosphere->GetWindNED().Magnitude();
257 return vw*cos(psiw - Propagate->GetEuler(ePsi));
260 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 double FGAuxiliary::GetCrossWind(void)
266 psiw = Atmosphere->GetWindPsi();
267 vw = Atmosphere->GetWindNED().Magnitude();
269 return vw*sin(psiw - Propagate->GetEuler(ePsi));
272 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 void FGAuxiliary::bind(void)
276 typedef double (FGAuxiliary::*PMF)(int) const;
277 typedef double (FGAuxiliary::*PF)(void) const;
278 PropertyManager->Tie("propulsion/tat-r", this, &FGAuxiliary::GetTotalTemperature);
279 PropertyManager->Tie("propulsion/tat-c", this, &FGAuxiliary::GetTAT_C);
280 PropertyManager->Tie("propulsion/pt-lbs_sqft", this, &FGAuxiliary::GetTotalPressure);
281 PropertyManager->Tie("velocities/vc-fps", this, &FGAuxiliary::GetVcalibratedFPS);
282 PropertyManager->Tie("velocities/vc-kts", this, &FGAuxiliary::GetVcalibratedKTS);
283 PropertyManager->Tie("velocities/ve-fps", this, &FGAuxiliary::GetVequivalentFPS);
284 PropertyManager->Tie("velocities/ve-kts", this, &FGAuxiliary::GetVequivalentKTS);
285 PropertyManager->Tie("velocities/machU", this, &FGAuxiliary::GetMachU);
286 PropertyManager->Tie("velocities/p-aero-rad_sec", this, eX, (PMF)&FGAuxiliary::GetAeroPQR);
287 PropertyManager->Tie("velocities/q-aero-rad_sec", this, eY, (PMF)&FGAuxiliary::GetAeroPQR);
288 PropertyManager->Tie("velocities/r-aero-rad_sec", this, eZ, (PMF)&FGAuxiliary::GetAeroPQR);
289 PropertyManager->Tie("velocities/phidot-rad_sec", this, ePhi, (PMF)&FGAuxiliary::GetEulerRates);
290 PropertyManager->Tie("velocities/thetadot-rad_sec", this, eTht, (PMF)&FGAuxiliary::GetEulerRates);
291 PropertyManager->Tie("velocities/psidot-rad_sec", this, ePsi, (PMF)&FGAuxiliary::GetEulerRates);
292 PropertyManager->Tie("velocities/u-aero-fps", this, eU, (PMF)&FGAuxiliary::GetAeroUVW);
293 PropertyManager->Tie("velocities/v-aero-fps", this, eV, (PMF)&FGAuxiliary::GetAeroUVW);
294 PropertyManager->Tie("velocities/w-aero-fps", this, eW, (PMF)&FGAuxiliary::GetAeroUVW);
295 PropertyManager->Tie("velocities/vt-fps", this, &FGAuxiliary::GetVt, &FGAuxiliary::SetVt, true);
296 PropertyManager->Tie("velocities/mach", this, &FGAuxiliary::GetMach, &FGAuxiliary::SetMach, true);
297 PropertyManager->Tie("velocities/vg-fps", this, &FGAuxiliary::GetVground);
298 PropertyManager->Tie("accelerations/a-pilot-x-ft_sec2", this, eX, (PMF)&FGAuxiliary::GetPilotAccel);
299 PropertyManager->Tie("accelerations/a-pilot-y-ft_sec2", this, eY, (PMF)&FGAuxiliary::GetPilotAccel);
300 PropertyManager->Tie("accelerations/a-pilot-z-ft_sec2", this, eZ, (PMF)&FGAuxiliary::GetPilotAccel);
301 PropertyManager->Tie("accelerations/n-pilot-x-norm", this, eX, (PMF)&FGAuxiliary::GetNpilot);
302 PropertyManager->Tie("accelerations/n-pilot-y-norm", this, eY, (PMF)&FGAuxiliary::GetNpilot);
303 PropertyManager->Tie("accelerations/n-pilot-z-norm", this, eZ, (PMF)&FGAuxiliary::GetNpilot);
304 PropertyManager->Tie("position/epa-rad", this, &FGAuxiliary::GetEarthPositionAngle);
305 /* PropertyManager->Tie("atmosphere/headwind-fps", this, &FGAuxiliary::GetHeadWind, true);
306 PropertyManager->Tie("atmosphere/crosswind-fps", this, &FGAuxiliary::GetCrossWind, true); */
307 PropertyManager->Tie("aero/alpha-rad", this, (PF)&FGAuxiliary::Getalpha, &FGAuxiliary::Setalpha, true);
308 PropertyManager->Tie("aero/beta-rad", this, (PF)&FGAuxiliary::Getbeta, &FGAuxiliary::Setbeta, true);
309 PropertyManager->Tie("aero/mag-beta-rad", this, (PF)&FGAuxiliary::GetMagBeta);
310 PropertyManager->Tie("aero/alpha-deg", this, inDegrees, (PMF)&FGAuxiliary::Getalpha);
311 PropertyManager->Tie("aero/beta-deg", this, inDegrees, (PMF)&FGAuxiliary::Getbeta);
312 PropertyManager->Tie("aero/mag-beta-deg", this, inDegrees, (PMF)&FGAuxiliary::GetMagBeta);
313 PropertyManager->Tie("aero/qbar-psf", this, &FGAuxiliary::Getqbar, &FGAuxiliary::Setqbar, true);
314 PropertyManager->Tie("aero/qbarUW-psf", this, &FGAuxiliary::GetqbarUW, &FGAuxiliary::SetqbarUW, true);
315 PropertyManager->Tie("aero/qbarUV-psf", this, &FGAuxiliary::GetqbarUV, &FGAuxiliary::SetqbarUV, true);
316 PropertyManager->Tie("aero/alphadot-rad_sec", this, (PF)&FGAuxiliary::Getadot, &FGAuxiliary::Setadot, true);
317 PropertyManager->Tie("aero/betadot-rad_sec", this, (PF)&FGAuxiliary::Getbdot, &FGAuxiliary::Setbdot, true);
318 PropertyManager->Tie("aero/alphadot-deg_sec", this, inDegrees, (PMF)&FGAuxiliary::Getadot);
319 PropertyManager->Tie("aero/betadot-deg_sec", this, inDegrees, (PMF)&FGAuxiliary::Getbdot);
320 PropertyManager->Tie("aero/h_b-cg-ft", this, &FGAuxiliary::GetHOverBCG);
321 PropertyManager->Tie("aero/h_b-mac-ft", this, &FGAuxiliary::GetHOverBMAC);
322 PropertyManager->Tie("flight-path/gamma-rad", this, &FGAuxiliary::GetGamma, &FGAuxiliary::SetGamma);
323 PropertyManager->Tie("flight-path/psi-gt-rad", this, &FGAuxiliary::GetGroundTrack);
326 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328 void FGAuxiliary::unbind(void)
330 PropertyManager->Untie("propulsion/tat-r");
331 PropertyManager->Untie("propulsion/tat-c");
332 PropertyManager->Untie("propulsion/pt-lbs_sqft");
334 PropertyManager->Untie("velocities/vc-fps");
335 PropertyManager->Untie("velocities/vc-kts");
336 PropertyManager->Untie("velocities/ve-fps");
337 PropertyManager->Untie("velocities/ve-kts");
338 PropertyManager->Untie("velocities/machU");
339 PropertyManager->Untie("velocities/p-aero-rad_sec");
340 PropertyManager->Untie("velocities/q-aero-rad_sec");
341 PropertyManager->Untie("velocities/r-aero-rad_sec");
342 PropertyManager->Untie("velocities/phidot-rad_sec");
343 PropertyManager->Untie("velocities/thetadot-rad_sec");
344 PropertyManager->Untie("velocities/psidot-rad_sec");
345 PropertyManager->Untie("velocities/u-aero-fps");
346 PropertyManager->Untie("velocities/v-aero-fps");
347 PropertyManager->Untie("velocities/w-aero-fps");
348 PropertyManager->Untie("velocities/vt-fps");
349 PropertyManager->Untie("velocities/mach");
350 PropertyManager->Untie("velocities/vg-fps");
351 PropertyManager->Untie("accelerations/a-pilot-x-ft_sec2");
352 PropertyManager->Untie("accelerations/a-pilot-y-ft_sec2");
353 PropertyManager->Untie("accelerations/a-pilot-z-ft_sec2");
354 PropertyManager->Untie("accelerations/n-pilot-x-norm");
355 PropertyManager->Untie("accelerations/n-pilot-y-norm");
356 PropertyManager->Untie("accelerations/n-pilot-z-norm");
357 PropertyManager->Untie("position/epa-rad");
358 /* PropertyManager->Untie("atmosphere/headwind-fps");
359 PropertyManager->Untie("atmosphere/crosswind-fps"); */
360 PropertyManager->Untie("aero/qbar-psf");
361 PropertyManager->Untie("aero/qbarUW-psf");
362 PropertyManager->Untie("aero/qbarUV-psf");
363 PropertyManager->Untie("aero/alpha-rad");
364 PropertyManager->Untie("aero/beta-rad");
365 PropertyManager->Untie("aero/alpha-deg");
366 PropertyManager->Untie("aero/beta-deg");
367 PropertyManager->Untie("aero/alphadot-rad_sec");
368 PropertyManager->Untie("aero/betadot-rad_sec");
369 PropertyManager->Untie("aero/mag-beta-rad");
370 PropertyManager->Untie("aero/alphadot-deg_sec");
371 PropertyManager->Untie("aero/betadot-deg_sec");
372 PropertyManager->Untie("aero/mag-beta-deg");
373 PropertyManager->Untie("aero/h_b-cg-ft");
374 PropertyManager->Untie("aero/h_b-mac-ft");
375 PropertyManager->Untie("flight-path/gamma-rad");
376 PropertyManager->Untie("flight-path/psi-gt-rad");
379 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380 // The bitmasked value choices are as follows:
381 // unset: In this case (the default) JSBSim would only print
382 // out the normally expected messages, essentially echoing
383 // the config files as they are read. If the environment
384 // variable is not set, debug_lvl is set to 1 internally
385 // 0: This requests JSBSim not to output any messages
387 // 1: This value explicity requests the normal JSBSim
389 // 2: This value asks for a message to be printed out when
390 // a class is instantiated
391 // 4: When this value is set, a message is displayed when a
392 // FGModel object executes its Run() method
393 // 8: When this value is set, various runtime state variables
394 // are printed out periodically
395 // 16: When set various parameters are sanity checked and
396 // a message is printed out when they go out of bounds
398 void FGAuxiliary::Debug(int from)
400 if (debug_lvl <= 0) return;
402 if (debug_lvl & 1) { // Standard console startup message output
403 if (from == 0) { // Constructor
407 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
408 if (from == 0) cout << "Instantiated: FGAuxiliary" << endl;
409 if (from == 1) cout << "Destroyed: FGAuxiliary" << endl;
411 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
413 if (debug_lvl & 8 ) { // Runtime state variables
415 if (debug_lvl & 16) { // Sanity checking
416 if (Mach > 100 || Mach < 0.00)
417 cout << "FGPropagate::Mach is out of bounds: " << Mach << endl;
418 if (qbar > 1e6 || qbar < 0.00)
419 cout << "FGPropagate::qbar is out of bounds: " << qbar << endl;
421 if (debug_lvl & 64) {
422 if (from == 0) { // Constructor
423 cout << IdSrc << endl;
424 cout << IdHdr << endl;
429 } // namespace JSBSim