From 6caf599f2bc5cb77dcdd67ef92cc3ff9984b8c8c Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 10 Oct 2000 17:44:35 +0000 Subject: [PATCH] Oct. 10, 2000 sync with JSBSim master repository. --- src/FDM/JSBSim.cxx | 4 +- src/FDM/JSBSim/FGAircraft.cpp | 55 ++++++++--------------- src/FDM/JSBSim/FGAircraft.h | 33 +++++++++++--- src/FDM/JSBSim/FGControls.cpp | 4 +- src/FDM/JSBSim/FGControls.h | 4 +- src/FDM/JSBSim/FGFDMExec.cpp | 68 +++++++++++++++++++++-------- src/FDM/JSBSim/FGFDMExec.h | 4 ++ src/FDM/JSBSim/FGInitialCondition.h | 2 +- src/FDM/JSBSim/FGLGear.cpp | 1 + src/FDM/JSBSim/FGOutput.cpp | 1 + src/FDM/JSBSim/FGState.cpp | 5 +-- src/FDM/JSBSim/FGState.h | 6 --- src/FDM/JSBSim/FGTranslation.cpp | 21 ++++++++- src/FDM/JSBSim/FGTranslation.h | 6 ++- src/FDM/JSBSim/JSBSim.cpp | 16 +++---- 15 files changed, 143 insertions(+), 87 deletions(-) diff --git a/src/FDM/JSBSim.cxx b/src/FDM/JSBSim.cxx index 192a5a080..a23e88bee 100644 --- a/src/FDM/JSBSim.cxx +++ b/src/FDM/JSBSim.cxx @@ -80,7 +80,7 @@ int FGJSBsim::init( double dt ) { current_options.get_aircraft() ); if (result) { - FG_LOG( FG_FLIGHT, FG_INFO, " loaded aircraft" << current_options.get_aircraft() ); + FG_LOG( FG_FLIGHT, FG_INFO, " loaded aircraft " << current_options.get_aircraft() ); } else { FG_LOG( FG_FLIGHT, FG_INFO, " aircraft" << current_options.get_aircraft() << " does not exist"); @@ -103,7 +103,7 @@ int FGJSBsim::init( double dt ) { FG_LOG( FG_FLIGHT, FG_INFO, " Initializing JSBSim with:" ); FGInitialCondition *fgic = new FGInitialCondition(&FDMExec); - fgic->SetAltitudeAGLFtIC(get_Altitude()); + fgic->SetAltitudeFtIC(get_Altitude()); if((current_options.get_mach() < 0) && (current_options.get_vc() < 0 )) { fgic->SetUBodyFpsIC(current_options.get_uBody()); fgic->SetVBodyFpsIC(current_options.get_vBody()); diff --git a/src/FDM/JSBSim/FGAircraft.cpp b/src/FDM/JSBSim/FGAircraft.cpp index 74859c38d..8184840f8 100644 --- a/src/FDM/JSBSim/FGAircraft.cpp +++ b/src/FDM/JSBSim/FGAircraft.cpp @@ -168,35 +168,20 @@ FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex), FGAircraft::~FGAircraft(void) { unsigned int i,j; - cout << " ~FGAircraft" << endl; if (Engine != NULL) { for (i=0; iForce(); -// vMoments += iGear->Moment(); -// iGear++; -// } - - for (unsigned int i=0;iForce(); - vMoments += lGear[i]->Moment(); + if ( !GearUp ) { + vector ::iterator iGear = lGear.begin(); + while (iGear != lGear.end()) { + vForces += iGear->Force(); + vMoments += iGear->Moment(); + iGear++; } + } else { + // Crash Routine } } @@ -581,7 +560,7 @@ void FGAircraft::ReadUndercarriage(FGConfigFile* AC_cfg) { AC_cfg->GetNextConfigLine(); while ((token = AC_cfg->GetValue()) != "/UNDERCARRIAGE") { - lGear.push_back(new FGLGear(AC_cfg, FDMExec)); + lGear.push_back(FGLGear(AC_cfg, FDMExec)); } } @@ -737,10 +716,10 @@ string FGAircraft::GetGroundReactionStrings(void) { for (unsigned int i=0;iGetName() + "_WOW, "); - GroundReactionStrings += (lGear[i]->GetName() + "_compressLength, "); - GroundReactionStrings += (lGear[i]->GetName() + "_compressSpeed, "); - GroundReactionStrings += (lGear[i]->GetName() + "_Force"); + GroundReactionStrings += (lGear[i].GetName() + "_WOW, "); + GroundReactionStrings += (lGear[i].GetName() + "_compressLength, "); + GroundReactionStrings += (lGear[i].GetName() + "_compressSpeed, "); + GroundReactionStrings += (lGear[i].GetName() + "_Force"); firstime = false; } @@ -758,10 +737,10 @@ string FGAircraft::GetGroundReactionValues(void) { for (unsigned int i=0;iGetWOW()?"1":"0" ) + ", "; - GroundReactionValues += (string(gcvt(lGear[i]->GetCompLen(), 5, buff)) + ", "); - GroundReactionValues += (string(gcvt(lGear[i]->GetCompVel(), 6, buff)) + ", "); - GroundReactionValues += (string(gcvt(lGear[i]->GetCompForce(), 10, buff))); + GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", "; + GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(), 5, buff)) + ", "); + GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(), 6, buff)) + ", "); + GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff))); firstime = false; } diff --git a/src/FDM/JSBSim/FGAircraft.h b/src/FDM/JSBSim/FGAircraft.h index 9c2b287cd..b831e92a1 100644 --- a/src/FDM/JSBSim/FGAircraft.h +++ b/src/FDM/JSBSim/FGAircraft.h @@ -125,6 +125,14 @@ INCLUDES DEFINITIONS *******************************************************************************/ +/** Encapsulates an Aircraft and its systems. + Owns all the parts (other classes) which make + up this aircraft. This includes the Engines, Tanks, Propellers, Nozzles, + aerodynamic and mass properties, landing gear, etc. + @author Jon S. Berndt + @version $Id$ + */ + /******************************************************************************* CLASS DECLARATION *******************************************************************************/ @@ -136,16 +144,31 @@ class FGAircraft : public FGModel { enum {ePhi=1, eTht, ePsi}; public: - FGAircraft(FGFDMExec*); + /** Constructor + @param Executive a pointer to the parent executive object + */ + FGAircraft(FGFDMExec *Executive); + /// Destructor ~FGAircraft(void); + /** Runs the model; called by the Executive + @see JSBSim.cpp documentation + @return bool returns false if no error + */ bool Run(void); - bool LoadAircraft(string, string, string); + /** Loads the aircraft. + The executive calls this method to load the aircraft into JSBSim. + @param apath path to the aircraft files (e.g. "aircraft/X15/") + @param epath path to engine files (e.g. "engine/") + @param acname name of aircraft (e.g. "X15") + @return true if succesful + */ + bool LoadAircraft(string apath, string epath, string acname); inline string GetAircraftName(void) { return AircraftName; } inline void SetGearUp(bool tt) { GearUp = tt; } inline bool GetGearUp(void) { return GearUp; } inline int GetNumGearUnits(void) { return lGear.size(); } - inline FGLGear* GetGearUnit(int ii) { return lGear[ii]; } + inline FGLGear* GetGearUnit(int ii) { return &(lGear[ii]); } inline float GetWingArea(void) { return WingArea; } inline float GetWingSpan(void) { return WingSpan; } inline float Getcbar(void) { return cbar; } @@ -177,8 +200,6 @@ public: string GetGroundReactionStrings(void); string GetGroundReactionValues(void); - vector ::iterator iGear; - enum { ssSimulation = 1, ssAerosurfaces = 2, ssRates = 4, @@ -235,7 +256,7 @@ private: bool GearUp; string Axis[6]; - vector lGear; + vector lGear; string AircraftPath; string EnginePath; diff --git a/src/FDM/JSBSim/FGControls.cpp b/src/FDM/JSBSim/FGControls.cpp index 4e5935586..de2ef278f 100644 --- a/src/FDM/JSBSim/FGControls.cpp +++ b/src/FDM/JSBSim/FGControls.cpp @@ -51,8 +51,8 @@ FGControls::~FGControls() { // $Log$ -// Revision 1.16 2000/10/09 19:16:22 curt -// Oct. 9, 2000 - synced with latest JSBsim code. +// Revision 1.17 2000/10/10 15:44:35 curt +// Oct. 10, 2000 sync with JSBSim master repository. // // Revision 1.3 2000/04/26 10:55:57 jsb // Made changes as required by Curt to install JSBSim into FGFS diff --git a/src/FDM/JSBSim/FGControls.h b/src/FDM/JSBSim/FGControls.h index 0b94d242d..57eb899fe 100644 --- a/src/FDM/JSBSim/FGControls.h +++ b/src/FDM/JSBSim/FGControls.h @@ -177,8 +177,8 @@ extern FGControls controls; // $Log$ -// Revision 1.15 2000/10/09 19:16:22 curt -// Oct. 9, 2000 - synced with latest JSBsim code. +// Revision 1.16 2000/10/10 15:44:35 curt +// Oct. 10, 2000 sync with JSBSim master repository. // // Revision 1.6 2000/06/03 13:59:52 jsb // Changes for compatibility with MSVC diff --git a/src/FDM/JSBSim/FGFDMExec.cpp b/src/FDM/JSBSim/FGFDMExec.cpp index e24b445a4..0eab1d6d0 100644 --- a/src/FDM/JSBSim/FGFDMExec.cpp +++ b/src/FDM/JSBSim/FGFDMExec.cpp @@ -84,8 +84,21 @@ FGFDMExec::FGFDMExec(void) Auxiliary = 0; Output = 0; - // Instantiate this FDM Executive's Models + allocated = false; + terminate = false; + frozen = false; +} + +FGFDMExec::~FGFDMExec(void){ + + DeAllocate(); +} + +bool FGFDMExec::Allocate(void) { + + bool result=true; + Atmosphere = new FGAtmosphere(this); FCS = new FGFCS(this); Aircraft = new FGAircraft(this); @@ -107,7 +120,9 @@ FGFDMExec::FGFDMExec(void) if (!Position->InitModel()) {cerr << "Position model init failed"; Error+=32;} if (!Auxiliary->InitModel()) {cerr << "Auxiliary model init failed"; Error+=64;} if (!Output->InitModel()) {cerr << "Output model init failed"; Error+=128;} - + + if(Error > 0) result=false; + // Schedule a model. The second arg (the integer) is the pass number. For // instance, the atmosphere model gets executed every fifth pass it is called // by the executive. Everything else here gets executed each pass. @@ -120,24 +135,41 @@ FGFDMExec::FGFDMExec(void) Schedule(Position, 1); Schedule(Auxiliary, 1); Schedule(Output, 1); + + allocated = true; + + return result; - terminate = false; - frozen = false; } - -FGFDMExec::~FGFDMExec(void){ +bool FGFDMExec::DeAllocate(void) { + if(allocated) { + if ( Atmosphere != 0 ) delete Atmosphere; + if ( FCS != 0 ) delete FCS; + if ( Aircraft != 0 ) delete Aircraft; + if ( Translation != 0 ) delete Translation; + if ( Rotation != 0 ) delete Rotation; + if ( Position != 0 ) delete Position; + if ( Auxiliary != 0 ) delete Auxiliary; + if ( Output != 0 ) delete Output; + if ( State != 0 ) delete State; + + FirstModel = 0L; + Error = 0; + + State = 0; + Atmosphere = 0; + FCS = 0; + Aircraft = 0; + Translation = 0; + Rotation = 0; + Position = 0; + Auxiliary = 0; + Output = 0; + + allocated = false; - if ( Atmosphere != NULL ) delete Atmosphere; - if ( FCS != NULL ) delete FCS; - if ( Aircraft != NULL ) delete Aircraft; - if ( Translation != NULL ) delete Translation; - if ( Rotation != NULL ) delete Rotation; - if ( Position != NULL ) delete Position; - if ( Auxiliary != NULL ) delete Auxiliary; - if ( Output != NULL ) delete Output; - if ( State != NULL ) delete State; - + } } @@ -199,7 +231,9 @@ bool FGFDMExec::RunIC(FGInitialCondition *fgic) bool FGFDMExec::LoadModel(string APath, string EPath, string model) { - AircraftPath = APath; + DeAllocate(); + Allocate(); + AircraftPath = APath; EnginePath = EPath; return Aircraft->LoadAircraft(AircraftPath, EnginePath, model); } diff --git a/src/FDM/JSBSim/FGFDMExec.h b/src/FDM/JSBSim/FGFDMExec.h index 307f31c05..3eebd503e 100644 --- a/src/FDM/JSBSim/FGFDMExec.h +++ b/src/FDM/JSBSim/FGFDMExec.h @@ -96,6 +96,7 @@ public: private: bool frozen; bool terminate; + bool allocated; int Error; string AircraftPath; @@ -112,6 +113,9 @@ private: FGPosition* Position; FGAuxiliary* Auxiliary; FGOutput* Output; + + bool Allocate(void); + bool DeAllocate(void); protected: }; diff --git a/src/FDM/JSBSim/FGInitialCondition.h b/src/FDM/JSBSim/FGInitialCondition.h index bd8d48a10..9e15820c5 100644 --- a/src/FDM/JSBSim/FGInitialCondition.h +++ b/src/FDM/JSBSim/FGInitialCondition.h @@ -126,7 +126,7 @@ public: void SetAltitudeAGLFtIC(float tt); //"vertical" flight path, recalculate theta - inline void SetFlightPathAngleDegIC(float tt) { SetFlightPathAngleRadIC(gamma=tt*DEGTORAD); } + inline void SetFlightPathAngleDegIC(float tt) { SetFlightPathAngleRadIC(tt*DEGTORAD); } void SetFlightPathAngleRadIC(float tt); //set speed first void SetClimbRateFpmIC(float tt); diff --git a/src/FDM/JSBSim/FGLGear.cpp b/src/FDM/JSBSim/FGLGear.cpp index 322412fd0..2ad970bae 100644 --- a/src/FDM/JSBSim/FGLGear.cpp +++ b/src/FDM/JSBSim/FGLGear.cpp @@ -83,6 +83,7 @@ FGLGear::FGLGear(FGConfigFile* AC_cfg, FGFDMExec* fdmex) : vXYZ(3), FGLGear::~FGLGear(void) { + cout << "Destructing Landing Gear ..." << endl; } /******************************************************************************/ diff --git a/src/FDM/JSBSim/FGOutput.cpp b/src/FDM/JSBSim/FGOutput.cpp index 7b698f520..ff0b07c90 100644 --- a/src/FDM/JSBSim/FGOutput.cpp +++ b/src/FDM/JSBSim/FGOutput.cpp @@ -61,6 +61,7 @@ FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex) Type = otNone; Filename = "JSBSim.out"; SubSystems = 0; + enabled = true; #ifdef FG_WITH_JSBSIM_SOCKET socket = new FGfdmSocket("localhost",1138); diff --git a/src/FDM/JSBSim/FGState.cpp b/src/FDM/JSBSim/FGState.cpp index 51d6deaff..b7649a405 100644 --- a/src/FDM/JSBSim/FGState.cpp +++ b/src/FDM/JSBSim/FGState.cpp @@ -87,7 +87,6 @@ FGState::FGState(FGFDMExec* fdex) : mTb2l(3,3), { FDMExec = fdex; - adot = bdot = 0.0; a = 1000.0; sim_time = 0.0; dt = 1.0/120.0; @@ -144,11 +143,11 @@ float FGState::GetParameter(eParam val_idx) { case FG_ALPHA: return FDMExec->GetTranslation()->Getalpha(); case FG_ALPHADOT: - return Getadot(); + return FDMExec->GetTranslation()->Getadot(); case FG_BETA: return FDMExec->GetTranslation()->Getbeta(); case FG_BETADOT: - return Getbdot(); + return FDMExec->GetTranslation()->Getbdot(); case FG_PITCHRATE: return (FDMExec->GetRotation()->GetPQR())(2); case FG_ROLLRATE: diff --git a/src/FDM/JSBSim/FGState.h b/src/FDM/JSBSim/FGState.h index b8705e81b..10896b4f5 100644 --- a/src/FDM/JSBSim/FGState.h +++ b/src/FDM/JSBSim/FGState.h @@ -81,9 +81,6 @@ public: void Initialize(FGInitialCondition *FGIC); bool StoreData(string); - inline float Getadot(void) { return adot; } - inline float Getbdot(void) { return bdot; } - inline float Geta(void) { return a; } inline float Getsim_time(void) { return sim_time; } @@ -96,8 +93,6 @@ public: float GetParameter(string val_string); eParam GetParameterIndex(string val_string); - inline void Setadot(float tt) { adot = tt; } - inline void Setbdot(float tt) { bdot = tt; } inline void Seta(float tt) { a = tt; } @@ -125,7 +120,6 @@ public: private: - float adot, bdot; // alpha dot and beta dot float a; // speed of sound float sim_time, dt; float saved_dt; diff --git a/src/FDM/JSBSim/FGTranslation.cpp b/src/FDM/JSBSim/FGTranslation.cpp index 82eff48ed..f17e13756 100644 --- a/src/FDM/JSBSim/FGTranslation.cpp +++ b/src/FDM/JSBSim/FGTranslation.cpp @@ -87,6 +87,7 @@ FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex), Vt = 0.0; Mach = 0.0; alpha = beta = 0.0; + adot = bdot = 0.0; rho = 0.002378; } @@ -127,7 +128,25 @@ bool FGTranslation::Run(void) { if (vUVW(eV) != 0.0) beta = vUVW(eU)*vUVW(eU)+vUVW(eW)*vUVW(eW) > 0.0 ? atan2(vUVW(eV), sqrt(vUVW(eU)*vUVW(eU) + vUVW(eW)*vUVW(eW))) : 0.0; - + + + + // stolen, quite shamelessly, from LaRCsim + float mUW = (vUVW(eU)*vUVW(eU) + vUVW(eW)*vUVW(eW)); + float signU=1; + if (vUVW(eU) != 0.0) + signU = vUVW(eU)/fabs(vUVW(eU)); + + if( (mUW == 0.0) || (Vt == 0.0) ) { + adot = 0.0; + bdot = 0.0; + } else { + adot = (vUVW(eU)*vUVWdot(eW) - vUVW(eW)*vUVWdot(eU))/mUW; + bdot = (signU*mUW*vUVWdot(eV) - vUVW(eV)*(vUVW(eU)*vUVWdot(eU) + + vUVW(eW)*vUVWdot(eW)))/(Vt*Vt*sqrt(mUW)); + } + // + qbar = 0.5*rho*Vt*Vt; Mach = Vt / State->Geta(); diff --git a/src/FDM/JSBSim/FGTranslation.h b/src/FDM/JSBSim/FGTranslation.h index c4a068b67..db9f9732f 100644 --- a/src/FDM/JSBSim/FGTranslation.h +++ b/src/FDM/JSBSim/FGTranslation.h @@ -88,7 +88,8 @@ public: inline float Getqbar (void) { return qbar; } inline float GetVt (void) { return Vt; } inline float GetMach (void) { return Mach; } - + inline float Getadot (void) { return adot; } + inline float Getbdot (void) { return bdot; } void SetUVW(FGColumnVector tt) { vUVW = tt; } @@ -97,6 +98,8 @@ public: inline void Setqbar (float tt) { qbar = tt; } inline void SetVt (float tt) { Vt = tt; } inline void SetMach (float tt) { Mach=tt; } + inline void Setadot (float tt) { adot = tt; } + inline void Setbdot (float tt) { bdot = tt; } inline void SetAB(float t1, float t2) { alpha=t1; beta=t2; } @@ -115,6 +118,7 @@ private: float Vt, qbar, Mach; float Mass, dt; float alpha, beta; + float adot,bdot; float rho; void GetState(void); diff --git a/src/FDM/JSBSim/JSBSim.cpp b/src/FDM/JSBSim/JSBSim.cpp index 99c9e1f6b..bbae63b13 100644 --- a/src/FDM/JSBSim/JSBSim.cpp +++ b/src/FDM/JSBSim/JSBSim.cpp @@ -144,24 +144,24 @@ int main(int argc, char** argv) while (FDMExec->GetState()->Getsim_time() <= 10.0) { // Fake an elevator ramp here after 1 second, hold for one second, ramp down - /* + if (FDMExec->GetState()->Getsim_time() >= 1.00 && FDMExec->GetState()->Getsim_time() < 2.0) { - cmd = FDMExec->GetState()->Getsim_time() - 1.00; + cmd = -(FDMExec->GetState()->Getsim_time() - 1.00)/2.0; } else if (FDMExec->GetState()->Getsim_time() >= 2.00 && - FDMExec->GetState()->Getsim_time() < 3.0) + FDMExec->GetState()->Getsim_time() < 6.0) { - cmd = 1.00; - } else if (FDMExec->GetState()->Getsim_time() >= 3.00 && - FDMExec->GetState()->Getsim_time() < 4.0) + cmd = -1.00/2.0; + } else if (FDMExec->GetState()->Getsim_time() >= 6.00 && + FDMExec->GetState()->Getsim_time() < 7.0) { - cmd = 4.0 - FDMExec->GetState()->Getsim_time(); + cmd = -(7.0 - FDMExec->GetState()->Getsim_time())/2.0; } else { cmd = 0.00; } FDMExec->GetFCS()->SetDeCmd(cmd); // input between -1 and 1 - */ + FDMExec->Run(); } -- 2.39.5