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()
104 double A,B,D, hdot_Vt;
105 const FGColumnVector3& vPQR = Propagate->GetPQR();
106 const FGColumnVector3& vUVW = Propagate->GetUVW();
107 const FGColumnVector3& vUVWdot = Propagate->GetUVWdot();
108 const FGColumnVector3& vVel = Propagate->GetVel();
110 if (FGModel::Run()) return true; // return true if error returned from base class
112 if (FDMExec->Holding()) return false;
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 if (vVel(eNorth) == 0) psigt = 0;
186 else psigt = atan2(vVel(eEast), vVel(eNorth));
188 if (psigt < 0.0) psigt += 2*M_PI;
190 if (Vground == 0.0) {
191 if (vVel(eDown) == 0.0) gamma = 0.0;
192 else if (vVel(eDown) < 0.0) gamma = 90.0*degtorad;
193 else gamma = -90.0*degtorad;
195 gamma = atan2(-vVel(eDown), Vground);
198 tat = sat*(1 + 0.2*Mach*Mach); // Total Temperature, isentropic flow
199 tatc = RankineToCelsius(tat);
201 if (MachU < 1) { // Calculate total pressure assuming isentropic flow
202 pt = p*pow((1 + 0.2*MachU*MachU),3.5);
204 // Use Rayleigh pitot tube formula for normal shock in front of pitot tube
205 B = 5.76*MachU*MachU/(5.6*MachU*MachU - 0.8);
206 D = (2.8*MachU*MachU-0.4)*0.4167;
210 A = pow(((pt-p)/psl+1),0.28571);
212 vcas = sqrt(7*psl/rhosl*(A-1));
213 veas = sqrt(2*qbar/rhosl);
218 vPilotAccel.InitMatrix();
220 vPilotAccel = Aerodynamics->GetForces()
221 + Propulsion->GetForces()
222 + GroundReactions->GetForces();
223 vPilotAccel /= MassBalance->GetMass();
224 vToEyePt = MassBalance->StructuralToBody(Aircraft->GetXYZep());
225 vPilotAccel += Propagate->GetPQRdot() * vToEyePt;
226 vPilotAccel += vPQR * (vPQR * vToEyePt);
228 // The line below handles low velocity (and on-ground) cases, basically
229 // representing the opposite of the force that the landing gear would
230 // exert on the ground (which is just the total weight). This eliminates
231 // any jitter that could be introduced by the landing gear. Theoretically,
232 // this branch could be eliminated, with a penalty of having a short
233 // transient at startup (lasting only a fraction of a second).
234 vPilotAccel = Propagate->GetTl2b() * FGColumnVector3( 0.0, 0.0, -Inertial->gravity() );
237 vPilotAccelN = vPilotAccel/Inertial->gravity();
239 earthPosAngle += State->Getdt()*Inertial->omega();
242 const FGLocation& vLocation = Propagate->GetLocation();
243 FGColumnVector3 vrpStructural = Aircraft->GetXYZvrp();
244 FGColumnVector3 vrpBody = MassBalance->StructuralToBody( vrpStructural );
245 FGColumnVector3 vrpLocal = Propagate->GetTb2l() * vrpBody;
246 vLocationVRP = vLocation.LocalToLocation( vrpLocal );
248 // Recompute some derived values now that we know the dependent parameters values ...
249 hoverbcg = Propagate->GetDistanceAGL() / Aircraft->GetWingSpan();
251 FGColumnVector3 vMac = Propagate->GetTb2l()*MassBalance->StructuralToBody(Aircraft->GetXYZrp());
252 hoverbmac = (Propagate->GetDistanceAGL() + vMac(3)) / Aircraft->GetWingSpan();
257 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 double FGAuxiliary::GetHeadWind(void)
263 psiw = Atmosphere->GetWindPsi();
264 vw = Atmosphere->GetWindNED().Magnitude();
266 return vw*cos(psiw - Propagate->GetEuler(ePsi));
269 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271 double FGAuxiliary::GetCrossWind(void)
275 psiw = Atmosphere->GetWindPsi();
276 vw = Atmosphere->GetWindNED().Magnitude();
278 return vw*sin(psiw - Propagate->GetEuler(ePsi));
281 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
283 void FGAuxiliary::bind(void)
285 typedef double (FGAuxiliary::*PMF)(int) const;
286 typedef double (FGAuxiliary::*PF)(void) const;
287 PropertyManager->Tie("propulsion/tat-r", this, &FGAuxiliary::GetTotalTemperature);
288 PropertyManager->Tie("propulsion/tat-c", this, &FGAuxiliary::GetTAT_C);
289 PropertyManager->Tie("propulsion/pt-lbs_sqft", this, &FGAuxiliary::GetTotalPressure);
290 PropertyManager->Tie("velocities/vc-fps", this, &FGAuxiliary::GetVcalibratedFPS);
291 PropertyManager->Tie("velocities/vc-kts", this, &FGAuxiliary::GetVcalibratedKTS);
292 PropertyManager->Tie("velocities/ve-fps", this, &FGAuxiliary::GetVequivalentFPS);
293 PropertyManager->Tie("velocities/ve-kts", this, &FGAuxiliary::GetVequivalentKTS);
294 PropertyManager->Tie("velocities/machU", this, &FGAuxiliary::GetMachU);
295 PropertyManager->Tie("velocities/p-aero-rad_sec", this, eX, (PMF)&FGAuxiliary::GetAeroPQR);
296 PropertyManager->Tie("velocities/q-aero-rad_sec", this, eY, (PMF)&FGAuxiliary::GetAeroPQR);
297 PropertyManager->Tie("velocities/r-aero-rad_sec", this, eZ, (PMF)&FGAuxiliary::GetAeroPQR);
298 PropertyManager->Tie("velocities/phidot-rad_sec", this, ePhi, (PMF)&FGAuxiliary::GetEulerRates);
299 PropertyManager->Tie("velocities/thetadot-rad_sec", this, eTht, (PMF)&FGAuxiliary::GetEulerRates);
300 PropertyManager->Tie("velocities/psidot-rad_sec", this, ePsi, (PMF)&FGAuxiliary::GetEulerRates);
301 PropertyManager->Tie("velocities/u-aero-fps", this, eU, (PMF)&FGAuxiliary::GetAeroUVW);
302 PropertyManager->Tie("velocities/v-aero-fps", this, eV, (PMF)&FGAuxiliary::GetAeroUVW);
303 PropertyManager->Tie("velocities/w-aero-fps", this, eW, (PMF)&FGAuxiliary::GetAeroUVW);
304 PropertyManager->Tie("velocities/vt-fps", this, &FGAuxiliary::GetVt, &FGAuxiliary::SetVt, true);
305 PropertyManager->Tie("velocities/mach", this, &FGAuxiliary::GetMach, &FGAuxiliary::SetMach, true);
306 PropertyManager->Tie("velocities/vg-fps", this, &FGAuxiliary::GetVground);
307 PropertyManager->Tie("accelerations/a-pilot-x-ft_sec2", this, eX, (PMF)&FGAuxiliary::GetPilotAccel);
308 PropertyManager->Tie("accelerations/a-pilot-y-ft_sec2", this, eY, (PMF)&FGAuxiliary::GetPilotAccel);
309 PropertyManager->Tie("accelerations/a-pilot-z-ft_sec2", this, eZ, (PMF)&FGAuxiliary::GetPilotAccel);
310 PropertyManager->Tie("accelerations/n-pilot-x-norm", this, eX, (PMF)&FGAuxiliary::GetNpilot);
311 PropertyManager->Tie("accelerations/n-pilot-y-norm", this, eY, (PMF)&FGAuxiliary::GetNpilot);
312 PropertyManager->Tie("accelerations/n-pilot-z-norm", this, eZ, (PMF)&FGAuxiliary::GetNpilot);
313 PropertyManager->Tie("position/epa-rad", this, &FGAuxiliary::GetEarthPositionAngle);
314 /* PropertyManager->Tie("atmosphere/headwind-fps", this, &FGAuxiliary::GetHeadWind, true);
315 PropertyManager->Tie("atmosphere/crosswind-fps", this, &FGAuxiliary::GetCrossWind, true); */
316 PropertyManager->Tie("aero/alpha-rad", this, (PF)&FGAuxiliary::Getalpha, &FGAuxiliary::Setalpha, true);
317 PropertyManager->Tie("aero/beta-rad", this, (PF)&FGAuxiliary::Getbeta, &FGAuxiliary::Setbeta, true);
318 PropertyManager->Tie("aero/mag-beta-rad", this, (PF)&FGAuxiliary::GetMagBeta);
319 PropertyManager->Tie("aero/alpha-deg", this, inDegrees, (PMF)&FGAuxiliary::Getalpha);
320 PropertyManager->Tie("aero/beta-deg", this, inDegrees, (PMF)&FGAuxiliary::Getbeta);
321 PropertyManager->Tie("aero/mag-beta-deg", this, inDegrees, (PMF)&FGAuxiliary::GetMagBeta);
322 PropertyManager->Tie("aero/qbar-psf", this, &FGAuxiliary::Getqbar, &FGAuxiliary::Setqbar, true);
323 PropertyManager->Tie("aero/qbarUW-psf", this, &FGAuxiliary::GetqbarUW, &FGAuxiliary::SetqbarUW, true);
324 PropertyManager->Tie("aero/qbarUV-psf", this, &FGAuxiliary::GetqbarUV, &FGAuxiliary::SetqbarUV, true);
325 PropertyManager->Tie("aero/alphadot-rad_sec", this, (PF)&FGAuxiliary::Getadot, &FGAuxiliary::Setadot, true);
326 PropertyManager->Tie("aero/betadot-rad_sec", this, (PF)&FGAuxiliary::Getbdot, &FGAuxiliary::Setbdot, true);
327 PropertyManager->Tie("aero/alphadot-deg_sec", this, inDegrees, (PMF)&FGAuxiliary::Getadot);
328 PropertyManager->Tie("aero/betadot-deg_sec", this, inDegrees, (PMF)&FGAuxiliary::Getbdot);
329 PropertyManager->Tie("aero/h_b-cg-ft", this, &FGAuxiliary::GetHOverBCG);
330 PropertyManager->Tie("aero/h_b-mac-ft", this, &FGAuxiliary::GetHOverBMAC);
331 PropertyManager->Tie("flight-path/gamma-rad", this, &FGAuxiliary::GetGamma, &FGAuxiliary::SetGamma);
332 PropertyManager->Tie("flight-path/psi-gt-rad", this, &FGAuxiliary::GetGroundTrack);
335 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 void FGAuxiliary::unbind(void)
339 PropertyManager->Untie("propulsion/tat-r");
340 PropertyManager->Untie("propulsion/tat-c");
341 PropertyManager->Untie("propulsion/pt-lbs_sqft");
343 PropertyManager->Untie("velocities/vc-fps");
344 PropertyManager->Untie("velocities/vc-kts");
345 PropertyManager->Untie("velocities/ve-fps");
346 PropertyManager->Untie("velocities/ve-kts");
347 PropertyManager->Untie("velocities/machU");
348 PropertyManager->Untie("velocities/p-aero-rad_sec");
349 PropertyManager->Untie("velocities/q-aero-rad_sec");
350 PropertyManager->Untie("velocities/r-aero-rad_sec");
351 PropertyManager->Untie("velocities/phidot-rad_sec");
352 PropertyManager->Untie("velocities/thetadot-rad_sec");
353 PropertyManager->Untie("velocities/psidot-rad_sec");
354 PropertyManager->Untie("velocities/u-aero-fps");
355 PropertyManager->Untie("velocities/v-aero-fps");
356 PropertyManager->Untie("velocities/w-aero-fps");
357 PropertyManager->Untie("velocities/vt-fps");
358 PropertyManager->Untie("velocities/mach");
359 PropertyManager->Untie("velocities/vg-fps");
360 PropertyManager->Untie("accelerations/a-pilot-x-ft_sec2");
361 PropertyManager->Untie("accelerations/a-pilot-y-ft_sec2");
362 PropertyManager->Untie("accelerations/a-pilot-z-ft_sec2");
363 PropertyManager->Untie("accelerations/n-pilot-x-norm");
364 PropertyManager->Untie("accelerations/n-pilot-y-norm");
365 PropertyManager->Untie("accelerations/n-pilot-z-norm");
366 PropertyManager->Untie("position/epa-rad");
367 /* PropertyManager->Untie("atmosphere/headwind-fps");
368 PropertyManager->Untie("atmosphere/crosswind-fps"); */
369 PropertyManager->Untie("aero/qbar-psf");
370 PropertyManager->Untie("aero/qbarUW-psf");
371 PropertyManager->Untie("aero/qbarUV-psf");
372 PropertyManager->Untie("aero/alpha-rad");
373 PropertyManager->Untie("aero/beta-rad");
374 PropertyManager->Untie("aero/alpha-deg");
375 PropertyManager->Untie("aero/beta-deg");
376 PropertyManager->Untie("aero/alphadot-rad_sec");
377 PropertyManager->Untie("aero/betadot-rad_sec");
378 PropertyManager->Untie("aero/mag-beta-rad");
379 PropertyManager->Untie("aero/alphadot-deg_sec");
380 PropertyManager->Untie("aero/betadot-deg_sec");
381 PropertyManager->Untie("aero/mag-beta-deg");
382 PropertyManager->Untie("aero/h_b-cg-ft");
383 PropertyManager->Untie("aero/h_b-mac-ft");
384 PropertyManager->Untie("flight-path/gamma-rad");
385 PropertyManager->Untie("flight-path/psi-gt-rad");
388 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
389 // The bitmasked value choices are as follows:
390 // unset: In this case (the default) JSBSim would only print
391 // out the normally expected messages, essentially echoing
392 // the config files as they are read. If the environment
393 // variable is not set, debug_lvl is set to 1 internally
394 // 0: This requests JSBSim not to output any messages
396 // 1: This value explicity requests the normal JSBSim
398 // 2: This value asks for a message to be printed out when
399 // a class is instantiated
400 // 4: When this value is set, a message is displayed when a
401 // FGModel object executes its Run() method
402 // 8: When this value is set, various runtime state variables
403 // are printed out periodically
404 // 16: When set various parameters are sanity checked and
405 // a message is printed out when they go out of bounds
407 void FGAuxiliary::Debug(int from)
409 if (debug_lvl <= 0) return;
411 if (debug_lvl & 1) { // Standard console startup message output
412 if (from == 0) { // Constructor
416 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
417 if (from == 0) cout << "Instantiated: FGAuxiliary" << endl;
418 if (from == 1) cout << "Destroyed: FGAuxiliary" << endl;
420 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
422 if (debug_lvl & 8 ) { // Runtime state variables
424 if (debug_lvl & 16) { // Sanity checking
425 if (Mach > 100 || Mach < 0.00)
426 cout << "FGPropagate::Mach is out of bounds: " << Mach << endl;
427 if (qbar > 1e6 || qbar < 0.00)
428 cout << "FGPropagate::qbar is out of bounds: " << qbar << endl;
430 if (debug_lvl & 64) {
431 if (from == 0) { // Constructor
432 cout << IdSrc << endl;
433 cout << IdHdr << endl;
438 } // namespace JSBSim