]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/JSBSim.cxx
Fix stall widths for the "auxilliary" (reverse flow) stalls so they
[flightgear.git] / src / FDM / JSBSim / JSBSim.cxx
index 61b8fdec4eab8c8ca1c05d43a50086032acab678..d7ffc2ad553b90bfc073435c67030be55e394f2a 100644 (file)
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/structure/commands.hxx>
 
 #include <FDM/flight.hxx>
 
 #include <Aircraft/aircraft.hxx>
-#include <Controls/controls.hxx>
+#include <Aircraft/controls.hxx>
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 
 #include <FDM/JSBSim/FGFDMExec.h>
 #include <FDM/JSBSim/FGAircraft.h>
 #include <FDM/JSBSim/FGFCS.h>
-#include <FDM/JSBSim/FGPosition.h>
-#include <FDM/JSBSim/FGRotation.h>
+#include <FDM/JSBSim/FGPropagate.h>
 #include <FDM/JSBSim/FGState.h>
-#include <FDM/JSBSim/FGTranslation.h>
 #include <FDM/JSBSim/FGAuxiliary.h>
 #include <FDM/JSBSim/FGInitialCondition.h>
 #include <FDM/JSBSim/FGTrim.h>
 #include <FDM/JSBSim/FGPropertyManager.h>
 #include <FDM/JSBSim/FGEngine.h>
 #include <FDM/JSBSim/FGPiston.h>
-#include <FDM/JSBSim/FGSimTurbine.h>
+#include <FDM/JSBSim/FGGroundCallback.h>
+#include <FDM/JSBSim/FGTurbine.h>
 #include <FDM/JSBSim/FGRocket.h>
+#include <FDM/JSBSim/FGElectric.h>
 #include <FDM/JSBSim/FGNozzle.h>
 #include <FDM/JSBSim/FGPropeller.h>
 #include <FDM/JSBSim/FGRotor.h>
+#include <FDM/JSBSim/FGTank.h>
 #include "JSBSim.hxx"
 
 static inline double
@@ -76,6 +78,38 @@ FMAX (double a, double b)
   return a > b ? a : b;
 }
 
+class FGFSGroundCallback : public FGGroundCallback {
+public:
+  FGFSGroundCallback(FGInterface* ifc) : mInterface(ifc) {}
+  virtual ~FGFSGroundCallback() {}
+
+  /** Get the altitude above sea level depenent on the location. */
+  virtual double GetAltitude(const FGLocation& l) const {
+    double pt[3] = { SG_FEET_TO_METER*l(eX),
+                     SG_FEET_TO_METER*l(eY),
+                     SG_FEET_TO_METER*l(eZ) };
+    double lat, lon, alt;
+    sgCartToGeod( pt, &lat, &lon, &alt);
+    return alt * SG_METER_TO_FEET;
+  }
+
+  /** Compute the altitude above ground. */
+  virtual double GetAGLevel(double t, const FGLocation& l,
+                            FGLocation& cont,
+                            FGColumnVector3& n, FGColumnVector3& v) const {
+    double loc_cart[3] = { l(eX), l(eY), l(eZ) };
+    double contact[3], normal[3], vel[3], lc, ff, agl;
+    int groundtype;
+    mInterface->get_agl_ft(t, loc_cart, contact, normal, vel,
+                           &groundtype, &lc, &ff, &agl);
+    n = l.GetTec2l()*FGColumnVector3( normal[0], normal[1], normal[2] );
+    v = l.GetTec2l()*FGColumnVector3( vel[0], vel[1], vel[2] );
+    cont = FGColumnVector3( contact[0], contact[1], contact[2] );
+    return agl;
+  }
+private:
+  FGInterface* mInterface;
+};
 
 /******************************************************************************/
 
@@ -83,7 +117,6 @@ FGJSBsim::FGJSBsim( double dt )
   : FGInterface(dt)
 {
     bool result;
-
                                 // Set up the debugging level
                                 // FIXME: this will not respond to
                                 // runtime changes
@@ -109,17 +142,22 @@ FGJSBsim::FGJSBsim( double dt )
         }
     }
 
