From: curt Date: Tue, 5 Jun 2001 20:58:48 +0000 (+0000) Subject: Synced with latest JSBSim as of June 5, 2001. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9c0925744d27363955b3f26caf3311bc0a91ea69;p=flightgear.git Synced with latest JSBSim as of June 5, 2001. --- diff --git a/FlightGear.dsp b/FlightGear.dsp index 62678f178..0bf3b8210 100644 --- a/FlightGear.dsp +++ b/FlightGear.dsp @@ -4450,40 +4450,6 @@ SOURCE=.\src\Input\input.hxx !ENDIF -# End Source File -# End Group -# Begin Group "Lib_Joystick" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\src\Joystick\joystick.cxx - -!IF "$(CFG)" == "FlightGear - Win32 Release" - -# PROP Intermediate_Dir "Release\Lib_Joystick" - -!ELSEIF "$(CFG)" == "FlightGear - Win32 Debug" - -# PROP Intermediate_Dir "Debug\Lib_Joystick" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\src\Joystick\joystick.hxx - -!IF "$(CFG)" == "FlightGear - Win32 Release" - -# PROP Intermediate_Dir "Release\Lib_Joystick" - -!ELSEIF "$(CFG)" == "FlightGear - Win32 Debug" - -# PROP Intermediate_Dir "Debug\Lib_Joystick" - -!ENDIF - # End Source File # End Group # Begin Group "main" diff --git a/src/FDM/JSBSim.cxx b/src/FDM/JSBSim.cxx index 901df669d..05fa4ec5d 100644 --- a/src/FDM/JSBSim.cxx +++ b/src/FDM/JSBSim.cxx @@ -53,7 +53,8 @@ #include #include #include - +#include +#include #include "JSBSim.hxx" /******************************************************************************/ @@ -65,15 +66,17 @@ FGJSBsim::FGJSBsim( double dt ) 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; @@ -292,15 +295,15 @@ bool FGJSBsim::copy_to_JSBsim() { 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), @@ -322,7 +325,7 @@ bool FGJSBsim::copy_from_JSBsim() { // Auxiliary->GetNpilot(2), // Auxiliary->GetNpilot(3) ); - _set_Nlf( Aircraft->GetNlf() ); + _set_Nlf( Aerodynamics->GetNlf() ); // Velocities diff --git a/src/FDM/JSBSim.hxx b/src/FDM/JSBSim.hxx index a25bb91b3..28718a2b3 100644 --- a/src/FDM/JSBSim.hxx +++ b/src/FDM/JSBSim.hxx @@ -38,7 +38,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include -#include + #undef MAX_ENGINES #include @@ -202,15 +202,17 @@ private: 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; diff --git a/src/FDM/JSBSim/FGAerodynamics.cpp b/src/FDM/JSBSim/FGAerodynamics.cpp index 6889ca275..778dd9538 100644 --- a/src/FDM/JSBSim/FGAerodynamics.cpp +++ b/src/FDM/JSBSim/FGAerodynamics.cpp @@ -30,6 +30,7 @@ FUNCTIONAL DESCRIPTION HISTORY -------------------------------------------------------------------------------- 09/13/00 JSB Created +04/22/01 JSB Moved code into here from FGAircraft %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% INCLUDES @@ -47,8 +48,24 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -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; } @@ -56,15 +73,56 @@ FGAerodynamics::FGAerodynamics(FGFDMExec* fgex) : FGModel(fgex) FGAerodynamics::~FGAerodynamics() { + unsigned int i,j; + for (i=0; i<6; i++) { + for (j=0; jGetalpha(); + 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; @@ -75,7 +133,104 @@ bool FGAerodynamics:: Run(void) { 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 multipliers) +{ + unsigned int i; + + cout << " Non-Dimensionalized by: "; + + for (i=0; iparamdef[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; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/FGAerodynamics.h b/src/FDM/JSBSim/FGAerodynamics.h index beb7d209f..5e97441c9 100644 --- a/src/FDM/JSBSim/FGAerodynamics.h +++ b/src/FDM/JSBSim/FGAerodynamics.h @@ -40,17 +40,24 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include +# include # else # include +# include # endif #else # include +# include #endif #include "FGModel.h" #include "FGConfigFile.h" +#include "FGState.h" +#include "FGMassBalance.h" +#include "FGTranslation.h" +#include "FGCoefficient.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -99,8 +106,50 @@ public: /** 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 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 AxisIndex; + AxisIndex AxisIdx; + typedef vector CoeffArray; + CoeffArray* Coeff; + FGColumnVector vFs; + FGColumnVector vForces; + FGColumnVector vMoments; + FGColumnVector vLastFs; + FGColumnVector vDXYZcg; + void Debug(void); }; diff --git a/src/FDM/JSBSim/FGAircraft.cpp b/src/FDM/JSBSim/FGAircraft.cpp index 6414a79b7..19294eaaf 100644 --- a/src/FDM/JSBSim/FGAircraft.cpp +++ b/src/FDM/JSBSim/FGAircraft.cpp @@ -5,7 +5,7 @@ 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 @@ -109,7 +109,7 @@ INCLUDES # ifndef __BORLANDC__ # include # endif -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include @@ -119,6 +119,9 @@ INCLUDES #endif #include "FGAircraft.h" +#include "FGMassBalance.h" +#include "FGInertial.h" +#include "FGAerodynamics.h" #include "FGTranslation.h" #include "FGRotation.h" #include "FGAtmosphere.h" @@ -161,28 +164,14 @@ CLASS IMPLEMENTATION 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; @@ -194,15 +183,8 @@ FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex), //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGAircraft::~FGAircraft() { - unsigned int i,j; - for (i=0; i<6; i++) { - for (j=0; j 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); } } @@ -256,160 +238,37 @@ bool FGAircraft::LoadAircraft(string aircraft_path, string engine_path, string f //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -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; eGetType()) { - 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; tGetContents(); - - Mass = Weight / GRAVITY; - // Calculate new CG here. - - Tw = 0; -// for (t=0; tGetX()*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; tGetX()-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 ::iterator iGear = lGear.begin(); while (iGear != lGear.end()) { @@ -424,22 +283,23 @@ void FGAircraft::FMGear(void) { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -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(); @@ -449,53 +309,66 @@ void FGAircraft::GetState(void) { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -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; - } + } } } @@ -517,24 +390,12 @@ void FGAircraft::ReadFlightControls(FGConfigFile* AC_cfg) { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -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; } + } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -631,75 +492,21 @@ void FGAircraft::ReadPrologue(FGConfigFile* AC_cfg) { 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 multipliers) { - cout << " Non-Dimensionalized by: "; - - for (unsigned int i=0; iparamdef[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; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -749,14 +556,3 @@ void FGAircraft::Debug(void) //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; -} diff --git a/src/FDM/JSBSim/FGAircraft.h b/src/FDM/JSBSim/FGAircraft.h index 9bc51cc1d..6d252e509 100644 --- a/src/FDM/JSBSim/FGAircraft.h +++ b/src/FDM/JSBSim/FGAircraft.h @@ -40,7 +40,7 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # include # include @@ -56,7 +56,6 @@ INCLUDES #endif #include "FGModel.h" -#include "FGCoefficient.h" #include "FGPropulsion.h" #include "FGConfigFile.h" #include "FGMatrix.h" @@ -157,27 +156,14 @@ public: 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; } @@ -185,9 +171,6 @@ public: 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); @@ -216,41 +199,22 @@ private: 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 AxisIndex; - AxisIndex AxisIdx; - - typedef vector CoeffArray; - - CoeffArray* Coeff; - - void DisplayCoeffFactors(vector multipliers); - bool GearUp; - string Axis[6]; vector lGear; string AircraftPath; diff --git a/src/FDM/JSBSim/FGAuxiliary.cpp b/src/FDM/JSBSim/FGAuxiliary.cpp index 0fdc05732..c8ddc8a3a 100644 --- a/src/FDM/JSBSim/FGAuxiliary.cpp +++ b/src/FDM/JSBSim/FGAuxiliary.cpp @@ -1,7 +1,7 @@ /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 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 @@ -62,7 +62,10 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -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; @@ -80,14 +83,15 @@ FGAuxiliary::~FGAuxiliary() //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -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 @@ -105,49 +109,55 @@ bool FGAuxiliary::Run() { 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(); - } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/FGAuxiliary.h b/src/FDM/JSBSim/FGAuxiliary.h index 2210dd368..e52dc15b7 100644 --- a/src/FDM/JSBSim/FGAuxiliary.h +++ b/src/FDM/JSBSim/FGAuxiliary.h @@ -97,10 +97,7 @@ public: float GetHeadWind(void); float GetCrossWind(void); - -protected: - private: float vcas; float veas; @@ -115,9 +112,9 @@ private: // isentropic flow equations FGColumnVector vPilotAccel; + FGColumnVector vToEyePt; float earthPosAngle; - void GetState(void); void Debug(void); diff --git a/src/FDM/JSBSim/FGCoefficient.cpp b/src/FDM/JSBSim/FGCoefficient.cpp index 61053881a..b8ec8528f 100644 --- a/src/FDM/JSBSim/FGCoefficient.cpp +++ b/src/FDM/JSBSim/FGCoefficient.cpp @@ -55,7 +55,7 @@ INCLUDES #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]; @@ -91,9 +91,11 @@ FGCoefficient::FGCoefficient(FGFDMExec* fdex, FGConfigFile* AC_cfg) 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; @@ -103,26 +105,26 @@ FGCoefficient::FGCoefficient(FGFDMExec* fdex, FGConfigFile* AC_cfg) 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 @@ -149,13 +151,12 @@ FGCoefficient::FGCoefficient(FGFDMExec* fdex, FGConfigFile* AC_cfg) 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: diff --git a/src/FDM/JSBSim/FGConfigFile.cpp b/src/FDM/JSBSim/FGConfigFile.cpp index 51e22c4c7..2aa97e12a 100644 --- a/src/FDM/JSBSim/FGConfigFile.cpp +++ b/src/FDM/JSBSim/FGConfigFile.cpp @@ -22,7 +22,7 @@ INCLUDES #include static const char *IdSrc = "$Id$"; -static const char *IdHdr = "ID_CONFIGFILE"; +static const char *IdHdr = ID_CONFIGFILE; extern short debug_lvl; diff --git a/src/FDM/JSBSim/FGConfigFile.h b/src/FDM/JSBSim/FGConfigFile.h index e5064cbcb..5a458bea9 100644 --- a/src/FDM/JSBSim/FGConfigFile.h +++ b/src/FDM/JSBSim/FGConfigFile.h @@ -40,16 +40,31 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES -# include -# else -# include -# 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 +# include +# include + 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 #include "FGDefs.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -58,9 +73,6 @@ DEFINITIONS #define ID_CONFIGFILE "$Id$" -using std::string; -using std::ifstream; - /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ diff --git a/src/FDM/JSBSim/FGControls.cpp b/src/FDM/JSBSim/FGControls.cpp index f35d82753..232f4b4f3 100644 --- a/src/FDM/JSBSim/FGControls.cpp +++ b/src/FDM/JSBSim/FGControls.cpp @@ -53,8 +53,8 @@ FGControls::~FGControls() { // $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 diff --git a/src/FDM/JSBSim/FGControls.h b/src/FDM/JSBSim/FGControls.h index 3212f9839..38ad206ac 100644 --- a/src/FDM/JSBSim/FGControls.h +++ b/src/FDM/JSBSim/FGControls.h @@ -178,8 +178,8 @@ extern FGControls controls; // $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 diff --git a/src/FDM/JSBSim/FGDefs.h b/src/FDM/JSBSim/FGDefs.h index f4d727a37..72ed411dd 100644 --- a/src/FDM/JSBSim/FGDefs.h +++ b/src/FDM/JSBSim/FGDefs.h @@ -39,7 +39,6 @@ SENTRY #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 @@ -54,8 +53,8 @@ SENTRY #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 diff --git a/src/FDM/JSBSim/FGEngine.cpp b/src/FDM/JSBSim/FGEngine.cpp index 7e94a01a7..47ff6da78 100644 --- a/src/FDM/JSBSim/FGEngine.cpp +++ b/src/FDM/JSBSim/FGEngine.cpp @@ -40,7 +40,7 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include @@ -53,7 +53,7 @@ INCLUDES #include "FGTank.h" static const char *IdSrc = "$Id$"; -static const char *IdHdr = "ID_ENGINE"; +static const char *IdHdr = ID_ENGINE; extern short debug_lvl; diff --git a/src/FDM/JSBSim/FGEngine.h b/src/FDM/JSBSim/FGEngine.h index becf4a3d8..12bfc7eaf 100644 --- a/src/FDM/JSBSim/FGEngine.h +++ b/src/FDM/JSBSim/FGEngine.h @@ -48,7 +48,7 @@ INCLUDES # include # include STL_STRING SG_USING_STD(string); -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include diff --git a/src/FDM/JSBSim/FGFCS.cpp b/src/FDM/JSBSim/FGFCS.cpp index f97ecadff..bb92800b6 100644 --- a/src/FDM/JSBSim/FGFCS.cpp +++ b/src/FDM/JSBSim/FGFCS.cpp @@ -57,7 +57,7 @@ INCLUDES #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; @@ -137,12 +137,14 @@ bool FGFCS::LoadFCS(FGConfigFile* AC_cfg) 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") || diff --git a/src/FDM/JSBSim/FGFCS.h b/src/FDM/JSBSim/FGFCS.h index b21dc8add..2dae2aa0d 100644 --- a/src/FDM/JSBSim/FGFCS.h +++ b/src/FDM/JSBSim/FGFCS.h @@ -40,7 +40,7 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include diff --git a/src/FDM/JSBSim/FGFDMExec.cpp b/src/FDM/JSBSim/FGFDMExec.cpp index dd5d275c2..32359bb3c 100644 --- a/src/FDM/JSBSim/FGFDMExec.cpp +++ b/src/FDM/JSBSim/FGFDMExec.cpp @@ -44,15 +44,9 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES -# include -# include -# include -# else -# include -# include -# include -# endif +# include STL_IOSTREAM +# include +# include STL_ITERATOR #else # include # include @@ -64,6 +58,9 @@ INCLUDES #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" @@ -73,7 +70,7 @@ INCLUDES #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' }; @@ -108,6 +105,8 @@ short debug_lvl; // This describes to any interested entity the debug level // 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 @@ -117,30 +116,28 @@ 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; @@ -149,6 +146,13 @@ FGFDMExec::FGFDMExec(void) 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(); @@ -167,19 +171,22 @@ bool FGFDMExec::Allocate(void) { 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 @@ -192,24 +199,33 @@ bool FGFDMExec::Allocate(void) { 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; @@ -217,15 +233,18 @@ bool FGFDMExec::Allocate(void) { // 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; @@ -239,6 +258,9 @@ bool FGFDMExec::DeAllocate(void) { 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; @@ -250,16 +272,19 @@ bool FGFDMExec::DeAllocate(void) { 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; @@ -302,7 +327,7 @@ bool FGFDMExec::Run(void) model_iterator = FirstModel; if (model_iterator == 0L) return false; - if (Scripted) { + if (Scripted) { RunScript(); if (State->Getsim_time() >= EndTime) return false; } @@ -338,12 +363,12 @@ bool FGFDMExec::RunIC(FGInitialCondition *fgic) 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); @@ -356,7 +381,7 @@ bool FGFDMExec::LoadModel(string APath, string EPath, string model) << fgdef << endl; } - cout << "\n\nJSBSim startup complete\n\n"; + if (debug_lvl > 0) cout << "\n\nJSBSim startup complete\n\n"; return result; } @@ -370,6 +395,7 @@ bool FGFDMExec::LoadScript(string script) string initialize=""; bool result=false; float dt=0.0; + int i; struct condition *newCondition; if (!Script.IsOpen()) return false; @@ -377,17 +403,17 @@ bool FGFDMExec::LoadScript(string script) 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; } @@ -461,76 +487,77 @@ bool FGFDMExec::LoadScript(string script) exit(-1); } - // print out conditions for double-checking + // print out conditions for double-checking if requested - vector ::iterator iterConditions = Conditions.begin(); - - int count=0; + if (debug_lvl > 0) { + vector ::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; iTestValue.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; iSetValue.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; iTestValue.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; iSetValue.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; @@ -549,6 +576,7 @@ void FGFDMExec::RunScript(void) vector ::iterator iC = Conditions.begin(); bool truth; bool WholeTruth; + int i; int count=0; @@ -558,7 +586,7 @@ void FGFDMExec::RunScript(void) while (iC < Conditions.end()) { // determine whether the set of conditional tests for this condition equate // to true - for (int i=0; iTestValue.size(); i++) { + for (i=0; iTestValue.size(); i++) { if (iC->Comparison[i] == "lt") truth = State->GetParameter(iC->TestParam[i]) < iC->TestValue[i]; else if (iC->Comparison[i] == "le") @@ -583,7 +611,7 @@ void FGFDMExec::RunScript(void) // if the conditions are true, do the setting of the desired parameters if (WholeTruth) { - for (int i=0; iSetValue.size(); i++) { + for (i=0; iSetValue.size(); i++) { if ( ! iC->Triggered[i]) { iC->OriginalValue[i] = State->GetParameter(iC->SetParam[i]); switch (iC->Type[i]) { diff --git a/src/FDM/JSBSim/FGFDMExec.h b/src/FDM/JSBSim/FGFDMExec.h index 973bc37b3..93388f364 100644 --- a/src/FDM/JSBSim/FGFDMExec.h +++ b/src/FDM/JSBSim/FGFDMExec.h @@ -42,7 +42,7 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include @@ -68,6 +68,9 @@ class FGState; class FGAtmosphere; class FGFCS; class FGPropulsion; +class FGMassBalance; +class FGAerodynamics; +class FGInertial; class FGAircraft; class FGTranslation; class FGRotation; @@ -191,6 +194,8 @@ CLASS DOCUMENTATION FGModel object executes its Run() method
  • 8: When this value is set, various runtime state variables are printed out periodically
  • +
  • 16: When set various parameters are sanity checked and + a message is printed out when they go out of bounds
  • */ @@ -275,6 +280,12 @@ public: /// 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;} @@ -311,16 +322,19 @@ private: float EndTime; vector 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); diff --git a/src/FDM/JSBSim/FGForce.cpp b/src/FDM/JSBSim/FGForce.cpp index 572e7cb62..aa762ac93 100644 --- a/src/FDM/JSBSim/FGForce.cpp +++ b/src/FDM/JSBSim/FGForce.cpp @@ -48,7 +48,7 @@ and the cg. #include "FGForce.h" static const char *IdSrc = "$Id$"; -static const char *IdHdr = "ID_FORCE"; +static const char *IdHdr = ID_FORCE; extern short debug_lvl; @@ -88,9 +88,9 @@ FGColumnVector FGForce::GetBodyForces(void) { //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; diff --git a/src/FDM/JSBSim/FGGroundReactions.cpp b/src/FDM/JSBSim/FGGroundReactions.cpp index f215f247e..66ee85ef3 100644 --- a/src/FDM/JSBSim/FGGroundReactions.cpp +++ b/src/FDM/JSBSim/FGGroundReactions.cpp @@ -69,6 +69,7 @@ bool FGGroundReactions:: Run(void) { bool FGGroundReactions::LoadGroundReactions(FGConfigFile* AC_cfg) { // + return true; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/FGGroundReactions.h b/src/FDM/JSBSim/FGGroundReactions.h index 29cafc574..e4bc87fc6 100644 --- a/src/FDM/JSBSim/FGGroundReactions.h +++ b/src/FDM/JSBSim/FGGroundReactions.h @@ -44,7 +44,7 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include diff --git a/src/FDM/JSBSim/FGInertial.cpp b/src/FDM/JSBSim/FGInertial.cpp index 026c9ca6b..db9ffe46e 100644 --- a/src/FDM/JSBSim/FGInertial.cpp +++ b/src/FDM/JSBSim/FGInertial.cpp @@ -36,6 +36,8 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGInertial.h" +#include "FGPosition.h" +#include "FGMassBalance.h" static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_INERTIAL; @@ -47,17 +49,62 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -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; @@ -68,7 +115,7 @@ bool FGInertial:: Run(void) { bool FGInertial::LoadInertial(FGConfigFile* AC_cfg) { -// + return true; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/FGInertial.h b/src/FDM/JSBSim/FGInertial.h index d24d17ca8..a4cf90074 100644 --- a/src/FDM/JSBSim/FGInertial.h +++ b/src/FDM/JSBSim/FGInertial.h @@ -44,7 +44,7 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include @@ -55,6 +55,7 @@ INCLUDES #include "FGModel.h" #include "FGConfigFile.h" +#include "FGMatrix.h" #define ID_INERTIAL "$Id$" @@ -67,10 +68,17 @@ class FGInertial : public FGModel { 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; }; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/FGLGear.cpp b/src/FDM/JSBSim/FGLGear.cpp index 0f36ade4f..6be481e9d 100644 --- a/src/FDM/JSBSim/FGLGear.cpp +++ b/src/FDM/JSBSim/FGLGear.cpp @@ -69,16 +69,18 @@ FGLGear::FGLGear(FGConfigFile* AC_cfg, FGFDMExec* fdmex) : vXYZ(3), >> 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; @@ -107,6 +109,7 @@ FGLGear::FGLGear(FGConfigFile* AC_cfg, FGFDMExec* fdmex) : vXYZ(3), Position = Exec->GetPosition(); Rotation = Exec->GetRotation(); FCS = Exec->GetFCS(); + MassBalance = Exec->GetMassBalance(); WOW = false; ReportEnable = true; @@ -114,8 +117,9 @@ FGLGear::FGLGear(FGConfigFile* AC_cfg, FGFDMExec* fdmex) : vXYZ(3), 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); @@ -134,6 +138,7 @@ FGLGear::FGLGear(const FGLGear& lgear) Rotation = lgear.Rotation; Exec = lgear.Exec; FCS = lgear.FCS; + MassBalance = lgear.MassBalance; vXYZ = lgear.vXYZ; vMoment = lgear.vMoment; @@ -187,7 +192,7 @@ FGColumnVector FGLGear::Force(void) 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); @@ -380,6 +385,8 @@ FGColumnVector FGLGear::Force(void) MaximumStrutForce = MaximumStrutTravel = 0.0; } + compressLength = 0.0; // reset compressLength to zero for data output validity + vForce.InitMatrix(); vMoment.InitMatrix(); } @@ -389,7 +396,7 @@ FGColumnVector FGLGear::Force(void) } if (ReportEnable && Position->GetVel().Magnitude() <= 0.05 && !Reported) { - Report(); + if (debug_lvl > 0) Report(); } return vForce; diff --git a/src/FDM/JSBSim/FGLGear.h b/src/FDM/JSBSim/FGLGear.h index 303e7239b..046853d5f 100644 --- a/src/FDM/JSBSim/FGLGear.h +++ b/src/FDM/JSBSim/FGLGear.h @@ -62,6 +62,7 @@ class FGPosition; class FGRotation; class FGFCS; class FGState; +class FGMassBalance; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs] @@ -257,6 +258,7 @@ private: FGPosition* Position; FGRotation* Rotation; FGFCS* FCS; + FGMassBalance* MassBalance; void Report(void); void Debug(void); @@ -266,6 +268,7 @@ private: #include "FGPosition.h" #include "FGRotation.h" #include "FGFCS.h" +#include "FGMassBalance.h" //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/FGMassBalance.cpp b/src/FDM/JSBSim/FGMassBalance.cpp index dc380b128..b670b2176 100644 --- a/src/FDM/JSBSim/FGMassBalance.cpp +++ b/src/FDM/JSBSim/FGMassBalance.cpp @@ -52,15 +52,41 @@ CLASS IMPLEMENTATION 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; @@ -71,6 +97,13 @@ bool FGMassBalance::Run(void) { 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; + } } diff --git a/src/FDM/JSBSim/FGMassBalance.h b/src/FDM/JSBSim/FGMassBalance.h index b182fb2e5..8dc53da84 100644 --- a/src/FDM/JSBSim/FGMassBalance.h +++ b/src/FDM/JSBSim/FGMassBalance.h @@ -43,6 +43,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGModel.h" +#include "FGPropulsion.h" #define ID_MASSBALANCE "$Id$" @@ -58,8 +59,42 @@ public: ~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); }; diff --git a/src/FDM/JSBSim/FGMatrix.h b/src/FDM/JSBSim/FGMatrix.h index 8c92e871c..99673444e 100644 --- a/src/FDM/JSBSim/FGMatrix.h +++ b/src/FDM/JSBSim/FGMatrix.h @@ -22,22 +22,17 @@ INCLUDES #include #ifdef FGFS +# include # include # 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 -# include -# include -# else -# include -# include -# include -# endif #else # include # include @@ -47,6 +42,7 @@ INCLUDES using std::ostream; using std::istream; using std::cerr; + using std::cout; using std::endl; #endif diff --git a/src/FDM/JSBSim/FGModel.cpp b/src/FDM/JSBSim/FGModel.cpp index 5a0fc8412..7006b1d0b 100644 --- a/src/FDM/JSBSim/FGModel.cpp +++ b/src/FDM/JSBSim/FGModel.cpp @@ -43,6 +43,10 @@ INCLUDES #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" @@ -68,16 +72,19 @@ FGModel::FGModel(FGFDMExec* fdmex) 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; @@ -95,21 +102,27 @@ FGModel::~FGModel() 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 || diff --git a/src/FDM/JSBSim/FGModel.h b/src/FDM/JSBSim/FGModel.h index d8bc729c0..dcb08daca 100644 --- a/src/FDM/JSBSim/FGModel.h +++ b/src/FDM/JSBSim/FGModel.h @@ -42,7 +42,7 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include @@ -70,6 +70,9 @@ class FGState; class FGAtmosphere; class FGFCS; class FGPropulsion; +class FGMassBalance; +class FGAerodynamics; +class FGInertial; class FGAircraft; class FGTranslation; class FGRotation; @@ -129,6 +132,9 @@ protected: FGAtmosphere* Atmosphere; FGFCS* FCS; FGPropulsion* Propulsion; + FGMassBalance* MassBalance; + FGAerodynamics* Aerodynamics; + FGInertial* Inertial; FGAircraft* Aircraft; FGTranslation* Translation; FGRotation* Rotation; diff --git a/src/FDM/JSBSim/FGNozzle.cpp b/src/FDM/JSBSim/FGNozzle.cpp index cf1ed5b0f..f4cf93393 100644 --- a/src/FDM/JSBSim/FGNozzle.cpp +++ b/src/FDM/JSBSim/FGNozzle.cpp @@ -52,29 +52,28 @@ FGNozzle::FGNozzle(FGFDMExec* FDMExec, FGConfigFile* Nzl_cfg) : FGThruster(FDMEx 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; } @@ -91,8 +90,8 @@ FGNozzle::~FGNozzle() 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; } diff --git a/src/FDM/JSBSim/FGNozzle.h b/src/FDM/JSBSim/FGNozzle.h index 78dfb1e46..d8737e059 100644 --- a/src/FDM/JSBSim/FGNozzle.h +++ b/src/FDM/JSBSim/FGNozzle.h @@ -27,10 +27,6 @@ HISTORY -------------------------------------------------------------------------------- 08/24/00 JSB Created -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -COMMENTS, REFERENCES, and NOTES -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SENTRY %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -44,8 +40,32 @@ INCLUDES #include "FGThruster.h" +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +DEFINITIONS +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + #define ID_NOZZLE "$Id$"; +#ifndef M_PI +# include +# 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -53,7 +73,9 @@ CLASS DECLARATION class FGNozzle : public FGThruster { public: + /// Constructor FGNozzle(FGFDMExec* exec, FGConfigFile* AC_cfg); + /// Destructor ~FGNozzle(); float Calculate(float CfPc); @@ -64,6 +86,8 @@ private: float ExpR; float nzlEff; float Diameter; + float AreaT; + float Area2; void Debug(void); }; diff --git a/src/FDM/JSBSim/FGOutput.cpp b/src/FDM/JSBSim/FGOutput.cpp index f7ed98b62..e03f0266e 100644 --- a/src/FDM/JSBSim/FGOutput.cpp +++ b/src/FDM/JSBSim/FGOutput.cpp @@ -43,7 +43,9 @@ INCLUDES #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" @@ -194,7 +196,7 @@ void FGOutput::DelimitedOutput(void) } if (SubSystems & FGAircraft::ssCoefficients) { cout << ", "; - cout << Aircraft->GetCoefficientStrings(); + cout << Aerodynamics->GetCoefficientStrings(); } if (SubSystems & FGAircraft::ssGroundReactions) { cout << ", "; @@ -235,8 +237,8 @@ void FGOutput::DelimitedOutput(void) } if (SubSystems & FGAircraft::ssForces) { cout << ", "; - cout << Aircraft->GetvFs() << ", "; - cout << Aircraft->GetLoD() << ", "; + cout << Aerodynamics->GetvFs() << ", "; + cout << Aerodynamics->GetLoD() << ", "; cout << Aircraft->GetForces(); } if (SubSystems & FGAircraft::ssMoments) { @@ -249,12 +251,12 @@ void FGOutput::DelimitedOutput(void) } 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 << ", "; @@ -268,7 +270,7 @@ void FGOutput::DelimitedOutput(void) } if (SubSystems & FGAircraft::ssCoefficients) { cout << ", "; - cout << Aircraft->GetCoefficientValues(); + cout << Aerodynamics->GetCoefficientValues(); } if (SubSystems & FGAircraft::ssGroundReactions) { cout << ", "; @@ -348,7 +350,7 @@ void FGOutput::DelimitedOutput(string fname) } if (SubSystems & FGAircraft::ssCoefficients) { datafile << ", "; - datafile << Aircraft->GetCoefficientStrings(); + datafile << Aerodynamics->GetCoefficientStrings(); } if (SubSystems & FGAircraft::ssGroundReactions) { datafile << ", "; @@ -392,8 +394,8 @@ void FGOutput::DelimitedOutput(string fname) } if (SubSystems & FGAircraft::ssForces) { datafile << ", "; - datafile << Aircraft->GetvFs() << ", "; - datafile << Aircraft->GetLoD() << ", "; + datafile << Aerodynamics->GetvFs() << ", "; + datafile << Aerodynamics->GetLoD() << ", "; datafile << Aircraft->GetForces(); } if (SubSystems & FGAircraft::ssMoments) { @@ -406,12 +408,12 @@ void FGOutput::DelimitedOutput(string fname) } 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 << ", "; @@ -425,7 +427,7 @@ void FGOutput::DelimitedOutput(string fname) } if (SubSystems & FGAircraft::ssCoefficients) { datafile << ", "; - datafile << Aircraft->GetCoefficientValues(); + datafile << Aerodynamics->GetCoefficientValues(); } if (SubSystems & FGAircraft::ssGroundReactions) { datafile << ", "; diff --git a/src/FDM/JSBSim/FGOutput.h b/src/FDM/JSBSim/FGOutput.h index 96aafb63f..6638a89bb 100644 --- a/src/FDM/JSBSim/FGOutput.h +++ b/src/FDM/JSBSim/FGOutput.h @@ -42,13 +42,8 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES -# include -# include -# else -# include -# include -# endif +# include STL_IOSTREAM +# include STL_FSTREAM #else # include # include diff --git a/src/FDM/JSBSim/FGPiston.cpp b/src/FDM/JSBSim/FGPiston.cpp index 5cd169293..e60a65fa3 100644 --- a/src/FDM/JSBSim/FGPiston.cpp +++ b/src/FDM/JSBSim/FGPiston.cpp @@ -54,34 +54,28 @@ FGPiston::FGPiston(FGFDMExec* exec, FGConfigFile* Eng_cfg) : FGEngine(exec) 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; diff --git a/src/FDM/JSBSim/FGPosition.cpp b/src/FDM/JSBSim/FGPosition.cpp index 984e1bc7b..e8e09b867 100644 --- a/src/FDM/JSBSim/FGPosition.cpp +++ b/src/FDM/JSBSim/FGPosition.cpp @@ -55,7 +55,7 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # include # else @@ -73,6 +73,7 @@ INCLUDES #include "FGFDMExec.h" #include "FGFCS.h" #include "FGAircraft.h" +#include "FGMassBalance.h" #include "FGTranslation.h" #include "FGRotation.h" #include "FGAuxiliary.h" @@ -140,7 +141,7 @@ bool FGPosition:: Run(void) { 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; diff --git a/src/FDM/JSBSim/FGPosition.h b/src/FDM/JSBSim/FGPosition.h index 8d2d45e85..acb7c265b 100644 --- a/src/FDM/JSBSim/FGPosition.h +++ b/src/FDM/JSBSim/FGPosition.h @@ -97,6 +97,7 @@ public: 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; } diff --git a/src/FDM/JSBSim/FGPropeller.cpp b/src/FDM/JSBSim/FGPropeller.cpp index 54321871f..650654047 100644 --- a/src/FDM/JSBSim/FGPropeller.cpp +++ b/src/FDM/JSBSim/FGPropeller.cpp @@ -52,50 +52,61 @@ FGPropeller::FGPropeller(FGFDMExec* exec, FGConfigFile* Prop_cfg) : FGThruster(e 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; diff --git a/src/FDM/JSBSim/FGPropeller.h b/src/FDM/JSBSim/FGPropeller.h index cd014c76f..34dc2e900 100644 --- a/src/FDM/JSBSim/FGPropeller.h +++ b/src/FDM/JSBSim/FGPropeller.h @@ -48,6 +48,11 @@ DEFINITIONS #define ID_PROPELLER "$Id$" +#ifndef M_PI +# include +# define M_PI SG_PI +#endif + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ diff --git a/src/FDM/JSBSim/FGPropulsion.cpp b/src/FDM/JSBSim/FGPropulsion.cpp index 555887df1..f31f1ed34 100644 --- a/src/FDM/JSBSim/FGPropulsion.cpp +++ b/src/FDM/JSBSim/FGPropulsion.cpp @@ -167,8 +167,8 @@ bool FGPropulsion::LoadPropulsion(FGConfigFile* AC_cfg) 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()) { @@ -194,19 +194,27 @@ bool FGPropulsion::LoadPropulsion(FGConfigFile* AC_cfg) 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++; @@ -219,7 +227,7 @@ bool FGPropulsion::LoadPropulsion(FGConfigFile* AC_cfg) } 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: @@ -238,8 +246,8 @@ bool FGPropulsion::LoadPropulsion(FGConfigFile* AC_cfg) 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()) { @@ -382,6 +390,100 @@ string FGPropulsion::GetPropulsionValues(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +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 diff --git a/src/FDM/JSBSim/FGPropulsion.h b/src/FDM/JSBSim/FGPropulsion.h index 049f48946..524cfefcb 100644 --- a/src/FDM/JSBSim/FGPropulsion.h +++ b/src/FDM/JSBSim/FGPropulsion.h @@ -40,13 +40,16 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include +# include # else # include +# include # endif #else # include +# include #endif #include "FGModel.h" @@ -162,10 +165,20 @@ public: 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 Engines; vector Tanks; + vector ::iterator iTank; vector Thrusters; unsigned int numSelectedFuelTanks; unsigned int numSelectedOxiTanks; @@ -177,6 +190,7 @@ private: float dt; FGColumnVector *Forces; FGColumnVector *Moments; + FGColumnVector vXYZtank; void Debug(void); }; diff --git a/src/FDM/JSBSim/FGRocket.cpp b/src/FDM/JSBSim/FGRocket.cpp index 0befe8c77..080dff9d5 100644 --- a/src/FDM/JSBSim/FGRocket.cpp +++ b/src/FDM/JSBSim/FGRocket.cpp @@ -54,42 +54,37 @@ FGRocket::FGRocket(FGFDMExec* exec, FGConfigFile* Eng_cfg) : FGEngine(exec) 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; @@ -106,17 +101,16 @@ FGRocket::~FGRocket() 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)); @@ -124,11 +118,7 @@ float FGRocket::Calculate(float pe) 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; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/FGRotation.cpp b/src/FDM/JSBSim/FGRotation.cpp index d9fbb0301..0a3df1f64 100644 --- a/src/FDM/JSBSim/FGRotation.cpp +++ b/src/FDM/JSBSim/FGRotation.cpp @@ -61,6 +61,7 @@ INCLUDES #include "FGFDMExec.h" #include "FGFCS.h" #include "FGAircraft.h" +#include "FGMassBalance.h" #include "FGTranslation.h" #include "FGPosition.h" #include "FGAuxiliary.h" @@ -102,60 +103,70 @@ FGRotation::~FGRotation() 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; + } } diff --git a/src/FDM/JSBSim/FGRotation.h b/src/FDM/JSBSim/FGRotation.h index 2c943bce9..3f64a2546 100644 --- a/src/FDM/JSBSim/FGRotation.h +++ b/src/FDM/JSBSim/FGRotation.h @@ -58,18 +58,14 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES -# include -# else -# include -# endif +# include #else # include #endif #ifndef M_PI # include -# define M_PI FG_PI +# define M_PI SG_PI #endif #include "FGModel.h" diff --git a/src/FDM/JSBSim/FGState.cpp b/src/FDM/JSBSim/FGState.cpp index 8c7bcedd6..58ca50ab5 100644 --- a/src/FDM/JSBSim/FGState.cpp +++ b/src/FDM/JSBSim/FGState.cpp @@ -38,18 +38,14 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES -# include -# else -# include -# endif +# include #else # include #endif #ifndef M_PI # include -# define M_PI FG_PI +# define M_PI SG_PI #endif #include "FGState.h" @@ -92,13 +88,14 @@ FGState::FGState(FGFDMExec* fdex) : mTb2l(3,3), 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 " ); @@ -190,7 +187,7 @@ float FGState::GetParameter(eParam val_idx) { 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; diff --git a/src/FDM/JSBSim/FGState.h b/src/FDM/JSBSim/FGState.h index 9061357f4..e494d2809 100644 --- a/src/FDM/JSBSim/FGState.h +++ b/src/FDM/JSBSim/FGState.h @@ -46,7 +46,7 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include @@ -165,6 +165,7 @@ private: FGOutput* Output; FGAtmosphere* Atmosphere; FGFCS* FCS; + FGAerodynamics* Aerodynamics; typedef map CoeffMap; CoeffMap coeffdef; @@ -184,7 +185,7 @@ private: #include "FGTranslation.h" #include "FGRotation.h" #include "FGPosition.h" -//#include "FGAuxiliary.h" +#include "FGAerodynamics.h" #include "FGOutput.h" #include "FGAircraft.h" diff --git a/src/FDM/JSBSim/FGTank.cpp b/src/FDM/JSBSim/FGTank.cpp index 2559b38b1..7162dd88e 100644 --- a/src/FDM/JSBSim/FGTank.cpp +++ b/src/FDM/JSBSim/FGTank.cpp @@ -80,10 +80,12 @@ FGTank::FGTank(FGConfigFile* AC_cfg) 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; } diff --git a/src/FDM/JSBSim/FGTank.h b/src/FDM/JSBSim/FGTank.h index cd7a2ecac..05790440a 100644 --- a/src/FDM/JSBSim/FGTank.h +++ b/src/FDM/JSBSim/FGTank.h @@ -44,13 +44,23 @@ SENTRY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#include "FGConfigFile.h" + #ifdef FGFS # include +# include STL_STRING + SG_USING_STD(string); + SG_USING_STD(cerr); + SG_USING_STD(endl); + SG_USING_STD(cout); +#else +# include + using std::string; + using std::cerr; + using std::endl; + using std::cout; #endif -#include -#include "FGConfigFile.h" - /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ diff --git a/src/FDM/JSBSim/FGTranslation.cpp b/src/FDM/JSBSim/FGTranslation.cpp index d19b18525..40b37267b 100644 --- a/src/FDM/JSBSim/FGTranslation.cpp +++ b/src/FDM/JSBSim/FGTranslation.cpp @@ -63,6 +63,7 @@ INCLUDES #include "FGState.h" #include "FGFDMExec.h" #include "FGFCS.h" +#include "FGMassBalance.h" #include "FGAircraft.h" #include "FGPosition.h" #include "FGAuxiliary.h" @@ -158,9 +159,12 @@ bool FGTranslation::Run(void) { vlastUVWdot = vUVWdot; - } else {} + if (debug_lvl > 1) Debug(); - return false; + return false; + } else { + return true; + } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -171,7 +175,7 @@ void FGTranslation::GetState(void) { vPQR = Rotation->GetPQR(); vForces = Aircraft->GetForces(); - Mass = Aircraft->GetMass(); + Mass = MassBalance->GetMass(); rho = Atmosphere->GetDensity(); vEuler = Rotation->GetEuler(); @@ -181,6 +185,23 @@ void FGTranslation::GetState(void) { 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; + } } diff --git a/src/FDM/JSBSim/FGTranslation.h b/src/FDM/JSBSim/FGTranslation.h index 680cab4d7..08e85453e 100644 --- a/src/FDM/JSBSim/FGTranslation.h +++ b/src/FDM/JSBSim/FGTranslation.h @@ -58,7 +58,7 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include diff --git a/src/FDM/JSBSim/FGTrim.cpp b/src/FDM/JSBSim/FGTrim.cpp index 6f32949f6..d9542e1e5 100644 --- a/src/FDM/JSBSim/FGTrim.cpp +++ b/src/FDM/JSBSim/FGTrim.cpp @@ -51,7 +51,8 @@ INCLUDES #include "FGInitialCondition.h" #include "FGTrim.h" #include "FGAircraft.h" - +#include "FGMassBalance.h" +#include "FGAerodynamics.h" #if _MSC_VER #pragma warning (disable : 4786 4788) #endif @@ -164,10 +165,10 @@ void FGTrim::ReportState(void) { 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"); @@ -197,7 +198,7 @@ void FGTrim::ReportState(void) { 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", diff --git a/src/FDM/JSBSim/FGTrim.h b/src/FDM/JSBSim/FGTrim.h index f8469f97d..de1b02cf0 100644 --- a/src/FDM/JSBSim/FGTrim.h +++ b/src/FDM/JSBSim/FGTrim.h @@ -162,7 +162,7 @@ private: 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 diff --git a/src/FDM/JSBSim/FGUtility.cpp b/src/FDM/JSBSim/FGUtility.cpp index 892db1ceb..c32abed4e 100644 --- a/src/FDM/JSBSim/FGUtility.cpp +++ b/src/FDM/JSBSim/FGUtility.cpp @@ -44,7 +44,7 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include diff --git a/src/FDM/JSBSim/FGfdmSocket.h b/src/FDM/JSBSim/FGfdmSocket.h index 0507a69f1..803c01f57 100644 --- a/src/FDM/JSBSim/FGfdmSocket.h +++ b/src/FDM/JSBSim/FGfdmSocket.h @@ -47,15 +47,10 @@ INCLUDES #ifdef FGFS # include # include STL_STRING +# include STL_IOSTREAM +# include STL_FSTREAM SG_USING_STD(cout); SG_USING_STD(endl); -# ifdef FG_HAVE_STD_INCLUDES -# include -# include -# else -# include -# include -# endif #else # include # include diff --git a/src/FDM/JSBSim/JSBSim.cpp b/src/FDM/JSBSim/JSBSim.cpp index 499be6817..400b6088b 100644 --- a/src/FDM/JSBSim/JSBSim.cpp +++ b/src/FDM/JSBSim/JSBSim.cpp @@ -54,7 +54,7 @@ INCLUDES #ifdef FGFS #include #include STL_IOSTREAM -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include @@ -64,6 +64,57 @@ INCLUDES #include #endif +#if __BORLANDC__ > 0x540 +#include +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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ diff --git a/src/FDM/JSBSim/Makefile.am b/src/FDM/JSBSim/Makefile.am index ce6d9dbc8..c05a09327 100644 --- a/src/FDM/JSBSim/Makefile.am +++ b/src/FDM/JSBSim/Makefile.am @@ -4,10 +4,7 @@ EXTRA_DIST = JSBSim.cpp Makefile.solo 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 \ @@ -15,6 +12,7 @@ noinst_LIBRARIES = libJSBSim.a # FGTurboShaft.cpp FGTurboShaft.h \ libJSBSim_a_SOURCES = \ + FGAerodynamics.cpp FGAerodynamics.h \ FGAircraft.cpp FGAircraft.h \ FGAtmosphere.cpp FGAtmosphere.h \ FGAuxiliary.cpp FGAuxiliary.h \ @@ -25,8 +23,10 @@ libJSBSim_a_SOURCES = \ 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 \ diff --git a/src/FDM/JSBSim/filtersjb/FGFilter.cpp b/src/FDM/JSBSim/filtersjb/FGFilter.cpp index fe57b1b43..2c2cabbea 100644 --- a/src/FDM/JSBSim/filtersjb/FGFilter.cpp +++ b/src/FDM/JSBSim/filtersjb/FGFilter.cpp @@ -70,10 +70,15 @@ FGFilter::FGFilter(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs), 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; @@ -83,31 +88,14 @@ FGFilter::FGFilter(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs), *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; @@ -136,6 +124,18 @@ FGFilter::FGFilter(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs), 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; } diff --git a/src/FDM/JSBSim/filtersjb/FGFlaps.cpp b/src/FDM/JSBSim/filtersjb/FGFlaps.cpp index 0ac76d357..ba743ee06 100644 --- a/src/FDM/JSBSim/filtersjb/FGFlaps.cpp +++ b/src/FDM/JSBSim/filtersjb/FGFlaps.cpp @@ -65,10 +65,8 @@ AC_cfg(AC_cfg) { *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); @@ -76,23 +74,30 @@ AC_cfg(AC_cfg) { } } else if ( token == "DETENTS" ) { *AC_cfg >> NumDetents; - cout << " DETENTS: " << NumDetents << endl; for(int i=0;i> 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: " <GetState()->GetParameterIndex(sOutputIdx); } } + if (debug_lvl > 1) { + cout << " ID: " << ID << endl; + cout << " INPUT: " << InputIdx << endl; + cout << " DETENTS: " << NumDetents << endl; + for(int i=0;i -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include @@ -67,6 +67,12 @@ CLASS DECLARATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ class FGFlaps : public FGFCSComponent { +public: + FGFlaps(FGFCS* fcs, FGConfigFile* AC_cfg); + ~FGFlaps(); + bool Run (void ); + +private: FGConfigFile* AC_cfg; vector Detents; vector TransitionTimes; @@ -76,12 +82,6 @@ class FGFlaps : public FGFCSComponent { float Flap_Position; bool Flaps_In_Transit; -public: - FGFlaps(FGFCS* fcs, FGConfigFile* AC_cfg); - ~FGFlaps(); - bool Run (void ); - -private: void Debug(void); }; diff --git a/src/FDM/JSBSim/filtersjb/FGGain.cpp b/src/FDM/JSBSim/filtersjb/FGGain.cpp index ada0b3db6..48505338b 100644 --- a/src/FDM/JSBSim/filtersjb/FGGain.cpp +++ b/src/FDM/JSBSim/filtersjb/FGGain.cpp @@ -55,10 +55,11 @@ FGGain::FGGain(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs), 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"); @@ -69,13 +70,11 @@ FGGain::FGGain(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs), *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; @@ -83,34 +82,41 @@ FGGain::FGGain(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs), } } 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(); } } @@ -129,40 +135,19 @@ FGGain::~FGGain() 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; } diff --git a/src/FDM/JSBSim/filtersjb/FGGain.h b/src/FDM/JSBSim/filtersjb/FGGain.h index 44f66e633..2ac845896 100644 --- a/src/FDM/JSBSim/filtersjb/FGGain.h +++ b/src/FDM/JSBSim/filtersjb/FGGain.h @@ -43,18 +43,15 @@ INCLUDES #ifdef FGFS # include -# ifdef FG_HAVE_STD_INCLUDES -# include -# else -# include -# endif +# include STL_STRING + SG_USING_STD(string); #else -# include +# include #endif -#include #include "FGFCSComponent.h" #include "../FGConfigFile.h" +#include "../FGTable.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINES @@ -78,10 +75,11 @@ public: 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); diff --git a/src/FDM/JSBSim/filtersjb/FGSummer.cpp b/src/FDM/JSBSim/filtersjb/FGSummer.cpp index b73af9af8..431a6bacf 100644 --- a/src/FDM/JSBSim/filtersjb/FGSummer.cpp +++ b/src/FDM/JSBSim/filtersjb/FGSummer.cpp @@ -67,14 +67,9 @@ FGSummer::FGSummer(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs), *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); @@ -85,24 +80,29 @@ FGSummer::FGSummer(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs), 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: " <GetState()->GetParameterIndex(sOutputIdx); } } + if (debug_lvl > 0) { + cout << " ID: " << ID << endl; + cout << " INPUTS: " << endl; + for (int i=0;i clipmin) cout << " CLIPTO: " << clipmin + << ", " << clipmax << endl; + if (IsOutput) cout << " OUTPUT: " < -# ifdef FG_HAVE_STD_INCLUDES +# ifdef SG_HAVE_STD_INCLUDES # include # else # include