From 72a09d198c71c6af1f650b8630c29e8ba19c3a7d Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 12 Oct 2000 01:06:31 +0000 Subject: [PATCH] Updates to track current JSBSim cvs. --- src/FDM/JSBSim.cxx | 28 +++++++++++-- src/FDM/JSBSim/FGFDMExec.cpp | 80 +++++++++++++++++++++--------------- src/FDM/JSBSim/FGFDMExec.h | 2 +- 3 files changed, 73 insertions(+), 37 deletions(-) diff --git a/src/FDM/JSBSim.cxx b/src/FDM/JSBSim.cxx index a23e88bee..48efe4341 100644 --- a/src/FDM/JSBSim.cxx +++ b/src/FDM/JSBSim.cxx @@ -60,6 +60,10 @@ // Initialize the JSBsim flight model, dt is the time increment for // each subsequent iteration through the EOM +static bool trimmed = false; +static bool trim_elev = false; +static bool trim_throttle = false; + int FGJSBsim::init( double dt ) { bool result; @@ -73,12 +77,13 @@ int FGJSBsim::init( double dt ) { FGPath engine_path( current_options.get_fg_root() ); engine_path.append( "Engine" ); - FDMExec.GetState()->Setdt( dt ); + //FDMExec.GetState()->Setdt( dt ); result = FDMExec.LoadModel( aircraft_path.str(), engine_path.str(), current_options.get_aircraft() ); - + FDMExec.GetState()->Setdt( dt ); + if (result) { FG_LOG( FG_FLIGHT, FG_INFO, " loaded aircraft " << current_options.get_aircraft() ); } else { @@ -160,9 +165,12 @@ int FGJSBsim::init( double dt ) { controls.set_elevator_trim(FDMExec.GetFCS()->GetPitchTrimCmd()); controls.set_throttle(FGControls::ALL_ENGINES,FDMExec.GetFCS()->GetThrottleCmd(0)/100); + trimmed=true; + trim_elev=FDMExec.GetFCS()->GetPitchTrimCmd(); + trim_throttle=FDMExec.GetFCS()->GetThrottleCmd(0)/100; //the trimming routine only knows how to get 1 value for throttle -// delete fgtrim; + delete fgtrim; FG_LOG( FG_FLIGHT, FG_INFO, " Trim complete." ); } else { FG_LOG( FG_FLIGHT, FG_INFO, " Initializing without trim" ); @@ -198,7 +206,19 @@ int FGJSBsim::update( int multiloop ) { save_alt = get_Altitude(); set_Altitude( 0.0 ); } - + + if(trimmed) { + + controls.set_elevator_trim(trim_elev); + controls.set_throttle(FGControls::ALL_ENGINES,trim_throttle); + + controls.set_elevator(0.0); + controls.set_aileron(0.0); + controls.set_rudder(0.0); + trimmed=false; + + } + copy_to_JSBsim(); for ( int i = 0; i < multiloop; i++ ) { diff --git a/src/FDM/JSBSim/FGFDMExec.cpp b/src/FDM/JSBSim/FGFDMExec.cpp index 0eab1d6d0..6c936cf44 100644 --- a/src/FDM/JSBSim/FGFDMExec.cpp +++ b/src/FDM/JSBSim/FGFDMExec.cpp @@ -84,9 +84,12 @@ FGFDMExec::FGFDMExec(void) Auxiliary = 0; Output = 0; - allocated = false; terminate = false; frozen = false; + modelLoaded = false; + + Allocate(); + } FGFDMExec::~FGFDMExec(void){ @@ -97,6 +100,7 @@ FGFDMExec::~FGFDMExec(void){ bool FGFDMExec::Allocate(void) { + cout << "FGFDMExec::Allocate ... "; bool result=true; Atmosphere = new FGAtmosphere(this); @@ -136,40 +140,41 @@ bool FGFDMExec::Allocate(void) { Schedule(Auxiliary, 1); Schedule(Output, 1); - allocated = true; - + modelLoaded = false; + cout << "done." << endl; return result; } 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; + cout << "FGFDMExec::DeAllocate ... "; + + 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; + + modelLoaded = false; - } + cout << "done" << endl; } @@ -231,11 +236,22 @@ bool FGFDMExec::RunIC(FGInitialCondition *fgic) bool FGFDMExec::LoadModel(string APath, string EPath, string model) { - DeAllocate(); - Allocate(); + bool result=false; + cout << "FGFDMExec::LoadModel ..." << endl; + if(modelLoaded) { + DeAllocate(); + Allocate(); + } AircraftPath = APath; EnginePath = EPath; - return Aircraft->LoadAircraft(AircraftPath, EnginePath, model); + result = Aircraft->LoadAircraft(AircraftPath, EnginePath, model); + if(result) { + modelLoaded=true; + } else { + cerr << "FGFDMExec: Failed to load aircraft and/or engine model" << endl; + } + cout << "FGFDMExec::LoadModel complete." << endl;; + return result; } diff --git a/src/FDM/JSBSim/FGFDMExec.h b/src/FDM/JSBSim/FGFDMExec.h index 3eebd503e..b2289e2bd 100644 --- a/src/FDM/JSBSim/FGFDMExec.h +++ b/src/FDM/JSBSim/FGFDMExec.h @@ -96,8 +96,8 @@ public: private: bool frozen; bool terminate; - bool allocated; int Error; + bool modelLoaded; string AircraftPath; string EnginePath; -- 2.39.5