+    reset_on_crash = fgGetBool("/sim/reset-on-crash", false);
+    crashed = false;
+    fgSetBool("/sim/crashed", false);
+
     fdmex = new FGFDMExec( (FGPropertyManager*)globals->get_props() );
 
+    // Register ground callback.
+    fdmex->SetGroundCallback( new FGFSGroundCallback(this) );
+
     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();
+    Propagate        = fdmex->GetPropagate();
     Auxiliary       = fdmex->GetAuxiliary();
     Aerodynamics    = fdmex->GetAerodynamics();
     GroundReactions = fdmex->GetGroundReactions();
@@ -127,16 +165,15 @@ FGJSBsim::FGJSBsim( double dt )
     fgic=fdmex->GetIC();
     needTrim=true;
 
-    SGPath aircraft_path( globals->get_fg_root() );
-    aircraft_path.append( "Aircraft" );
+    SGPath aircraft_path( fgGetString("/sim/aircraft-dir") );
 
-    SGPath engine_path( globals->get_fg_root() );
+    SGPath engine_path( fgGetString("/sim/aircraft-dir") );
     engine_path.append( "Engine" );
     State->Setdt( dt );
 
     result = fdmex->LoadModel( aircraft_path.str(),
                                engine_path.str(),
-                               fgGetString("/sim/aero") );
+                               fgGetString("/sim/aero"), false );
 
     if (result) {
       SG_LOG( SG_FLIGHT, SG_INFO, "  loaded aero.");
@@ -157,9 +194,9 @@ FGJSBsim::FGJSBsim( double dt )
         SG_LOG( SG_FLIGHT, SG_ALERT, "num gear units = "
                 << GroundReactions->GetNumGearUnits() );
         SG_LOG( SG_FLIGHT, SG_ALERT, "This is a very bad thing because with 0 gear units, the ground trimming");
-         SG_LOG( SG_FLIGHT, SG_ALERT, "routine (coming up later in the code) will core dump.");
-         SG_LOG( SG_FLIGHT, SG_ALERT, "Halting the sim now, and hoping a solution will present itself soon!");
-         exit(-1);
+        SG_LOG( SG_FLIGHT, SG_ALERT, "routine (coming up later in the code) will core dump.");
+        SG_LOG( SG_FLIGHT, SG_ALERT, "Halting the sim now, and hoping a solution will present itself soon!");
+        exit(-1);
     }
 
     init_gear();
@@ -174,6 +211,7 @@ FGJSBsim::FGJSBsim( double dt )
         node->setDoubleValue("level-gal_us", Propulsion->GetTank(i)->GetContents() / 6.6);
       }
     }
+    Propulsion->SetFuelFreeze((fgGetNode("/sim/freeze/fuel",true))->getBoolValue());
 
     fgSetDouble("/fdm/trim/pitch-trim", FCS->GetPitchTrimCmd());
     fgSetDouble("/fdm/trim/throttle",   FCS->GetThrottleCmd(0));
@@ -225,8 +263,8 @@ FGJSBsim::FGJSBsim( double dt )
 
     for (unsigned int i = 0; i < Propulsion->GetNumEngines(); i++) {
       SGPropertyNode * node = fgGetNode("engines/engine", i, true);
-      Propulsion->GetThruster(i)->SetRPM(node->getDoubleValue("rpm") /
-                     Propulsion->GetThruster(i)->GetGearRatio());
+      Propulsion->GetEngine(i)->GetThruster()->SetRPM(node->getDoubleValue("rpm") /
+                     Propulsion->GetEngine(i)->GetThruster()->GetGearRatio());
     }
 }
 
@@ -282,6 +320,14 @@ void FGJSBsim::init()
      << ", " << fdmex->GetAtmosphere()->GetPressure()
      << ", " << fdmex->GetAtmosphere()->GetDensity() );
 
