\r
!ENDIF \r
\r
-# End Source File\r
-# End Group\r
-# Begin Group "Lib_Joystick"\r
-\r
-# PROP Default_Filter ""\r
-# Begin Source File\r
-\r
-SOURCE=.\src\Joystick\joystick.cxx\r
-\r
-!IF "$(CFG)" == "FlightGear - Win32 Release"\r
-\r
-# PROP Intermediate_Dir "Release\Lib_Joystick"\r
-\r
-!ELSEIF "$(CFG)" == "FlightGear - Win32 Debug"\r
-\r
-# PROP Intermediate_Dir "Debug\Lib_Joystick"\r
-\r
-!ENDIF \r
-\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\src\Joystick\joystick.hxx\r
-\r
-!IF "$(CFG)" == "FlightGear - Win32 Release"\r
-\r
-# PROP Intermediate_Dir "Release\Lib_Joystick"\r
-\r
-!ELSEIF "$(CFG)" == "FlightGear - Win32 Debug"\r
-\r
-# PROP Intermediate_Dir "Debug\Lib_Joystick"\r
-\r
-!ENDIF \r
-\r
# End Source File\r
# End Group\r
# Begin Group "main"\r
#include <FDM/JSBSim/FGInitialCondition.h>
#include <FDM/JSBSim/FGTrim.h>
#include <FDM/JSBSim/FGAtmosphere.h>
-
+#include <FDM/JSBSim/FGMassBalance.h>
+#include <FDM/JSBSim/FGAerodynamics.h>
#include "JSBSim.hxx"
/******************************************************************************/
fdmex=new FGFDMExec;
- State = fdmex->GetState();
- Atmosphere = fdmex->GetAtmosphere();
- FCS = fdmex->GetFCS();
- Propulsion = fdmex->GetPropulsion();
- Aircraft = fdmex->GetAircraft();
- Translation = fdmex->GetTranslation();
- Rotation = fdmex->GetRotation();
- Position = fdmex->GetPosition();
- Auxiliary = fdmex->GetAuxiliary();
+ State = fdmex->GetState();
+ Atmosphere = fdmex->GetAtmosphere();
+ FCS = fdmex->GetFCS();
+ MassBalance = fdmex->GetMassBalance();
+ Propulsion = fdmex->GetPropulsion();
+ Aircraft = fdmex->GetAircraft();
+ Translation = fdmex->GetTranslation();
+ Rotation = fdmex->GetRotation();
+ Position = fdmex->GetPosition();
+ Auxiliary = fdmex->GetAuxiliary();
+ Aerodynamics = fdmex->GetAerodynamics();
fgic=new FGInitialCondition(fdmex);
needTrim=true;
bool FGJSBsim::copy_from_JSBsim() {
unsigned int i, j;
- _set_Inertias( Aircraft->GetMass(),
- Aircraft->GetIxx(),
- Aircraft->GetIyy(),
- Aircraft->GetIzz(),
- Aircraft->GetIxz() );
+ _set_Inertias( MassBalance->GetMass(),
+ MassBalance->GetIxx(),
+ MassBalance->GetIyy(),
+ MassBalance->GetIzz(),
+ MassBalance->GetIxz() );
- _set_CG_Position( Aircraft->GetXYZcg(1),
- Aircraft->GetXYZcg(2),
- Aircraft->GetXYZcg(3) );
+ _set_CG_Position( MassBalance->GetXYZcg(1),
+ MassBalance->GetXYZcg(2),
+ MassBalance->GetXYZcg(3) );
_set_Accels_Body( Translation->GetUVWdot(1),
Translation->GetUVWdot(2),
// Auxiliary->GetNpilot(2),
// Auxiliary->GetNpilot(3) );
- _set_Nlf( Aircraft->GetNlf() );
+ _set_Nlf( Aerodynamics->GetNlf() );
// Velocities
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include <FDM/JSBSim/FGFDMExec.h>
-#include <FDM/JSBSim/FGInitialCondition.h>
+
#undef MAX_ENGINES
#include <Aircraft/aircraft.hxx>
FGInitialCondition *fgic;
bool needTrim;
- FGState* State;
- FGAtmosphere* Atmosphere;
- FGFCS* FCS;
- FGPropulsion* Propulsion;
- FGAircraft* Aircraft;
- FGTranslation* Translation;
- FGRotation* Rotation;
- FGPosition* Position;
- FGAuxiliary* Auxiliary;
+ FGState* State;
+ FGAtmosphere* Atmosphere;
+ FGFCS* FCS;
+ FGPropulsion* Propulsion;
+ FGMassBalance* MassBalance;
+ FGAircraft* Aircraft;
+ FGTranslation* Translation;
+ FGRotation* Rotation;
+ FGPosition* Position;
+ FGAuxiliary* Auxiliary;
+ FGAerodynamics* Aerodynamics;
int runcount;
float trim_elev;
HISTORY
--------------------------------------------------------------------------------
09/13/00 JSB Created
+04/22/01 JSB Moved code into here from FGAircraft
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-FGAerodynamics::FGAerodynamics(FGFDMExec* fgex) : FGModel(fgex)
+FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec),
+ vMoments(3),
+ vForces(3),
+ vFs(3),
+ vLastFs(3),
+ vDXYZcg(3)
{
+ Name = "FGAerodynamics";
+
+ AxisIdx["DRAG"] = 0;
+ AxisIdx["SIDE"] = 1;
+ AxisIdx["LIFT"] = 2;
+ AxisIdx["ROLL"] = 3;
+ AxisIdx["PITCH"] = 4;
+ AxisIdx["YAW"] = 5;
+
+ Coeff = new CoeffArray[6];
+
if (debug_lvl & 2) cout << "Instantiated: FGAerodynamics" << endl;
}
FGAerodynamics::~FGAerodynamics()
{
+ unsigned int i,j;
+ 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: FGAerodynamics" << endl;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-bool FGAerodynamics:: Run(void) {
+bool FGAerodynamics::Run(void)
+{
+ float alpha, beta;
+ unsigned int axis_ctr,ctr;
if (!FGModel::Run()) {
+ alpha = Translation->Getalpha();
+ beta = Translation->Getbeta();
+
+ vLastFs = vFs;
+ vFs.InitMatrix();
+
+ for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
+ for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
+ vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
+ }
+ }
+
+ vForces = State->GetTs2b(alpha, beta)*vFs;
+
+ // see http://home.earthlink.net/~apeden/jsbsim_moments_due_to_forces.txt
+ // for details on this
+
+ vDXYZcg(eX) = -(Aircraft->GetXYZrp(eX) - MassBalance->GetXYZcg(eX))/12.0;
+ vDXYZcg(eY) = (Aircraft->GetXYZrp(eY) - MassBalance->GetXYZcg(eY))/12.0;
+ vDXYZcg(eZ) = -(Aircraft->GetXYZrp(eZ) - MassBalance->GetXYZcg(eZ))/12.0;
+
+ vMoments(eL) = vForces(eZ)*vDXYZcg(eY) - vForces(eY)*vDXYZcg(eZ);
+ vMoments(eM) = vForces(eX)*vDXYZcg(eZ) - vForces(eZ)*vDXYZcg(eX);
+ vMoments(eN) = vForces(eY)*vDXYZcg(eX) - vForces(eX)*vDXYZcg(eY);
+
+ for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
+ for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
+ vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
+ }
+ }
return false;
} else {
return true;
bool FGAerodynamics::LoadAerodynamics(FGConfigFile* AC_cfg)
{
-//
+ string token, axis;
+
+ AC_cfg->GetNextConfigLine();
+
+ while ((token = AC_cfg->GetValue()) != string("/AERODYNAMICS")) {
+ if (token == "AXIS") {
+ CoeffArray ca;
+ axis = AC_cfg->GetValue("NAME");
+ AC_cfg->GetNextConfigLine();
+ while ((token = AC_cfg->GetValue()) != string("/AXIS")) {
+ ca.push_back(new FGCoefficient(FDMExec, AC_cfg));
+ if (debug_lvl > 0) DisplayCoeffFactors(ca.back()->Getmultipliers());
+ }
+ Coeff[AxisIdx[axis]] = ca;
+ AC_cfg->GetNextConfigLine();
+ }
+ }
+
+ return true;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGAerodynamics::DisplayCoeffFactors(vector <eParam> multipliers)
+{
+ unsigned int i;
+
+ cout << " Non-Dimensionalized by: ";
+
+ for (i=0; i<multipliers.size();i++) cout << State->paramdef[multipliers[i]];
+
+ cout << endl;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+string FGAerodynamics::GetCoefficientStrings(void)
+{
+ string CoeffStrings = "";
+ bool firstime = true;
+ unsigned int axis, sd;
+
+ for (axis = 0; axis < 6; axis++) {
+ for (sd = 0; sd < Coeff[axis].size(); sd++) {
+ if (firstime) {
+ firstime = false;
+ } else {
+ CoeffStrings += ", ";
+ }
+ CoeffStrings += Coeff[axis][sd]->Getname();
+ }
+ }
+
+ return CoeffStrings;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+string FGAerodynamics::GetCoefficientValues(void)
+{
+ string SDValues = "";
+ char buffer[10];
+ bool firstime = true;
+
+ for (unsigned int axis = 0; axis < 6; axis++) {
+ for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
+ if (firstime) {
+ firstime = false;
+ } else {
+ SDValues += ", ";
+ }
+ sprintf(buffer, "%9.6f", Coeff[axis][sd]->GetSD());
+ SDValues += string(buffer);
+ }
+ }
+
+ return SDValues;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+float FGAerodynamics::GetNlf(void)
+{
+ if (fabs(Position->GetGamma()) < 1.57) {
+ return (vFs(eZ)/(MassBalance->GetWeight()*cos(Position->GetGamma())));
+ } else {
+ return 0.0;
+ }
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+float FGAerodynamics::GetLoD(void)
+{
+ float LoD;
+
+ if (vFs(1) != 0.00) return vFs(3)/vFs(1);
+ else return 0.00;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <vector>
+# include <map>
# else
# include <vector.h>
+# include <map.h>
# endif
#else
# include <vector>
+# include <map>
#endif
#include "FGModel.h"
#include "FGConfigFile.h"
+#include "FGState.h"
+#include "FGMassBalance.h"
+#include "FGTranslation.h"
+#include "FGCoefficient.h"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
/** Loads the Aerodynamics model
@return true if successful */
bool LoadAerodynamics(FGConfigFile* AC_cfg);
-
+
+ /** Outputs coefficient information.
+ Non-dimensionalizing parameter descriptions are output
+ for each aero coefficient defined.
+ @param multipliers the list of multipliers for this coefficient.*/
+ void DisplayCoeffFactors(vector <eParam> multipliers);
+
+ /** Gets the total aerodynamic force vector.
+ @return a force vector reference. */
+ FGColumnVector& GetForces(void) {return vForces;}
+
+ /** Gets the total aerodynamic moment vector.
+ @return a moment vector reference. */
+ FGColumnVector& GetMoments(void) {return vMoments;}
+
+ inline FGColumnVector GetvLastFs(void) { return vLastFs; }
+ inline float GetvLastFs(int axis) { return vLastFs(axis); }
+ inline FGColumnVector GetvFs(void) { return vFs; }
+ inline float GetvFs(int axis) { return vFs(axis); }
+ float GetLoD(void);
+
+ /** Gets the strings for the current set of coefficients.
+ @return a string containing the descriptive names for all coefficients */
+ string GetCoefficientStrings(void);
+
+ /** Gets the coefficient values.
+ @return a string containing the numeric values for the current set of
+ coefficients */
+ string GetCoefficientValues(void);
+
+ /// Gets the Normal Load Factor
+ float GetNlf(void);
+
private:
+ typedef map<string,int> AxisIndex;
+ AxisIndex AxisIdx;
+ typedef vector<FGCoefficient*> CoeffArray;
+ CoeffArray* Coeff;
+ FGColumnVector vFs;
+ FGColumnVector vForces;
+ FGColumnVector vMoments;
+ FGColumnVector vLastFs;
+ FGColumnVector vDXYZcg;
+
void Debug(void);
};
Date started: 12/12/98
Purpose: Encapsulates an aircraft
Called by: FGFDMExec
-
+
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
This program is free software; you can redistribute it and/or modify it under
# ifndef __BORLANDC__
# include <simgear/compiler.h>
# endif
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <cmath>
# else
# include <math.h>
#endif
#include "FGAircraft.h"
+#include "FGMassBalance.h"
+#include "FGInertial.h"
+#include "FGAerodynamics.h"
#include "FGTranslation.h"
#include "FGRotation.h"
#include "FGAtmosphere.h"
FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex),
vMoments(3),
vForces(3),
- vFs(3),
- vLastFs(3),
vXYZrp(3),
- vbaseXYZcg(3),
- vXYZcg(3),
vXYZep(3),
vEuler(3),
- vXYZtank(3),
vDXYZcg(3),
vAeroBodyForces(3)
{
Name = "FGAircraft";
- AxisIdx["DRAG"] = 0;
- AxisIdx["SIDE"] = 1;
- AxisIdx["LIFT"] = 2;
- AxisIdx["ROLL"] = 3;
- AxisIdx["PITCH"] = 4;
- AxisIdx["YAW"] = 5;
-
- Coeff = new CoeffArray[6];
-
GearUp = false;
alphaclmin = alphaclmax = 0;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-FGAircraft::~FGAircraft() {
- unsigned int i,j;
- for (i=0; i<6; i++) {
- for (j=0; j<Coeff[i].size(); j++) {
- delete Coeff[i][j];
- }
- }
- delete[] Coeff;
-
+FGAircraft::~FGAircraft()
+{
if (debug_lvl & 2) cout << "Destroyed: FGAircraft" << endl;
}
while ((AC_cfg.GetNextConfigLine() != string("EOF")) &&
(token = AC_cfg.GetValue()) != string("/FDM_CONFIG")) {
if (token == "METRICS") {
- cout << fgcyan << "\n Reading Metrics" << fgdef << endl;
+ if (debug_lvl > 0) cout << fgcyan << "\n Reading Metrics" << fgdef << endl;
ReadMetrics(&AC_cfg);
} else if (token == "AERODYNAMICS") {
- cout << fgcyan << "\n Reading Aerodynamics" << fgdef << endl;
+ if (debug_lvl > 0) cout << fgcyan << "\n Reading Aerodynamics" << fgdef << endl;
ReadAerodynamics(&AC_cfg);
} else if (token == "UNDERCARRIAGE") {
- cout << fgcyan << "\n Reading Landing Gear" << fgdef << endl;
+ if (debug_lvl > 0) cout << fgcyan << "\n Reading Landing Gear" << fgdef << endl;
ReadUndercarriage(&AC_cfg);
} else if (token == "PROPULSION") {
- cout << fgcyan << "\n Reading Propulsion" << fgdef << endl;
+ if (debug_lvl > 0) cout << fgcyan << "\n Reading Propulsion" << fgdef << endl;
ReadPropulsion(&AC_cfg);
} else if (token == "FLIGHT_CONTROL") {
- cout << fgcyan << "\n Reading Flight Control" << fgdef << endl;
+ if (debug_lvl > 0) cout << fgcyan << "\n Reading Flight Control" << fgdef << endl;
ReadFlightControls(&AC_cfg);
} else if (token == "OUTPUT") {
- cout << fgcyan << "\n Reading Output directives" << fgdef << endl;
+ if (debug_lvl > 0) cout << fgcyan << "\n Reading Output directives" << fgdef << endl;
ReadOutput(&AC_cfg);
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-bool FGAircraft::Run(void) {
+bool FGAircraft::Run(void)
+{
if (!FGModel::Run()) { // if false then execute this Run()
GetState();
- for (int i = 1; i <= 3; i++) vForces(i) = vMoments(i) = 0.0;
+ vForces.InitMatrix();
+ vMoments.InitMatrix();
- MassChange();
FMProp();
FMAero();
FMMass();
FMGear();
- nlf = 0;
- if (fabs(Position->GetGamma()) < 1.57) {
- nlf = vFs(eZ)/(Weight*cos(Position->GetGamma()));
- }
-
+ return false;
} else { // skip Run() execution this time
+ return true;
}
-
-
- return false;
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-void FGAircraft::MassChange() {
- float Tw;
- float IXXt, IYYt, IZZt, IXZt;
-// unsigned int t;
-// unsigned int axis_ctr;
-/*
- for (axis_ctr=1; axis_ctr<=3; axis_ctr++) vXYZtank(axis_ctr) = 0.0;
-
- // UPDATE TANK CONTENTS
- //
- // For each engine, cycle through the tanks and draw an equal amount of
- // fuel (or oxidizer) from each active tank. The needed amount of fuel is
- // determined by the engine in the FGEngine class. If more fuel is needed
- // than is available in the tank, then that amount is considered a shortage,
- // and will be drawn from the next tank. If the engine cannot be fed what it
- // needs, it will be considered to be starved, and will shut down.
-
- float Oshortage, Fshortage;
-
- for (unsigned int e=0; e<numEngines; e++) {
- Fshortage = Oshortage = 0.0;
- for (t=0; t<numTanks; t++) {
- switch(Engine[e]->GetType()) {
- case FGEngine::etRocket:
-
- switch(Tank[t]->GetType()) {
- case FGTank::ttFUEL:
- if (Tank[t]->GetSelected()) {
- Fshortage = Tank[t]->Reduce((Engine[e]->CalcFuelNeed()/
- numSelectedFuelTanks)*(dt*rate) + Fshortage);
- }
- break;
- case FGTank::ttOXIDIZER:
- if (Tank[t]->GetSelected()) {
- Oshortage = Tank[t]->Reduce((Engine[e]->CalcOxidizerNeed()/
- numSelectedOxiTanks)*(dt*rate) + Oshortage);
- }
- break;
- }
- break;
-
- case FGEngine::etPiston:
- case FGEngine::etTurboJet:
- case FGEngine::etTurboProp:
-
- if (Tank[t]->GetSelected()) {
- Fshortage = Tank[t]->Reduce((Engine[e]->CalcFuelNeed()/
- numSelectedFuelTanks)*(dt*rate) + Fshortage);
- }
- break;
- }
- }
- 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();
-
- 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();
-// }
-
- 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;
-// }
-
- Ixx = baseIxx + IXXt;
- Iyy = baseIyy + IYYt;
- Izz = baseIzz + IZZt;
- Ixz = baseIxz + IXZt;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGAircraft::FMAero(void) {
- unsigned int axis_ctr,ctr;
-
- vLastFs = vFs;
- for (axis_ctr=1; axis_ctr<=3; axis_ctr++) vFs(axis_ctr) = 0.0;
-
- for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
- for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
- vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
- }
- }
-
- vAeroBodyForces = State->GetTs2b(alpha, beta)*vFs;
- vForces += vAeroBodyForces;
-
- // 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;
-
- vMoments(eL) += vAeroBodyForces(eZ)*vDXYZcg(eY) - vAeroBodyForces(eY)*vDXYZcg(eZ); // rolling moment
- vMoments(eM) += vAeroBodyForces(eX)*vDXYZcg(eZ) - vAeroBodyForces(eZ)*vDXYZcg(eX); // pitching moment
- vMoments(eN) += vAeroBodyForces(eY)*vDXYZcg(eX) - vAeroBodyForces(eX)*vDXYZcg(eY); // yawing moment
-
- for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
- for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
- vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
- }
- }
+void FGAircraft::FMAero(void)
+{
+ vForces += Aerodynamics->GetForces();
+ vMoments += Aerodynamics->GetMoments();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGAircraft::FMGear(void) {
-
+void FGAircraft::FMGear(void)
+{
if ( !GearUp ) {
vector <FGLGear>::iterator iGear = lGear.begin();
while (iGear != lGear.end()) {
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGAircraft::FMMass(void) {
- vForces(eX) += -GRAVITY*sin(vEuler(eTht)) * Mass;
- vForces(eY) += GRAVITY*sin(vEuler(ePhi))*cos(vEuler(eTht)) * Mass;
- vForces(eZ) += GRAVITY*cos(vEuler(ePhi))*cos(vEuler(eTht)) * Mass;
+void FGAircraft::FMMass(void)
+{
+ vForces += Inertial->GetForces();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGAircraft::FMProp(void) {
- vForces += Propulsion->GetForces();
- vMoments += Propulsion->GetMoments();
+void FGAircraft::FMProp(void)
+{
+ vForces += Propulsion->GetForces();
+ vMoments += Propulsion->GetMoments();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGAircraft::GetState(void) {
+void FGAircraft::GetState(void)
+{
dt = State->Getdt();
alpha = Translation->Getalpha();
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGAircraft::ReadMetrics(FGConfigFile* AC_cfg) {
+void FGAircraft::ReadMetrics(FGConfigFile* AC_cfg)
+{
string token = "";
string parameter;
+ float EW, bixx, biyy, bizz, bixz, biyz;
+ FGColumnVector vbaseXYZcg(3);
AC_cfg->GetNextConfigLine();
while ((token = AC_cfg->GetValue()) != string("/METRICS")) {
*AC_cfg >> parameter;
if (parameter == string("AC_WINGAREA")) {
- *AC_cfg >> WingArea;
- cout << " WingArea: " << WingArea << endl;
+ *AC_cfg >> WingArea;
+ if (debug_lvl > 0) cout << " WingArea: " << WingArea << endl;
} else if (parameter == "AC_WINGSPAN") {
- *AC_cfg >> WingSpan;
- cout << " WingSpan: " << WingSpan << endl;
+ *AC_cfg >> WingSpan;
+ if (debug_lvl > 0) cout << " WingSpan: " << WingSpan << endl;
} else if (parameter == "AC_CHORD") {
- *AC_cfg >> cbar;
- cout << " Chord: " << cbar << endl;
+ *AC_cfg >> cbar;
+ if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
} else if (parameter == "AC_IXX") {
- *AC_cfg >> baseIxx;
- cout << " baseIxx: " << baseIxx << endl;
+ *AC_cfg >> bixx;
+ if (debug_lvl > 0) cout << " baseIxx: " << bixx << endl;
+ MassBalance->SetBaseIxx(bixx);
} else if (parameter == "AC_IYY") {
- *AC_cfg >> baseIyy;
- cout << " baseIyy: " << baseIyy << endl;
- } else if (parameter == "AC_IZZ") {
- *AC_cfg >> baseIzz;
- cout << " baseIzz: " << baseIzz << endl;
- } else if (parameter == "AC_IXZ") {
- *AC_cfg >> baseIxz;
- cout << " baseIxz: " << baseIxz << endl;
+ *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);
+ } else if (parameter == "AC_IXZ") {
+ *AC_cfg >> bixz;
+ if (debug_lvl > 0) cout << " baseIxz: " << bixz << endl;
+ MassBalance->SetBaseIxz(bixz);
+ } else if (parameter == "AC_IYZ") {
+ *AC_cfg >> biyz;
+ if (debug_lvl > 0) cout << " baseIyz: " << biyz << endl;
+ MassBalance->SetBaseIyz(biyz);
} else if (parameter == "AC_EMPTYWT") {
- *AC_cfg >> EmptyWeight;
- cout << " EmptyWeight: " << EmptyWeight << endl;
+ *AC_cfg >> EW;
+ MassBalance->SetEmptyWeight(EW);
+ if (debug_lvl > 0) cout << " EmptyWeight: " << EW << endl;
} else if (parameter == "AC_CGLOC") {
- *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
- cout << " CG (x, y, z): " << vbaseXYZcg << endl;
+ *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
+ MassBalance->SetBaseCG(vbaseXYZcg);
+ if (debug_lvl > 0) cout << " CG (x, y, z): " << vbaseXYZcg << endl;
} else if (parameter == "AC_EYEPTLOC") {
- *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
- cout << " Eyepoint (x, y, z): " << vXYZep << endl;
+ *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
+ if (debug_lvl > 0) cout << " Eyepoint (x, y, z): " << vXYZep << endl;
} else if (parameter == "AC_AERORP") {
- *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
- cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
+ *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
+ if (debug_lvl > 0) cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
} else if (parameter == "AC_ALPHALIMITS") {
- *AC_cfg >> alphaclmin >> alphaclmax;
- cout << " Maximum Alpha: " << alphaclmax
- << " Minimum Alpha: " << alphaclmin
+ *AC_cfg >> alphaclmin >> alphaclmax;
+ if (debug_lvl > 0) cout << " Maximum Alpha: " << alphaclmax
+ << " Minimum Alpha: " << alphaclmin
<< endl;
- }
+ }
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGAircraft::ReadAerodynamics(FGConfigFile* AC_cfg) {
- string token, axis;
-
- AC_cfg->GetNextConfigLine();
-
- while ((token = AC_cfg->GetValue()) != string("/AERODYNAMICS")) {
- if (token == "AXIS") {
- CoeffArray ca;
- axis = AC_cfg->GetValue("NAME");
- AC_cfg->GetNextConfigLine();
- while ((token = AC_cfg->GetValue()) != string("/AXIS")) {
- ca.push_back(new FGCoefficient(FDMExec, AC_cfg));
- DisplayCoeffFactors(ca.back()->Getmultipliers());
- }
- Coeff[AxisIdx[axis]]=ca;
- AC_cfg->GetNextConfigLine();
- }
+void FGAircraft::ReadAerodynamics(FGConfigFile* AC_cfg)
+{
+ if (!Aerodynamics->LoadAerodynamics(AC_cfg)) {
+ cerr << "Aerodynamics not successfully loaded" << endl;
}
+
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string token = AC_cfg->GetValue();
string scratch;
AircraftName = AC_cfg->GetValue("NAME");
- cout << underon << "Reading Aircraft Configuration File" << underoff << ": "
- << highint << AircraftName << normint << endl;
+ if (debug_lvl > 0) 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: " << highint << CFGVersion
+
+ if (debug_lvl > 0)
+ cout << " Version: " << highint << CFGVersion
<< normint << endl;
if (CFGVersion != string(NEEDED_CFG_VERSION)) {
- 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 << fgdef << endl;
- //exit(-1);
+ cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
+ " RESULTS WILL BE UNPREDICTABLE !!" << endl;
+ cerr << "Current version needed is: " << NEEDED_CFG_VERSION << endl;
+ cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
}
-
-
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-void FGAircraft::DisplayCoeffFactors(vector <eParam> multipliers) {
- cout << " Non-Dimensionalized by: ";
-
- for (unsigned int i=0; i<multipliers.size();i++)
- cout << State->paramdef[multipliers[i]];
-
- cout << endl;
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-string FGAircraft::GetCoefficientStrings(void) {
- string CoeffStrings = "";
- bool firstime = true;
-
- for (unsigned int axis = 0; axis < 6; axis++) {
- for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
- if (firstime) {
- firstime = false;
- } else {
- CoeffStrings += ", ";
- }
- CoeffStrings += Coeff[axis][sd]->Getname();
- }
- }
-
- return CoeffStrings;
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-string FGAircraft::GetCoefficientValues(void) {
- string SDValues = "";
- char buffer[10];
- bool firstime = true;
-
- for (unsigned int axis = 0; axis < 6; axis++) {
- for (unsigned int sd = 0; sd < Coeff[axis].size(); sd++) {
- if (firstime) {
- firstime = false;
- } else {
- SDValues += ", ";
- }
- sprintf(buffer, "%9.6f", Coeff[axis][sd]->GetSD());
- SDValues += string(buffer);
- }
- }
-
- return SDValues;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//TODO: Add your source code here
}
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-float FGAircraft::GetLoD(void) {
- float LoD;
- if (vFs(1) != 0.00)
- LoD = vFs(3)/vFs(1);
- else
- LoD = 0.00;
-
- return LoD;
-}
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <vector>
# include <iterator>
# include <map>
#endif
#include "FGModel.h"
-#include "FGCoefficient.h"
#include "FGPropulsion.h"
#include "FGConfigFile.h"
#include "FGMatrix.h"
inline float GetWingSpan(void) { return WingSpan; }
/// Gets the average wing chord
inline float Getcbar(void) { return cbar; }
- inline float GetWeight(void) { return Weight; }
- inline float GetMass(void) { return Mass; }
inline FGColumnVector GetMoments(void) { return vMoments; }
inline FGColumnVector GetForces(void) { return vForces; }
inline FGColumnVector GetAeroBodyForces(void) { return vAeroBodyForces; }
inline float GetAeroBodyForces(int axis) { return vAeroBodyForces(axis); }
- inline FGColumnVector GetvFs(void) { return vFs; }
- inline float GetvFs(int axis) { return vFs(axis); }
- inline FGColumnVector GetvLastFs(void) { return vLastFs; }
- inline float GetvLastFs(int axis) { return vLastFs(axis); }
- inline float GetIxx(void) { return Ixx; }
- inline float GetIyy(void) { return Iyy; }
- inline float GetIzz(void) { return Izz; }
- inline float GetIxz(void) { return Ixz; }
- inline FGColumnVector GetXYZcg(void) { return vXYZcg; }
inline FGColumnVector GetXYZrp(void) { return vXYZrp; }
inline FGColumnVector GetXYZep(void) { return vXYZep; }
- inline float GetXYZcg(int idx) { return vXYZcg(idx); }
inline float GetXYZrp(int idx) { return vXYZrp(idx); }
inline float GetXYZep(int idx) { return vXYZep(idx); }
- inline float GetNlf(void) { return nlf; }
inline float GetAlphaCLMax(void) { return alphaclmax; }
inline float GetAlphaCLMin(void) { return alphaclmin; }
inline void SetAlphaCLMax(float tt) { alphaclmax=tt; }
inline void SetAlphaCLMin(float tt) { alphaclmin=tt; }
- inline FGCoefficient* GetCoeff(int axis, int idx) { return Coeff[axis][idx]; }
- string GetCoefficientStrings(void);
- string GetCoefficientValues(void);
string GetGroundReactionStrings(void);
string GetGroundReactionValues(void);
void FMGear(void);
void FMMass(void);
void FMProp(void);
- void MassChange(void);
FGColumnVector vMoments;
FGColumnVector vForces;
- FGColumnVector vFs;
- FGColumnVector vLastFs;
FGColumnVector vXYZrp;
- FGColumnVector vbaseXYZcg;
- FGColumnVector vXYZcg;
FGColumnVector vXYZep;
FGColumnVector vEuler;
- FGColumnVector vXYZtank;
FGColumnVector vDXYZcg;
FGColumnVector vAeroBodyForces;
- float baseIxx, baseIyy, baseIzz, baseIxz, EmptyMass, Mass;
- float Ixx, Iyy, Izz, Ixz;
float alpha, beta;
float WingArea, WingSpan, cbar;
- float Weight, EmptyWeight;
- float nlf,alphaclmax,alphaclmin;
+ float alphaclmax,alphaclmin;
float dt;
string CFGVersion;
string AircraftName;
- typedef map<string,int> AxisIndex;
- AxisIndex AxisIdx;
-
- typedef vector<FGCoefficient*> CoeffArray;
-
- CoeffArray* Coeff;
-
- void DisplayCoeffFactors(vector <eParam> multipliers);
-
bool GearUp;
- string Axis[6];
vector <FGLGear> lGear;
string AircraftPath;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Module: FGAuxiliary.cpp
- Author: Jon Berndt
+ Author: Tony Peden, Jon Berndt
Date started: 01/26/99
Purpose: Calculates additional parameters needed by the visual system, etc.
Called by: FGSimExec
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex) {
+FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex),
+ vPilotAccel(3),
+ vToEyePt(3)
+{
Name = "FGAuxiliary";
vcas = veas = mach = qbar = pt = 0;
psl = rhosl = 1;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-bool FGAuxiliary::Run() {
+bool FGAuxiliary::Run()
+{
float A,B,D;
if (!FGModel::Run()) {
GetState();
- if(mach < 1) //calculate total pressure assuming isentropic flow
+ if (mach < 1) { //calculate total pressure assuming isentropic flow
pt=p*pow((1 + 0.2*mach*mach),3.5);
- else {
+ } else {
// shock in front of pitot tube, we'll assume its normal and use
// the Rayleigh Pitot Tube Formula, i.e. the ratio of total
// pressure behind the shock to the static pressure in front
vcas = sqrt(7*psl/rhosl*(A-1));
veas = sqrt(2*qbar/rhosl);
- vPilotAccel = Translation->GetUVWdot() + Aircraft->GetXYZep() * Rotation->GetPQRdot();
+ // vPilotAccel = Translation->GetUVWdot() + Aircraft->GetXYZep() * Rotation->GetPQRdot();
+
+ vToEyePt = Aircraft->GetXYZep() - MassBalance->GetXYZcg();
+ vPilotAccel = Translation->GetUVWdot()
+ + Rotation->GetPQRdot() * vToEyePt
+ + Rotation->GetPQR() * (Rotation->GetPQR() * vToEyePt);
earthPosAngle += State->Getdt()*OMEGA_EARTH;
-
+ return false;
} else {
+ return true;
}
-
- return false;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-float FGAuxiliary::GetHeadWind(void) {
-
+float FGAuxiliary::GetHeadWind(void)
+{
float psiw,vw,psi;
psiw = Atmosphere->GetWindPsi();
psi = Rotation->Getpsi();
vw = Atmosphere->GetWindNED().Magnitude();
+
return -vw*cos(psiw - psi);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-float FGAuxiliary::GetCrossWind(void) {
-
+float FGAuxiliary::GetCrossWind(void)
+{
float psiw,vw,psi;
psiw = Atmosphere->GetWindPsi();
psi = Rotation->Getpsi();
vw = Atmosphere->GetWindNED().Magnitude();
+
return vw*sin(psiw - psi);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGAuxiliary::GetState(void) {
+void FGAuxiliary::GetState(void)
+{
qbar = Translation->Getqbar();
mach = Translation->GetMach();
p = Atmosphere->GetPressure();
rhosl = Atmosphere->GetDensitySL();
psl = Atmosphere->GetPressureSL();
-
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
float GetHeadWind(void);
float GetCrossWind(void);
-
-protected:
-
private:
float vcas;
float veas;
// isentropic flow equations
FGColumnVector vPilotAccel;
+ FGColumnVector vToEyePt;
float earthPosAngle;
-
void GetState(void);
void Debug(void);
#endif
static const char *IdSrc = "$Id$";
-static const char *IdHdr = "ID_COEFFICIENT";
+static const char *IdHdr = ID_COEFFICIENT;
extern char highint[5];
extern char halfint[5];
AC_cfg->GetNextConfigLine();
*AC_cfg >> description;
- cout << "\n " << highint << underon << name << underoff << normint << endl;
- cout << " " << description << endl;
- cout << " " << method << endl;
+ if (debug_lvl > 0) {
+ cout << "\n " << highint << underon << name << underoff << normint << endl;
+ cout << " " << description << endl;
+ cout << " " << method << endl;
+ }
if (method == "EQUATION") type = EQUATION;
else if (method == "TABLE") type = TABLE;
if (type == VECTOR || type == TABLE) {
*AC_cfg >> rows;
- cout << " Rows: " << rows << " ";
+ if (debug_lvl > 0) cout << " Rows: " << rows << " ";
if (type == TABLE) {
*AC_cfg >> columns;
- cout << "Cols: " << columns;
+ if (debug_lvl > 0) cout << "Cols: " << columns;
Table = new FGTable(rows, columns);
} else {
Table = new FGTable(rows);
}
- cout << endl;
+ if (debug_lvl > 0) cout << endl;
*AC_cfg >> multparms;
LookupR = State->GetParameterIndex(multparms);
- cout << " Row indexing parameter: " << multparms << endl;
+ if (debug_lvl > 0) cout << " Row indexing parameter: " << multparms << endl;
}
if (type == TABLE) {
*AC_cfg >> multparms;
LookupC = State->GetParameterIndex(multparms);
- cout << " Column indexing parameter: " << multparms << endl;
+ if (debug_lvl > 0) cout << " Column indexing parameter: " << multparms << endl;
}
// Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
switch(type) {
case VALUE:
*AC_cfg >> StaticValue;
- cout << " Value = " << StaticValue << endl;
+ if (debug_lvl > 0) cout << " Value = " << StaticValue << endl;
break;
case VECTOR:
case TABLE:
*Table << *AC_cfg;
- Table->Print();
-
+ if (debug_lvl > 0) Table->Print();
break;
case EQUATION:
case UNKNOWN:
#include <math.h>
static const char *IdSrc = "$Id$";
-static const char *IdHdr = "ID_CONFIGFILE";
+static const char *IdHdr = ID_CONFIGFILE;
extern short debug_lvl;
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
-# include <fstream>
-# else
-# include <fstream.h>
-# endif
+# include STL_STRING
+# include STL_FSTREAM
+# include STL_IOSTREAM
+ SG_USING_STD(string);
+ SG_USING_STD(ostream);
+ SG_USING_STD(istream);
+ SG_USING_STD(ifstream);
+ SG_USING_STD(cerr);
+ SG_USING_STD(endl);
+ SG_USING_STD(ios);
+ SG_USING_STD(cout);
#else
# include <fstream>
+# include <iostream>
+# include <string>
+ using std::string;
+ using std::ostream;
+ using std::istream;
+ using std::ifstream;
+ using std::ios;
+ using std::cerr;
+ using std::endl;
+ using std::cout;
#endif
-#include <string>
#include "FGDefs.h"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#define ID_CONFIGFILE "$Id$"
-using std::string;
-using std::ifstream;
-
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
// $Log$
-// Revision 1.25 2001/04/06 20:59:31 curt
-// More JSBSim updates.
+// Revision 1.26 2001/06/05 18:58:49 curt
+// Synced with latest JSBSim as of June 5, 2001.
//
// Revision 1.7 2001/03/22 14:10:24 jberndt
// Fixed ID comment
// $Log$
-// Revision 1.24 2001/04/06 20:59:31 curt
-// More JSBSim updates.
+// Revision 1.25 2001/06/05 18:58:49 curt
+// Synced with latest JSBSim as of June 5, 2001.
//
// Revision 1.10 2001/03/22 14:10:24 jberndt
// Fixed ID comment
#define GRAVITY 32.174
#define INVGRAVITY 0.031081
#define EARTHRAD 20925650.00 // feet, equatorial
-#define OMEGAEARTH 7.2685E-3 // rad/sec
#define EARTHRADSQRD 437882827922500.0
#define ONESECOND 4.848136811E-6
#define ECCENT 0.996647186
#define FPSTOKTS 0.592484
#define INCHTOFT 0.08333333
#define OMEGA_EARTH .00007272205217
-#define NEEDED_CFG_VERSION "1.38"
-#define JSBSIM_VERSION "0.8.2"
+#define NEEDED_CFG_VERSION "1.40"
+#define JSBSIM_VERSION "0.8.6"
#define HPTOFTLBSSEC 550
#define METERS_TO_FEET 3.2808
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <fstream>
# else
# include <fstream.h>
#include "FGTank.h"
static const char *IdSrc = "$Id$";
-static const char *IdHdr = "ID_ENGINE";
+static const char *IdHdr = ID_ENGINE;
extern short debug_lvl;
# include <simgear/compiler.h>
# include STL_STRING
SG_USING_STD(string);
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <vector>
# else
# include <vector.h>
#include "filtersjb/FGFlaps.h"
static const char *IdSrc = "$Id$";
-static const char *IdHdr = "ID_FCS";
+static const char *IdHdr = ID_FCS;
extern short debug_lvl;
string token;
FCSName = AC_cfg->GetValue("NAME");
- cout << " Control System Name: " << FCSName << endl;
+ if (debug_lvl > 0) cout << " Control System Name: " << FCSName << endl;
AC_cfg->GetNextConfigLine();
while ((token = AC_cfg->GetValue()) != "/FLIGHT_CONTROL") {
if (token == "COMPONENT") {
token = AC_cfg->GetValue("TYPE");
- cout << " Loading Component \"" << AC_cfg->GetValue("NAME") << "\" of type: " << token << endl;
+ if (debug_lvl > 0) cout << " Loading Component \""
+ << AC_cfg->GetValue("NAME")
+ << "\" of type: " << token << endl;
if ((token == "LAG_FILTER") ||
(token == "LEAD_LAG_FILTER") ||
(token == "SECOND_ORDER_FILTER") ||
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <vector>
# else
# include <vector.h>
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
-# include <iostream>
-# include <ctime>
-# include <iterator>
-# else
-# include <iostream.h>
-# include <time.h>
-# include <iterator.h>
-# endif
+# include STL_IOSTREAM
+# include <time.h>
+# include STL_ITERATOR
#else
# include <iostream>
# include <ctime>
#include "FGAtmosphere.h"
#include "FGFCS.h"
#include "FGPropulsion.h"
+#include "FGMassBalance.h"
+#include "FGAerodynamics.h"
+#include "FGInertial.h"
#include "FGAircraft.h"
#include "FGTranslation.h"
#include "FGRotation.h"
#include "FGConfigFile.h"
static const char *IdSrc = "$Id$";
-static const char *IdHdr = "ID_FDMEXEC";
+static const char *IdHdr = ID_FDMEXEC;
char highint[5] = {27, '[', '1', 'm', '\0' };
char halfint[5] = {27, '[', '2', 'm', '\0' };
// FGModel object executes its Run() method
// f) 8: When this value is set, various runtime state variables
// are printed out periodically
+ // g) 16: When set various parameters are sanity checked and
+ // a message is printed out when they go out of bounds.
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS IMPLEMENTATION
FGFDMExec::FGFDMExec(void)
{
- Frame = 0;
- FirstModel = 0;
- Error = 0;
- State = 0;
- Atmosphere = 0;
- FCS = 0;
- Propulsion = 0;
- Aircraft = 0;
- Translation = 0;
- Rotation = 0;
- Position = 0;
- Auxiliary = 0;
- Output = 0;
+ Frame = 0;
+ FirstModel = 0;
+ Error = 0;
+ State = 0;
+ Atmosphere = 0;
+ FCS = 0;
+ Propulsion = 0;
+ MassBalance = 0;
+ Aerodynamics = 0;
+ Inertial = 0;
+ Aircraft = 0;
+ Translation = 0;
+ Rotation = 0;
+ Position = 0;
+ Auxiliary = 0;
+ Output = 0;
terminate = false;
frozen = false;
modelLoaded = false;
Scripted = false;
- cout << "\n\n " << highint << underon << "JSBSim Flight Dynamics Model v"
- << JSBSIM_VERSION << underoff << normint << endl;
- cout << halfint << " [cfg file spec v" << NEEDED_CFG_VERSION << "]\n\n";
- cout << normint << "JSBSim startup beginning ...\n\n";
-
try {
char* num = getenv("JSBSIM_DEBUG");
if (!num) debug_lvl = 1;
debug_lvl = 1;
}
+ if (debug_lvl > 0) {
+ cout << "\n\n " << highint << underon << "JSBSim Flight Dynamics Model v"
+ << JSBSIM_VERSION << underoff << normint << endl;
+ cout << halfint << " [cfg file spec v" << NEEDED_CFG_VERSION << "]\n\n";
+ cout << normint << "JSBSim startup beginning ...\n\n";
+ }
+
if (debug_lvl & 2) cout << "Instantiated: FGFDMExec" << endl;
Allocate();
bool result=true;
- Atmosphere = new FGAtmosphere(this);
- FCS = new FGFCS(this);
- Propulsion = new FGPropulsion(this);
- Aircraft = new FGAircraft(this);
- Translation = new FGTranslation(this);
- Rotation = new FGRotation(this);
- Position = new FGPosition(this);
- Auxiliary = new FGAuxiliary(this);
- Output = new FGOutput(this);
-
- State = new FGState(this); // This must be done here, as the FGState
- // class needs valid pointers to the above
- // model classes
+ Atmosphere = new FGAtmosphere(this);
+ FCS = new FGFCS(this);
+ Propulsion = new FGPropulsion(this);
+ MassBalance = new FGMassBalance(this);
+ Aerodynamics = new FGAerodynamics (this);
+ Inertial = new FGInertial(this);
+ Aircraft = new FGAircraft(this);
+ Translation = new FGTranslation(this);
+ Rotation = new FGRotation(this);
+ Position = new FGPosition(this);
+ Auxiliary = new FGAuxiliary(this);
+ Output = new FGOutput(this);
+
+ State = new FGState(this); // This must be done here, as the FGState
+ // class needs valid pointers to the above
+ // model classes
// Initialize models so they can communicate with each other
if (!Propulsion->InitModel()) {
cerr << fgred << "FGPropulsion model init failed" << fgdef << endl;
Error+=4;}
+ if (!MassBalance->InitModel()) {
+ cerr << fgred << "FGMassBalance model init failed" << fgdef << endl;
+ Error+=8;}
+ if (!Aerodynamics->InitModel()) {
+ cerr << fgred << "FGAerodynamics model init failed" << fgdef << endl;
+ Error+=16;}
+ if (!Inertial->InitModel()) {
+ cerr << fgred << "FGInertial model init failed" << fgdef << endl;
+ Error+=32;}
if (!Aircraft->InitModel()) {
cerr << fgred << "Aircraft model init failed" << fgdef << endl;
- Error+=8;}
+ Error+=64;}
if (!Translation->InitModel()){
cerr << fgred << "Translation model init failed" << fgdef << endl;
- Error+=16;}
+ Error+=128;}
if (!Rotation->InitModel()) {
cerr << fgred << "Rotation model init failed" << fgdef << endl;
- Error+=32;}
+ Error+=256;}
if (!Position->InitModel()) {
cerr << fgred << "Position model init failed" << fgdef << endl;
- Error+=64;}
+ Error+=512;}
if (!Auxiliary->InitModel()) {
cerr << fgred << "Auxiliary model init failed" << fgdef << endl;
- Error+=128;}
+ Error+=1024;}
if (!Output->InitModel()) {
cerr << fgred << "Output model init failed" << fgdef << endl;
- Error+=256;}
+ Error+=2048;}
if (Error > 0) result = false;
// instance, the atmosphere model gets executed every fifth pass it is called
// by the executive. Everything else here gets executed each pass.
- Schedule(Atmosphere, 1);
- Schedule(FCS, 1);
- Schedule(Propulsion, 1);
- Schedule(Aircraft, 1);
- Schedule(Rotation, 1);
- Schedule(Translation, 1);
- Schedule(Position, 1);
- Schedule(Auxiliary, 1);
- Schedule(Output, 1);
+ Schedule(Atmosphere, 1);
+ Schedule(FCS, 1);
+ Schedule(Propulsion, 1);
+ Schedule(MassBalance, 1);
+ Schedule(Aerodynamics, 1);
+ Schedule(Inertial, 1);
+ Schedule(Aircraft, 1);
+ Schedule(Rotation, 1);
+ Schedule(Translation, 1);
+ Schedule(Position, 1);
+ Schedule(Auxiliary, 1);
+ Schedule(Output, 1);
modelLoaded = false;
if ( Atmosphere != 0 ) delete Atmosphere;
if ( FCS != 0 ) delete FCS;
if ( Propulsion != 0) delete Propulsion;
+ if ( MassBalance != 0) delete MassBalance;
+ if ( Aerodynamics != 0) delete Aerodynamics;
+ if ( Inertial != 0) delete Inertial;
if ( Aircraft != 0 ) delete Aircraft;
if ( Translation != 0 ) delete Translation;
if ( Rotation != 0 ) delete Rotation;
FirstModel = 0L;
Error = 0;
- State = 0;
- Atmosphere = 0;
- FCS = 0;
- Propulsion = 0;
- Aircraft = 0;
- Translation = 0;
- Rotation = 0;
- Position = 0;
- Auxiliary = 0;
- Output = 0;
+ State = 0;
+ Atmosphere = 0;
+ FCS = 0;
+ Propulsion = 0;
+ MassBalance = 0;
+ Aerodynamics = 0;
+ Inertial = 0;
+ Aircraft = 0;
+ Translation = 0;
+ Rotation = 0;
+ Position = 0;
+ Auxiliary = 0;
+ Output = 0;
modelLoaded = false;
return modelLoaded;
model_iterator = FirstModel;
if (model_iterator == 0L) return false;
- if (Scripted) {
+ if (Scripted) {
RunScript();
if (State->Getsim_time() >= EndTime) return false;
}
bool FGFDMExec::LoadModel(string APath, string EPath, string model)
{
bool result = false;
-
+
if (modelLoaded) {
DeAllocate();
Allocate();
}
-
+
AircraftPath = APath;
EnginePath = EPath;
result = Aircraft->LoadAircraft(AircraftPath, EnginePath, model);
<< fgdef << endl;
}
- cout << "\n\nJSBSim startup complete\n\n";
+ if (debug_lvl > 0) cout << "\n\nJSBSim startup complete\n\n";
return result;
}
string initialize="";
bool result=false;
float dt=0.0;
+ int i;
struct condition *newCondition;
if (!Script.IsOpen()) return false;
Script.GetNextConfigLine();
ScriptName = Script.GetValue("name");
Scripted = true;
- cout << "Reading Script File " << ScriptName << endl;
+ if (debug_lvl > 0) cout << "Reading Script File " << ScriptName << endl;
while (Script.GetNextConfigLine() != "EOF" && Script.GetValue() != "/runscript") {
token = Script.GetValue();
if (token == "use") {
if ((token = Script.GetValue("aircraft")) != "") {
aircraft = token;
- cout << " Use aircraft: " << token << endl;
+ if (debug_lvl > 0) cout << " Use aircraft: " << token << endl;
} else if ((token = Script.GetValue("initialize")) != "") {
initialize = token;
- cout << " Use reset file: " << token << endl;
+ if (debug_lvl > 0) cout << " Use reset file: " << token << endl;
} else {
cerr << "Unknown 'use' keyword: \"" << token << "\"" << endl;
}
exit(-1);
}
- // print out conditions for double-checking
+ // print out conditions for double-checking if requested
- vector <struct condition>::iterator iterConditions = Conditions.begin();
-
- int count=0;
+ if (debug_lvl > 0) {
+ vector <struct condition>::iterator iterConditions = Conditions.begin();
+ int count=0;
- cout << "\n Script goes from " << StartTime << " to " << EndTime
- << " with dt = " << dt << endl << endl;
+ cout << "\n Script goes from " << StartTime << " to " << EndTime
+ << " with dt = " << dt << endl << endl;
- while (iterConditions < Conditions.end()) {
- cout << " Condition: " << count++ << endl;
- cout << " if (";
+ while (iterConditions < Conditions.end()) {
+ cout << " Condition: " << count++ << endl;
+ cout << " if (";
- for (int i=0; i<iterConditions->TestValue.size(); i++) {
- if (i>0) cout << " and" << endl << " ";
- cout << "(" << State->paramdef[iterConditions->TestParam[i]]
- << iterConditions->Comparison[i] << " "
- << iterConditions->TestValue[i] << ")";
- }
- cout << ") then {" << endl;
-
- for (int i=0; i<iterConditions->SetValue.size(); i++) {
- cout << " set" << State->paramdef[iterConditions->SetParam[i]]
- << "to " << iterConditions->SetValue[i];
-
- switch (iterConditions->Type[i]) {
- case FG_VALUE:
- cout << " (constant";
- break;
- case FG_DELTA:
- cout << " (delta";
- break;
- case FG_BOOL:
- cout << " (boolean";
- break;
- default:
- cout << " (unspecified type";
+ for (i=0; i<iterConditions->TestValue.size(); i++) {
+ if (i>0) cout << " and" << endl << " ";
+ cout << "(" << State->paramdef[iterConditions->TestParam[i]]
+ << iterConditions->Comparison[i] << " "
+ << iterConditions->TestValue[i] << ")";
}
+ cout << ") then {" << endl;
- switch (iterConditions->Action[i]) {
- case FG_RAMP:
- cout << " via ramp";
- break;
- case FG_STEP:
- cout << " via step";
- break;
- case FG_EXP:
- cout << " via exponential approach";
- break;
- default:
- cout << " via unspecified action";
- }
+ for (i=0; i<iterConditions->SetValue.size(); i++) {
+ cout << " set" << State->paramdef[iterConditions->SetParam[i]]
+ << "to " << iterConditions->SetValue[i];
+
+ switch (iterConditions->Type[i]) {
+ case FG_VALUE:
+ cout << " (constant";
+ break;
+ case FG_DELTA:
+ cout << " (delta";
+ break;
+ case FG_BOOL:
+ cout << " (boolean";
+ break;
+ default:
+ cout << " (unspecified type";
+ }
+
+ switch (iterConditions->Action[i]) {
+ case FG_RAMP:
+ cout << " via ramp";
+ break;
+ case FG_STEP:
+ cout << " via step";
+ break;
+ case FG_EXP:
+ cout << " via exponential approach";
+ break;
+ default:
+ cout << " via unspecified action";
+ }
- if (!iterConditions->Persistent[i]) cout << endl
- << " once";
- else cout << endl
- << " repeatedly";
+ if (!iterConditions->Persistent[i]) cout << endl
+ << " once";
+ else cout << endl
+ << " repeatedly";
- if (iterConditions->Action[i] == FG_RAMP ||
- iterConditions->Action[i] == FG_EXP) cout << endl
- << " with time constant "
- << iterConditions->TC[i];
+ if (iterConditions->Action[i] == FG_RAMP ||
+ iterConditions->Action[i] == FG_EXP) cout << endl
+ << " with time constant "
+ << iterConditions->TC[i];
+ }
+ cout << ")" << endl << " }" << endl << endl;
+
+ iterConditions++;
}
- cout << ")" << endl << " }" << endl << endl;
- iterConditions++;
+ cout << endl;
}
- cout << endl;
-
result = LoadModel("aircraft", "engine", aircraft);
if (!result) {
cerr << "Aircraft file " << aircraft << " was not found" << endl;
vector <struct condition>::iterator iC = Conditions.begin();
bool truth;
bool WholeTruth;
+ int i;
int count=0;
while (iC < Conditions.end()) {
// determine whether the set of conditional tests for this condition equate
// to true
- for (int i=0; i<iC->TestValue.size(); i++) {
+ for (i=0; i<iC->TestValue.size(); i++) {
if (iC->Comparison[i] == "lt")
truth = State->GetParameter(iC->TestParam[i]) < iC->TestValue[i];
else if (iC->Comparison[i] == "le")
// if the conditions are true, do the setting of the desired parameters
if (WholeTruth) {
- for (int i=0; i<iC->SetValue.size(); i++) {
+ for (i=0; i<iC->SetValue.size(); i++) {
if ( ! iC->Triggered[i]) {
iC->OriginalValue[i] = State->GetParameter(iC->SetParam[i]);
switch (iC->Type[i]) {
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <vector>
# else
# include <vector.h>
class FGAtmosphere;
class FGFCS;
class FGPropulsion;
+class FGMassBalance;
+class FGAerodynamics;
+class FGInertial;
class FGAircraft;
class FGTranslation;
class FGRotation;
FGModel object executes its Run() method</li>
<li><b>8</b>: When this value is set, various runtime state variables
are printed out periodically</li>
+ <li><b>16</b>: When set various parameters are sanity checked and
+ a message is printed out when they go out of bounds</li>
</ol>
*/
/// Returns the FGPropulsion pointer.
inline FGPropulsion* GetPropulsion(void) {return Propulsion;}
/// Returns the FGAircraft pointer.
+ inline FGMassBalance* GetMassBalance(void) {return MassBalance;}
+ /// Returns the FGAerodynamics pointer
+ inline FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
+ /// Returns the FGInertial pointer.
+ inline FGInertial* GetInertial(void) {return Inertial;}
+ /// Returns the FGAircraft pointer.
inline FGAircraft* GetAircraft(void) {return Aircraft;}
/// Returns the FGTranslation pointer.
inline FGTranslation* GetTranslation(void) {return Translation;}
float EndTime;
vector <struct condition> Conditions;
- FGState* State;
- FGAtmosphere* Atmosphere;
- FGFCS* FCS;
- FGPropulsion* Propulsion;
- FGAircraft* Aircraft;
- FGTranslation* Translation;
- FGRotation* Rotation;
- FGPosition* Position;
- FGAuxiliary* Auxiliary;
- FGOutput* Output;
+ FGState* State;
+ FGAtmosphere* Atmosphere;
+ FGFCS* FCS;
+ FGPropulsion* Propulsion;
+ FGMassBalance* MassBalance;
+ FGAerodynamics* Aerodynamics;
+ FGInertial* Inertial;
+ FGAircraft* Aircraft;
+ FGTranslation* Translation;
+ FGRotation* Rotation;
+ FGPosition* Position;
+ FGAuxiliary* Auxiliary;
+ FGOutput* Output;
bool Allocate(void);
bool DeAllocate(void);
#include "FGForce.h"
static const char *IdSrc = "$Id$";
-static const char *IdHdr = "ID_FORCE";
+static const char *IdHdr = ID_FORCE;
extern short debug_lvl;
//find the distance from this vector's location to the cg
//needs to be done like this to convert from structural to body coords
- vDXYZ(1) = -(vXYZn(1) - fdmex->GetAircraft()->GetXYZcg(1))*INCHTOFT;
- vDXYZ(2) = (vXYZn(2) - fdmex->GetAircraft()->GetXYZcg(2))*INCHTOFT; //cg and rp values are in inches
- vDXYZ(3) = -(vXYZn(3) - fdmex->GetAircraft()->GetXYZcg(3))*INCHTOFT;
+ vDXYZ(1) = -(vXYZn(1) - fdmex->GetMassBalance()->GetXYZcg(1))*INCHTOFT;
+ vDXYZ(2) = (vXYZn(2) - fdmex->GetMassBalance()->GetXYZcg(2))*INCHTOFT; //cg and rp values are in inches
+ vDXYZ(3) = -(vXYZn(3) - fdmex->GetMassBalance()->GetXYZcg(3))*INCHTOFT;
vM=vMn +vDXYZ*vFb;
bool FGGroundReactions::LoadGroundReactions(FGConfigFile* AC_cfg)
{
//
+ return true;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <vector>
# else
# include <vector.h>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGInertial.h"
+#include "FGPosition.h"
+#include "FGMassBalance.h"
static const char *IdSrc = "$Id$";
static const char *IdHdr = ID_INERTIAL;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-FGInertial::FGInertial(FGFDMExec* fgex) : FGModel(fgex)
+FGInertial::FGInertial(FGFDMExec* fgex) : FGModel(fgex),
+ vForces(3),
+ vOmegaLocal(3),
+ vRadius(3)
{
+ Name = "FGInertial";
+
+ vRadius.InitMatrix();
+
if (debug_lvl & 2) cout << "Instantiated: FGInertial" << endl;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-bool FGInertial:: Run(void) {
+FGInertial::~FGInertial(void)
+{
+ if (debug_lvl & 2) cout << "Destroyed: FGInertial" << endl;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+bool FGInertial::Run(void)
+{
+ float stht, ctht, sphi, cphi;
if (!FGModel::Run()) {
+ stht = sin(Rotation->GetEuler(eTht));
+ ctht = cos(Rotation->GetEuler(eTht));
+ sphi = sin(Rotation->GetEuler(ePhi));
+ cphi = cos(Rotation->GetEuler(ePhi));
+
+ vForces(eX) = -GRAVITY*stht;
+ vForces(eY) = GRAVITY*sphi*ctht;
+ vForces(eZ) = GRAVITY*cphi*ctht;
+
+ // The following equation for vOmegaLocal terms shows the angular velocity
+ // calculation _for_the_local_frame_ given the earth's rotation (first set)
+ // at the current latitude, and also the component due to the aircraft
+ // motion over the curved surface of the earth (second set).
+
+ vOmegaLocal(eX) = OMEGA_EARTH * cos(Position->GetLatitude());
+ vOmegaLocal(eY) = 0.0;
+ vOmegaLocal(eZ) = OMEGA_EARTH * -sin(Position->GetLatitude());
+
+ vOmegaLocal(eX) += Position->GetVe() / Position->GetRadius();
+ vOmegaLocal(eY) += -Position->GetVn() / Position->GetRadius();
+ vOmegaLocal(eZ) += 0.00;
+
+// vForces = State->GetTl2b()*(-2.0*vOmegaLocal * Position->GetVel());
+
+ vRadius(3) = Position->GetRadius();
+ vForces += State->GetTl2b()*(vOmegaLocal * (vOmegaLocal * vRadius));
+
+ vForces *= MassBalance->GetMass(); // IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
return false;
} else {
return true;
bool FGInertial::LoadInertial(FGConfigFile* AC_cfg)
{
-//
+ return true;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <vector>
# else
# include <vector.h>
#include "FGModel.h"
#include "FGConfigFile.h"
+#include "FGMatrix.h"
#define ID_INERTIAL "$Id$"
public:
FGInertial(FGFDMExec*);
- ~FGInertial();
+ ~FGInertial(void);
bool Run(void);
+ FGColumnVector GetForces(void) {return vForces;}
bool LoadInertial(FGConfigFile* AC_cfg);
+
+private:
+ void Debug(void);
+ FGColumnVector vOmegaLocal;
+ FGColumnVector vForces;
+ FGColumnVector vRadius;
};
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>> kSpring >> bDamp>> dynamicFCoeff >> staticFCoeff
>> rollingFCoeff >> sSteerType >> sBrakeGroup >> maxSteerAngle;
- cout << " Name: " << name << endl;
- cout << " Location: " << vXYZ << endl;
- cout << " Spring Constant: " << kSpring << endl;
- cout << " Damping Constant: " << bDamp << endl;
- cout << " Dynamic Friction: " << dynamicFCoeff << endl;
- cout << " Static Friction: " << staticFCoeff << endl;
- cout << " Rolling Friction: " << rollingFCoeff << endl;
- cout << " Steering Type: " << sSteerType << endl;
- cout << " Grouping: " << sBrakeGroup << endl;
- cout << " Max Steer Angle: " << maxSteerAngle << endl;
+ if (debug_lvl > 0) {
+ cout << " Name: " << name << endl;
+ cout << " Location: " << vXYZ << endl;
+ cout << " Spring Constant: " << kSpring << endl;
+ cout << " Damping Constant: " << bDamp << endl;
+ cout << " Dynamic Friction: " << dynamicFCoeff << endl;
+ cout << " Static Friction: " << staticFCoeff << endl;
+ cout << " Rolling Friction: " << rollingFCoeff << endl;
+ cout << " Steering Type: " << sSteerType << endl;
+ cout << " Grouping: " << sBrakeGroup << endl;
+ cout << " Max Steer Angle: " << maxSteerAngle << endl;
+ }
if (sBrakeGroup == "LEFT" ) eBrakeGrp = bgLeft;
else if (sBrakeGroup == "RIGHT" ) eBrakeGrp = bgRight;
Position = Exec->GetPosition();
Rotation = Exec->GetRotation();
FCS = Exec->GetFCS();
+ MassBalance = Exec->GetMassBalance();
WOW = false;
ReportEnable = true;
Reported = false;
DistanceTraveled = 0.0;
MaximumStrutForce = MaximumStrutTravel = 0.0;
+ SinkRate = GroundSpeed = 0.0;
- vWhlBodyVec = (vXYZ - Aircraft->GetXYZcg()) / 12.0;
+ vWhlBodyVec = (vXYZ - MassBalance->GetXYZcg()) / 12.0;
vWhlBodyVec(eX) = -vWhlBodyVec(eX);
vWhlBodyVec(eZ) = -vWhlBodyVec(eZ);
Rotation = lgear.Rotation;
Exec = lgear.Exec;
FCS = lgear.FCS;
+ MassBalance = lgear.MassBalance;
vXYZ = lgear.vXYZ;
vMoment = lgear.vMoment;
FGColumnVector vLocalForce(3);
FGColumnVector vWhlVelVec(3); // Velocity of this wheel (Local)
- vWhlBodyVec = (vXYZ - Aircraft->GetXYZcg()) / 12.0;
+ vWhlBodyVec = (vXYZ - MassBalance->GetXYZcg()) / 12.0;
vWhlBodyVec(eX) = -vWhlBodyVec(eX);
vWhlBodyVec(eZ) = -vWhlBodyVec(eZ);
MaximumStrutForce = MaximumStrutTravel = 0.0;
}
+ compressLength = 0.0; // reset compressLength to zero for data output validity
+
vForce.InitMatrix();
vMoment.InitMatrix();
}
}
if (ReportEnable && Position->GetVel().Magnitude() <= 0.05 && !Reported) {
- Report();
+ if (debug_lvl > 0) Report();
}
return vForce;
class FGRotation;
class FGFCS;
class FGState;
+class FGMassBalance;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
FGPosition* Position;
FGRotation* Rotation;
FGFCS* FCS;
+ FGMassBalance* MassBalance;
void Report(void);
void Debug(void);
#include "FGPosition.h"
#include "FGRotation.h"
#include "FGFCS.h"
+#include "FGMassBalance.h"
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGMassBalance::FGMassBalance(FGFDMExec* fdmex) : FGModel(fdmex)
{
+ Name = "FGMassBalance";
+
if (debug_lvl & 2) cout << "Instantiated: FGMassBalance" << endl;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-bool FGMassBalance::Run(void) {
+FGMassBalance::~FGMassBalance()
+{
+ if (debug_lvl & 2) cout << "Destroyed: FGMassBalance" << endl;
+}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+bool FGMassBalance::Run(void)
+{
if (!FGModel::Run()) {
+ Weight = EmptyWeight + Propulsion->GetTanksWeight();
+
+ Mass = Weight / GRAVITY;
+
+// Calculate new CG here.
+
+ vXYZcg = (Propulsion->GetTanksCG() + EmptyWeight*vbaseXYZcg) / Weight;
+
+// Calculate new moments of inertia here
+
+ Ixx = baseIxx + Propulsion->GetTanksIxx(vXYZcg);
+ Iyy = baseIyy + Propulsion->GetTanksIyy(vXYZcg);
+ Izz = baseIzz + Propulsion->GetTanksIzz(vXYZcg);
+ Ixz = baseIxz + Propulsion->GetTanksIxz(vXYZcg);
+
+ if (debug_lvl > 1) Debug();
+
return false;
} else {
return true;
void FGMassBalance::Debug(void)
{
- // TODO: Add user code here
+ if (debug_lvl & 16) { // Sanity check variables
+ if (EmptyWeight <= 0.0 || EmptyWeight > 1e9)
+ cout << "MassBalance::EmptyWeight out of bounds: " << EmptyWeight << endl;
+ if (Weight <= 0.0 || Weight > 1e9)
+ cout << "MassBalance::Weight out of bounds: " << Weight << endl;
+ if (Mass <= 0.0 || Mass > 1e9)
+ cout << "MassBalance::Mass out of bounds: " << Mass << endl;
+ }
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGModel.h"
+#include "FGPropulsion.h"
#define ID_MASSBALANCE "$Id$"
~FGMassBalance();
bool Run(void);
-
-private:
+
+ inline float GetMass(void) {return Mass;}
+ inline float GetWeight(void) {return Weight;}
+ inline float GetIxx(void) {return Ixx;}
+ inline float GetIyy(void) {return Iyy;}
+ inline float GetIzz(void) {return Izz;}
+ inline float GetIxz(void) {return Ixz;}
+ inline float GetIyz(void) {return Iyz;}
+ inline FGColumnVector& GetXYZcg(void) {return vXYZcg;}
+ inline float GetXYZcg(int axis) {return vXYZcg(axis);}
+
+ inline void SetEmptyWeight(float EW) { EmptyWeight = EW;}
+ inline void SetBaseIxx(float bixx) { baseIxx = bixx;}
+ inline void SetBaseIyy(float biyy) { baseIyy = biyy;}
+ inline void SetBaseIzz(float bizz) { baseIzz = bizz;}
+ inline void SetBaseIxz(float bixz) { baseIxz = bixz;}
+ inline void SetBaseIyz(float biyz) { baseIyz = biyz;}
+ inline void SetBaseCG(const FGColumnVector& CG) {vbaseXYZcg = CG;}
+
+private:
+ float Weight;
+ float EmptyWeight;
+ float Mass;
+ float Ixx;
+ float Iyy;
+ float Izz;
+ float Ixz;
+ float Iyz;
+ float baseIxx;
+ float baseIyy;
+ float baseIzz;
+ float baseIxz;
+ float baseIyz;
+ FGColumnVector vXYZcg;
+ FGColumnVector vXYZtank;
+ FGColumnVector vbaseXYZcg;
void Debug(void);
};
#include <stdlib.h>
#ifdef FGFS
+# include <math.h>
# include <simgear/compiler.h>
# include STL_STRING
+# include STL_FSTREAM
+# include STL_IOSTREAM
SG_USING_STD(string);
SG_USING_STD(ostream);
SG_USING_STD(istream);
SG_USING_STD(cerr);
+ SG_USING_STD(cout);
SG_USING_STD(endl);
-# ifdef FG_HAVE_STD_INCLUDES
-# include <fstream>
-# include <cmath>
-# include <iostream>
-# else
-# include <fstream.h>
-# include <math.h>
-# include <iostream.h>
-# endif
#else
# include <fstream>
# include <cmath>
using std::ostream;
using std::istream;
using std::cerr;
+ using std::cout;
using std::endl;
#endif
#include "FGFDMExec.h"
#include "FGAtmosphere.h"
#include "FGFCS.h"
+#include "FGPropulsion.h"
+#include "FGMassBalance.h"
+#include "FGAerodynamics.h"
+#include "FGInertial.h"
#include "FGAircraft.h"
#include "FGTranslation.h"
#include "FGRotation.h"
FDMExec = fdmex;
NextModel = 0L;
- State = 0;
- Atmosphere = 0;
- FCS = 0;
- Propulsion = 0;
- Aircraft = 0;
- Translation = 0;
- Rotation = 0;
- Position = 0;
- Auxiliary = 0;
- Output = 0;
+ State = 0;
+ Atmosphere = 0;
+ FCS = 0;
+ Propulsion = 0;
+ MassBalance = 0;
+ Aerodynamics = 0;
+ Inertial = 0;
+ Aircraft = 0;
+ Translation = 0;
+ Rotation = 0;
+ Position = 0;
+ Auxiliary = 0;
+ Output = 0;
exe_ctr = 1;
bool FGModel::InitModel(void)
{
- State = FDMExec->GetState();
- Atmosphere = FDMExec->GetAtmosphere();
- FCS = FDMExec->GetFCS();
- Propulsion = FDMExec->GetPropulsion();
- Aircraft = FDMExec->GetAircraft();
- Translation = FDMExec->GetTranslation();
- Rotation = FDMExec->GetRotation();
- Position = FDMExec->GetPosition();
- Auxiliary = FDMExec->GetAuxiliary();
- Output = FDMExec->GetOutput();
+ State = FDMExec->GetState();
+ Atmosphere = FDMExec->GetAtmosphere();
+ FCS = FDMExec->GetFCS();
+ Propulsion = FDMExec->GetPropulsion();
+ MassBalance = FDMExec->GetMassBalance();
+ Aerodynamics = FDMExec->GetAerodynamics();
+ Inertial = FDMExec->GetInertial();
+ Aircraft = FDMExec->GetAircraft();
+ Translation = FDMExec->GetTranslation();
+ Rotation = FDMExec->GetRotation();
+ Position = FDMExec->GetPosition();
+ Auxiliary = FDMExec->GetAuxiliary();
+ Output = FDMExec->GetOutput();
if (!State ||
!Atmosphere ||
!FCS ||
!Propulsion ||
+ !MassBalance ||
+ !Aerodynamics ||
+ !Inertial ||
!Aircraft ||
!Translation ||
!Rotation ||
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <iostream>
# else
# include <iostream.h>
class FGAtmosphere;
class FGFCS;
class FGPropulsion;
+class FGMassBalance;
+class FGAerodynamics;
+class FGInertial;
class FGAircraft;
class FGTranslation;
class FGRotation;
FGAtmosphere* Atmosphere;
FGFCS* FCS;
FGPropulsion* Propulsion;
+ FGMassBalance* MassBalance;
+ FGAerodynamics* Aerodynamics;
+ FGInertial* Inertial;
FGAircraft* Aircraft;
FGTranslation* Translation;
FGRotation* Rotation;
string token;
Name = Nzl_cfg->GetValue("NAME");
- cout << " Nozzle Name: " << Name << endl;
Nzl_cfg->GetNextConfigLine();
while (Nzl_cfg->GetValue() != "/FG_NOZZLE") {
*Nzl_cfg >> token;
- if (token == "PE") {
- *Nzl_cfg >> PE;
- cout << " Nozzle Exit Pressure = " << PE << endl;
- } else if (token == "EXPR") {
- *Nzl_cfg >> ExpR;
- cout << " Nozzle Expansion Ratio = " << ExpR << endl;
- } else if (token == "NZL_EFF") {
- *Nzl_cfg >> nzlEff;
- cout << " Nozzle Efficiency = " << nzlEff << endl;
- } else if (token == "DIAM") {
- *Nzl_cfg >> Diameter;
- cout << " Nozzle Diameter = " << Diameter << endl;
- } else {
- cout << "Unhandled token in Nozzle config file: " << token << endl;
- }
+ if (token == "PE") *Nzl_cfg >> PE;
+ else if (token == "EXPR") *Nzl_cfg >> ExpR;
+ else if (token == "NZL_EFF") *Nzl_cfg >> nzlEff;
+ else if (token == "DIAM") *Nzl_cfg >> Diameter;
+ else cerr << "Unhandled token in Nozzle config file: " << token << endl;
+ }
+
+ if (debug_lvl > 0) {
+ cout << " Nozzle Name: " << Name << endl;
+ cout << " Nozzle Exit Pressure = " << PE << endl;
+ cout << " Nozzle Expansion Ratio = " << ExpR << endl;
+ cout << " Nozzle Efficiency = " << nzlEff << endl;
+ cout << " Nozzle Diameter = " << Diameter << endl;
}
Thrust = 0;
Type = ttNozzle;
+ Area2 = (Diameter*Diameter/4.0)*M_PI;
+ AreaT = Area2/ExpR;
if (debug_lvl & 2) cout << "Instantiated: FGNozzle" << endl;
}
float FGNozzle::Calculate(float CfPc)
{
float pAtm = fdmex->GetAtmosphere()->GetPressure();
-
- Thrust = (CfPc + (PE - pAtm)*ExpR) * (Diameter / ExpR) * nzlEff;
+ Thrust = (CfPc * AreaT + (PE - pAtm)*Area2) * nzlEff;
+ vFn(1) = Thrust;
return Thrust;
}
--------------------------------------------------------------------------------
08/24/00 JSB Created
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-COMMENTS, REFERENCES, and NOTES
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SENTRY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGThruster.h"
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+DEFINITIONS
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
#define ID_NOZZLE "$Id$";
+#ifndef M_PI
+# include <simgear/constants.h>
+# define M_PI SG_PI
+#endif
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+FORWARD DECLARATIONS
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS DOCUMENTATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/** Models a rocket nozzle.
+ */
+
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS DECLARATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
class FGNozzle : public FGThruster {
public:
+ /// Constructor
FGNozzle(FGFDMExec* exec, FGConfigFile* AC_cfg);
+ /// Destructor
~FGNozzle();
float Calculate(float CfPc);
float ExpR;
float nzlEff;
float Diameter;
+ float AreaT;
+ float Area2;
void Debug(void);
};
#include "FGFDMExec.h"
#include "FGAtmosphere.h"
#include "FGFCS.h"
+#include "FGAerodynamics.h"
#include "FGAircraft.h"
+#include "FGMassBalance.h"
#include "FGTranslation.h"
#include "FGRotation.h"
#include "FGPosition.h"
}
if (SubSystems & FGAircraft::ssCoefficients) {
cout << ", ";
- cout << Aircraft->GetCoefficientStrings();
+ cout << Aerodynamics->GetCoefficientStrings();
}
if (SubSystems & FGAircraft::ssGroundReactions) {
cout << ", ";
}
if (SubSystems & FGAircraft::ssForces) {
cout << ", ";
- cout << Aircraft->GetvFs() << ", ";
- cout << Aircraft->GetLoD() << ", ";
+ cout << Aerodynamics->GetvFs() << ", ";
+ cout << Aerodynamics->GetLoD() << ", ";
cout << Aircraft->GetForces();
}
if (SubSystems & FGAircraft::ssMoments) {
}
if (SubSystems & FGAircraft::ssMassProps) {
cout << ", ";
- cout << Aircraft->GetIxx() << ", ";
- cout << Aircraft->GetIyy() << ", ";
- cout << Aircraft->GetIzz() << ", ";
- cout << Aircraft->GetIxz() << ", ";
- cout << Aircraft->GetMass() << ", ";
- cout << Aircraft->GetXYZcg();
+ cout << MassBalance->GetIxx() << ", ";
+ cout << MassBalance->GetIyy() << ", ";
+ cout << MassBalance->GetIzz() << ", ";
+ cout << MassBalance->GetIxz() << ", ";
+ cout << MassBalance->GetMass() << ", ";
+ cout << MassBalance->GetXYZcg();
}
if (SubSystems & FGAircraft::ssPosition) {
cout << ", ";
}
if (SubSystems & FGAircraft::ssCoefficients) {
cout << ", ";
- cout << Aircraft->GetCoefficientValues();
+ cout << Aerodynamics->GetCoefficientValues();
}
if (SubSystems & FGAircraft::ssGroundReactions) {
cout << ", ";
}
if (SubSystems & FGAircraft::ssCoefficients) {
datafile << ", ";
- datafile << Aircraft->GetCoefficientStrings();
+ datafile << Aerodynamics->GetCoefficientStrings();
}
if (SubSystems & FGAircraft::ssGroundReactions) {
datafile << ", ";
}
if (SubSystems & FGAircraft::ssForces) {
datafile << ", ";
- datafile << Aircraft->GetvFs() << ", ";
- datafile << Aircraft->GetLoD() << ", ";
+ datafile << Aerodynamics->GetvFs() << ", ";
+ datafile << Aerodynamics->GetLoD() << ", ";
datafile << Aircraft->GetForces();
}
if (SubSystems & FGAircraft::ssMoments) {
}
if (SubSystems & FGAircraft::ssMassProps) {
datafile << ", ";
- datafile << Aircraft->GetIxx() << ", ";
- datafile << Aircraft->GetIyy() << ", ";
- datafile << Aircraft->GetIzz() << ", ";
- datafile << Aircraft->GetIxz() << ", ";
- datafile << Aircraft->GetMass() << ", ";
- datafile << Aircraft->GetXYZcg();
+ datafile << MassBalance->GetIxx() << ", ";
+ datafile << MassBalance->GetIyy() << ", ";
+ datafile << MassBalance->GetIzz() << ", ";
+ datafile << MassBalance->GetIxz() << ", ";
+ datafile << MassBalance->GetMass() << ", ";
+ datafile << MassBalance->GetXYZcg();
}
if (SubSystems & FGAircraft::ssPosition) {
datafile << ", ";
}
if (SubSystems & FGAircraft::ssCoefficients) {
datafile << ", ";
- datafile << Aircraft->GetCoefficientValues();
+ datafile << Aerodynamics->GetCoefficientValues();
}
if (SubSystems & FGAircraft::ssGroundReactions) {
datafile << ", ";
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
-# include <iostream>
-# include <fstream>
-# else
-# include <iostream.h>
-# include <fstream.h>
-# endif
+# include STL_IOSTREAM
+# include STL_FSTREAM
#else
# include <iostream>
# include <fstream>
string token;
Name = Eng_cfg->GetValue("NAME");
- cout << "\n Engine Name: " << Name << endl;
Eng_cfg->GetNextConfigLine();
while (Eng_cfg->GetValue() != "/FG_PISTON") {
*Eng_cfg >> token;
- if (token == "BRAKEHORSEPOWER") {
- *Eng_cfg >> BrakeHorsePower;
- cout << " BrakeHorsePower = " << BrakeHorsePower << endl;
- } else if (token == "MAXTHROTTLE") {
- *Eng_cfg >> MaxThrottle;
- cout << " MaxThrottle = " << MaxThrottle << endl;
- } else if (token == "MINTHROTTLE") {
- *Eng_cfg >> MinThrottle;
- cout << " MinThrottle = " << MinThrottle << endl;
- } else if (token == "SLFUELFLOWMAX") {
- *Eng_cfg >> SLFuelFlowMax;
- cout << " SLFuelFlowMax = " << SLFuelFlowMax << endl;
- } else if (token == "SPEEDSLOPE") {
- *Eng_cfg >> SpeedSlope;
- cout << " SpeedSlope = " << SpeedSlope << endl;
- } else if (token == "SPEEDINTERCEPT") {
- *Eng_cfg >> SpeedIntercept;
- cout << " SpeedIntercept = " << SpeedIntercept << endl;
- } else if (token == "ALTITUDESLOPE") {
- *Eng_cfg >> AltitudeSlope;
- cout << " AltitudeSlope = " << AltitudeSlope << endl;
- } else {
- cout << "Unhandled token in Engine config file: " << token << endl;
- }
+ if (token == "BRAKEHORSEPOWER") *Eng_cfg >> BrakeHorsePower;
+ else if (token == "MAXTHROTTLE") *Eng_cfg >> MaxThrottle;
+ else if (token == "MINTHROTTLE") *Eng_cfg >> MinThrottle;
+ else if (token == "SLFUELFLOWMAX") *Eng_cfg >> SLFuelFlowMax;
+ else if (token == "SPEEDSLOPE") *Eng_cfg >> SpeedSlope;
+ else if (token == "SPEEDINTERCEPT") *Eng_cfg >> SpeedIntercept;
+ else if (token == "ALTITUDESLOPE") *Eng_cfg >> AltitudeSlope;
+ else cerr << "Unhandled token in Engine config file: " << token << endl;
+ }
+
+ if (debug_lvl > 0) {
+ cout << "\n Engine Name: " << Name << endl;
+ cout << " BrakeHorsePower = " << BrakeHorsePower << endl;
+ cout << " MaxThrottle = " << MaxThrottle << endl;
+ cout << " MinThrottle = " << MinThrottle << endl;
+ cout << " SLFuelFlowMax = " << SLFuelFlowMax << endl;
+ cout << " SpeedSlope = " << SpeedSlope << endl;
+ cout << " SpeedIntercept = " << SpeedIntercept << endl;
+ cout << " AltitudeSlope = " << AltitudeSlope << endl;
}
Type = etPiston;
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <cmath>
# include <iomanip>
# else
#include "FGFDMExec.h"
#include "FGFCS.h"
#include "FGAircraft.h"
+#include "FGMassBalance.h"
#include "FGTranslation.h"
#include "FGRotation.h"
#include "FGAuxiliary.h"
if(psigt < 0.0)
psigt += 2*M_PI;
- invMass = 1.0 / Aircraft->GetMass();
+ invMass = 1.0 / MassBalance->GetMass();
Radius = h + SeaLevelRadius;
invRadius = 1.0 / Radius;
inline double GetLongitudeDot(void) { return LongitudeDot; }
inline double GetRunwayRadius(void) { return RunwayRadius; }
inline double GetDistanceAGL(void) { return DistanceAGL; }
+ inline double GetRadius(void) { return Radius; }
inline FGColumnVector GetRunwayNormal(void) { return vRunwayNormal; }
inline double GetGamma(void) { return gamma; }
string token;
int rows, cols;
+ MaxPitch = MinPitch = 0.0;
+
Name = Prop_cfg->GetValue("NAME");
- cout << "\n Propeller Name: " << Name << endl;
Prop_cfg->GetNextConfigLine();
while (Prop_cfg->GetValue() != "/FG_PROPELLER") {
*Prop_cfg >> token;
if (token == "IXX") {
*Prop_cfg >> Ixx;
- cout << " IXX = " << Ixx << endl;
} else if (token == "DIAMETER") {
*Prop_cfg >> Diameter;
Diameter /= 12.0;
- cout << " Diameter = " << Diameter << " ft." << endl;
} else if (token == "NUMBLADES") {
*Prop_cfg >> numBlades;
- cout << " Number of Blades = " << numBlades << endl;
+ } else if (token == "MINPITCH") {
+ *Prop_cfg >> MinPitch;
+ } else if (token == "MAXPITCH") {
+ *Prop_cfg >> MaxPitch;
} else if (token == "EFFICIENCY") {
- *Prop_cfg >> rows >> cols;
- if (cols == 1) Efficiency = new FGTable(rows);
- else Efficiency = new FGTable(rows, cols);
- *Efficiency << *Prop_cfg;
- cout << " Efficiency: " << endl;
- Efficiency->Print();
+ *Prop_cfg >> rows >> cols;
+ if (cols == 1) Efficiency = new FGTable(rows);
+ else Efficiency = new FGTable(rows, cols);
+ *Efficiency << *Prop_cfg;
} else if (token == "C_THRUST") {
- *Prop_cfg >> rows >> cols;
- if (cols == 1) cThrust = new FGTable(rows);
- else cThrust = new FGTable(rows, cols);
- *cThrust << *Prop_cfg;
- cout << " Thrust Coefficient: " << endl;
- cThrust->Print();
+ *Prop_cfg >> rows >> cols;
+ if (cols == 1) cThrust = new FGTable(rows);
+ else cThrust = new FGTable(rows, cols);
+ *cThrust << *Prop_cfg;
} else if (token == "C_POWER") {
- *Prop_cfg >> rows >> cols;
- if (cols == 1) cPower = new FGTable(rows);
- else cPower = new FGTable(rows, cols);
- *cPower << *Prop_cfg;
- cout << " Power Coefficient: " << endl;
- cPower->Print();
+ *Prop_cfg >> rows >> cols;
+ if (cols == 1) cPower = new FGTable(rows);
+ else cPower = new FGTable(rows, cols);
+ *cPower << *Prop_cfg;
} else if (token == "EOF") {
- cout << " End of file reached" << endl;
- break;
+ cerr << " End of file reached" << endl;
+ break;
} else {
- cout << "Unhandled token in Propeller config file: " << token << endl;
+ cerr << "Unhandled token in Propeller config file: " << token << endl;
}
}
+ if (debug_lvl > 0) {
+ cout << "\n Propeller Name: " << Name << endl;
+ cout << " IXX = " << Ixx << endl;
+ cout << " Diameter = " << Diameter << " ft." << endl;
+ cout << " Number of Blades = " << numBlades << endl;
+ cout << " Minimum Pitch = " << MinPitch << endl;
+ cout << " Maximum Pitch = " << MaxPitch << endl;
+ cout << " Efficiency: " << endl;
+ Efficiency->Print();
+ cout << " Thrust Coefficient: " << endl;
+ cThrust->Print();
+ cout << " Power Coefficient: " << endl;
+ cPower->Print();
+ }
+
Type = ttPropeller;
RPM = 0;
#define ID_PROPELLER "$Id$"
+#ifndef M_PI
+# include <simgear/constants.h>
+# define M_PI SG_PI
+#endif
+
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
engineFileName = AC_cfg->GetValue("FILE");
- cout << "\n Reading engine from file: " << fullpath
- + engineFileName + ".xml"<< endl;
+ if (debug_lvl > 0) cout << "\n Reading engine from file: " << fullpath
+ + engineFileName + ".xml"<< endl;
FGConfigFile Eng_cfg(fullpath + engineFileName + ".xml");
if (Eng_cfg.IsOpen()) {
AC_cfg->GetNextConfigLine();
while ((token = AC_cfg->GetValue()) != "/AC_ENGINE") {
*AC_cfg >> token;
- if (token == "XLOC") { *AC_cfg >> xLoc; cout << " X = " << xLoc << endl;}
- else if (token == "YLOC") { *AC_cfg >> yLoc; cout << " Y = " << yLoc << endl;}
- else if (token == "ZLOC") { *AC_cfg >> zLoc; cout << " Z = " << zLoc << endl;}
- else if (token == "PITCH") { *AC_cfg >> Pitch; cout << " Pitch = " << Pitch << endl;}
- else if (token == "YAW") { *AC_cfg >> Yaw; cout << " Yaw = " << Yaw << endl;}
- else if (token == "FEED") {
+ if (token == "XLOC") { *AC_cfg >> xLoc; }
+ else if (token == "YLOC") { *AC_cfg >> yLoc; }
+ else if (token == "ZLOC") { *AC_cfg >> zLoc; }
+ else if (token == "PITCH") { *AC_cfg >> Pitch;}
+ else if (token == "YAW") { *AC_cfg >> Yaw;}
+ else if (token == "FEED") {
*AC_cfg >> Feed;
Engines[numEngines]->AddFeedTank(Feed);
- cout << " Feed tank: " << Feed << endl;
+ if (debug_lvl > 0) cout << " Feed tank: " << Feed << endl;
} else cerr << "Unknown identifier: " << token << " in engine file: "
<< engineFileName << endl;
}
+ if (debug_lvl > 0) {
+ cout << " X = " << xLoc << endl;
+ cout << " Y = " << yLoc << endl;
+ cout << " Z = " << zLoc << endl;
+ cout << " Pitch = " << Pitch << endl;
+ cout << " Yaw = " << Yaw << endl;
+ }
+
Engines[numEngines]->SetPlacement(xLoc, yLoc, zLoc, Pitch, Yaw);
numEngines++;
} else if (token == "AC_TANK") { // ============== READING TANKS
- cout << "\n Reading tank definition" << endl;
+ if (debug_lvl > 0) cout << "\n Reading tank definition" << endl;
Tanks.push_back(new FGTank(AC_cfg));
switch(Tanks[numTanks]->GetType()) {
case FGTank::ttFUEL:
thrusterFileName = AC_cfg->GetValue("FILE");
- cout << "\n Reading thruster from file: " <<
- fullpath + thrusterFileName + ".xml" << endl;
+ if (debug_lvl > 0) cout << "\n Reading thruster from file: " <<
+ fullpath + thrusterFileName + ".xml" << endl;
FGConfigFile Thruster_cfg(fullpath + thrusterFileName + ".xml");
if (Thruster_cfg.IsOpen()) {
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+FGColumnVector& FGPropulsion::GetTanksCG(void)
+{
+ iTank = Tanks.begin();
+ vXYZtank.InitMatrix();
+ while (iTank < Tanks.end()) {
+ vXYZtank(eX) += (*iTank)->GetX()*(*iTank)->GetContents();
+ vXYZtank(eY) += (*iTank)->GetY()*(*iTank)->GetContents();
+ vXYZtank(eZ) += (*iTank)->GetZ()*(*iTank)->GetContents();
+ iTank++;
+ }
+ return vXYZtank;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+float FGPropulsion::GetTanksWeight(void)
+{
+ float Tw = 0.0;
+
+ iTank = Tanks.begin();
+ while (iTank < Tanks.end()) {
+ Tw += (*iTank)->GetContents();
+ iTank++;
+ }
+ return Tw;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+float FGPropulsion::GetTanksIxx(const FGColumnVector& vXYZcg)
+{
+ float I = 0.0;
+ iTank = Tanks.begin();
+ while (iTank < Tanks.end()) {
+ I += ((*iTank)->GetX() - vXYZcg(eX))*((*iTank)->GetX() - vXYZcg(eX)) * (*iTank)->GetContents()/(144.0*GRAVITY);
+ iTank++;
+ }
+ return I;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+float FGPropulsion::GetTanksIyy(const FGColumnVector& vXYZcg)
+{
+ float I = 0.0;
+ iTank = Tanks.begin();
+ while (iTank < Tanks.end()) {
+ I += ((*iTank)->GetY() - vXYZcg(eY))*((*iTank)->GetY() - vXYZcg(eY)) * (*iTank)->GetContents()/(144.0*GRAVITY);
+ iTank++;
+ }
+ return I;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+float FGPropulsion::GetTanksIzz(const FGColumnVector& vXYZcg)
+{
+ float I = 0.0;
+ iTank = Tanks.begin();
+ while (iTank < Tanks.end()) {
+ I += ((*iTank)->GetZ() - vXYZcg(eZ))*((*iTank)->GetZ() - vXYZcg(eZ)) * (*iTank)->GetContents()/(144.0*GRAVITY);
+ iTank++;
+ }
+ return I;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+float FGPropulsion::GetTanksIxz(const FGColumnVector& vXYZcg)
+{
+ float I = 0.0;
+ iTank = Tanks.begin();
+ while (iTank < Tanks.end()) {
+ I += ((*iTank)->GetX() - vXYZcg(eX))*((*iTank)->GetZ() - vXYZcg(eZ)) * (*iTank)->GetContents()/(144.0*GRAVITY);
+ iTank++;
+ }
+ return I;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+float FGPropulsion::GetTanksIxy(const FGColumnVector& vXYZcg)
+{
+ float I = 0.0;
+ iTank = Tanks.begin();
+ while (iTank != Tanks.end()) {
+ I += ((*iTank)->GetX() - vXYZcg(eX))*((*iTank)->GetY() - vXYZcg(eY)) * (*iTank)->GetContents()/(144.0*GRAVITY);
+ iTank++;
+ }
+ return I;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
void FGPropulsion::Debug(void)
{
//TODO: Add your source code here
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <vector>
+# include <iterator>
# else
# include <vector.h>
+# include <iterator.h>
# endif
#else
# include <vector>
+# include <iterator>
#endif
#include "FGModel.h"
inline FGColumnVector& GetForces(void) {return *Forces; }
inline FGColumnVector& GetMoments(void) {return *Moments;}
+
+ FGColumnVector& GetTanksCG(void);
+ float GetTanksWeight(void);
+
+ float GetTanksIxx(const FGColumnVector& vXYZcg);
+ float GetTanksIyy(const FGColumnVector& vXYZcg);
+ float GetTanksIzz(const FGColumnVector& vXYZcg);
+ float GetTanksIxz(const FGColumnVector& vXYZcg);
+ float GetTanksIxy(const FGColumnVector& vXYZcg);
private:
vector <FGEngine*> Engines;
vector <FGTank*> Tanks;
+ vector <FGTank*>::iterator iTank;
vector <FGThruster*> Thrusters;
unsigned int numSelectedFuelTanks;
unsigned int numSelectedOxiTanks;
float dt;
FGColumnVector *Forces;
FGColumnVector *Moments;
+ FGColumnVector vXYZtank;
void Debug(void);
};
string token;
Name = Eng_cfg->GetValue("NAME");
- cout << " Engine Name: " << Name << endl;
Eng_cfg->GetNextConfigLine();
+
while (Eng_cfg->GetValue() != "/FG_ROCKET") {
*Eng_cfg >> token;
- if (token == "SHR") {
- *Eng_cfg >> SHR;
- cout << " Specific Heat Ratio = " << SHR << endl;
- } else if (token == "MAX_PC") {
- *Eng_cfg >> maxPC;
- cout << " Maximum Chamber Pressure = " << maxPC << endl;
- } else if (token == "PROP_EFF") {
- *Eng_cfg >> propEff;
- cout << " Propulsive Efficiency = " << propEff << endl;
- } else if (token == "MAXTHROTTLE") {
- *Eng_cfg >> MaxThrottle;
- cout << " MaxThrottle = " << MaxThrottle << endl;
- } else if (token == "MINTHROTTLE") {
- *Eng_cfg >> MinThrottle;
- cout << " MinThrottle = " << MinThrottle << endl;
- } else if (token == "SLFUELFLOWMAX") {
- *Eng_cfg >> SLFuelFlowMax;
- cout << " FuelFlowMax = " << SLFuelFlowMax << endl;
- } else if (token == "SLOXIFLOWMAX") {
- *Eng_cfg >> SLOxiFlowMax;
- cout << " OxiFlowMax = " << SLOxiFlowMax << endl;
- } else if (token == "VARIANCE") {
- *Eng_cfg >> Variance;
- cout << " Variance = " << Variance << endl;
- } else {
- cout << "Unhandled token in Engine config file: " << token << endl;
- }
+ if (token == "SHR") *Eng_cfg >> SHR;
+ else if (token == "MAX_PC") *Eng_cfg >> maxPC;
+ else if (token == "PROP_EFF") *Eng_cfg >> propEff;
+ else if (token == "MAXTHROTTLE") *Eng_cfg >> MaxThrottle;
+ else if (token == "MINTHROTTLE") *Eng_cfg >> MinThrottle;
+ else if (token == "SLFUELFLOWMAX") *Eng_cfg >> SLFuelFlowMax;
+ else if (token == "SLOXIFLOWMAX") *Eng_cfg >> SLOxiFlowMax;
+ else if (token == "VARIANCE") *Eng_cfg >> Variance;
+ else cerr << "Unhandled token in Engine config file: " << token << endl;
+ }
+
+ if (debug_lvl > 0) {
+ cout << " Engine Name: " << Name << endl;
+ cout << " Specific Heat Ratio = " << SHR << endl;
+ cout << " Maximum Chamber Pressure = " << maxPC << endl;
+ cout << " Propulsive Efficiency = " << propEff << endl;
+ cout << " MaxThrottle = " << MaxThrottle << endl;
+ cout << " MinThrottle = " << MinThrottle << endl;
+ cout << " FuelFlowMax = " << SLFuelFlowMax << endl;
+ cout << " OxiFlowMax = " << SLOxiFlowMax << endl;
+ cout << " Variance = " << Variance << endl;
}
EngineNumber = 0;
Type = etRocket;
+ PC = 0.0;
kFactor = (2.0*SHR*SHR/(SHR-1.0))*pow(2.0/(SHR+1), (SHR+1)/(SHR-1));
if (debug_lvl & 2) cout << "Instantiated: FGRocket" << endl;
float FGRocket::Calculate(float pe)
{
- float lastThrust;
float Cf;
ConsumeFuel();
Throttle = FCS->GetThrottlePos(EngineNumber);
- lastThrust = Thrust; // last actual thrust
if (Throttle < MinThrottle || Starved) {
PctPower = Thrust = 0.0; // desired thrust
Flameout = true;
+ PC = 0.0;
} else {
PctPower = Throttle / MaxThrottle;
PC = maxPC*PctPower * (1.0 + Variance * ((float)rand()/(float)RAND_MAX - 0.5));
Flameout = false;
}
- if (State->Getdt() > 0.0) { // actual thrust - if not in freeze
- Thrust -= 0.8*(Thrust - lastThrust);
- }
-
- return Cf*maxPC*PctPower;
+ return Cf*maxPC*PctPower*propEff;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include "FGFDMExec.h"
#include "FGFCS.h"
#include "FGAircraft.h"
+#include "FGMassBalance.h"
#include "FGTranslation.h"
#include "FGPosition.h"
#include "FGAuxiliary.h"
bool FGRotation::Run(void)
{
- float L2, N1;
- float tTheta;
-
- if (!FGModel::Run()) {
- GetState();
-
- L2 = vMoments(eL) + Ixz*vPQR(eP)*vPQR(eQ) - (Izz-Iyy)*vPQR(eR)*vPQR(eQ);
- N1 = vMoments(eN) - (Iyy-Ixx)*vPQR(eP)*vPQR(eQ) - Ixz*vPQR(eR)*vPQR(eQ);
-
- vPQRdot(eP) = (L2*Izz - N1*Ixz) / (Ixx*Izz - Ixz*Ixz);
- vPQRdot(eQ) = (vMoments(eM) - (Ixx-Izz)*vPQR(eP)*vPQR(eR) - Ixz*(vPQR(eP)*vPQR(eP) - vPQR(eR)*vPQR(eR)))/Iyy;
- vPQRdot(eR) = (N1*Ixx + L2*Ixz) / (Ixx*Izz - Ixz*Ixz);
-
- vPQR += dt*rate*(vlastPQRdot + vPQRdot)/2.0;
-
- State->IntegrateQuat(vPQR, rate);
- State->CalcMatrices();
- vEuler = State->CalcEuler();
-
- cTht = cos(vEuler(eTht)); sTht = sin(vEuler(eTht));
- cPhi = cos(vEuler(ePhi)); sPhi = sin(vEuler(ePhi));
- cPsi = cos(vEuler(ePsi)); sPsi = sin(vEuler(ePsi));
-
- vEulerRates(eTht) = vPQR(2)*cPhi - vPQR(3)*sPhi;
- if (cTht != 0.0) {
- tTheta = sTht/cTht; // what's cheaper: / or tan() ?
- vEulerRates(ePhi) = vPQR(1) + (vPQR(2)*sPhi + vPQR(3)*cPhi)*tTheta;
- vEulerRates(ePsi) = (vPQR(2)*sPhi + vPQR(3)*cPhi)/cTht;
- }
-
- vlastPQRdot = vPQRdot;
-
- } else {
+ float L2, N1;
+ float tTheta;
+
+ if (!FGModel::Run()) {
+ GetState();
+
+ L2 = vMoments(eL) + Ixz*vPQR(eP)*vPQR(eQ) - (Izz-Iyy)*vPQR(eR)*vPQR(eQ);
+ N1 = vMoments(eN) - (Iyy-Ixx)*vPQR(eP)*vPQR(eQ) - Ixz*vPQR(eR)*vPQR(eQ);
+
+ vPQRdot(eP) = (L2*Izz - N1*Ixz) / (Ixx*Izz - Ixz*Ixz);
+ vPQRdot(eQ) = (vMoments(eM) - (Ixx-Izz)*vPQR(eP)*vPQR(eR) - Ixz*(vPQR(eP)*vPQR(eP) - vPQR(eR)*vPQR(eR)))/Iyy;
+ vPQRdot(eR) = (N1*Ixx + L2*Ixz) / (Ixx*Izz - Ixz*Ixz);
+
+ vPQR += dt*rate*(vlastPQRdot + vPQRdot)/2.0;
+
+ State->IntegrateQuat(vPQR, rate);
+ State->CalcMatrices();
+ vEuler = State->CalcEuler();
+
+ cTht = cos(vEuler(eTht)); sTht = sin(vEuler(eTht));
+ cPhi = cos(vEuler(ePhi)); sPhi = sin(vEuler(ePhi));
+ cPsi = cos(vEuler(ePsi)); sPsi = sin(vEuler(ePsi));
+
+ vEulerRates(eTht) = vPQR(2)*cPhi - vPQR(3)*sPhi;
+ if (cTht != 0.0) {
+ tTheta = sTht/cTht; // what's cheaper: / or tan() ?
+ vEulerRates(ePhi) = vPQR(1) + (vPQR(2)*sPhi + vPQR(3)*cPhi)*tTheta;
+ vEulerRates(ePsi) = (vPQR(2)*sPhi + vPQR(3)*cPhi)/cTht;
}
+
+ vlastPQRdot = vPQRdot;
+
+ if (debug_lvl > 1) Debug();
+
return false;
+ } else {
+ return true;
+ }
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGRotation::GetState(void)
{
- dt = State->Getdt();
- vMoments = Aircraft->GetMoments();
+ dt = State->Getdt();
+ vMoments = Aircraft->GetMoments();
- Ixx = Aircraft->GetIxx();
- Iyy = Aircraft->GetIyy();
- Izz = Aircraft->GetIzz();
- Ixz = Aircraft->GetIxz();
+ Ixx = MassBalance->GetIxx();
+ Iyy = MassBalance->GetIyy();
+ Izz = MassBalance->GetIzz();
+ Ixz = MassBalance->GetIxz();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGRotation::Debug(void)
{
- //TODO: Add your source code here
+ if (debug_lvl & 16) { // Sanity check variables
+ if (fabs(vPQR(eP)) > 100)
+ cout << "FGRotation::P (Roll Rate) out of bounds: " << vPQR(eP) << endl;
+ if (fabs(vPQR(eQ)) > 100)
+ cout << "FGRotation::Q (Pitch Rate) out of bounds: " << vPQR(eQ) << endl;
+ if (fabs(vPQR(eR)) > 100)
+ cout << "FGRotation::R (Yaw Rate) out of bounds: " << vPQR(eR) << endl;
+ }
}
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
-# include <cmath>
-# else
-# include <math.h>
-# endif
+# include <math.h>
#else
# include <cmath>
#endif
#ifndef M_PI
# include <simgear/constants.h>
-# define M_PI FG_PI
+# define M_PI SG_PI
#endif
#include "FGModel.h"
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
-# include <cmath>
-# else
-# include <math.h>
-# endif
+# include <math.h>
#else
# include <cmath>
#endif
#ifndef M_PI
# include <simgear/constants.h>
-# define M_PI FG_PI
+# define M_PI SG_PI
#endif
#include "FGState.h"
dt = 1.0/120.0;
ActiveEngine = -1;
- Aircraft = FDMExec->GetAircraft();
- Translation = FDMExec->GetTranslation();
- Rotation = FDMExec->GetRotation();
- Position = FDMExec->GetPosition();
- FCS = FDMExec->GetFCS();
- Output = FDMExec->GetOutput();
- Atmosphere = FDMExec->GetAtmosphere();
+ Aircraft = FDMExec->GetAircraft();
+ Translation = FDMExec->GetTranslation();
+ Rotation = FDMExec->GetRotation();
+ Position = FDMExec->GetPosition();
+ FCS = FDMExec->GetFCS();
+ Output = FDMExec->GetOutput();
+ Atmosphere = FDMExec->GetAtmosphere();
+ Aerodynamics = FDMExec->GetAerodynamics();
RegisterVariable(FG_TIME, " time " );
RegisterVariable(FG_QBAR, " qbar " );
return Rotation->GetPQR(eR);
case FG_CL_SQRD:
if (Translation->Getqbar() > 0.00)
- scratch = Aircraft->GetvLastFs(eLift)/(Aircraft->GetWingArea()*Translation->Getqbar());
+ scratch = Aerodynamics->GetvLastFs(eLift)/(Aircraft->GetWingArea()*Translation->Getqbar());
else
scratch = 0.0;
return scratch*scratch;
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <fstream>
# else
# include <fstream.h>
FGOutput* Output;
FGAtmosphere* Atmosphere;
FGFCS* FCS;
+ FGAerodynamics* Aerodynamics;
typedef map<string, eParam> CoeffMap;
CoeffMap coeffdef;
#include "FGTranslation.h"
#include "FGRotation.h"
#include "FGPosition.h"
-//#include "FGAuxiliary.h"
+#include "FGAerodynamics.h"
#include "FGOutput.h"
#include "FGAircraft.h"
PctFull = 0;
}
- cout << " " << type << " tank holds " << Capacity << " lbs. " << type << endl;
- cout << " currently at " << PctFull << "% of maximum capacity" << endl;
- cout << " Tank location (X, Y, Z): " << X << ", " << Y << ", " << Z << endl;
- cout << " Effective radius: " << Radius << " inches" << endl;
+ if (debug_lvl > 0) {
+ cout << " " << type << " tank holds " << Capacity << " lbs. " << type << endl;
+ cout << " currently at " << PctFull << "% of maximum capacity" << endl;
+ cout << " Tank location (X, Y, Z): " << X << ", " << Y << ", " << Z << endl;
+ cout << " Effective radius: " << Radius << " inches" << endl;
+ }
if (debug_lvl & 2) cout << "Instantiated: FGTank" << endl;
}
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#include "FGConfigFile.h"
+
#ifdef FGFS
# include <simgear/compiler.h>
+# include STL_STRING
+ SG_USING_STD(string);
+ SG_USING_STD(cerr);
+ SG_USING_STD(endl);
+ SG_USING_STD(cout);
+#else
+# include <string>
+ using std::string;
+ using std::cerr;
+ using std::endl;
+ using std::cout;
#endif
-#include <string>
-#include "FGConfigFile.h"
-
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGState.h"
#include "FGFDMExec.h"
#include "FGFCS.h"
+#include "FGMassBalance.h"
#include "FGAircraft.h"
#include "FGPosition.h"
#include "FGAuxiliary.h"
vlastUVWdot = vUVWdot;
- } else {}
+ if (debug_lvl > 1) Debug();
- return false;
+ return false;
+ } else {
+ return true;
+ }
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
vPQR = Rotation->GetPQR();
vForces = Aircraft->GetForces();
- Mass = Aircraft->GetMass();
+ Mass = MassBalance->GetMass();
rho = Atmosphere->GetDensity();
vEuler = Rotation->GetEuler();
void FGTranslation::Debug(void)
{
- //TODO: Add your source code here
+ if (debug_lvl & 16) { // Sanity check variables
+ if (fabs(vUVW(eU)) > 1e6)
+ cout << "FGTranslation::U velocity out of bounds: " << vUVW(eU) << endl;
+ if (fabs(vUVW(eV)) > 1e6)
+ cout << "FGTranslation::V velocity out of bounds: " << vUVW(eV) << endl;
+ if (fabs(vUVW(eW)) > 1e6)
+ cout << "FGTranslation::W velocity out of bounds: " << vUVW(eW) << endl;
+ if (fabs(vUVWdot(eU)) > 1e4)
+ cout << "FGTranslation::U acceleration out of bounds: " << vUVWdot(eU) << endl;
+ if (fabs(vUVWdot(eV)) > 1e4)
+ cout << "FGTranslation::V acceleration out of bounds: " << vUVWdot(eV) << endl;
+ if (fabs(vUVWdot(eW)) > 1e4)
+ cout << "FGTranslation::W acceleration out of bounds: " << vUVWdot(eW) << endl;
+ if (Mach > 100 || Mach < 0.00)
+ cout << "FGTranslation::Mach is out of bounds: " << Mach << endl;
+ if (qbar > 1e6 || qbar < 0.00)
+ cout << "FGTranslation::qbar is out of bounds: " << qbar << endl;
+ }
}
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <cmath>
# else
# include <math.h>
#include "FGInitialCondition.h"
#include "FGTrim.h"
#include "FGAircraft.h"
-
+#include "FGMassBalance.h"
+#include "FGAerodynamics.h"
#if _MSC_VER
#pragma warning (disable : 4786 4788)
#endif
cout << endl << " JSBSim State" << endl;
sprintf(out," Weight: %7.0f lbs. CG: %5.1f, %5.1f, %5.1f inches\n",
- fdmex->GetAircraft()->GetWeight(),
- fdmex->GetAircraft()->GetXYZcg(1),
- fdmex->GetAircraft()->GetXYZcg(2),
- fdmex->GetAircraft()->GetXYZcg(3));
+ fdmex->GetMassBalance()->GetWeight(),
+ fdmex->GetMassBalance()->GetXYZcg(1),
+ fdmex->GetMassBalance()->GetXYZcg(2),
+ fdmex->GetMassBalance()->GetXYZcg(3));
cout << out;
if( fdmex->GetFCS()->GetDfPos() <= 0.01)
sprintf(flap,"Up");
fdmex->GetPosition()->Gethdot()*60 );
cout << out;
sprintf(out, " Normal Load Factor: %4.2f g's Pitch Rate: %5.2f deg/s\n",
- fdmex->GetAircraft()->GetNlf(),
+ fdmex->GetAerodynamics()->GetNlf(),
fdmex->GetState()->GetParameter(FG_PITCHRATE)*RADTODEG );
cout << out;
sprintf(out, " Heading: %3.0f deg true Sideslip: %5.2f deg\n",
FGFDMExec* fdmex;
FGInitialCondition* fgic;
- bool solve(void);
+ bool solve(void);
/** @return false if there is no change in the current axis accel
between accel(control_min) and accel(control_max). If there is a
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <cmath>
# else
# include <math.h>
#ifdef FGFS
# include <simgear/compiler.h>
# include STL_STRING
+# include STL_IOSTREAM
+# include STL_FSTREAM
SG_USING_STD(cout);
SG_USING_STD(endl);
-# ifdef FG_HAVE_STD_INCLUDES
-# include <iostream>
-# include <fstream>
-# else
-# include <iostream.h>
-# include <fstream.h>
-# endif
#else
# include <iostream>
# include <fstream>
#ifdef FGFS
#include <simgear/compiler.h>
#include STL_IOSTREAM
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <ctime>
# else
# include <time.h>
#include <ctime>
#endif
+#if __BORLANDC__ > 0x540
+#include <condefs.h>
+USEUNIT("FGUtility.cpp");
+USEUNIT("FGAircraft.cpp");
+USEUNIT("FGAtmosphere.cpp");
+USEUNIT("FGAuxiliary.cpp");
+USEUNIT("FGCoefficient.cpp");
+USEUNIT("FGConfigFile.cpp");
+USEUNIT("FGEngine.cpp");
+USEUNIT("FGFCS.cpp");
+USEUNIT("FGFDMExec.cpp");
+USEUNIT("FGfdmSocket.cpp");
+USEUNIT("FGForce.cpp");
+USEUNIT("FGGroundReactions.cpp");
+USEUNIT("FGInertial.cpp");
+USEUNIT("FGInitialCondition.cpp");
+USEUNIT("FGLGear.cpp");
+USEUNIT("FGMassBalance.cpp");
+USEUNIT("FGMatrix.cpp");
+USEUNIT("FGModel.cpp");
+USEUNIT("FGNozzle.cpp");
+USEUNIT("FGOutput.cpp");
+USEUNIT("FGPiston.cpp");
+USEUNIT("FGPosition.cpp");
+USEUNIT("FGPropeller.cpp");
+USEUNIT("FGPropulsion.cpp");
+USEUNIT("FGRocket.cpp");
+USEUNIT("FGRotation.cpp");
+USEUNIT("FGRotor.cpp");
+USEUNIT("FGState.cpp");
+USEUNIT("FGTable.cpp");
+USEUNIT("FGTank.cpp");
+USEUNIT("FGThruster.cpp");
+USEUNIT("FGTranslation.cpp");
+USEUNIT("FGTrim.cpp");
+USEUNIT("FGTrimAxis.cpp");
+USEUNIT("FGTurboJet.cpp");
+USEUNIT("FGTurboProp.cpp");
+USEUNIT("FGTurboShaft.cpp");
+USEUNIT("FGAerodynamics.cpp");
+USEUNIT("filtersjb\FGSwitch.cpp");
+USEUNIT("filtersjb\FGFCSComponent.cpp");
+USEUNIT("filtersjb\FGFilter.cpp");
+USEUNIT("filtersjb\FGFlaps.cpp");
+USEUNIT("filtersjb\FGGain.cpp");
+USEUNIT("filtersjb\FGGradient.cpp");
+USEUNIT("filtersjb\FGSummer.cpp");
+USEUNIT("filtersjb\FGDeadBand.cpp");
+//---------------------------------------------------------------------------
+#endif
+
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
noinst_LIBRARIES = libJSBSim.a
-# FGAerodynamics.cpp FGAerodynamics.h \
# FGGroundReactions.cpp FGGroundReactions.h \
-# FGInertial.cpp FGInertial.h \
-# FGMassBalance.cpp FGMassBalance.h \
# FGPiston.cpp FGPiston.h \
# FGPropulsion.cpp FGPropulsion.h \
# FGRocket.cpp FGRocket.h \
# FGTurboShaft.cpp FGTurboShaft.h \
libJSBSim_a_SOURCES = \
+ FGAerodynamics.cpp FGAerodynamics.h \
FGAircraft.cpp FGAircraft.h \
FGAtmosphere.cpp FGAtmosphere.h \
FGAuxiliary.cpp FGAuxiliary.h \
FGFCS.cpp FGFCS.h \
FGFDMExec.cpp FGFDMExec.h \
FGForce.cpp FGForce.h \
+ FGInertial.cpp FGInertial.h \
FGInitialCondition.cpp FGInitialCondition.h \
FGLGear.cpp FGLGear.h \
+ FGMassBalance.cpp FGMassBalance.h \
FGMatrix.cpp FGMatrix.h \
FGModel.cpp FGModel.h \
FGNozzle.cpp FGNozzle.h \
while ((token = AC_cfg->GetValue()) != string("/COMPONENT")) {
*AC_cfg >> token;
- if (token == "ID") {
- *AC_cfg >> ID;
- cout << " ID: " << ID << endl;
- } else if (token == "INPUT") {
+ if (token == "ID") *AC_cfg >> ID;
+ else if (token == "C1") *AC_cfg >> C1;
+ else if (token == "C2") *AC_cfg >> C2;
+ else if (token == "C3") *AC_cfg >> C3;
+ else if (token == "C4") *AC_cfg >> C4;
+ else if (token == "C5") *AC_cfg >> C5;
+ else if (token == "C6") *AC_cfg >> C6;
+ else if (token == "INPUT")
+ {
token = AC_cfg->GetValue("INPUT");
if (token.find("FG_") != token.npos) {
*AC_cfg >> token;
*AC_cfg >> InputIdx;
InputType = itFCS;
}
- cout << " INPUT: " << token << endl;
- } else if (token == "C1") {
- *AC_cfg >> C1;
- cout << " C1: " << C1 << endl;
- } else if (token == "C2") {
- *AC_cfg >> C2;
- cout << " C2: " << C2 << endl;
- } else if (token == "C3") {
- *AC_cfg >> C3;
- cout << " C3: " << C3 << endl;
- } else if (token == "C4") {
- *AC_cfg >> C4;
- cout << " C4: " << C4 << endl;
- } else if (token == "C5") {
- *AC_cfg >> C5;
- cout << " C5: " << C5 << endl;
- } else if (token == "C6") {
- *AC_cfg >> C6;
- cout << " C6: " << C6 << endl;
- } else if (token == "OUTPUT") {
+ }
+ else if (token == "OUTPUT")
+ {
IsOutput = true;
*AC_cfg >> sOutputIdx;
OutputIdx = fcs->GetState()->GetParameterIndex(sOutputIdx);
- cout << " OUTPUT: " << sOutputIdx << endl;
}
+ else cerr << "Unknown filter type: " << token << endl;
}
Initialize = true;
break;
}
+ if (debug_lvl > 0) {
+ cout << " ID: " << ID << endl;
+ cout << " INPUT: " << InputIdx << endl;
+ cout << " C1: " << C1 << endl;
+ cout << " C2: " << C2 << endl;
+ cout << " C3: " << C3 << endl;
+ cout << " C4: " << C4 << endl;
+ cout << " C5: " << C5 << endl;
+ cout << " C6: " << C6 << endl;
+ if (IsOutput) cout << " OUTPUT: " << sOutputIdx << endl;
+ }
+
if (debug_lvl & 2) cout << "Instantiated: FGFilter" << endl;
}
*AC_cfg >> token;
if (token == "ID") {
*AC_cfg >> ID;
- cout << " ID: " << ID << endl;
} else if (token == "INPUT") {
token = AC_cfg->GetValue("INPUT");
- cout << " INPUT: " << token << endl;
if (token.find("FG_") != token.npos) {
*AC_cfg >> token;
InputIdx = fcs->GetState()->GetParameterIndex(token);
}
} else if ( token == "DETENTS" ) {
*AC_cfg >> NumDetents;
- cout << " DETENTS: " << NumDetents << endl;
for(int i=0;i<NumDetents;i++) {
*AC_cfg >> tmpDetent;
*AC_cfg >> tmpTime;
Detents.push_back(tmpDetent);
TransitionTimes.push_back(tmpTime);
- cout << " " << Detents[i] << " " << TransitionTimes[i] << endl;
}
} else if (token == "OUTPUT") {
IsOutput = true;
*AC_cfg >> sOutputIdx;
- cout << " OUTPUT: " <<sOutputIdx << endl;
OutputIdx = fcs->GetState()->GetParameterIndex(sOutputIdx);
}
}
+ if (debug_lvl > 1) {
+ cout << " ID: " << ID << endl;
+ cout << " INPUT: " << InputIdx << endl;
+ cout << " DETENTS: " << NumDetents << endl;
+ for(int i=0;i<NumDetents;i++) {
+ cout << " " << Detents[i] << " " << TransitionTimes[i] << endl;
+ }
+ if (IsOutput) cout << " OUTPUT: " <<sOutputIdx << endl;
+ }
+
if (debug_lvl & 2) cout << "Instantiated: FGFlaps" << endl;
}
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- Header: FGFlap.h
+ Header: FGFlaps.h
Author: Tony Peden, for flight control system authored by Jon S. Berndt
Date started: 5/11/00
SENTRY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#ifndef FGFlap_H
-#define FGFlap_H
+#ifndef FGFLAPS_H
+#define FGFLAPS_H
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
INCLUDES
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <vector>
# else
# include <vector.h>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
class FGFlaps : public FGFCSComponent {
+public:
+ FGFlaps(FGFCS* fcs, FGConfigFile* AC_cfg);
+ ~FGFlaps();
+ bool Run (void );
+
+private:
FGConfigFile* AC_cfg;
vector<float> Detents;
vector<float> TransitionTimes;
float Flap_Position;
bool Flaps_In_Transit;
-public:
- FGFlaps(FGFCS* fcs, FGConfigFile* AC_cfg);
- ~FGFlaps();
- bool Run (void );
-
-private:
void Debug(void);
};
string token;
string strScheduledBy;
- lookup = NULL;
- Schedule.clear();
+ State = fcs->GetState();
+
Gain = 1.000;
- Min = Max = 0;
+ Rows = 0;
+ Min = Max = 0.0;
ScheduledBy = FG_UNDEF;
Type = AC_cfg->GetValue("TYPE");
*AC_cfg >> token;
if (token == "ID") {
*AC_cfg >> ID;
- cout << " ID: " << ID << endl;
} else if (token == "INPUT") {
token = AC_cfg->GetValue("INPUT");
- cout << " INPUT: " << token << endl;
if (token.find("FG_") != token.npos) {
*AC_cfg >> token;
- InputIdx = fcs->GetState()->GetParameterIndex(token);
+ InputIdx = State->GetParameterIndex(token);
InputType = itPilotAC;
} else {
*AC_cfg >> InputIdx;
}
} else if (token == "GAIN") {
*AC_cfg >> Gain;
- cout << " GAIN: " << Gain << endl;
} else if (token == "MIN") {
*AC_cfg >> Min;
- cout << " MIN: " << Min << endl;
} else if (token == "MAX") {
*AC_cfg >> Max;
- cout << " MAX: " << Max << endl;
+ } else if (token == "ROWS") {
+ *AC_cfg >> Rows;
+ Table = new FGTable(Rows);
} else if (token == "SCHEDULED_BY") {
token = AC_cfg->GetValue("SCHEDULED_BY");
if (token.find("FG_") != token.npos) {
*AC_cfg >> strScheduledBy;
- ScheduledBy = fcs->GetState()->GetParameterIndex(strScheduledBy);
- cout << " Scheduled by parameter: " << token << endl;
+ ScheduledBy = State->GetParameterIndex(strScheduledBy);
} else {
*AC_cfg >> ScheduledBy;
- cout << " Scheduled by FCS output: " << ScheduledBy << endl;
}
} else if (token == "OUTPUT") {
IsOutput = true;
*AC_cfg >> sOutputIdx;
- OutputIdx = fcs->GetState()->GetParameterIndex(sOutputIdx);
- cout << " OUTPUT: " << sOutputIdx << endl;
+ OutputIdx = State->GetParameterIndex(sOutputIdx);
} else {
AC_cfg->ResetLineIndexToZero();
- lookup = new float[2];
- *AC_cfg >> lookup[0] >> lookup[1];
- cout << " " << lookup[0] << " " << lookup[1] << endl;
- Schedule.push_back(lookup);
+ *Table << *AC_cfg;
+ }
+ }
+
+ if (debug_lvl > 0) {
+ cout << " ID: " << ID << endl;
+ cout << " INPUT: " << InputIdx << endl;
+ cout << " GAIN: " << Gain << endl;
+ if (IsOutput) cout << " OUTPUT: " << sOutputIdx << endl;
+ cout << " MIN: " << Min << endl;
+ cout << " MAX: " << Max << endl;
+ if (ScheduledBy != FG_UNDEF) {
+ cout << " Scheduled by parameter: " << ScheduledBy << endl;
+ Table->Print();
}
}
bool FGGain::Run(void )
{
float SchedGain = 1.0;
+ float LookupVal = 0;
FGFCSComponent::Run(); // call the base class for initialization of Input
if (Type == "PURE_GAIN") {
-
Output = Gain * Input;
-
} else if (Type == "SCHEDULED_GAIN") {
-
- float LookupVal = fcs->GetState()->GetParameter(ScheduledBy);
- unsigned int last = Schedule.size()-1;
- float lowVal = Schedule[0][0], hiVal = Schedule[last][0];
- float factor = 1.0;
-
- if (LookupVal <= lowVal) Output = Gain * Schedule[0][1] * Input;
- else if (LookupVal >= hiVal) Output = Gain * Schedule[last][1] * Input;
- else {
- for (unsigned int ctr = 1; ctr < last; ctr++) {
- if (LookupVal < Schedule[ctr][0]) {
- hiVal = Schedule[ctr][0];
- lowVal = Schedule[ctr-1][0];
- factor = (LookupVal - lowVal) / (hiVal - lowVal);
- SchedGain = Schedule[ctr-1][1] + factor*(Schedule[ctr][1] - Schedule[ctr-1][1]);
- Output = Gain * SchedGain * Input;
- break;
- }
- }
- }
-
+ LookupVal = State->GetParameter(ScheduledBy);
+ SchedGain = Table->GetValue(LookupVal);
+ Output = Gain * SchedGain * Input;
} else if (Type == "AEROSURFACE_SCALE") {
-
if (Output >= 0.0) Output = Input * Max;
else Output = Input * (-Min);
-
Output *= Gain;
}
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
-# include <vector>
-# else
-# include <vector.h>
-# endif
+# include STL_STRING
+ SG_USING_STD(string);
#else
-# include <vector>
+# include <string>
#endif
-#include <string>
#include "FGFCSComponent.h"
#include "../FGConfigFile.h"
+#include "../FGTable.h"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINES
private:
FGConfigFile* AC_cfg;
+ FGTable* Table;
+ FGState* State;
float Gain;
- float* lookup;
- vector < float* > Schedule;
float Min, Max;
+ int Rows;
eParam ScheduledBy;
void Debug(void);
*AC_cfg >> token;
if (token == "ID") {
-
*AC_cfg >> ID;
- cout << " ID: " << ID << endl;
-
} else if (token == "INPUT") {
-
token = AC_cfg->GetValue("INPUT");
- cout << " INPUT: " << token << endl;
if (token.find("FG_") != token.npos) {
*AC_cfg >> token;
tmpInputIndex = fcs->GetState()->GetParameterIndex(token);
InputIndices.push_back(tmpInputIndex);
InputTypes.push_back(itFCS);
}
-
} else if (token == "CLIPTO") {
-
*AC_cfg >> clipmin >> clipmax;
if (clipmax > clipmin) {
clip = true;
- cout << " CLIPTO: " << clipmin << ", " << clipmax << endl;
}
-
} else if (token == "OUTPUT") {
-
IsOutput = true;
*AC_cfg >> sOutputIdx;
- cout << " OUTPUT: " <<sOutputIdx << endl;
OutputIdx = fcs->GetState()->GetParameterIndex(sOutputIdx);
}
}
+ if (debug_lvl > 0) {
+ cout << " ID: " << ID << endl;
+ cout << " INPUTS: " << endl;
+ for (int i=0;i<InputIndices.size();i++) {
+ cout << " " << InputIndices[i] << endl;
+ }
+ if (clipmax > clipmin) cout << " CLIPTO: " << clipmin
+ << ", " << clipmax << endl;
+ if (IsOutput) cout << " OUTPUT: " <<sOutputIdx << endl;
+ }
+
if (debug_lvl & 2) cout << "Instantiated: FGSummer" << endl;
}
#ifdef FGFS
# include <simgear/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# ifdef SG_HAVE_STD_INCLUDES
# include <vector>
# else
# include <vector.h>