-/*******************************************************************************
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Module: FGAircraft.cpp
Author: Jon S. Berndt
point to config file. Added calculations for moments due to
difference in cg and aero reference point
-********************************************************************************
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
COMMENTS, REFERENCES, and NOTES
-********************************************************************************
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
School, January 1994
CnDr - Yaw moment due to rudder
CnDa - Yaw moment due to aileron
-********************************************************************************
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
INCLUDES
-*******************************************************************************/
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include <sys/stat.h>
#include <sys/types.h>
#include "FGAuxiliary.h"
#include "FGOutput.h"
-const char *IdSrc = "$Header$";
-const char *IdHdr = ID_AIRCRAFT;
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+DEFINITIONS
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+GLOBAL DATA
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+static const char *IdSrc = "$Id$";
+static const char *IdHdr = ID_AIRCRAFT;
-/*******************************************************************************
-************************************ CODE **************************************
-*******************************************************************************/
+extern char highint[5];
+extern char halfint[5];
+extern char normint[6];
+extern char reset[5];
+extern char underon[5];
+extern char underoff[6];
+extern char fgblue[6];
+extern char fgcyan[6];
+extern char fgred[6];
+extern char fggreen[6];
+extern char fgdef[6];
+
+extern short debug_lvl;
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS IMPLEMENTATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex),
vMoments(3),
vXYZcg(3),
vXYZep(3),
vEuler(3)
-
+
{
Name = "FGAircraft";
AxisIdx["ROLL"] = 3;
AxisIdx["PITCH"] = 4;
AxisIdx["YAW"] = 5;
-
+
Coeff = new CoeffArray[6];
GearUp = false;
-
+
alphaclmin = alphaclmax = 0;
- numTanks = numEngines = numSelectedFuelTanks = numSelectedOxiTanks = 0;
+ if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-FGAircraft::~FGAircraft(void) {
+FGAircraft::~FGAircraft() {
unsigned int i,j;
-
- if (Engine != NULL) {
- for (i=0; i<numEngines; i++)
- delete Engine[i];
- }
- if (Tank != NULL) {
- for (i=0; i<numTanks; i++)
- delete Tank[i];
- }
for (i=0; i<6; i++) {
for (j=0; j<Coeff[i].size(); j++) {
delete Coeff[i][j];
}
}
delete[] Coeff;
+
+ if (debug_lvl & 2) cout << "Destroyed: FGAircraft" << endl;
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bool FGAircraft::LoadAircraft(string aircraft_path, string engine_path, string fname) {
string path;
# ifndef macintosh
aircraftCfgFileName = AircraftPath + "/" + fname + "/" + fname + ".xml";
-# else
+# else
aircraftCfgFileName = AircraftPath + ";" + fname + ";" + fname + ".xml";
# endif
while ((AC_cfg.GetNextConfigLine() != "EOF") &&
(token = AC_cfg.GetValue()) != "/FDM_CONFIG") {
if (token == "METRICS") {
- cout << " Reading Metrics" << endl;
+ cout << fgcyan << "\n Reading Metrics" << fgdef << endl;
ReadMetrics(&AC_cfg);
} else if (token == "AERODYNAMICS") {
- cout << " Reading Aerodynamics" << endl;
+ cout << fgcyan << "\n Reading Aerodynamics" << fgdef << endl;
ReadAerodynamics(&AC_cfg);
} else if (token == "UNDERCARRIAGE") {
- cout << " Reading Landing Gear" << endl;
+ cout << fgcyan << "\n Reading Landing Gear" << fgdef << endl;
ReadUndercarriage(&AC_cfg);
} else if (token == "PROPULSION") {
- cout << " Reading Propulsion" << endl;
+ cout << fgcyan << "\n Reading Propulsion" << fgdef << endl;
ReadPropulsion(&AC_cfg);
} else if (token == "FLIGHT_CONTROL") {
- cout << " Reading Flight Control" << endl;
+ cout << fgcyan << "\n Reading Flight Control" << fgdef << endl;
ReadFlightControls(&AC_cfg);
} else if (token == "OUTPUT") {
+ cout << fgcyan << "\n Reading Output directives" << fgdef << endl;
ReadOutput(&AC_cfg);
}
}
return true;
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bool FGAircraft::Run(void) {
if (!FGModel::Run()) { // if false then execute this Run()
return false;
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::MassChange() {
static FGColumnVector vXYZtank(3);
float Tw;
float IXXt, IYYt, IZZt, IXZt;
- unsigned int t;
- unsigned int axis_ctr;
-
+// unsigned int t;
+// unsigned int axis_ctr;
+/*
for (axis_ctr=1; axis_ctr<=3; axis_ctr++) vXYZtank(axis_ctr) = 0.0;
// UPDATE TANK CONTENTS
if ((Fshortage <= 0.0) || (Oshortage <= 0.0)) Engine[e]->SetStarved();
else Engine[e]->SetStarved(false);
}
-
+*/
Weight = EmptyWeight;
- for (t=0; t<numTanks; t++)
- Weight += Tank[t]->GetContents();
+// for (t=0; t<numTanks; t++)
+// Weight += Tank[t]->GetContents();
Mass = Weight / GRAVITY;
// Calculate new CG here.
Tw = 0;
- for (t=0; t<numTanks; t++) {
- vXYZtank(eX) += Tank[t]->GetX()*Tank[t]->GetContents();
- vXYZtank(eY) += Tank[t]->GetY()*Tank[t]->GetContents();
- vXYZtank(eZ) += Tank[t]->GetZ()*Tank[t]->GetContents();
-
- Tw += Tank[t]->GetContents();
- }
+// for (t=0; t<numTanks; t++) {
+// vXYZtank(eX) += Tank[t]->GetX()*Tank[t]->GetContents();
+// vXYZtank(eY) += Tank[t]->GetY()*Tank[t]->GetContents();
+// vXYZtank(eZ) += Tank[t]->GetZ()*Tank[t]->GetContents();
+//
+// Tw += Tank[t]->GetContents();
+// }
vXYZcg = (vXYZtank + EmptyWeight*vbaseXYZcg) / (Tw + EmptyWeight);
// Calculate new moments of inertia here
IXXt = IYYt = IZZt = IXZt = 0.0;
- for (t=0; t<numTanks; t++) {
- IXXt += ((Tank[t]->GetX()-vXYZcg(eX))/12.0)*((Tank[t]->GetX() - vXYZcg(eX))/12.0)*Tank[t]->GetContents()/GRAVITY;
- IYYt += ((Tank[t]->GetY()-vXYZcg(eY))/12.0)*((Tank[t]->GetY() - vXYZcg(eY))/12.0)*Tank[t]->GetContents()/GRAVITY;
- IZZt += ((Tank[t]->GetZ()-vXYZcg(eZ))/12.0)*((Tank[t]->GetZ() - vXYZcg(eZ))/12.0)*Tank[t]->GetContents()/GRAVITY;
- IXZt += ((Tank[t]->GetX()-vXYZcg(eX))/12.0)*((Tank[t]->GetZ() - vXYZcg(eZ))/12.0)*Tank[t]->GetContents()/GRAVITY;
- }
+// for (t=0; t<numTanks; t++) {
+// IXXt += ((Tank[t]->GetX()-vXYZcg(eX))/12.0)*((Tank[t]->GetX() - vXYZcg(eX))/12.0)*Tank[t]->GetContents()/GRAVITY;
+// IYYt += ((Tank[t]->GetY()-vXYZcg(eY))/12.0)*((Tank[t]->GetY() - vXYZcg(eY))/12.0)*Tank[t]->GetContents()/GRAVITY;
+// IZZt += ((Tank[t]->GetZ()-vXYZcg(eZ))/12.0)*((Tank[t]->GetZ() - vXYZcg(eZ))/12.0)*Tank[t]->GetContents()/GRAVITY;
+// IXZt += ((Tank[t]->GetX()-vXYZcg(eX))/12.0)*((Tank[t]->GetZ() - vXYZcg(eZ))/12.0)*Tank[t]->GetContents()/GRAVITY;
+// }
Ixx = baseIxx + IXXt;
Iyy = baseIyy + IYYt;
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::FMAero(void) {
static FGColumnVector vDXYZcg(3);
vAeroBodyForces = State->GetTs2b(alpha, beta)*vFs;
vForces += vAeroBodyForces;
- // The d*cg distances below, given in inches, are the distances FROM the c.g.
- // TO the reference point. Since the c.g. and ref point are given in inches in
- // the structural system (X positive rearwards) and the body coordinate system
- // is given with X positive out the nose, the dxcg and dzcg values are
- // *rotated* 180 degrees about the Y axis.
-
+ // see http://home.earthlink.net/~apeden/jsbsim_moments_due_to_forces.txt
+ // for details on this
vDXYZcg(eX) = -(vXYZrp(eX) - vXYZcg(eX))/12.0; //cg and rp values are in inches
vDXYZcg(eY) = (vXYZrp(eY) - vXYZcg(eY))/12.0;
vDXYZcg(eZ) = -(vXYZrp(eZ) - vXYZcg(eZ))/12.0;
}
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::FMGear(void) {
}
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::FMMass(void) {
vForces(eX) += -GRAVITY*sin(vEuler(eTht)) * Mass;
vForces(eZ) += GRAVITY*cos(vEuler(ePhi))*cos(vEuler(eTht)) * Mass;
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::FMProp(void) {
- for (unsigned int i=0;i<numEngines;i++) {
-
- // Changes required here for new engine placement parameters (i.e. location and direction)
-
- vForces(eX) += Engine[i]->CalcThrust();
- }
-
+ vForces += Propulsion->GetForces();
+ vMoments += Propulsion->GetMoments();
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::GetState(void) {
dt = State->Getdt();
vEuler = Rotation->GetEuler();
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::ReadMetrics(FGConfigFile* AC_cfg) {
string token = "";
}
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::ReadPropulsion(FGConfigFile* AC_cfg) {
- string token;
- string engine_name;
- string parameter;
-
- AC_cfg->GetNextConfigLine();
-
- while ((token = AC_cfg->GetValue()) != "/PROPULSION") {
- *AC_cfg >> parameter;
-
- if (parameter == "AC_ENGINE") {
-
- *AC_cfg >> engine_name;
- Engine[numEngines] = new FGEngine(FDMExec, EnginePath, engine_name, numEngines);
- numEngines++;
-
- } else if (parameter == "AC_TANK") {
-
- Tank[numTanks] = new FGTank(AC_cfg);
- switch(Tank[numTanks]->GetType()) {
- case FGTank::ttFUEL:
- numSelectedFuelTanks++;
- break;
- case FGTank::ttOXIDIZER:
- numSelectedOxiTanks++;
- break;
- }
- numTanks++;
- }
+ if (!Propulsion->LoadPropulsion(AC_cfg)) {
+ cerr << "Propulsion not successfully loaded" << endl;
}
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::ReadFlightControls(FGConfigFile* AC_cfg) {
- string token;
-
- FCS->LoadFCS(AC_cfg);
+ if (!FCS->LoadFCS(AC_cfg)) {
+ cerr << "Flight Controls not successfully loaded" << endl;
+ }
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::ReadAerodynamics(FGConfigFile* AC_cfg) {
string token, axis;
}
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::ReadUndercarriage(FGConfigFile* AC_cfg) {
string token;
}
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::ReadOutput(FGConfigFile* AC_cfg) {
string token, parameter;
*AC_cfg >> parameter;
if (parameter == "ON") subsystems += ssGroundReactions;
}
+ if (parameter == "FCS") {
+ *AC_cfg >> parameter;
+ if (parameter == "ON") subsystems += ssFCS;
+ }
}
Output->SetSubsystems(subsystems);
Output->SetRate( (int)(0.5 + 1.0/(State->Getdt()*OutRate)) );
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::ReadPrologue(FGConfigFile* AC_cfg) {
string token = AC_cfg->GetValue();
string scratch;
AircraftName = AC_cfg->GetValue("NAME");
- cout << "Reading Aircraft Configuration File: " << AircraftName << endl;
- scratch=AC_cfg->GetValue("VERSION").c_str();
+ cout << underon << "Reading Aircraft Configuration File" << underoff << ": "
+ << highint << AircraftName << normint << endl;
+ scratch = AC_cfg->GetValue("VERSION").c_str();
CFGVersion = AC_cfg->GetValue("VERSION");
- cout << " Version: " << CFGVersion << endl;
+ cout << " Version: " << highint << CFGVersion
+ << normint << endl;
if (CFGVersion != NEEDED_CFG_VERSION) {
- cout << endl << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
+ cout << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
" RESULTS WILL BE UNPREDICTABLE !!" << endl;
cout << "Current version needed is: " << NEEDED_CFG_VERSION << endl;
- cout << " You have version: " << CFGVersion << endl << endl;
+ cout << " You have version: " << CFGVersion << endl << fgdef << endl;
//exit(-1);
}
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAircraft::DisplayCoeffFactors(vector <eParam> multipliers) {
cout << " Non-Dimensionalized by: ";
cout << endl;
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGAircraft::GetCoefficientStrings(void) {
string CoeffStrings = "";
return CoeffStrings;
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGAircraft::GetCoefficientValues(void) {
string SDValues = "";
}
return SDValues;
- ;
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGAircraft::GetGroundReactionStrings(void) {
string GroundReactionStrings = "";
return GroundReactionStrings;
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGAircraft::GetGroundReactionValues(void) {
char buff[20];
return GroundReactionValues;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGAircraft::Debug(void)
+{
+ //TODO: Add your source code here
+}
+