1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Encapsulates an aircraft
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 Models the aircraft reactions and forces. This class is instantiated by the
31 FGFDMExec class and scheduled as an FDM entry.
34 --------------------------------------------------------------------------------
36 04/03/99 JSB Changed Aero() method to correct body axis force calculation
37 from wind vector. Fix provided by Tony Peden.
38 05/03/99 JSB Changed (for the better?) the way configurations are read in.
39 9/17/99 TP Combined force and moment functions. Added aero reference
40 point to config file. Added calculations for moments due to
41 difference in cg and aero reference point
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 COMMENTS, REFERENCES, and NOTES
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52 #include <sys/types.h>
56 # include <simgear/compiler.h>
58 # ifdef SG_HAVE_STD_INCLUDES
64 # if defined (sgi) && !defined(__GNUC__)
71 #include "FGAircraft.h"
72 #include "FGMassBalance.h"
73 #include "FGInertial.h"
74 #include "FGGroundReactions.h"
75 #include "FGAerodynamics.h"
76 #include "FGTranslation.h"
77 #include "FGRotation.h"
78 #include "FGAtmosphere.h"
80 #include "FGFDMExec.h"
82 #include "FGPosition.h"
83 #include "FGAuxiliary.h"
85 #include "FGPropertyManager.h"
87 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
91 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
95 static const char *IdSrc = "$Id$";
96 static const char *IdHdr = ID_AIRCRAFT;
98 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
102 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
106 impending_stall = stall_hyst = 0.0;
107 alphaclmin = alphaclmax = 0.0;
108 alphahystmin = alphahystmax = 0.0;
109 HTailArea = VTailArea = 0.0;
110 HTailArm = VTailArm = 0.0;
113 bi2vel = ci2vel = 0.0;
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 FGAircraft::~FGAircraft()
129 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 bool FGAircraft::Run(void)
136 if (!FGModel::Run()) { // if false then execute this Run()
137 vForces.InitMatrix();
138 vForces += Aerodynamics->GetForces();
139 vForces += Inertial->GetForces();
140 vForces += Propulsion->GetForces();
141 vForces += GroundReactions->GetForces();
143 vMoments.InitMatrix();
144 vMoments += Aerodynamics->GetMoments();
145 vMoments += Propulsion->GetMoments();
146 vMoments += GroundReactions->GetMoments();
148 vBodyAccel = vForces/MassBalance->GetMass();
150 vNcg = vBodyAccel/Inertial->gravity();
152 vNwcg = State->GetTb2s() * vNcg;
153 vNwcg(3) = -1*vNwcg(3) + 1;
155 twovel = 2*Translation->GetVt();
157 bi2vel = WingSpan / twovel;
158 ci2vel = cbar / twovel;
161 alphaw = Translation->Getalpha() + WingIncidence;
163 alpha=Translation->Getalpha();
165 if (alphaclmax != 0) {
166 if (alpha > 0.85*alphaclmax) {
167 impending_stall = 10*(alpha/alphaclmax - 0.85);
173 if(alphahystmax != 0.0 && alphahystmin != 0.0) {
174 if( alpha > alphahystmax ) {
176 } else if(alpha < alphahystmin) {
184 } else { // skip Run() execution this time
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 float FGAircraft::GetNlf(void)
193 return -1*Aerodynamics->GetvFs(3)/MassBalance->GetWeight();
196 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 bool FGAircraft::Load(FGConfigFile* AC_cfg)
202 double EW, bixx, biyy, bizz, bixy, bixz;
203 double pmWt, pmX, pmY, pmZ;
204 FGColumnVector3 vbaseXYZcg;
206 AC_cfg->GetNextConfigLine();
208 while ((token = AC_cfg->GetValue()) != string("/METRICS")) {
209 *AC_cfg >> parameter;
210 if (parameter == "AC_WINGAREA") {
212 if (debug_lvl > 0) cout << " WingArea: " << WingArea << endl;
213 } else if (parameter == "AC_WINGSPAN") {
215 if (debug_lvl > 0) cout << " WingSpan: " << WingSpan << endl;
216 } else if (parameter == "AC_WINGINCIDENCE") {
217 *AC_cfg >> WingIncidence;
218 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
219 } else if (parameter == "AC_CHORD") {
221 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
222 } else if (parameter == "AC_HTAILAREA") {
223 *AC_cfg >> HTailArea;
224 if (debug_lvl > 0) cout << " H. Tail Area: " << HTailArea << endl;
225 } else if (parameter == "AC_HTAILARM") {
227 if (debug_lvl > 0) cout << " H. Tail Arm: " << HTailArm << endl;
228 } else if (parameter == "AC_VTAILAREA") {
229 *AC_cfg >> VTailArea;
230 if (debug_lvl > 0) cout << " V. Tail Area: " << VTailArea << endl;
231 } else if (parameter == "AC_VTAILARM") {
233 if (debug_lvl > 0) cout << " V. Tail Arm: " << VTailArm << endl;
234 } else if (parameter == "AC_IXX") {
236 if (debug_lvl > 0) cout << " baseIxx: " << bixx << endl;
237 MassBalance->SetBaseIxx(bixx);
238 } else if (parameter == "AC_IYY") {
240 if (debug_lvl > 0) cout << " baseIyy: " << biyy << endl;
241 MassBalance->SetBaseIyy(biyy);
242 } else if (parameter == "AC_IZZ") {
244 if (debug_lvl > 0) cout << " baseIzz: " << bizz << endl;
245 MassBalance->SetBaseIzz(bizz);
246 } else if (parameter == "AC_IXY") {
248 if (debug_lvl > 0) cout << " baseIxy: " << bixy << endl;
249 MassBalance->SetBaseIxy(bixy);
250 } else if (parameter == "AC_IXZ") {
252 if (debug_lvl > 0) cout << " baseIxz: " << bixz << endl;
253 MassBalance->SetBaseIxz(bixz);
254 } else if (parameter == "AC_EMPTYWT") {
256 MassBalance->SetEmptyWeight(EW);
257 if (debug_lvl > 0) cout << " EmptyWeight: " << EW << endl;
258 } else if (parameter == "AC_CGLOC") {
259 *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
260 MassBalance->SetBaseCG(vbaseXYZcg);
261 if (debug_lvl > 0) cout << " CG (x, y, z): " << vbaseXYZcg << endl;
262 } else if (parameter == "AC_EYEPTLOC") {
263 *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
264 if (debug_lvl > 0) cout << " Eyepoint (x, y, z): " << vXYZep << endl;
265 } else if (parameter == "AC_AERORP") {
266 *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
267 if (debug_lvl > 0) cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
268 } else if (parameter == "AC_ALPHALIMITS") {
269 *AC_cfg >> alphaclmin >> alphaclmax;
270 if (debug_lvl > 0) cout << " Maximum Alpha: " << alphaclmax
271 << " Minimum Alpha: " << alphaclmin
273 } else if (parameter == "AC_HYSTLIMITS") {
274 *AC_cfg >> alphahystmin >> alphahystmax;
275 if (debug_lvl > 0) cout << " Hysteresis Start: " << alphahystmax
276 << " Hysteresis End: " << alphahystmin
278 } else if (parameter == "AC_POINTMASS") {
279 *AC_cfg >> pmWt >> pmX >> pmY >> pmZ;
280 MassBalance->AddPointMass(pmWt, pmX, pmY, pmZ);
281 if (debug_lvl > 0) cout << " Point Mass Object: " << pmWt << " lbs. at "
282 << "X, Y, Z (in.): " << pmX << " " << pmY << " " << pmZ
287 // calculate some derived parameters
289 lbarh = HTailArm/cbar;
290 lbarv = VTailArm/cbar;
291 if (WingArea != 0.0) {
292 vbarh = HTailArm*HTailArea / (cbar*WingArea);
293 vbarv = VTailArm*VTailArea / (cbar*WingArea);
299 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301 void FGAircraft::bind(void)
303 typedef double (FGAircraft::*PMF)(int) const;
304 PropertyManager->Tie("metrics/Sw-sqft", this,
305 &FGAircraft::GetWingArea);
306 PropertyManager->Tie("metrics/bw-ft", this,
307 &FGAircraft::GetWingSpan);
308 PropertyManager->Tie("metrics/cbarw-ft", this,
309 &FGAircraft::Getcbar);
310 PropertyManager->Tie("metrics/iw-deg", this,
311 &FGAircraft::GetWingIncidence);
312 PropertyManager->Tie("metrics/Sh-sqft", this,
313 &FGAircraft::GetHTailArea);
314 PropertyManager->Tie("metrics/lh-ft", this,
315 &FGAircraft::GetHTailArm);
316 PropertyManager->Tie("metrics/Sv-sqft", this,
317 &FGAircraft::GetVTailArea);
318 PropertyManager->Tie("metrics/lv-ft", this,
319 &FGAircraft::GetVTailArm);
320 PropertyManager->Tie("metrics/lh-norm", this,
321 &FGAircraft::Getlbarh);
322 PropertyManager->Tie("metrics/lv-norm", this,
323 &FGAircraft::Getlbarv);
324 PropertyManager->Tie("metrics/vbarh-norm", this,
325 &FGAircraft::Getvbarh);
326 PropertyManager->Tie("metrics/vbarv-norm", this,
327 &FGAircraft::Getvbarv);
328 PropertyManager->Tie("moments/l-total-lbsft", this,1,
329 (PMF)&FGAircraft::GetMoments);
330 PropertyManager->Tie("moments/m-total-lbsft", this,2,
331 (PMF)&FGAircraft::GetMoments);
332 PropertyManager->Tie("moments/n-total-lbsft", this,3,
333 (PMF)&FGAircraft::GetMoments);
334 PropertyManager->Tie("forces/fbx-total-lbs", this,1,
335 (PMF)&FGAircraft::GetForces);
336 PropertyManager->Tie("forces/fby-total-lbs", this,2,
337 (PMF)&FGAircraft::GetForces);
338 PropertyManager->Tie("forces/fbz-total-lbs", this,3,
339 (PMF)&FGAircraft::GetForces);
340 PropertyManager->Tie("metrics/aero-rp-x-ft", this,1,
341 (PMF)&FGAircraft::GetXYZrp);
342 PropertyManager->Tie("metrics/aero-rp-y-ft", this,2,
343 (PMF)&FGAircraft::GetXYZrp);
344 PropertyManager->Tie("metrics/aero-rp-z-ft", this,3,
345 (PMF)&FGAircraft::GetXYZrp);
346 PropertyManager->Tie("metrics/eyepoint-x-ft", this,1,
347 (PMF)&FGAircraft::GetXYZep);
348 PropertyManager->Tie("metrics/eyepoint-y-ft", this,2,
349 (PMF)&FGAircraft::GetXYZep);
350 PropertyManager->Tie("metrics/eyepoint-z-ft", this,3,
351 (PMF)&FGAircraft::GetXYZep);
352 PropertyManager->Tie("metrics/alpha-max-deg", this,
353 &FGAircraft::GetAlphaCLMax,
354 &FGAircraft::SetAlphaCLMax,
356 PropertyManager->Tie("metrics/alpha-min-deg", this,
357 &FGAircraft::GetAlphaCLMin,
358 &FGAircraft::SetAlphaCLMin,
360 PropertyManager->Tie("aero/bi2vel", this,
361 &FGAircraft::GetBI2Vel);
362 PropertyManager->Tie("aero/ci2vel", this,
363 &FGAircraft::GetCI2Vel);
364 PropertyManager->Tie("aero/alpha-wing-rad", this,
365 &FGAircraft::GetAlphaW);
366 PropertyManager->Tie("systems/stall-warn-norm", this,
367 &FGAircraft::GetStallWarn);
368 PropertyManager->Tie("aero/stall-hyst-norm", this,
369 &FGAircraft::GetHysteresisParm);
373 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
375 void FGAircraft::unbind(void)
377 PropertyManager->Untie("metrics/Sw-sqft");
378 PropertyManager->Untie("metrics/bw-ft");
379 PropertyManager->Untie("metrics/cbarw-ft");
380 PropertyManager->Untie("metrics/iw-deg");
381 PropertyManager->Untie("metrics/Sh-sqft");
382 PropertyManager->Untie("metrics/lh-ft");
383 PropertyManager->Untie("metrics/Sv-sqft");
384 PropertyManager->Untie("metrics/lv-ft");
385 PropertyManager->Untie("metrics/lh-norm");
386 PropertyManager->Untie("metrics/lv-norm");
387 PropertyManager->Untie("metrics/vbarh-norm");
388 PropertyManager->Untie("metrics/vbarv-norm");
389 PropertyManager->Untie("moments/l-total-lbsft");
390 PropertyManager->Untie("moments/m-total-lbsft");
391 PropertyManager->Untie("moments/n-total-lbsft");
392 PropertyManager->Untie("forces/fbx-total-lbs");
393 PropertyManager->Untie("forces/fby-total-lbs");
394 PropertyManager->Untie("forces/fbz-total-lbs");
395 PropertyManager->Untie("metrics/aero-rp-x-ft");
396 PropertyManager->Untie("metrics/aero-rp-y-ft");
397 PropertyManager->Untie("metrics/aero-rp-z-ft");
398 PropertyManager->Untie("metrics/eyepoint-x-ft");
399 PropertyManager->Untie("metrics/eyepoint-y-ft");
400 PropertyManager->Untie("metrics/eyepoint-z-ft");
401 PropertyManager->Untie("metrics/alpha-max-deg");
402 PropertyManager->Untie("metrics/alpha-min-deg");
403 PropertyManager->Untie("aero/bi2vel");
404 PropertyManager->Untie("aero/ci2vel");
405 PropertyManager->Untie("aero/alpha-wing-rad");
406 PropertyManager->Untie("systems/stall-warn-norm");
409 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410 // The bitmasked value choices are as follows:
411 // unset: In this case (the default) JSBSim would only print
412 // out the normally expected messages, essentially echoing
413 // the config files as they are read. If the environment
414 // variable is not set, debug_lvl is set to 1 internally
415 // 0: This requests JSBSim not to output any messages
417 // 1: This value explicity requests the normal JSBSim
419 // 2: This value asks for a message to be printed out when
420 // a class is instantiated
421 // 4: When this value is set, a message is displayed when a
422 // FGModel object executes its Run() method
423 // 8: When this value is set, various runtime state variables
424 // are printed out periodically
425 // 16: When set various parameters are sanity checked and
426 // a message is printed out when they go out of bounds
428 void FGAircraft::Debug(int from)
430 if (debug_lvl <= 0) return;
432 if (debug_lvl & 1) { // Standard console startup message output
433 if (from == 0) { // Constructor
436 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
437 if (from == 0) cout << "Instantiated: FGAircraft" << endl;
438 if (from == 1) cout << "Destroyed: FGAircraft" << endl;
440 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
442 if (debug_lvl & 8 ) { // Runtime state variables
444 if (debug_lvl & 16) { // Sanity checking
446 if (debug_lvl & 64) {
447 if (from == 0) { // Constructor
448 cout << IdSrc << endl;
449 cout << IdHdr << endl;