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