+    if (fgGetBool("/sim/presets/running")) {
+          for (int i=0; i < Propulsion->GetNumEngines(); i++) {
+            SGPropertyNode * node = fgGetNode("engines/engine", i, true);
+            node->setBoolValue("running", true);
+            Propulsion->GetEngine(i)->SetRunning(true);
+          }
+    }
+
     common_init();
 
     copy_to_JSBsim();
@@ -293,19 +339,19 @@ void FGJSBsim::init()
     switch(fgic->GetSpeedSet()) {
     case setned:
         SG_LOG(SG_FLIGHT,SG_INFO, "  Vn,Ve,Vd= "
-               << Position->GetVn() << ", "
-               << Position->GetVe() << ", "
-               << Position->GetVd() << " ft/s");
+               << Propagate->GetVel(eNorth) << ", "
+               << Propagate->GetVel(eEast) << ", "
+               << Propagate->GetVel(eDown) << " ft/s");
     break;
     case setuvw:
         SG_LOG(SG_FLIGHT,SG_INFO, "  U,V,W= "
-               << Translation->GetUVW(1) << ", "
-               << Translation->GetUVW(2) << ", "
-               << Translation->GetUVW(3) << " ft/s");
+               << Propagate->GetUVW(1) << ", "
+               << Propagate->GetUVW(2) << ", "
+               << Propagate->GetUVW(3) << " ft/s");
     break;
     case setmach:
         SG_LOG(SG_FLIGHT,SG_INFO, "  Mach: "
-               << Translation->GetMach() );
+               << Auxiliary->GetMach() );
     break;
     case setvc:
     default:
@@ -317,17 +363,17 @@ void FGJSBsim::init()
     stall_warning->setDoubleValue(0);
 
     SG_LOG( SG_FLIGHT, SG_INFO, "  Bank Angle: "
-            <<  Rotation->Getphi()*RADTODEG << " deg" );
+            << Propagate->GetEuler(ePhi)*RADTODEG << " deg" );
     SG_LOG( SG_FLIGHT, SG_INFO, "  Pitch Angle: "
-            << Rotation->Gettht()*RADTODEG << " deg" );
+            << Propagate->GetEuler(eTht)*RADTODEG << " deg" );
     SG_LOG( SG_FLIGHT, SG_INFO, "  True Heading: "
-            << Rotation->Getpsi()*RADTODEG << " deg" );
+            << Propagate->GetEuler(ePsi)*RADTODEG << " deg" );
     SG_LOG( SG_FLIGHT, SG_INFO, "  Latitude: "
-            << Position->GetLatitude() << " deg" );
+            << Propagate->GetLocation().GetLatitudeDeg() << " deg" );
     SG_LOG( SG_FLIGHT, SG_INFO, "  Longitude: "
-            << Position->GetLongitude() << " deg" );
+            << Propagate->GetLocation().GetLongitudeDeg() << " deg" );
     SG_LOG( SG_FLIGHT, SG_INFO, "  Altitude: "
-        << Position->Geth() << " feet" );
+            << Propagate->Geth() << " feet" );
     SG_LOG( SG_FLIGHT, SG_INFO, "  loaded initial conditions" );
 
     SG_LOG( SG_FLIGHT, SG_INFO, "  set dt" );
@@ -351,7 +397,41 @@ void FGJSBsim::update( double dt )
 
     int i;
 
