]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/flight.cxx
Initial revision.
[flightgear.git] / src / FDM / flight.cxx
index 5c065ca21b2215ad1ad4a5ae9e2bef0e022e1974..e061e543286e2ef69006a203c07de4b3d30e0e64 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <stdio.h>
 
+#include <plib/sg.h>
+
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/sg_geodesy.hxx>
@@ -71,6 +73,14 @@ FGEngInterface::FGEngInterface() {
 FGEngInterface::~FGEngInterface(void) {
 }
 
+FGGearInterface::FGGearInterface(void) {
+    x=y=z=0.0;
+    brake=rolls=WoW=false;
+    position=1.0;
+}    
+
+FGGearInterface::~FGGearInterface() {
+}
 
 // Constructor
 FGInterface::FGInterface() {
@@ -78,7 +88,6 @@ FGInterface::FGInterface() {
 }  
 
 FGInterface::FGInterface( double dt ) {
-    
     _setup();
     delta_t = dt;
     remainder = elapsed = multi_loop = 0;
@@ -98,6 +107,9 @@ FGInterface::~FGInterface() {
 void
 FGInterface::_setup ()
 {
+    inited = false;
+    bound = false;
+
     init_vec( d_pilot_rp_body_v );
     init_vec( d_cg_rp_body_v );
     init_vec( f_body_total_v );
@@ -165,81 +177,101 @@ FGInterface::_setup ()
     altitude_agl=0;
 }
 
+void
+FGInterface::init () {}
 
 /**
  * Initialize the state of the FDM.
  *
  * Subclasses of FGInterface may do their own, additional initialization,
- * but normally they should invoke this method explicitly first as
- * FGInterface::init() to make sure the basic structures are set up
- * properly.
+ * but there is some that is common to all.  Normally, they should call
+ * this before they begin their own init to make sure the basic structures 
+ * are set up properly.
  */
 void
-FGInterface::init ()
+FGInterface::common_init ()
 {
-  SG_LOG(SG_FLIGHT, SG_INFO, "Start initializing FGInterface");
-
-  stamp();
-  set_remainder(0);
-
-                               // Set initial position
-  SG_LOG(SG_FLIGHT, SG_INFO, "...initializing position...");
-  set_Longitude(fgGetDouble("/position/longitude-deg") * SGD_DEGREES_TO_RADIANS);
-  set_Latitude(fgGetDouble("/position/latitude-deg") * SGD_DEGREES_TO_RADIANS);
-  double ground_elev_m = scenery.cur_elev + 1;
-  double ground_elev_ft = ground_elev_m * METERS_TO_FEET;
-  if (fgGetBool("/sim/startup/onground") ||
-      fgGetDouble("/position/altitude-ft") < ground_elev_ft)
-    fgSetDouble("/position/altitude-ft", ground_elev_ft);
-  set_Altitude(fgGetDouble("/position/altitude-ft"));
-
-                               // Set ground elevation
-  SG_LOG(SG_FLIGHT, SG_INFO,
-        "...initializing ground elevation to "
-        << ground_elev_ft << "ft...");
-  fgFDMSetGroundElevation("jsb", ground_elev_m);
-
-                               // Set sea-level radius
-  SG_LOG(SG_FLIGHT, SG_INFO, "...initializing sea-level radius...");
-  double sea_level_radius_meters;
-  double lat_geoc;
-  sgGeodToGeoc(get_Latitude(), get_Altitude(),
-              &sea_level_radius_meters, &lat_geoc);
-  set_Sea_level_radius(sea_level_radius_meters * SG_METER_TO_FEET);
-
-                               // Set initial velocities
-  SG_LOG(SG_FLIGHT, SG_INFO, "...initializing velocities...");
-  if (!fgHasNode("/sim/startup/speed-set")) {
-    set_V_calibrated_kts(0.0);
-  } else {
-    const string speedset = fgGetString("/sim/startup/speed-set");
-    if (speedset == "knots" || speedset == "KNOTS") {
-      set_V_calibrated_kts(fgGetDouble("/velocities/airspeed-kt"));
-    } else if (speedset == "mach" || speedset == "MACH") {
-      set_Mach_number(fgGetDouble("/velocities/mach"));
-    } else if (speedset == "UVW" || speedset == "uvw") {
-      set_Velocities_Wind_Body(fgGetDouble("/velocities/uBody-fps"),
-                              fgGetDouble("/velocities/vBody-fps"),
-                              fgGetDouble("/velocities/wBody-fps"));
-    } else if (speedset == "NED" || speedset == "ned") {
-      set_Velocities_Local(fgGetDouble("/velocities/speed-north-fps"),
-                          fgGetDouble("/velocities/speed-east-fps"),
-                          fgGetDouble("/velocities/speed-down-fps"));
+    SG_LOG( SG_FLIGHT, SG_INFO, "Start common FDM init" );
+
+    set_inited( true );
+
+    stamp();
+    set_remainder( 0 );
+
+    // Set initial position
+    SG_LOG( SG_FLIGHT, SG_INFO, "...initializing position..." );
+    set_Longitude( fgGetDouble("/position/longitude-deg")
+                   * SGD_DEGREES_TO_RADIANS );
+    set_Latitude( fgGetDouble("/position/latitude-deg")
+                  * SGD_DEGREES_TO_RADIANS );
+    double ground_elev_m = scenery.get_cur_elev();
+    double ground_elev_ft = ground_elev_m * SG_METER_TO_FEET;
+    if ( fgGetBool("/sim/startup/onground")
+         || fgGetDouble("/position/altitude-ft") < ground_elev_ft ) {
+        fgSetDouble("/position/altitude-ft", ground_elev_ft);
+    }
+    set_Altitude( fgGetDouble("/position/altitude-ft") );
+
+    // Set ground elevation
+    SG_LOG( SG_FLIGHT, SG_INFO,
+            "...initializing ground elevation to " << ground_elev_ft
+            << "ft..." );
+    SG_LOG( SG_FLIGHT, SG_INFO, "common_init(): set ground elevation "
+            << ground_elev_ft ); 
+    base_fdm_state.set_Runway_altitude( ground_elev_ft );
+    set_Runway_altitude( ground_elev_ft );
+
+    // Set sea-level radius
+    SG_LOG( SG_FLIGHT, SG_INFO, "...initializing sea-level radius..." );
+    SG_LOG( SG_FLIGHT, SG_INFO, " lat = "
+            << fgGetDouble("/position/latitude-deg")
+            << " alt = " << fgGetDouble("/position/altitude-ft") );
+    double sea_level_radius_meters;
+    double lat_geoc;
+    sgGeodToGeoc( fgGetDouble("/position/latitude-deg")
+                    * SGD_DEGREES_TO_RADIANS,
+                  fgGetDouble("/position/altitude-ft") * SG_FEET_TO_METER,
+                  &sea_level_radius_meters, &lat_geoc );
+    set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET );
+
+    // Set initial velocities
+    SG_LOG( SG_FLIGHT, SG_INFO, "...initializing velocities..." );
+    if ( !fgHasNode("/sim/startup/speed-set") ) {
+        set_V_calibrated_kts(0.0);
     } else {
-      SG_LOG(SG_FLIGHT, SG_ALERT,
-            "Unrecognized value for /sim/startup/speed-set: " << speedset);
-      set_V_calibrated_kts(0.0);
+        const string speedset = fgGetString("/sim/startup/speed-set");
+        if ( speedset == "knots" || speedset == "KNOTS" ) {
+            set_V_calibrated_kts( fgGetDouble("/velocities/airspeed-kt") );
+        } else if ( speedset == "mach" || speedset == "MACH" ) {
+            set_Mach_number( fgGetDouble("/velocities/mach") );
+        } else if ( speedset == "UVW" || speedset == "uvw" ) {
+            set_Velocities_Wind_Body(
+                                     fgGetDouble("/velocities/uBody-fps"),
+                                     fgGetDouble("/velocities/vBody-fps"),
+                                     fgGetDouble("/velocities/wBody-fps") );
+        } else if ( speedset == "NED" || speedset == "ned" ) {
+            set_Velocities_Local(
+                                 fgGetDouble("/velocities/speed-north-fps"),
+                                 fgGetDouble("/velocities/speed-east-fps"),
+                                 fgGetDouble("/velocities/speed-down-fps") );
+        } else {
+            SG_LOG( SG_FLIGHT, SG_ALERT,
+                    "Unrecognized value for /sim/startup/speed-set: "
+                    << speedset);
+            set_V_calibrated_kts( 0.0 );
+        }
     }
-  }
 
-                               // Set initial Euler angles
-  SG_LOG(SG_FLIGHT, SG_INFO, "...initializing Euler angles...");
-  set_Euler_Angles
-    (fgGetDouble("/orientation/roll-deg") * SGD_DEGREES_TO_RADIANS,
-     fgGetDouble("/orientation/pitch-deg") * SGD_DEGREES_TO_RADIANS,
-     fgGetDouble("/orientation/heading-deg") * SGD_DEGREES_TO_RADIANS);
+    // Set initial Euler angles
+    SG_LOG( SG_FLIGHT, SG_INFO, "...initializing Euler angles..." );
+    set_Euler_Angles( fgGetDouble("/orientation/roll-deg")
+                        * SGD_DEGREES_TO_RADIANS,
+                      fgGetDouble("/orientation/pitch-deg")
+                        * SGD_DEGREES_TO_RADIANS,
+                      fgGetDouble("/orientation/heading-deg")
+                        * SGD_DEGREES_TO_RADIANS );
 
-  SG_LOG(SG_FLIGHT, SG_INFO, "End initializing FGInterface");
+    SG_LOG( SG_FLIGHT, SG_INFO, "End common FDM init" );
 }
 
 
@@ -255,6 +287,8 @@ FGInterface::init ()
 void
 FGInterface::bind ()
 {
+  bound = true;
+
                                 // Time management (read-only)
   fgTie("/fdm/time/delta_t", this, 
        &FGInterface::get_delta_t); // read-only
@@ -301,7 +335,8 @@ FGInterface::bind ()
                                // Calibrated airspeed
   fgTie("/velocities/airspeed-kt", this,
        &FGInterface::get_V_calibrated_kts,
-       &FGInterface::set_V_calibrated_kts);
+       &FGInterface::set_V_calibrated_kts,
+       false);
 
                                // Local velocities
 //   fgTie("/velocities/speed-north-fps", this,
@@ -332,15 +367,18 @@ FGInterface::bind ()
                                // the NED problem is fixed.
   fgTie("/velocities/uBody-fps", this,
        &FGInterface::get_uBody,
-       &FGInterface::set_uBody);
+       &FGInterface::set_uBody,
+       false);
   fgSetArchivable("/velocities/uBody-fps");
   fgTie("/velocities/vBody-fps", this,
        &FGInterface::get_vBody,
-       &FGInterface::set_vBody);
+       &FGInterface::set_vBody,
+       false);
   fgSetArchivable("/velocities/vBody-fps");
   fgTie("/velocities/wBody-fps", this,
        &FGInterface::get_wBody,
-       &FGInterface::set_wBody);
+       &FGInterface::set_wBody,
+       false);
   fgSetArchivable("/velocities/wBody-fps");
 
                                // Climb and slip (read-only)
@@ -360,6 +398,8 @@ FGInterface::bind ()
 void
 FGInterface::unbind ()
 {
+  bound = false;
+
   fgUntie("/fdm/time/delta_t");
   fgUntie("/fdm/time/elapsed");
   fgUntie("/fdm/time/remainder");
@@ -367,9 +407,10 @@ FGInterface::unbind ()
   fgUntie("/position/latitude-deg");
   fgUntie("/position/longitude-deg");
   fgUntie("/position/altitude-ft");
-  fgUntie("/position/heading");
-  fgUntie("/position/pitch");
-  fgUntie("/position/roll");
+  fgUntie("/position/altitude-agl-ft");
+  fgUntie("/orientation/heading-deg");
+  fgUntie("/orientation/pitch-deg");
+  fgUntie("/orientation/roll-deg");
   fgUntie("/velocities/airspeed-kt");
   fgUntie("/velocities/speed-north-fps");
   fgUntie("/velocities/speed-east-fps");
@@ -401,6 +442,8 @@ bool FGInterface::update( int multi_loop ) {
 void FGInterface::_updatePosition( double lat_geoc, double lon, double alt ) {
     double lat_geod, tmp_alt, sl_radius1, sl_radius2, tmp_lat_geoc;
        
+    // cout << "starting sea level rad = " << get_Sea_level_radius() << endl;
+
     sgGeocToGeod( lat_geoc, ( get_Sea_level_radius() + alt ) * SG_FEET_TO_METER,
                  &lat_geod, &tmp_alt, &sl_radius1 );
     sgGeodToGeoc( lat_geod, alt * SG_FEET_TO_METER, &sl_radius2, &tmp_lat_geoc );
@@ -420,7 +463,7 @@ void FGInterface::_updatePosition( double lat_geoc, double lon, double alt ) {
     _set_Geodetic_Position( lat_geod, lon, alt );
        
     _set_Sea_level_radius( sl_radius2 * SG_METER_TO_FEET );
-    _set_Runway_altitude( scenery.cur_elev*METERS_TO_FEET ); 
+    _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET ); 
        
     _set_sin_lat_geocentric( lat_geoc );
     _set_cos_lat_geocentric( lat_geoc );
@@ -506,15 +549,6 @@ void fgFDMForceAltitude(const string &model, double alt_meters) {
 }
 
 
-// Set the local ground elevation
-void fgFDMSetGroundElevation(const string &model, double ground_meters) {
-    SG_LOG( SG_FLIGHT,SG_INFO, "fgFDMSetGroundElevation: "
-           << ground_meters*SG_METER_TO_FEET ); 
-    base_fdm_state.set_Runway_altitude( ground_meters * SG_METER_TO_FEET );
-    cur_fdm_state->set_Runway_altitude( ground_meters * SG_METER_TO_FEET );
-}
-
-
 // Positions
 void FGInterface::set_Latitude(double lat) { 
     geodetic_position_v[0] = lat;
@@ -705,4 +739,3 @@ void FGInterface::_busdump(void) {
 void fgToggleFDMdataLogging(void) {
   cur_fdm_state->ToggleDataLogging();
 }
-