1
0
Fork 0
flightgear/src/FDM/JSBSim/FGAircraft.cpp

387 lines
14 KiB
C++
Raw Normal View History

2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-05 21:26:01 +00:00
Module: FGAircraft.cpp
Author: Jon S. Berndt
Date started: 12/12/98
1999-02-05 21:26:01 +00:00
Purpose: Encapsulates an aircraft
Called by: FGFDMExec
1999-02-05 21:26:01 +00:00
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
1999-02-05 21:26:01 +00:00
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
1999-02-05 21:26:01 +00:00
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
1999-02-05 21:26:01 +00:00
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA.
1999-02-05 21:26:01 +00:00
Further information about the GNU General Public License can also be found on
the world wide web at http://www.gnu.org.
1999-02-05 21:26:01 +00:00
FUNCTIONAL DESCRIPTION
--------------------------------------------------------------------------------
Models the aircraft reactions and forces. This class is instantiated by the
2001-07-10 15:56:38 +00:00
FGFDMExec class and scheduled as an FDM entry.
1999-02-05 21:26:01 +00:00
HISTORY
--------------------------------------------------------------------------------
12/12/98 JSB Created
04/03/99 JSB Changed Aero() method to correct body axis force calculation
from wind vector. Fix provided by Tony Peden.
1999-05-08 03:19:08 +00:00
05/03/99 JSB Changed (for the better?) the way configurations are read in.
1999-12-20 20:24:49 +00:00
9/17/99 TP Combined force and moment functions. Added aero reference
point to config file. Added calculations for moments due to
2000-04-24 23:49:06 +00:00
difference in cg and aero reference point
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-05 21:26:01 +00:00
COMMENTS, REFERENCES, and NOTES
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-05 21:26:01 +00:00
INCLUDES
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
1999-05-08 03:19:08 +00:00
#include <sys/stat.h>
2000-04-24 23:49:06 +00:00
#include <sys/types.h>
#ifdef FGFS
# ifndef __BORLANDC__
# include <simgear/compiler.h>
# endif
# ifdef SG_HAVE_STD_INCLUDES
# include <cmath>
# else
# include <math.h>
# endif
#else
# if defined (sgi) && !defined(__GNUC__)
# include <math.h>
# else
# include <cmath>
# endif
#endif
1999-02-05 21:26:01 +00:00
#include "FGAircraft.h"
#include "FGMassBalance.h"
#include "FGInertial.h"
#include "FGGroundReactions.h"
#include "FGAerodynamics.h"
#include "FGTranslation.h"
#include "FGRotation.h"
#include "FGAtmosphere.h"
#include "FGState.h"
#include "FGFDMExec.h"
#include "FGFCS.h"
#include "FGPosition.h"
#include "FGAuxiliary.h"
#include "FGOutput.h"
#include "FGPropertyManager.h"
namespace JSBSim {
2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GLOBAL DATA
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
2001-03-30 01:04:50 +00:00
static const char *IdSrc = "$Id$";
static const char *IdHdr = ID_AIRCRAFT;
2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
1999-02-05 21:26:01 +00:00
2001-12-07 17:10:17 +00:00
FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
2000-05-27 05:48:14 +00:00
{
Name = "FGAircraft";
2003-06-03 08:46:15 +00:00
WingSpan = 0.0;
HTailArea = VTailArea = 0.0;
HTailArm = VTailArm = 0.0;
lbarh = lbarv = 0.0;
vbarh = vbarv = 0.0;
WingIncidence = 0.0;
bind();
2000-05-27 05:48:14 +00:00
Debug(0);
1999-02-05 21:26:01 +00:00
}
2000-11-03 23:02:47 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2000-04-24 23:49:06 +00:00
FGAircraft::~FGAircraft()
{
unbind();
Debug(1);
2000-10-02 23:07:30 +00:00
}
1999-02-05 21:26:01 +00:00
2000-11-03 23:02:47 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2000-04-24 23:49:06 +00:00
bool FGAircraft::Run(void)
{
1999-02-05 21:26:01 +00:00
if (!FGModel::Run()) { // if false then execute this Run()
vForces.InitMatrix();
vForces += Aerodynamics->GetForces();
vForces += Inertial->GetForces();
vForces += Propulsion->GetForces();
vForces += GroundReactions->GetForces();
vMoments.InitMatrix();
vMoments += Aerodynamics->GetMoments();
vMoments += Propulsion->GetMoments();
vMoments += GroundReactions->GetMoments();
vBodyAccel = vForces/MassBalance->GetMass();
2001-11-12 16:06:29 +00:00
vNcg = vBodyAccel/Inertial->gravity();
2001-11-30 17:49:37 +00:00
vNwcg = State->GetTb2s() * vNcg;
vNwcg(3) = -1*vNwcg(3) + 1;
2001-11-06 22:33:05 +00:00
return false;
1999-02-05 21:26:01 +00:00
} else { // skip Run() execution this time
return true;
1999-02-05 21:26:01 +00:00
}
}
2000-11-03 23:02:47 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2001-11-30 17:49:37 +00:00
float FGAircraft::GetNlf(void)
{
2002-02-26 22:28:41 +00:00
return -1*Aerodynamics->GetvFs(3)/MassBalance->GetWeight();
2001-11-30 17:49:37 +00:00
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2001-12-24 13:54:55 +00:00
bool FGAircraft::Load(FGConfigFile* AC_cfg)
{
2000-04-24 23:49:06 +00:00
string token = "";
string parameter;
2001-12-07 17:10:17 +00:00
double EW, bixx, biyy, bizz, bixy, bixz;
double pmWt, pmX, pmY, pmZ;
FGColumnVector3 vbaseXYZcg;
2000-04-24 23:49:06 +00:00
AC_cfg->GetNextConfigLine();
2001-11-20 22:34:24 +00:00
while ((token = AC_cfg->GetValue()) != string("/METRICS")) {
2000-04-24 23:49:06 +00:00
*AC_cfg >> parameter;
if (parameter == "AC_WINGAREA") {
*AC_cfg >> WingArea;
if (debug_lvl > 0) cout << " WingArea: " << WingArea << endl;
2000-07-06 21:02:46 +00:00
} else if (parameter == "AC_WINGSPAN") {
*AC_cfg >> WingSpan;
if (debug_lvl > 0) cout << " WingSpan: " << WingSpan << endl;
} else if (parameter == "AC_WINGINCIDENCE") {
*AC_cfg >> WingIncidence;
if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
2000-07-06 21:02:46 +00:00
} else if (parameter == "AC_CHORD") {
*AC_cfg >> cbar;
if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
} else if (parameter == "AC_HTAILAREA") {
*AC_cfg >> HTailArea;
if (debug_lvl > 0) cout << " H. Tail Area: " << HTailArea << endl;
} else if (parameter == "AC_HTAILARM") {
*AC_cfg >> HTailArm;
if (debug_lvl > 0) cout << " H. Tail Arm: " << HTailArm << endl;
} else if (parameter == "AC_VTAILAREA") {
*AC_cfg >> VTailArea;
if (debug_lvl > 0) cout << " V. Tail Area: " << VTailArea << endl;
} else if (parameter == "AC_VTAILARM") {
*AC_cfg >> VTailArm;
if (debug_lvl > 0) cout << " V. Tail Arm: " << VTailArm << endl;
2000-07-06 21:02:46 +00:00
} else if (parameter == "AC_IXX") {
*AC_cfg >> bixx;
if (debug_lvl > 0) cout << " baseIxx: " << bixx << endl;
MassBalance->SetBaseIxx(bixx);
2000-07-06 21:02:46 +00:00
} else if (parameter == "AC_IYY") {
*AC_cfg >> biyy;
if (debug_lvl > 0) cout << " baseIyy: " << biyy << endl;
MassBalance->SetBaseIyy(biyy);
} else if (parameter == "AC_IZZ") {
*AC_cfg >> bizz;
if (debug_lvl > 0) cout << " baseIzz: " << bizz << endl;
MassBalance->SetBaseIzz(bizz);
2001-12-07 17:10:17 +00:00
} else if (parameter == "AC_IXY") {
*AC_cfg >> bixy;
if (debug_lvl > 0) cout << " baseIxy: " << bixy << endl;
MassBalance->SetBaseIxy(bixy);
} else if (parameter == "AC_IXZ") {
*AC_cfg >> bixz;
if (debug_lvl > 0) cout << " baseIxz: " << bixz << endl;
MassBalance->SetBaseIxz(bixz);
2000-07-06 21:02:46 +00:00
} else if (parameter == "AC_EMPTYWT") {
*AC_cfg >> EW;
MassBalance->SetEmptyWeight(EW);
if (debug_lvl > 0) cout << " EmptyWeight: " << EW << endl;
2000-07-06 21:02:46 +00:00
} else if (parameter == "AC_CGLOC") {
*AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
MassBalance->SetBaseCG(vbaseXYZcg);
if (debug_lvl > 0) cout << " CG (x, y, z): " << vbaseXYZcg << endl;
2000-07-06 21:02:46 +00:00
} else if (parameter == "AC_EYEPTLOC") {
*AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
if (debug_lvl > 0) cout << " Eyepoint (x, y, z): " << vXYZep << endl;
2000-07-06 21:02:46 +00:00
} else if (parameter == "AC_AERORP") {
*AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
if (debug_lvl > 0) cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
2001-12-07 17:10:17 +00:00
} else if (parameter == "AC_POINTMASS") {
*AC_cfg >> pmWt >> pmX >> pmY >> pmZ;
MassBalance->AddPointMass(pmWt, pmX, pmY, pmZ);
2001-12-07 17:10:17 +00:00
if (debug_lvl > 0) cout << " Point Mass Object: " << pmWt << " lbs. at "
<< "X, Y, Z (in.): " << pmX << " " << pmY << " " << pmZ
<< endl;
}
2000-04-24 23:49:06 +00:00
}
// calculate some derived parameters
if (cbar != 0.0) {
lbarh = HTailArm/cbar;
lbarv = VTailArm/cbar;
if (WingArea != 0.0) {
vbarh = HTailArm*HTailArea / (cbar*WingArea);
vbarv = VTailArm*VTailArea / (cbar*WingArea);
}
}
2001-12-01 04:03:57 +00:00
return true;
2000-04-24 23:49:06 +00:00
}
2000-11-03 23:02:47 +00:00
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2000-05-27 05:48:14 +00:00
void FGAircraft::bind(void)
2001-03-30 01:04:50 +00:00
{
typedef double (FGAircraft::*PMF)(int) const;
PropertyManager->Tie("metrics/Sw-sqft", this,
&FGAircraft::GetWingArea);
PropertyManager->Tie("metrics/bw-ft", this,
&FGAircraft::GetWingSpan);
PropertyManager->Tie("metrics/cbarw-ft", this,
&FGAircraft::Getcbar);
PropertyManager->Tie("metrics/iw-deg", this,
&FGAircraft::GetWingIncidence);
PropertyManager->Tie("metrics/Sh-sqft", this,
&FGAircraft::GetHTailArea);
PropertyManager->Tie("metrics/lh-ft", this,
&FGAircraft::GetHTailArm);
PropertyManager->Tie("metrics/Sv-sqft", this,
&FGAircraft::GetVTailArea);
PropertyManager->Tie("metrics/lv-ft", this,
&FGAircraft::GetVTailArm);
PropertyManager->Tie("metrics/lh-norm", this,
&FGAircraft::Getlbarh);
PropertyManager->Tie("metrics/lv-norm", this,
&FGAircraft::Getlbarv);
PropertyManager->Tie("metrics/vbarh-norm", this,
&FGAircraft::Getvbarh);
PropertyManager->Tie("metrics/vbarv-norm", this,
&FGAircraft::Getvbarv);
PropertyManager->Tie("moments/l-total-lbsft", this,1,
(PMF)&FGAircraft::GetMoments);
PropertyManager->Tie("moments/m-total-lbsft", this,2,
(PMF)&FGAircraft::GetMoments);
PropertyManager->Tie("moments/n-total-lbsft", this,3,
(PMF)&FGAircraft::GetMoments);
PropertyManager->Tie("forces/fbx-total-lbs", this,1,
(PMF)&FGAircraft::GetForces);
PropertyManager->Tie("forces/fby-total-lbs", this,2,
(PMF)&FGAircraft::GetForces);
PropertyManager->Tie("forces/fbz-total-lbs", this,3,
(PMF)&FGAircraft::GetForces);
PropertyManager->Tie("metrics/aero-rp-x-ft", this,1,
(PMF)&FGAircraft::GetXYZrp);
PropertyManager->Tie("metrics/aero-rp-y-ft", this,2,
(PMF)&FGAircraft::GetXYZrp);
PropertyManager->Tie("metrics/aero-rp-z-ft", this,3,
(PMF)&FGAircraft::GetXYZrp);
PropertyManager->Tie("metrics/eyepoint-x-ft", this,1,
(PMF)&FGAircraft::GetXYZep);
PropertyManager->Tie("metrics/eyepoint-y-ft", this,2,
(PMF)&FGAircraft::GetXYZep);
PropertyManager->Tie("metrics/eyepoint-z-ft", this,3,
(PMF)&FGAircraft::GetXYZep);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::unbind(void)
{
PropertyManager->Untie("metrics/Sw-sqft");
PropertyManager->Untie("metrics/bw-ft");
PropertyManager->Untie("metrics/cbarw-ft");
PropertyManager->Untie("metrics/iw-deg");
PropertyManager->Untie("metrics/Sh-sqft");
PropertyManager->Untie("metrics/lh-ft");
PropertyManager->Untie("metrics/Sv-sqft");
PropertyManager->Untie("metrics/lv-ft");
PropertyManager->Untie("metrics/lh-norm");
PropertyManager->Untie("metrics/lv-norm");
PropertyManager->Untie("metrics/vbarh-norm");
PropertyManager->Untie("metrics/vbarv-norm");
PropertyManager->Untie("moments/l-total-lbsft");
PropertyManager->Untie("moments/m-total-lbsft");
PropertyManager->Untie("moments/n-total-lbsft");
PropertyManager->Untie("forces/fbx-total-lbs");
PropertyManager->Untie("forces/fby-total-lbs");
PropertyManager->Untie("forces/fbz-total-lbs");
PropertyManager->Untie("metrics/aero-rp-x-ft");
PropertyManager->Untie("metrics/aero-rp-y-ft");
PropertyManager->Untie("metrics/aero-rp-z-ft");
PropertyManager->Untie("metrics/eyepoint-x-ft");
PropertyManager->Untie("metrics/eyepoint-y-ft");
PropertyManager->Untie("metrics/eyepoint-z-ft");
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// The bitmasked value choices are as follows:
// unset: In this case (the default) JSBSim would only print
// out the normally expected messages, essentially echoing
// the config files as they are read. If the environment
// variable is not set, debug_lvl is set to 1 internally
// 0: This requests JSBSim not to output any messages
// whatsoever.
// 1: This value explicity requests the normal JSBSim
// startup messages
// 2: This value asks for a message to be printed out when
// a class is instantiated
// 4: When this value is set, a message is displayed when a
// FGModel object executes its Run() method
// 8: When this value is set, various runtime state variables
// are printed out periodically
// 16: When set various parameters are sanity checked and
// a message is printed out when they go out of bounds
void FGAircraft::Debug(int from)
{
if (debug_lvl <= 0) return;
if (debug_lvl & 1) { // Standard console startup message output
if (from == 0) { // Constructor
}
}
if (debug_lvl & 2 ) { // Instantiation/Destruction notification
if (from == 0) cout << "Instantiated: FGAircraft" << endl;
if (from == 1) cout << "Destroyed: FGAircraft" << endl;
}
if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
}
if (debug_lvl & 8 ) { // Runtime state variables
}
if (debug_lvl & 16) { // Sanity checking
}
if (debug_lvl & 64) {
if (from == 0) { // Constructor
cout << IdSrc << endl;
cout << IdHdr << endl;
}
}
}
} // namespace JSBSim