-    // double save_alt = 0.0;
+    // Compute the radius of the aircraft. That is the radius of a ball
+    // where all gear units are in. At the moment it is at least 10ft ...
+    double acrad = 10.0;
+    int n_gears = GroundReactions->GetNumGearUnits();
+    for (i=0; i<n_gears; ++i) {
+      FGColumnVector3 bl = GroundReactions->GetGearUnit(i)->GetBodyLocation();
+      double r = bl.Magnitude();
+      if (acrad < r)
+        acrad = r;
+    }
+
+    // Compute the potential movement of this aircraft and query for the
+    // ground in this area.
+    double groundCacheRadius = acrad + 2*dt*Propagate->GetUVW().Magnitude();
+    double alt, slr, lat, lon;
+    FGColumnVector3 cart = Auxiliary->GetLocationVRP();
+    if ( needTrim && startup_trim->getBoolValue() ) {
+      alt = fgic->GetAltitudeFtIC();
+      slr = fgic->GetSeaLevelRadiusFtIC();
+      lat = fgic->GetLatitudeDegIC() * SGD_DEGREES_TO_RADIANS;
+      lon = fgic->GetLongitudeDegIC() * SGD_DEGREES_TO_RADIANS;
+      cart = FGLocation(lon, lat, alt+slr);
+    }
+    double cart_pos[3] = { cart(1), cart(2), cart(3) };
+    bool cache_ok = prepare_ground_cache_ft( State->Getsim_time(), cart_pos,
+                                             groundCacheRadius );
+    if (!cache_ok) {
+      SG_LOG(SG_FLIGHT, SG_WARN,
+             "FGInterface is being called without scenery below the aircraft!");
+      cout << "altitude         = " << alt << endl;
+      cout << "sea level radius = " << slr << endl;
+      cout << "latitude         = " << lat << endl;
+      cout << "longitude        = " << lon << endl;
+      //return;
+    }
 
     copy_to_JSBsim();
 
@@ -359,10 +439,18 @@ void FGJSBsim::update( double dt )
 
     if ( needTrim ) {
       if ( startup_trim->getBoolValue() ) {
+        double contact[3], dummy[3], lc, ff, agl;
+        int groundtype;
+        get_agl_ft(State->Getsim_time(), cart_pos, contact,
+                   dummy, dummy, &groundtype, &lc, &ff, &agl);
+        double terrain_alt = sqrt(contact[0]*contact[0] + contact[1]*contact[1]
+             + contact[2]*contact[2]) - fgic->GetSeaLevelRadiusFtIC();
+
         SG_LOG(SG_FLIGHT, SG_INFO,
           "Ready to trim, terrain altitude is: "
-            << cur_fdm_state->get_Runway_altitude() * SG_METER_TO_FEET );
-        fgic->SetTerrainAltitudeFtIC( cur_fdm_state->get_ground_elev_ft() );
+            << terrain_alt * SG_METER_TO_FEET );
+
+        fgic->SetTerrainAltitudeFtIC( terrain_alt );
         do_trim();
       } else {
         fdmex->RunIC();  //apply any changes made through the set_ functions
@@ -399,6 +487,12 @@ void FGJSBsim::update( double dt )
     // translate JSBsim back to FG structure so that the
     // autopilot (and the rest of the sim can use the updated values
     copy_from_JSBsim();
+
+    // crashed (altitude AGL < 0)
+    if (get_Altitude_AGL() < 0.0) {
+      crash_message = "Attempted to fly under ground.";
+      crash_handler();
+    }
 }
 
 /******************************************************************************/
@@ -418,7 +512,10 @@ bool FGJSBsim::copy_to_JSBsim()
     FCS->SetPitchTrimCmd( globals->get_controls()->get_elevator_trim() );
     FCS->SetDrCmd( -globals->get_controls()->get_rudder() );
     FCS->SetYawTrimCmd( -globals->get_controls()->get_rudder_trim() );
-    FCS->SetDfCmd(  globals->get_controls()->get_flaps() );
+    // FIXME: make that get_steering work
+//     FCS->SetDsCmd( globals->get_controls()->get_steering()/80.0 );
+    FCS->SetDsCmd( globals->get_controls()->get_rudder() );
+    FCS->SetDfCmd( globals->get_controls()->get_flaps() );
     FCS->SetDsbCmd( globals->get_controls()->get_speedbrake() );
     FCS->SetDspCmd( globals->get_controls()->get_spoilers() );
 
