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 = 0.0;
107 alphaclmin = alphaclmax = 0.0;
108 HTailArea = VTailArea = 0.0;
109 HTailArm = VTailArm = 0.0;
112 bi2vel = ci2vel = 0.0;
120 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 FGAircraft::~FGAircraft()
128 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 bool FGAircraft::Run(void)
134 if (!FGModel::Run()) { // if false then execute this Run()
135 vForces.InitMatrix();
136 vForces += Aerodynamics->GetForces();
137 vForces += Inertial->GetForces();
138 vForces += Propulsion->GetForces();
139 vForces += GroundReactions->GetForces();
141 vMoments.InitMatrix();
142 vMoments += Aerodynamics->GetMoments();
143 vMoments += Propulsion->GetMoments();
144 vMoments += GroundReactions->GetMoments();
146 vBodyAccel = vForces/MassBalance->GetMass();
148 vNcg = vBodyAccel/Inertial->gravity();
150 vNwcg = State->GetTb2s() * vNcg;
151 vNwcg(3) = -1*vNwcg(3) + 1;
153 twovel = 2*Translation->GetVt();
155 bi2vel = WingSpan / twovel;
156 ci2vel = cbar / twovel;
159 alphaw = Translation->Getalpha() + WingIncidence;
161 if (alphaclmax != 0) {
162 if (Translation->Getalpha() > 0.85*alphaclmax) {
163 impending_stall = 10*(Translation->Getalpha()/alphaclmax - 0.85);
170 } else { // skip Run() execution this time
175 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 float FGAircraft::GetNlf(void)
179 return -1*Aerodynamics->GetvFs(3)/MassBalance->GetWeight();
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 bool FGAircraft::Load(FGConfigFile* AC_cfg)
188 double EW, bixx, biyy, bizz, bixy, bixz;
189 double pmWt, pmX, pmY, pmZ;
190 FGColumnVector3 vbaseXYZcg;
192 AC_cfg->GetNextConfigLine();
194 while ((token = AC_cfg->GetValue()) != string("/METRICS")) {
195 *AC_cfg >> parameter;
196 if (parameter == "AC_WINGAREA") {
198 if (debug_lvl > 0) cout << " WingArea: " << WingArea << endl;
199 } else if (parameter == "AC_WINGSPAN") {
201 if (debug_lvl > 0) cout << " WingSpan: " << WingSpan << endl;
202 } else if (parameter == "AC_WINGINCIDENCE") {
203 *AC_cfg >> WingIncidence;
204 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
205 } else if (parameter == "AC_CHORD") {
207 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
208 } else if (parameter == "AC_HTAILAREA") {
209 *AC_cfg >> HTailArea;
210 if (debug_lvl > 0) cout << " H. Tail Area: " << HTailArea << endl;
211 } else if (parameter == "AC_HTAILARM") {
213 if (debug_lvl > 0) cout << " H. Tail Arm: " << HTailArm << endl;
214 } else if (parameter == "AC_VTAILAREA") {
215 *AC_cfg >> VTailArea;
216 if (debug_lvl > 0) cout << " V. Tail Area: " << VTailArea << endl;
217 } else if (parameter == "AC_VTAILARM") {
219 if (debug_lvl > 0) cout << " V. Tail Arm: " << VTailArm << endl;
220 } else if (parameter == "AC_IXX") {
222 if (debug_lvl > 0) cout << " baseIxx: " << bixx << endl;
223 MassBalance->SetBaseIxx(bixx);
224 } else if (parameter == "AC_IYY") {
226 if (debug_lvl > 0) cout << " baseIyy: " << biyy << endl;
227 MassBalance->SetBaseIyy(biyy);
228 } else if (parameter == "AC_IZZ") {
230 if (debug_lvl > 0) cout << " baseIzz: " << bizz << endl;
231 MassBalance->SetBaseIzz(bizz);
232 } else if (parameter == "AC_IXY") {
234 if (debug_lvl > 0) cout << " baseIxy: " << bixy << endl;
235 MassBalance->SetBaseIxy(bixy);
236 } else if (parameter == "AC_IXZ") {
238 if (debug_lvl > 0) cout << " baseIxz: " << bixz << endl;
239 MassBalance->SetBaseIxz(bixz);
240 } else if (parameter == "AC_EMPTYWT") {
242 MassBalance->SetEmptyWeight(EW);
243 if (debug_lvl > 0) cout << " EmptyWeight: " << EW << endl;
244 } else if (parameter == "AC_CGLOC") {
245 *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
246 MassBalance->SetBaseCG(vbaseXYZcg);
247 if (debug_lvl > 0) cout << " CG (x, y, z): " << vbaseXYZcg << endl;
248 } else if (parameter == "AC_EYEPTLOC") {
249 *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
250 if (debug_lvl > 0) cout << " Eyepoint (x, y, z): " << vXYZep << endl;
251 } else if (parameter == "AC_AERORP") {
252 *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
253 if (debug_lvl > 0) cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
254 } else if (parameter == "AC_ALPHALIMITS") {
255 *AC_cfg >> alphaclmin >> alphaclmax;
256 if (debug_lvl > 0) cout << " Maximum Alpha: " << alphaclmax
257 << " Minimum Alpha: " << alphaclmin
259 } else if (parameter == "AC_POINTMASS") {
260 *AC_cfg >> pmWt >> pmX >> pmY >> pmZ;
261 MassBalance->AddPointMass(pmWt, pmX, pmY, pmZ);
262 if (debug_lvl > 0) cout << " Point Mass Object: " << pmWt << " lbs. at "
263 << "X, Y, Z (in.): " << pmX << " " << pmY << " " << pmZ
268 // calculate some derived parameters
270 lbarh = HTailArm/cbar;
271 lbarv = VTailArm/cbar;
272 if (WingArea != 0.0) {
273 vbarh = HTailArm*HTailArea / (cbar*WingArea);
274 vbarv = VTailArm*VTailArea / (cbar*WingArea);
280 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
282 void FGAircraft::bind(void)
284 PropertyManager->Tie("metrics/Sw-sqft", this,
285 &FGAircraft::GetWingArea);
286 PropertyManager->Tie("metrics/bw-ft", this,
287 &FGAircraft::GetWingSpan);
288 PropertyManager->Tie("metrics/cbarw-ft", this,
289 &FGAircraft::Getcbar);
290 PropertyManager->Tie("metrics/iw-deg", this,
291 &FGAircraft::GetWingIncidence);
292 PropertyManager->Tie("metrics/Sh-sqft", this,
293 &FGAircraft::GetHTailArea);
294 PropertyManager->Tie("metrics/lh-ft", this,
295 &FGAircraft::GetHTailArm);
296 PropertyManager->Tie("metrics/Sv-sqft", this,
297 &FGAircraft::GetVTailArea);
298 PropertyManager->Tie("metrics/lv-ft", this,
299 &FGAircraft::GetVTailArm);
300 PropertyManager->Tie("metrics/lh-norm", this,
301 &FGAircraft::Getlbarh);
302 PropertyManager->Tie("metrics/lv-norm", this,
303 &FGAircraft::Getlbarv);
304 PropertyManager->Tie("metrics/vbarh-norm", this,
305 &FGAircraft::Getvbarh);
306 PropertyManager->Tie("metrics/vbarv-norm", this,
307 &FGAircraft::Getvbarv);
308 PropertyManager->Tie("moments/l-total-lbsft", this,1,
309 &FGAircraft::GetMoments);
310 PropertyManager->Tie("moments/m-total-lbsft", this,2,
311 &FGAircraft::GetMoments);
312 PropertyManager->Tie("moments/n-total-lbsft", this,3,
313 &FGAircraft::GetMoments);
314 PropertyManager->Tie("forces/fbx-total-lbs", this,1,
315 &FGAircraft::GetForces);
316 PropertyManager->Tie("forces/fby-total-lbs", this,2,
317 &FGAircraft::GetForces);
318 PropertyManager->Tie("forces/fbz-total-lbs", this,3,
319 &FGAircraft::GetForces);
320 PropertyManager->Tie("metrics/aero-rp-x-ft", this,1,
321 &FGAircraft::GetXYZrp);
322 PropertyManager->Tie("metrics/aero-rp-y-ft", this,2,
323 &FGAircraft::GetXYZrp);
324 PropertyManager->Tie("metrics/aero-rp-z-ft", this,3,
325 &FGAircraft::GetXYZrp);
326 PropertyManager->Tie("metrics/eyepoint-x-ft", this,1,
327 &FGAircraft::GetXYZep);
328 PropertyManager->Tie("metrics/eyepoint-y-ft", this,2,
329 &FGAircraft::GetXYZep);
330 PropertyManager->Tie("metrics/eyepoint-z-ft", this,3,
331 &FGAircraft::GetXYZep);
332 PropertyManager->Tie("metrics/alpha-max-deg", this,
333 &FGAircraft::GetAlphaCLMax,
334 &FGAircraft::SetAlphaCLMax,
336 PropertyManager->Tie("metrics/alpha-min-deg", this,
337 &FGAircraft::GetAlphaCLMin,
338 &FGAircraft::SetAlphaCLMin,
340 PropertyManager->Tie("aero/bi2vel", this,
341 &FGAircraft::GetBI2Vel);
342 PropertyManager->Tie("aero/ci2vel", this,
343 &FGAircraft::GetCI2Vel);
344 PropertyManager->Tie("aero/alpha-wing-rad", this,
345 &FGAircraft::GetAlphaW);
346 PropertyManager->Tie("systems/stall-warn-norm", this,
347 &FGAircraft::GetStallWarn);
350 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
352 void FGAircraft::unbind(void)
354 PropertyManager->Untie("metrics/Sw-sqft");
355 PropertyManager->Untie("metrics/bw-ft");
356 PropertyManager->Untie("metrics/cbarw-ft");
357 PropertyManager->Untie("metrics/iw-deg");
358 PropertyManager->Untie("metrics/Sh-sqft");
359 PropertyManager->Untie("metrics/lh-ft");
360 PropertyManager->Untie("metrics/Sv-sqft");
361 PropertyManager->Untie("metrics/lv-ft");
362 PropertyManager->Untie("metrics/lh-norm");
363 PropertyManager->Untie("metrics/lv-norm");
364 PropertyManager->Untie("metrics/vbarh-norm");
365 PropertyManager->Untie("metrics/vbarv-norm");
366 PropertyManager->Untie("moments/l-total-lbsft");
367 PropertyManager->Untie("moments/m-total-lbsft");
368 PropertyManager->Untie("moments/n-total-lbsft");
369 PropertyManager->Untie("forces/fbx-total-lbs");
370 PropertyManager->Untie("forces/fby-total-lbs");
371 PropertyManager->Untie("forces/fbz-total-lbs");
372 PropertyManager->Untie("metrics/aero-rp-x-ft");
373 PropertyManager->Untie("metrics/aero-rp-y-ft");
374 PropertyManager->Untie("metrics/aero-rp-z-ft");
375 PropertyManager->Untie("metrics/eyepoint-x-ft");
376 PropertyManager->Untie("metrics/eyepoint-y-ft");
377 PropertyManager->Untie("metrics/eyepoint-z-ft");
378 PropertyManager->Untie("metrics/alpha-max-deg");
379 PropertyManager->Untie("metrics/alpha-min-deg");
380 PropertyManager->Untie("aero/bi2vel");
381 PropertyManager->Untie("aero/ci2vel");
382 PropertyManager->Untie("aero/alpha-wing-rad");
383 PropertyManager->Untie("systems/stall-warn-norm");
386 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387 // The bitmasked value choices are as follows:
388 // unset: In this case (the default) JSBSim would only print
389 // out the normally expected messages, essentially echoing
390 // the config files as they are read. If the environment
391 // variable is not set, debug_lvl is set to 1 internally
392 // 0: This requests JSBSim not to output any messages
394 // 1: This value explicity requests the normal JSBSim
396 // 2: This value asks for a message to be printed out when
397 // a class is instantiated
398 // 4: When this value is set, a message is displayed when a
399 // FGModel object executes its Run() method
400 // 8: When this value is set, various runtime state variables
401 // are printed out periodically
402 // 16: When set various parameters are sanity checked and
403 // a message is printed out when they go out of bounds
405 void FGAircraft::Debug(int from)
407 if (debug_lvl <= 0) return;
409 if (debug_lvl & 1) { // Standard console startup message output
410 if (from == 0) { // Constructor
413 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
414 if (from == 0) cout << "Instantiated: FGAircraft" << endl;
415 if (from == 1) cout << "Destroyed: FGAircraft" << endl;
417 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
419 if (debug_lvl & 8 ) { // Runtime state variables
421 if (debug_lvl & 16) { // Sanity checking
423 if (debug_lvl & 64) {
424 if (from == 0) { // Constructor
425 cout << IdSrc << endl;
426 cout << IdHdr << endl;