2006-01-12 15:04:22 +00:00
|
|
|
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
|
|
|
Module: FGAircraft.cpp
|
|
|
|
Author: Jon S. Berndt
|
|
|
|
Date started: 12/12/98
|
|
|
|
Purpose: Encapsulates an aircraft
|
|
|
|
Called by: FGFDMExec
|
|
|
|
|
2009-08-30 08:22:03 +00:00
|
|
|
------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
|
2006-01-12 15:04:22 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
2007-01-15 12:48:54 +00:00
|
|
|
the terms of the GNU Lesser General Public License as published by the Free Software
|
2006-01-12 15:04:22 +00:00
|
|
|
Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
version.
|
|
|
|
|
|
|
|
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
|
2007-01-15 12:48:54 +00:00
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
2006-01-12 15:04:22 +00:00
|
|
|
details.
|
|
|
|
|
2007-01-15 12:48:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along with
|
2006-01-12 15:04:22 +00:00
|
|
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
|
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
2007-01-15 12:48:54 +00:00
|
|
|
Further information about the GNU Lesser General Public License can also be found on
|
2006-01-12 15:04:22 +00:00
|
|
|
the world wide web at http://www.gnu.org.
|
|
|
|
|
|
|
|
FUNCTIONAL DESCRIPTION
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
Models the aircraft reactions and forces. This class is instantiated by the
|
|
|
|
FGFDMExec class and scheduled as an FDM entry.
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
COMMENTS, REFERENCES, and NOTES
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
INCLUDES
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2010-11-28 09:58:47 +00:00
|
|
|
#include <iostream>
|
2008-07-22 08:49:15 +00:00
|
|
|
#include <cmath>
|
2006-01-12 15:04:22 +00:00
|
|
|
|
|
|
|
#include "FGAircraft.h"
|
|
|
|
#include "FGMassBalance.h"
|
|
|
|
#include "FGInertial.h"
|
|
|
|
#include "FGGroundReactions.h"
|
2008-07-10 17:23:02 +00:00
|
|
|
#include "FGExternalReactions.h"
|
|
|
|
#include "FGBuoyantForces.h"
|
2006-01-12 15:04:22 +00:00
|
|
|
#include "FGAerodynamics.h"
|
2009-10-12 07:24:41 +00:00
|
|
|
#include "FGFDMExec.h"
|
2006-01-12 15:04:22 +00:00
|
|
|
#include "FGPropagate.h"
|
2009-10-26 13:29:58 +00:00
|
|
|
#include "FGPropulsion.h"
|
2009-10-12 07:24:41 +00:00
|
|
|
#include "input_output/FGPropertyManager.h"
|
2009-10-26 13:29:58 +00:00
|
|
|
|
|
|
|
using namespace std;
|
2006-01-12 15:04:22 +00:00
|
|
|
|
|
|
|
namespace JSBSim {
|
|
|
|
|
|
|
|
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
DEFINITIONS
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
|
|
|
|
|
|
|
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
GLOBAL DATA
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
|
|
|
|
2010-11-30 12:44:10 +00:00
|
|
|
static const char *IdSrc = "$Id: FGAircraft.cpp,v 1.30 2010/11/29 12:33:57 jberndt Exp $";
|
2006-01-12 15:04:22 +00:00
|
|
|
static const char *IdHdr = ID_AIRCRAFT;
|
|
|
|
|
|
|
|
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
CLASS IMPLEMENTATION
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
|
|
|
|
|
|
|
FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
|
|
|
|
{
|
|
|
|
Name = "FGAircraft";
|
|
|
|
WingSpan = 0.0;
|
|
|
|
HTailArea = VTailArea = 0.0;
|
|
|
|
HTailArm = VTailArm = 0.0;
|
|
|
|
lbarh = lbarv = 0.0;
|
|
|
|
vbarh = vbarv = 0.0;
|
|
|
|
WingIncidence = 0.0;
|
2007-06-03 09:37:02 +00:00
|
|
|
HoldDown = 0;
|
2006-01-12 15:04:22 +00:00
|
|
|
|
|
|
|
bind();
|
|
|
|
|
|
|
|
Debug(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
|
|
|
FGAircraft::~FGAircraft()
|
|
|
|
{
|
|
|
|
Debug(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2008-07-10 17:23:02 +00:00
|
|
|
bool FGAircraft::InitModel(void)
|
|
|
|
{
|
|
|
|
if (!FGModel::InitModel()) return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2006-01-12 15:04:22 +00:00
|
|
|
bool FGAircraft::Run(void)
|
|
|
|
{
|
|
|
|
if (FGModel::Run()) return true;
|
|
|
|
if (FDMExec->Holding()) return false;
|
|
|
|
|
2009-11-27 08:54:33 +00:00
|
|
|
RunPreFunctions();
|
|
|
|
|
2006-01-12 15:04:22 +00:00
|
|
|
vForces.InitMatrix();
|
2007-06-03 09:37:02 +00:00
|
|
|
if (!HoldDown) {
|
2010-11-28 09:58:47 +00:00
|
|
|
vForces += FDMExec->GetAerodynamics()->GetForces();
|
|
|
|
vForces += FDMExec->GetPropulsion()->GetForces();
|
|
|
|
vForces += FDMExec->GetGroundReactions()->GetForces();
|
|
|
|
vForces += FDMExec->GetExternalReactions()->GetForces();
|
|
|
|
vForces += FDMExec->GetBuoyantForces()->GetForces();
|
2010-07-16 09:05:59 +00:00
|
|
|
} else {
|
2010-11-28 09:58:47 +00:00
|
|
|
const FGMatrix33& mTl2b = FDMExec->GetPropagate()->GetTl2b();
|
|
|
|
vForces = mTl2b * FGColumnVector3(0,0,-FDMExec->GetMassBalance()->GetWeight());
|
2007-06-03 09:37:02 +00:00
|
|
|
}
|
2006-01-12 15:04:22 +00:00
|
|
|
|
|
|
|
vMoments.InitMatrix();
|
2007-06-03 09:37:02 +00:00
|
|
|
if (!HoldDown) {
|
2010-11-28 09:58:47 +00:00
|
|
|
vMoments += FDMExec->GetAerodynamics()->GetMoments();
|
|
|
|
vMoments += FDMExec->GetPropulsion()->GetMoments();
|
|
|
|
vMoments += FDMExec->GetGroundReactions()->GetMoments();
|
|
|
|
vMoments += FDMExec->GetExternalReactions()->GetMoments();
|
|
|
|
vMoments += FDMExec->GetBuoyantForces()->GetMoments();
|
2007-06-03 09:37:02 +00:00
|
|
|
}
|
2006-01-12 15:04:22 +00:00
|
|
|
|
2010-11-28 09:58:47 +00:00
|
|
|
vBodyAccel = vForces/FDMExec->GetMassBalance()->GetMass();
|
2006-01-12 15:04:22 +00:00
|
|
|
|
2010-11-28 09:58:47 +00:00
|
|
|
vNcg = vBodyAccel/FDMExec->GetInertial()->SLgravity();
|
2006-01-12 15:04:22 +00:00
|
|
|
|
2010-11-28 09:58:47 +00:00
|
|
|
vNwcg = FDMExec->GetAerodynamics()->GetTb2w() * vNcg;
|
2010-08-03 07:51:13 +00:00
|
|
|
vNwcg(3) = 1.0 - vNwcg(3);
|
2006-01-12 15:04:22 +00:00
|
|
|
|
2009-11-27 08:54:33 +00:00
|
|
|
RunPostFunctions();
|
|
|
|
|
2006-01-12 15:04:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2009-01-26 20:36:17 +00:00
|
|
|
double FGAircraft::GetNlf(void) const
|
2006-01-12 15:04:22 +00:00
|
|
|
{
|
2010-11-29 08:57:45 +00:00
|
|
|
if (FDMExec->GetMassBalance()->GetWeight() != 0)
|
2010-11-30 12:44:10 +00:00
|
|
|
return (-FDMExec->GetAerodynamics()->GetvFw(3))/FDMExec->GetMassBalance()->GetWeight();
|
2010-11-29 08:57:45 +00:00
|
|
|
else
|
|
|
|
return 0.;
|
2006-01-12 15:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
|
|
|
bool FGAircraft::Load(Element* el)
|
|
|
|
{
|
|
|
|
string element_name;
|
|
|
|
Element* element;
|
|
|
|
|
2009-06-13 07:55:25 +00:00
|
|
|
FGModel::Load(el);
|
|
|
|
|
2006-01-12 15:04:22 +00:00
|
|
|
if (el->FindElement("wingarea"))
|
|
|
|
WingArea = el->FindElementValueAsNumberConvertTo("wingarea", "FT2");
|
|
|
|
if (el->FindElement("wingspan"))
|
|
|
|
WingSpan = el->FindElementValueAsNumberConvertTo("wingspan", "FT");
|
|
|
|
if (el->FindElement("chord"))
|
|
|
|
cbar = el->FindElementValueAsNumberConvertTo("chord", "FT");
|
|
|
|
if (el->FindElement("wing_incidence"))
|
2008-07-10 17:23:02 +00:00
|
|
|
WingIncidence = el->FindElementValueAsNumberConvertTo("wing_incidence", "RAD");
|
2006-01-12 15:04:22 +00:00
|
|
|
if (el->FindElement("htailarea"))
|
|
|
|
HTailArea = el->FindElementValueAsNumberConvertTo("htailarea", "FT2");
|
|
|
|
if (el->FindElement("htailarm"))
|
|
|
|
HTailArm = el->FindElementValueAsNumberConvertTo("htailarm", "FT");
|
|
|
|
if (el->FindElement("vtailarea"))
|
|
|
|
VTailArea = el->FindElementValueAsNumberConvertTo("vtailarea", "FT2");
|
|
|
|
if (el->FindElement("vtailarm"))
|
|
|
|
VTailArm = el->FindElementValueAsNumberConvertTo("vtailarm", "FT");
|
|
|
|
|
|
|
|
// Find all LOCATION elements that descend from this METRICS branch of the
|
|
|
|
// config file. This would be CG location, eyepoint, etc.
|
|
|
|
|
|
|
|
element = el->FindElement("location");
|
|
|
|
while (element) {
|
|
|
|
element_name = element->GetAttributeValue("name");
|
|
|
|
|
|
|
|
if (element_name == "AERORP") vXYZrp = element->FindElementTripletConvertTo("IN");
|
|
|
|
else if (element_name == "EYEPOINT") vXYZep = element->FindElementTripletConvertTo("IN");
|
|
|
|
else if (element_name == "VRP") vXYZvrp = element->FindElementTripletConvertTo("IN");
|
|
|
|
|
|
|
|
element = el->FindNextElement("location");
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate some derived parameters
|
|
|
|
if (cbar != 0.0) {
|
|
|
|
lbarh = HTailArm/cbar;
|
|
|
|
lbarv = VTailArm/cbar;
|
|
|
|
if (WingArea != 0.0) {
|
|
|
|
vbarh = HTailArm*HTailArea / (cbar*WingArea);
|
2008-07-10 17:23:02 +00:00
|
|
|
vbarv = VTailArm*VTailArea / (WingSpan*WingArea);
|
2006-01-12 15:04:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-19 09:16:29 +00:00
|
|
|
PostLoad(el, PropertyManager);
|
2009-11-27 08:54:33 +00:00
|
|
|
|
2006-01-12 15:04:22 +00:00
|
|
|
Debug(2);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
|
|
|
void FGAircraft::bind(void)
|
|
|
|
{
|
|
|
|
typedef double (FGAircraft::*PMF)(int) const;
|
2008-07-10 17:23:02 +00:00
|
|
|
PropertyManager->Tie("metrics/Sw-sqft", this, &FGAircraft::GetWingArea, &FGAircraft::SetWingArea);
|
2006-01-12 15:04:22 +00:00
|
|
|
PropertyManager->Tie("metrics/bw-ft", this, &FGAircraft::GetWingSpan);
|
|
|
|
PropertyManager->Tie("metrics/cbarw-ft", this, &FGAircraft::Getcbar);
|
2008-07-10 17:23:02 +00:00
|
|
|
PropertyManager->Tie("metrics/iw-rad", this, &FGAircraft::GetWingIncidence);
|
|
|
|
PropertyManager->Tie("metrics/iw-deg", this, &FGAircraft::GetWingIncidenceDeg);
|
2006-01-12 15:04:22 +00:00
|
|
|
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("metrics/aero-rp-x-in", this, eX, (PMF)&FGAircraft::GetXYZrp);
|
|
|
|
PropertyManager->Tie("metrics/aero-rp-y-in", this, eY, (PMF)&FGAircraft::GetXYZrp);
|
|
|
|
PropertyManager->Tie("metrics/aero-rp-z-in", this, eZ, (PMF)&FGAircraft::GetXYZrp);
|
|
|
|
PropertyManager->Tie("metrics/eyepoint-x-in", this, eX, (PMF)&FGAircraft::GetXYZep);
|
|
|
|
PropertyManager->Tie("metrics/eyepoint-y-in", this, eY,(PMF)&FGAircraft::GetXYZep);
|
|
|
|
PropertyManager->Tie("metrics/eyepoint-z-in", this, eZ, (PMF)&FGAircraft::GetXYZep);
|
|
|
|
PropertyManager->Tie("metrics/visualrefpoint-x-in", this, eX, (PMF)&FGAircraft::GetXYZvrp);
|
|
|
|
PropertyManager->Tie("metrics/visualrefpoint-y-in", this, eY, (PMF)&FGAircraft::GetXYZvrp);
|
|
|
|
PropertyManager->Tie("metrics/visualrefpoint-z-in", this, eZ, (PMF)&FGAircraft::GetXYZvrp);
|
2009-01-26 20:36:17 +00:00
|
|
|
PropertyManager->Tie("forces/fbx-total-lbs", this, eX, (PMF)&FGAircraft::GetForces);
|
|
|
|
PropertyManager->Tie("forces/fby-total-lbs", this, eY, (PMF)&FGAircraft::GetForces);
|
|
|
|
PropertyManager->Tie("forces/fbz-total-lbs", this, eZ, (PMF)&FGAircraft::GetForces);
|
|
|
|
PropertyManager->Tie("forces/load-factor", this, &FGAircraft::GetNlf);
|
|
|
|
PropertyManager->Tie("forces/hold-down", this, &FGAircraft::GetHoldDown, &FGAircraft::SetHoldDown);
|
|
|
|
PropertyManager->Tie("moments/l-total-lbsft", this, eL, (PMF)&FGAircraft::GetMoments);
|
|
|
|
PropertyManager->Tie("moments/m-total-lbsft", this, eM, (PMF)&FGAircraft::GetMoments);
|
|
|
|
PropertyManager->Tie("moments/n-total-lbsft", this, eN, (PMF)&FGAircraft::GetMoments);
|
2006-01-12 15:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
// 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 == 2) { // Loading
|
|
|
|
cout << endl << " Aircraft Metrics:" << endl;
|
|
|
|
cout << " WingArea: " << WingArea << endl;
|
|
|
|
cout << " WingSpan: " << WingSpan << endl;
|
|
|
|
cout << " Incidence: " << WingIncidence << endl;
|
|
|
|
cout << " Chord: " << cbar << endl;
|
|
|
|
cout << " H. Tail Area: " << HTailArea << endl;
|
|
|
|
cout << " H. Tail Arm: " << HTailArm << endl;
|
|
|
|
cout << " V. Tail Area: " << VTailArea << endl;
|
|
|
|
cout << " V. Tail Arm: " << VTailArm << endl;
|
|
|
|
cout << " Eyepoint (x, y, z): " << vXYZep << endl;
|
|
|
|
cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
|
|
|
|
cout << " Visual Ref Pt (x, y, z): " << vXYZvrp << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|