// 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;
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 {
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" );
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++ ) {
Auxiliary = 0;
Output = 0;
- allocated = false;
terminate = false;
frozen = false;
+ modelLoaded = false;
+
+ Allocate();
+
}
FGFDMExec::~FGFDMExec(void){
bool FGFDMExec::Allocate(void) {
+ cout << "FGFDMExec::Allocate ... ";
bool result=true;
Atmosphere = new FGAtmosphere(this);
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;
}
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;
}