]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim.cxx
- catch exception from readProperties and exit
[flightgear.git] / src / FDM / JSBSim.cxx
index 05fa4ec5d5d265eaabfbc957611ed36babc1c05b..dc308ffd5e95b2d65882727f54cbfd0f8aa30c03 100644 (file)
@@ -77,7 +77,9 @@ FGJSBsim::FGJSBsim( double dt )
     Position     = fdmex->GetPosition();
     Auxiliary    = fdmex->GetAuxiliary();
     Aerodynamics = fdmex->GetAerodynamics();
-
+    
+    Atmosphere->UseInternal();
+    
     fgic=new FGInitialCondition(fdmex);
     needTrim=true;
   
@@ -93,6 +95,16 @@ FGJSBsim::FGJSBsim( double dt )
                                engine_path.str(),
                                fgGetString("/sim/aircraft") );
     
+
+    if (result) {
+       SG_LOG( SG_FLIGHT, SG_INFO,
+               "  loaded aircraft.");
+    } else {
+       SG_LOG( SG_FLIGHT, SG_INFO,
+               "  aircraft does not exist (you may have mis-typed the name).");
+       throw(-1);
+    }
+
     int Neng = Propulsion->GetNumEngines();
     SG_LOG(SG_FLIGHT,SG_INFO, "Neng: " << Neng );
     
@@ -105,16 +117,22 @@ FGJSBsim::FGJSBsim( double dt )
     fgSetDouble("/fdm/trim/aileron",    FCS->GetDaCmd());
     fgSetDouble("/fdm/trim/rudder",     FCS->GetDrCmd());
 
-    trimmed = fgGetValue("/fdm/trim/trimmed",true);
+    startup_trim = fgGetNode("/sim/startup/trim", true);
+
+    trimmed = fgGetNode("/fdm/trim/trimmed", true);
     trimmed->setBoolValue(false);
 
+    pitch_trim = fgGetNode("/fdm/trim/pitch-trim", true );
+    throttle_trim = fgGetNode("/fdm/trim/throttle", true );
+    aileron_trim = fgGetNode("/fdm/trim/aileron", true );
+    rudder_trim = fgGetNode("/fdm/trim/rudder", true );
 }
 
 /******************************************************************************/
 FGJSBsim::~FGJSBsim(void) {
-    if(fdmex != NULL) {
-        delete fdmex;
-        delete fgic;
+    if (fdmex != NULL) {
+        delete fdmex; fdmex=NULL;
+        delete fgic; fgic=NULL;
     }  
 }
 
@@ -124,15 +142,12 @@ FGJSBsim::~FGJSBsim(void) {
 // each subsequent iteration through the EOM
 
 void FGJSBsim::init() {
-                // Explicitly call the superclass's
-                // init method first.
-    FGInterface::init();
-
-    bool result;
-
+    
     SG_LOG( SG_FLIGHT, SG_INFO, "Starting and initializing JSBsim" );
-
-    Atmosphere->UseInternal();
+   
+    // Explicitly call the superclass's
+    // init method first.
+    FGInterface::init();
 
     SG_LOG( SG_FLIGHT, SG_INFO, "  Initializing JSBSim with:" );
 
@@ -192,44 +207,44 @@ bool FGJSBsim::update( int multiloop ) {
 
     trimmed->setBoolValue(false);
 
-    if (needTrim && fgGetBool("/sim/startup/trim")) {
+    if ( needTrim && startup_trim->getBoolValue() ) {
 
-      //fgic->SetSeaLevelRadiusFtIC( get_Sea_level_radius() );
-      //fgic->SetTerrainAltitudeFtIC( scenery.cur_elev * SG_METER_TO_FEET );
+        //fgic->SetSeaLevelRadiusFtIC( get_Sea_level_radius() );
+        //fgic->SetTerrainAltitudeFtIC( scenery.cur_elev * SG_METER_TO_FEET );
 
-    FGTrim *fgtrim;
-    if(fgic->GetVcalibratedKtsIC() < 10 ) {
-        fgic->SetVcalibratedKtsIC(0.0);
-        fgtrim=new FGTrim(fdmex,fgic,tGround);
-    } else {
-        fgtrim=new FGTrim(fdmex,fgic,tLongitudinal);
-    }
-    if(!fgtrim->DoTrim()) {
-        fgtrim->Report();
-        fgtrim->TrimStats();
-    } else {
-        trimmed->setBoolValue(true);
-    }
-    fgtrim->ReportState();
-    delete fgtrim;
+        FGTrim *fgtrim;
+        if(fgic->GetVcalibratedKtsIC() < 10 ) {
+            fgic->SetVcalibratedKtsIC(0.0);
+            fgtrim=new FGTrim(fdmex,fgic,tGround);
+        } else {
+            fgtrim=new FGTrim(fdmex,fgic,tLongitudinal);
+        }
+        if(!fgtrim->DoTrim()) {
+            fgtrim->Report();
+            fgtrim->TrimStats();
+        } else {
+            trimmed->setBoolValue(true);
+        }
+        fgtrim->ReportState();
+        delete fgtrim;
 
-    needTrim=false;
+        needTrim=false;
 
-    fgSetDouble("/fdm/trim/pitch-trim", FCS->GetPitchTrimCmd());
-    fgSetDouble("/fdm/trim/throttle",   FCS->GetThrottleCmd(0));
-    fgSetDouble("/fdm/trim/aileron",    FCS->GetDaCmd());
-    fgSetDouble("/fdm/trim/rudder",     FCS->GetDrCmd());
+        pitch_trim->setDoubleValue( FCS->GetPitchTrimCmd() );
+        throttle_trim->setDoubleValue( FCS->GetThrottleCmd(0) );
+        aileron_trim->setDoubleValue( FCS->GetDaCmd() );
+        rudder_trim->setDoubleValue( FCS->GetDrCmd() );
 
-    controls.set_elevator_trim(FCS->GetPitchTrimCmd());
-    controls.set_elevator(FCS->GetDeCmd());
-    controls.set_throttle(FGControls::ALL_ENGINES,
-                          FCS->GetThrottleCmd(0));
+        controls.set_elevator_trim(FCS->GetPitchTrimCmd());
+        controls.set_elevator(FCS->GetDeCmd());
+        controls.set_throttle(FGControls::ALL_ENGINES,
+                              FCS->GetThrottleCmd(0));
 
-    controls.set_aileron(FCS->GetDaCmd());
-    controls.set_rudder( FCS->GetDrCmd());
+        controls.set_aileron(FCS->GetDaCmd());
+        controls.set_rudder( FCS->GetDrCmd());
     
-    SG_LOG( SG_FLIGHT, SG_INFO, "  Trim complete" );
-    }  
+        SG_LOG( SG_FLIGHT, SG_INFO, "  Trim complete" );
+    }
   
     for( i=0; i<get_num_engines(); i++ ) {
       get_engine(i)->set_RPM( Propulsion->GetThruster(i)->GetRPM() );