@@ -445,16 +542,16 @@ bool FGJSBsim::copy_to_JSBsim()
         eng->SetMagnetos( globals->get_controls()->get_magnetos(i) );
         break;
         } // end FGPiston code block
-      case FGEngine::etSimTurbine:
-        { // FGSimTurbine code block
-        FGSimTurbine* eng = (FGSimTurbine*)Propulsion->GetEngine(i);
+      case FGEngine::etTurbine:
+        { // FGTurbine code block
+        FGTurbine* eng = (FGTurbine*)Propulsion->GetEngine(i);
         eng->SetAugmentation( globals->get_controls()->get_augmentation(i) );
         eng->SetReverse( globals->get_controls()->get_reverser(i) );
         eng->SetInjection( globals->get_controls()->get_water_injection(i) );
         eng->SetCutoff( globals->get_controls()->get_cutoff(i) );
         eng->SetIgnition( globals->get_controls()->get_ignition(i) );
         break;
-        } // end FGSimTurbine code block
+        } // end FGTurbine code block
       case FGEngine::etRocket:
         { // FGRocket code block
         FGRocket* eng = (FGRocket*)Propulsion->GetEngine(i);
@@ -470,10 +567,8 @@ bool FGJSBsim::copy_to_JSBsim()
       } // end FGEngine code block
     }
 
-    _set_Runway_altitude( cur_fdm_state->get_Runway_altitude() );
-    Position->SetSeaLevelRadius( get_Sea_level_radius() );
-    Position->SetRunwayRadius( get_Runway_altitude()
-                               + get_Sea_level_radius() );
+
+    Propagate->SetSeaLevelRadius( get_Sea_level_radius() );
 
     Atmosphere->SetExTemperature(
                   9.0/5.0*(temperature->getDoubleValue()+273.15) );
@@ -500,6 +595,9 @@ bool FGJSBsim::copy_to_JSBsim()
       tank->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
 //       tank->SetContents(node->getDoubleValue("level-lb"));
     }
+    SGPropertyNode* node = fgGetNode("/systems/refuel", true);
+    Propulsion->SetRefuel(node->getDoubleValue("contact"));
+    Propulsion->SetFuelFreeze((fgGetNode("/sim/freeze/fuel",true))->getBoolValue());
 
     return true;
 }
@@ -538,72 +636,72 @@ bool FGJSBsim::copy_from_JSBsim()
 
     // Velocities
 
-    _set_Velocities_Local( Position->GetVn(),
-                           Position->GetVe(),
-                           Position->GetVd() );
+    _set_Velocities_Local( Propagate->GetVel(eNorth),
+                           Propagate->GetVel(eEast),
+                           Propagate->GetVel(eDown) );
 
-    _set_Velocities_Wind_Body( Translation->GetUVW(1),
-                               Translation->GetUVW(2),
-                               Translation->GetUVW(3) );
+    _set_Velocities_Wind_Body( Propagate->GetUVW(1),
+                               Propagate->GetUVW(2),
+                               Propagate->GetUVW(3) );
 
     // Make the HUD work ...
-    _set_Velocities_Ground( Position->GetVn(),
-                            Position->GetVe(),
-                            -Position->GetVd() );
+    _set_Velocities_Ground( Propagate->GetVel(eNorth),
+                            Propagate->GetVel(eEast),
+                            -Propagate->GetVel(eDown) );
 
-    _set_V_rel_wind( Translation->GetVt() );
+    _set_V_rel_wind( Auxiliary->GetVt() );
 
     _set_V_equiv_kts( Auxiliary->GetVequivalentKTS() );
 
     _set_V_calibrated_kts( Auxiliary->GetVcalibratedKTS() );
 
-    _set_V_ground_speed( Position->GetVground() );
-
-    _set_Omega_Body( Rotation->GetPQR(1),
-                     Rotation->GetPQR(2),
-                     Rotation->GetPQR(3) );
-
-    _set_Euler_Rates( Rotation->GetEulerRates(1),
-                      Rotation->GetEulerRates(2),
-                      Rotation->GetEulerRates(3) );
+    _set_V_ground_speed( Auxiliary->GetVground() );
 
