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 "FGPropagate.h"
46 #include "FGAtmosphere.h"
48 #include "FGFDMExec.h"
49 #include "FGAircraft.h"
50 #include "FGInertial.h"
51 #include "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();
112 p = Atmosphere->GetPressure();
113 rhosl = Atmosphere->GetDensitySL();
114 psl = Atmosphere->GetPressureSL();
115 sat = Atmosphere->GetTemperature();
119 double cTht = Propagate->GetCosEuler(eTht);
120 double cPhi = Propagate->GetCosEuler(ePhi);
121 double sPhi = Propagate->GetSinEuler(ePhi);
123 vEulerRates(eTht) = vPQR(eQ)*cPhi - vPQR(eR)*sPhi;
125 vEulerRates(ePsi) = (vPQR(eQ)*sPhi + vPQR(eR)*cPhi)/cTht;
126 vEulerRates(ePhi) = vPQR(eP) + vEulerRates(ePsi)*sPhi;
129 vAeroPQR = vPQR + Atmosphere->GetTurbPQR();
133 vAeroUVW = vUVW + Propagate->GetTl2b()*Atmosphere->GetWindNED();
135 Vt = vAeroUVW.Magnitude();
137 if (vAeroUVW(eW) != 0.0)
138 alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
139 if (vAeroUVW(eV) != 0.0)
140 beta = vAeroUVW(eU)*vAeroUVW(eU)+vAeroUVW(eW)*vAeroUVW(eW) > 0.0 ? atan2(vAeroUVW(eV),
141 sqrt(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW))) : 0.0;
143 double mUW = (vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW));
145 if (vAeroUVW(eU) != 0.0)
146 signU = vAeroUVW(eU)/fabs(vAeroUVW(eU));
148 if ( (mUW == 0.0) || (Vt == 0.0) ) {
152 adot = (vAeroUVW(eU)*vUVWdot(eW) - vAeroUVW(eW)*vUVWdot(eU))/mUW;
153 bdot = (signU*mUW*vUVWdot(eV) - vAeroUVW(eV)*(vAeroUVW(eU)*vUVWdot(eU)
154 + vAeroUVW(eW)*vUVWdot(eW)))/(Vt*Vt*sqrt(mUW));
157 alpha = beta = adot = bdot = 0;
160 qbar = 0.5*Atmosphere->GetDensity()*Vt*Vt;
161 qbarUW = 0.5*Atmosphere->GetDensity()*(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW));
162 qbarUV = 0.5*Atmosphere->GetDensity()*(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eV)*vAeroUVW(eV));
163 Mach = Vt / Atmosphere->GetSoundSpeed();
164 MachU = vMachUVW(eU) = vAeroUVW(eU) / Atmosphere->GetSoundSpeed();
165 vMachUVW(eV) = vAeroUVW(eV) / Atmosphere->GetSoundSpeed();
166 vMachUVW(eW) = vAeroUVW(eW) / Atmosphere->GetSoundSpeed();
170 Vground = sqrt( vVel(eNorth)*vVel(eNorth) + vVel(eEast)*vVel(eEast) );
172 if (vVel(eNorth) == 0) psigt = 0;
173 else psigt = atan2(vVel(eEast), vVel(eNorth));
175 if (psigt < 0.0) psigt += 2*M_PI;
178 hdot_Vt = -vVel(eDown)/Vt;
179 if (fabs(hdot_Vt) <= 1) gamma = asin(hdot_Vt);
184 tat = sat*(1 + 0.2*Mach*Mach); // Total Temperature, isentropic flow
185 tatc = RankineToCelsius(tat);
187 if (MachU < 1) { // Calculate total pressure assuming isentropic flow
188 pt = p*pow((1 + 0.2*MachU*MachU),3.5);
190 // Use Rayleigh pitot tube formula for normal shock in front of pitot tube
191 B = 5.76*MachU*MachU/(5.6*MachU*MachU - 0.8);
192 D = (2.8*MachU*MachU-0.4)*0.4167;
196 A = pow(((pt-p)/psl+1),0.28571);
198 vcas = sqrt(7*psl/rhosl*(A-1));
199 veas = sqrt(2*qbar/rhosl);
204 vPilotAccel.InitMatrix();
206 vPilotAccel = Aerodynamics->GetForces()
207 + Propulsion->GetForces()
208 + GroundReactions->GetForces();
209 vPilotAccel /= MassBalance->GetMass();
210 vToEyePt = MassBalance->StructuralToBody(Aircraft->GetXYZep());
211 vPilotAccel += Propagate->GetPQRdot() * vToEyePt;
212 vPilotAccel += vPQR * (vPQR * vToEyePt);
214 vPilotAccel = Propagate->GetTl2b() * FGColumnVector3( 0.0, 0.0, Inertial->gravity() );
217 vPilotAccelN = vPilotAccel/Inertial->gravity();
219 earthPosAngle += State->Getdt()*Inertial->omega();
222 const FGLocation& vLocation = Propagate->GetLocation();
223 FGColumnVector3 vrpStructural = Aircraft->GetXYZvrp();
224 FGColumnVector3 vrpBody = MassBalance->StructuralToBody( vrpStructural );
225 FGColumnVector3 vrpLocal = Propagate->GetTb2l() * vrpBody;
226 vLocationVRP = vLocation.LocalToLocation( vrpLocal );
228 // Recompute some derived values now that we know the dependent parameters values ...
229 hoverbcg = Propagate->GetDistanceAGL() / Aircraft->GetWingSpan();
231 FGColumnVector3 vMac = Propagate->GetTb2l()*MassBalance->StructuralToBody(Aircraft->GetXYZrp());
232 hoverbmac = (Propagate->GetDistanceAGL() + vMac(3)) / Aircraft->GetWingSpan();
240 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242 double FGAuxiliary::GetHeadWind(void)
246 psiw = Atmosphere->GetWindPsi();
247 vw = Atmosphere->GetWindNED().Magnitude();
249 return vw*cos(psiw - Propagate->GetEuler(ePsi));
252 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254 double FGAuxiliary::GetCrossWind(void)
258 psiw = Atmosphere->GetWindPsi();
259 vw = Atmosphere->GetWindNED().Magnitude();
261 return vw*sin(psiw - Propagate->GetEuler(ePsi));
264 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266 void FGAuxiliary::bind(void)
268 typedef double (FGAuxiliary::*PMF)(int) const;
269 typedef double (FGAuxiliary::*PF)(void) const;
270 PropertyManager->Tie("velocities/vc-fps", this, &FGAuxiliary::GetVcalibratedFPS);
271 PropertyManager->Tie("velocities/vc-kts", this, &FGAuxiliary::GetVcalibratedKTS);
272 PropertyManager->Tie("velocities/ve-fps", this, &FGAuxiliary::GetVequivalentFPS);
273 PropertyManager->Tie("velocities/ve-kts", this, &FGAuxiliary::GetVequivalentKTS);
274 PropertyManager->Tie("velocities/machU", this, &FGAuxiliary::GetMachU);
275 PropertyManager->Tie("velocities/tat-r", this, &FGAuxiliary::GetTotalTemperature);
276 PropertyManager->Tie("velocities/tat-c", this, &FGAuxiliary::GetTAT_C);
277 PropertyManager->Tie("velocities/pt-lbs_sqft", this, &FGAuxiliary::GetTotalPressure);
278 PropertyManager->Tie("velocities/p-aero-rad_sec", this, eX, (PMF)&FGAuxiliary::GetAeroPQR);
279 PropertyManager->Tie("velocities/q-aero-rad_sec", this, eY, (PMF)&FGAuxiliary::GetAeroPQR);
280 PropertyManager->Tie("velocities/r-aero-rad_sec", this, eZ, (PMF)&FGAuxiliary::GetAeroPQR);
281 PropertyManager->Tie("velocities/phidot-rad_sec", this, ePhi, (PMF)&FGAuxiliary::GetEulerRates);
282 PropertyManager->Tie("velocities/thetadot-rad_sec", this, eTht, (PMF)&FGAuxiliary::GetEulerRates);
283 PropertyManager->Tie("velocities/psidot-rad_sec", this, ePsi, (PMF)&FGAuxiliary::GetEulerRates);
284 PropertyManager->Tie("velocities/u-aero-fps", this, eU, (PMF)&FGAuxiliary::GetAeroUVW);
285 PropertyManager->Tie("velocities/v-aero-fps", this, eV, (PMF)&FGAuxiliary::GetAeroUVW);
286 PropertyManager->Tie("velocities/w-aero-fps", this, eW, (PMF)&FGAuxiliary::GetAeroUVW);
287 PropertyManager->Tie("velocities/vt-fps", this, &FGAuxiliary::GetVt, &FGAuxiliary::SetVt, true);
288 PropertyManager->Tie("velocities/mach-norm", this, &FGAuxiliary::GetMach, &FGAuxiliary::SetMach, true);
289 PropertyManager->Tie("velocities/vg-fps", this, &FGAuxiliary::GetVground);
290 PropertyManager->Tie("accelerations/a-pilot-x-ft_sec2", this, eX, (PMF)&FGAuxiliary::GetPilotAccel);
291 PropertyManager->Tie("accelerations/a-pilot-y-ft_sec2", this, eY, (PMF)&FGAuxiliary::GetPilotAccel);
292 PropertyManager->Tie("accelerations/a-pilot-z-ft_sec2", this, eZ, (PMF)&FGAuxiliary::GetPilotAccel);
293 PropertyManager->Tie("accelerations/n-pilot-x-norm", this, eX, (PMF)&FGAuxiliary::GetNpilot);
294 PropertyManager->Tie("accelerations/n-pilot-y-norm", this, eY, (PMF)&FGAuxiliary::GetNpilot);
295 PropertyManager->Tie("accelerations/n-pilot-z-norm", this, eZ, (PMF)&FGAuxiliary::GetNpilot);
296 PropertyManager->Tie("position/epa-rad", this, &FGAuxiliary::GetEarthPositionAngle);
297 /* PropertyManager->Tie("atmosphere/headwind-fps", this, &FGAuxiliary::GetHeadWind, true);
298 PropertyManager->Tie("atmosphere/crosswind-fps", this, &FGAuxiliary::GetCrossWind, true); */
299 PropertyManager->Tie("aero/alpha-rad", this, (PF)&FGAuxiliary::Getalpha, &FGAuxiliary::Setalpha, true);
300 PropertyManager->Tie("aero/beta-rad", this, (PF)&FGAuxiliary::Getbeta, &FGAuxiliary::Setbeta, true);
301 PropertyManager->Tie("aero/mag-beta-rad", this, (PF)&FGAuxiliary::GetMagBeta);
302 PropertyManager->Tie("aero/alpha-deg", this, inDegrees, (PMF)&FGAuxiliary::Getalpha);
303 PropertyManager->Tie("aero/beta-deg", this, inDegrees, (PMF)&FGAuxiliary::Getbeta);
304 PropertyManager->Tie("aero/mag-beta-deg", this, inDegrees, (PMF)&FGAuxiliary::GetMagBeta);
305 PropertyManager->Tie("aero/qbar-psf", this, &FGAuxiliary::Getqbar, &FGAuxiliary::Setqbar, true);
306 PropertyManager->Tie("aero/qbarUW-psf", this, &FGAuxiliary::GetqbarUW, &FGAuxiliary::SetqbarUW, true);
307 PropertyManager->Tie("aero/qbarUV-psf", this, &FGAuxiliary::GetqbarUV, &FGAuxiliary::SetqbarUV, true);
308 PropertyManager->Tie("aero/alphadot-rad_sec", this, (PF)&FGAuxiliary::Getadot, &FGAuxiliary::Setadot, true);
309 PropertyManager->Tie("aero/betadot-rad_sec", this, (PF)&FGAuxiliary::Getbdot, &FGAuxiliary::Setbdot, true);
310 PropertyManager->Tie("aero/alphadot-deg_sec", this, inDegrees, (PMF)&FGAuxiliary::Getadot);
311 PropertyManager->Tie("aero/betadot-deg_sec", this, inDegrees, (PMF)&FGAuxiliary::Getbdot);
312 PropertyManager->Tie("aero/h_b-cg-ft", this, &FGAuxiliary::GetHOverBCG);
313 PropertyManager->Tie("aero/h_b-mac-ft", this, &FGAuxiliary::GetHOverBMAC);
314 PropertyManager->Tie("flight-path/gamma-rad", this, &FGAuxiliary::GetGamma, &FGAuxiliary::SetGamma);
315 PropertyManager->Tie("flight-path/psi-gt-rad", this, &FGAuxiliary::GetGroundTrack);
318 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
320 void FGAuxiliary::unbind(void)
322 PropertyManager->Untie("velocities/vc-fps");
323 PropertyManager->Untie("velocities/vc-kts");
324 PropertyManager->Untie("velocities/ve-fps");
325 PropertyManager->Untie("velocities/ve-kts");
326 PropertyManager->Untie("velocities/machU");
327 PropertyManager->Untie("velocities/tat-r");
328 PropertyManager->Untie("velocities/tat-c");
329 PropertyManager->Untie("velocities/p-aero-rad_sec");
330 PropertyManager->Untie("velocities/q-aero-rad_sec");
331 PropertyManager->Untie("velocities/r-aero-rad_sec");
332 PropertyManager->Untie("velocities/pt-lbs_sqft");
333 PropertyManager->Untie("velocities/phidot-rad_sec");
334 PropertyManager->Untie("velocities/thetadot-rad_sec");
335 PropertyManager->Untie("velocities/psidot-rad_sec");
336 PropertyManager->Untie("velocities/u-aero-fps");
337 PropertyManager->Untie("velocities/v-aero-fps");
338 PropertyManager->Untie("velocities/w-aero-fps");
339 PropertyManager->Untie("velocities/vt-fps");
340 PropertyManager->Untie("velocities/mach-norm");
341 PropertyManager->Untie("velocities/vg-fps");
342 PropertyManager->Untie("accelerations/a-pilot-x-ft_sec2");
343 PropertyManager->Untie("accelerations/a-pilot-y-ft_sec2");
344 PropertyManager->Untie("accelerations/a-pilot-z-ft_sec2");
345 PropertyManager->Untie("accelerations/n-pilot-x-norm");
346 PropertyManager->Untie("accelerations/n-pilot-y-norm");
347 PropertyManager->Untie("accelerations/n-pilot-z-norm");
348 PropertyManager->Untie("position/epa-rad");
349 /* PropertyManager->Untie("atmosphere/headwind-fps");
350 PropertyManager->Untie("atmosphere/crosswind-fps"); */
351 PropertyManager->Untie("aero/qbar-psf");
352 PropertyManager->Untie("aero/qbarUW-psf");
353 PropertyManager->Untie("aero/qbarUV-psf");
354 PropertyManager->Untie("aero/alpha-rad");
355 PropertyManager->Untie("aero/beta-rad");
356 PropertyManager->Untie("aero/alpha-deg");
357 PropertyManager->Untie("aero/beta-deg");
358 PropertyManager->Untie("aero/alphadot-rad_sec");
359 PropertyManager->Untie("aero/betadot-rad_sec");
360 PropertyManager->Untie("aero/mag-beta-rad");
361 PropertyManager->Untie("aero/alphadot-deg_sec");
362 PropertyManager->Untie("aero/betadot-deg_sec");
363 PropertyManager->Untie("aero/mag-beta-deg");
364 PropertyManager->Untie("aero/h_b-cg-ft");
365 PropertyManager->Untie("aero/h_b-mac-ft");
366 PropertyManager->Untie("flight-path/gamma-rad");
367 PropertyManager->Untie("flight-path/psi-gt-rad");
370 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
371 // The bitmasked value choices are as follows:
372 // unset: In this case (the default) JSBSim would only print
373 // out the normally expected messages, essentially echoing
374 // the config files as they are read. If the environment
375 // variable is not set, debug_lvl is set to 1 internally
376 // 0: This requests JSBSim not to output any messages
378 // 1: This value explicity requests the normal JSBSim
380 // 2: This value asks for a message to be printed out when
381 // a class is instantiated
382 // 4: When this value is set, a message is displayed when a
383 // FGModel object executes its Run() method
384 // 8: When this value is set, various runtime state variables
385 // are printed out periodically
386 // 16: When set various parameters are sanity checked and
387 // a message is printed out when they go out of bounds
389 void FGAuxiliary::Debug(int from)
391 if (debug_lvl <= 0) return;
393 if (debug_lvl & 1) { // Standard console startup message output
394 if (from == 0) { // Constructor
398 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
399 if (from == 0) cout << "Instantiated: FGAuxiliary" << endl;
400 if (from == 1) cout << "Destroyed: FGAuxiliary" << endl;
402 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
404 if (debug_lvl & 8 ) { // Runtime state variables
406 if (debug_lvl & 16) { // Sanity checking
407 if (Mach > 100 || Mach < 0.00)
408 cout << "FGPropagate::Mach is out of bounds: " << Mach << endl;
409 if (qbar > 1e6 || qbar < 0.00)
410 cout << "FGPropagate::qbar is out of bounds: " << qbar << endl;
412 if (debug_lvl & 64) {
413 if (from == 0) { // Constructor
414 cout << IdSrc << endl;
415 cout << IdHdr << endl;
420 } // namespace JSBSim