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