-    _set_Geocentric_Rates(Position->GetLatitudeDot(),
-                          Position->GetLongitudeDot(),
-                          Position->Gethdot() );
+    _set_Omega_Body( Propagate->GetPQR(eP),
+                     Propagate->GetPQR(eQ),
+                     Propagate->GetPQR(eR) );
 
-    _set_Mach_number( Translation->GetMach() );
+    _set_Euler_Rates( Auxiliary->GetEulerRates(ePhi),
+                      Auxiliary->GetEulerRates(eTht),
+                      Auxiliary->GetEulerRates(ePsi) );
 
-    // Positions
-    _updateGeocentricPosition( Position->GetLatitude(),
-             Position->GetLongitude(),
-             Position->Geth() );
+    _set_Mach_number( Auxiliary->GetMach() );
 
     // Positions of Visual Reference Point
-/*
-    _updateGeocentricPosition( Position->GetLatitudeVRP(),
-             Position->GetLongitudeVRP(),
-             Position->GethVRP() );
-*/
-    _set_Altitude_AGL( Position->GetDistanceAGL() );
+    FGLocation l = Auxiliary->GetLocationVRP();
+    _updateGeocentricPosition( l.GetLatitude(), l.GetLongitude(),
+                               l.GetRadius() - get_Sea_level_radius() );
+
+    _set_Altitude_AGL( Propagate->GetDistanceAGL() );
+    {
+      double loc_cart[3] = { l(eX), l(eY), l(eZ) };
+      double contact[3], d[3], sd, t;
+      int id;
+      is_valid_m(&t, d, &sd);
+      get_agl_ft(t, loc_cart, contact, d, d, &id, &sd, &sd, &sd);
+      double rwrad
+        = FGColumnVector3( contact[0], contact[1], contact[2] ).Magnitude();
+      _set_Runway_altitude( rwrad - get_Sea_level_radius() );
+    }
 
-    _set_Euler_Angles( Rotation->Getphi(),
-                       Rotation->Gettht(),
-                       Rotation->Getpsi() );
+    _set_Euler_Angles( Propagate->GetEuler(ePhi),
+                       Propagate->GetEuler(eTht),
+                       Propagate->GetEuler(ePsi) );
 
-    _set_Alpha( Translation->Getalpha() );
-    _set_Beta( Translation->Getbeta() );
+    _set_Alpha( Auxiliary->Getalpha() );
+    _set_Beta( Auxiliary->Getbeta() );
 
 
-    _set_Gamma_vert_rad( Position->GetGamma() );
+    _set_Gamma_vert_rad( Auxiliary->GetGamma() );
 
     _set_Earth_position_angle( Auxiliary->GetEarthPositionAngle() );
 
-    _set_Climb_Rate( Position->Gethdot() );
-
+    _set_Climb_Rate( Propagate->Gethdot() );
 
+    const FGMatrix33& Tl2b = Propagate->GetTl2b();
     for ( i = 1; i <= 3; i++ ) {
         for ( j = 1; j <= 3; j++ ) {
-            _set_T_Local_to_Body( i, j, State->GetTl2b(i,j) );
+            _set_T_Local_to_Body( i, j, Tl2b(i,j) );
         }
     }
 
@@ -613,7 +711,7 @@ bool FGJSBsim::copy_from_JSBsim()
       char buf[30];
       sprintf(buf, "engines/engine[%d]/thruster", i);
       SGPropertyNode * tnode = fgGetNode(buf, true);
-      FGThruster * thruster = Propulsion->GetThruster(i);
+      FGThruster * thruster = Propulsion->GetEngine(i)->GetThruster();
 
       switch (Propulsion->GetEngine(i)->GetType()) {
       case FGEngine::etPiston:
@@ -632,9 +730,9 @@ bool FGJSBsim::copy_from_JSBsim()
         FGRocket* eng = (FGRocket*)Propulsion->GetEngine(i);
         } // end FGRocket code block
         break;
-      case FGEngine::etSimTurbine:
-        { // FGSimTurbine code block
-        FGSimTurbine* eng = (FGSimTurbine*)Propulsion->GetEngine(i);
+      case FGEngine::etTurbine:
+        { // FGTurbine code block
+        FGTurbine* eng = (FGTurbine*)Propulsion->GetEngine(i);
         node->setDoubleValue("n1", eng->GetN1());
         node->setDoubleValue("n2", eng->GetN2());
         node->setDoubleValue("egt_degf", 32 + eng->GetEGT()*9/5);
@@ -646,11 +744,18 @@ bool FGJSBsim::copy_from_JSBsim()
         node->setDoubleValue("oil-pressure-psi", eng->getOilPressure_psi());
         node->setBoolValue("reversed", eng->GetReversed());
         node->setBoolValue("cutoff", eng->GetCutoff());
+        node->setDoubleValue("epr", eng->GetEPR());
         globals->get_controls()->set_reverser(i, eng->GetReversed() );
         globals->get_controls()->set_cutoff(i, eng->GetCutoff() );
         globals->get_controls()->set_water_injection(i, eng->GetInjection() );
         globals->get_controls()->set_augmentation(i, eng->GetAugmentation() );
-        } // end FGSimTurbine code block
+        } // end FGTurbine code block
+        break;
+      case FGEngine::etElectric:
+        { // FGElectric code block
+        FGElectric* eng = (FGElectric*)Propulsion->GetEngine(i);
+        node->setDoubleValue("rpm", eng->getRPM());
+        } // end FGElectric code block
         break;
       }
 
@@ -692,17 +797,17 @@ bool FGJSBsim::copy_from_JSBsim()
 
     }
 
-    static const SGPropertyNode *fuel_freeze = fgGetNode("/sim/freeze/fuel");
-
     // Copy the fuel levels from JSBSim if fuel
     // freeze not enabled.
-    if ( ! fuel_freeze->getBoolValue() ) {
+    if ( ! Propulsion->GetFuelFreeze() ) {
       for (i = 0; i < Propulsion->GetNumTanks(); i++) {
         SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
-        double contents = Propulsion->GetTank(i)->GetContents();
+        FGTank* tank = Propulsion->GetTank(i);
+        double contents = tank->GetContents();
+        double temp = tank->GetTemperature_degC();
         node->setDoubleValue("level-gal_us", contents/6.6);
         node->setDoubleValue("level-lb", contents);
-        // node->setDoubleValue("temperature_degC",
+        if (temp != -9999.0) node->setDoubleValue("temperature_degC", temp);
       }
     }
 
@@ -764,8 +869,6 @@ void FGJSBsim::set_Latitude(double lat)
                       &sea_level_radius_meters, &lat_geoc );
     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET  );
-    _set_Runway_altitude( cur_fdm_state->get_Runway_altitude() );
-    fgic->SetTerrainAltitudeFtIC( cur_fdm_state->get_ground_elev_ft() );
     fgic->SetLatitudeRadIC( lat_geoc );
     needTrim=true;
 }
@@ -780,8 +883,6 @@ void FGJSBsim::set_Longitude(double lon)
 
     update_ic();
     fgic->SetLongitudeRadIC( lon );
-    _set_Runway_altitude( cur_fdm_state->get_Runway_altitude() );
-    fgic->SetTerrainAltitudeFtIC( cur_fdm_state->get_ground_elev_ft() );
     needTrim=true;
 }
 
@@ -802,8 +903,6 @@ void FGJSBsim::set_Altitude(double alt)
                   &sea_level_radius_meters, &lat_geoc);
     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
-    _set_Runway_altitude( cur_fdm_state->get_Runway_altitude() );
-    fgic->SetTerrainAltitudeFtIC( cur_fdm_state->get_ground_elev_ft() );
     SG_LOG(SG_FLIGHT, SG_INFO,
           "Terrain altitude: " << cur_fdm_state->get_Runway_altitude() * SG_METER_TO_FEET );
     fgic->SetLatitudeRadIC( lat_geoc );
@@ -915,17 +1014,18 @@ void FGJSBsim::init_gear(void )
     FGGroundReactions* gr=fdmex->GetGroundReactions();
     int Ngear=GroundReactions->GetNumGearUnits();
     for (int i=0;i<Ngear;i++) {
+      FGLGear *gear = gr->GetGearUnit(i);
       SGPropertyNode * node = fgGetNode("gear/gear", i, true);
-      node->setDoubleValue("xoffset-in",
-         gr->GetGearUnit(i)->GetBodyLocation()(1));
-      node->setDoubleValue("yoffset-in",
-         gr->GetGearUnit(i)->GetBodyLocation()(2));
-      node->setDoubleValue("zoffset-in",
-         gr->GetGearUnit(i)->GetBodyLocation()(3));
-      node->setBoolValue("wow", gr->GetGearUnit(i)->GetWOW());
-      node->setBoolValue("has-brake", gr->GetGearUnit(i)->GetBrakeGroup() > 0);
+      node->setDoubleValue("xoffset-in", gear->GetBodyLocation()(1));
+      node->setDoubleValue("yoffset-in", gear->GetBodyLocation()(2));
+      node->setDoubleValue("zoffset-in", gear->GetBodyLocation()(3));
+      node->setBoolValue("wow", gear->GetWOW());
+      node->setBoolValue("has-brake", gear->GetBrakeGroup() > 0);
       node->setDoubleValue("position-norm", FCS->GetGearPos());
-      node->setDoubleValue("tire-pressure-norm", gr->GetGearUnit(i)->GetTirePressure());
+      node->setDoubleValue("tire-pressure-norm", gear->GetTirePressure());
+      node->setDoubleValue("compression-norm", gear->GetCompLen());
+      if ( gear->GetSteerable() )
+        node->setDoubleValue("steering-norm", gear->GetSteerNorm());
     }
 }
 
@@ -934,10 +1034,14 @@ void FGJSBsim::update_gear(void)
     FGGroundReactions* gr=fdmex->GetGroundReactions();
     int Ngear=GroundReactions->GetNumGearUnits();
     for (int i=0;i<Ngear;i++) {
+      FGLGear *gear = gr->GetGearUnit(i);
       SGPropertyNode * node = fgGetNode("gear/gear", i, true);
-      node->getChild("wow", 0, true)->setBoolValue(gr->GetGearUnit(i)->GetWOW());
+      node->getChild("wow", 0, true)->setBoolValue( gear->GetWOW());
       node->getChild("position-norm", 0, true)->setDoubleValue(FCS->GetGearPos());
-      gr->GetGearUnit(i)->SetTirePressure(node->getDoubleValue("tire-pressure-norm"));
+      gear->SetTirePressure(node->getDoubleValue("tire-pressure-norm"));
+      node->setDoubleValue("compression-norm", gear->GetCompLen());
+      if ( gear->GetSteerable() )
+        node->setDoubleValue("steering-norm", gear->GetSteerNorm());
     }
 }
 
@@ -994,3 +1098,17 @@ void FGJSBsim::update_ic(void)
    }
 }
 
+void FGJSBsim::crash_handler(void)
+{
+   if (crashed) return;  // we already crashed
+   crashed = true;
+   fgSetBool("/sim/crashed", true);
+   SG_LOG( SG_FLIGHT, SG_WARN, "  Crash: " << crash_message );
+   if (reset_on_crash) {
+     SGPropertyNode* node = fgGetNode("/sim/presets", true);
+     globals->get_commands()->execute("old-reinit-dialog", node);   
+   } else {
+     fgSetBool("/sim/freeze/master", true);
+     fgSetBool("/sim/freeze/clock", true);
+   }
+}