]> git.mxchange.org Git - flightgear.git/commitdiff
Initial work on FDM shell, and removal of cur_fdm_state
authorJames Turner <jmt@Dulux.local>
Wed, 16 Jun 2010 07:31:59 +0000 (08:31 +0100)
committerJames Turner <zakalawe@mac.com>
Sat, 26 Jun 2010 09:31:22 +0000 (10:31 +0100)
46 files changed:
src/Aircraft/aircraft.cxx
src/Aircraft/aircraft.hxx
src/Aircraft/replay.cxx
src/Autopilot/route_mgr.cxx
src/Cockpit/cockpit.cxx
src/Cockpit/hud_rwy.cxx
src/Environment/environment_mgr.cxx
src/Environment/environment_mgr.hxx
src/FDM/ExternalPipe/ExternalPipe.cxx
src/FDM/ExternalPipe/ExternalPipe.hxx
src/FDM/JSBSim/JSBSim.cxx
src/FDM/fdm_shell.cxx [new file with mode: 0644]
src/FDM/fdm_shell.hxx [new file with mode: 0644]
src/FDM/flight.cxx
src/FDM/flight.hxx
src/FDM/flightProperties.cxx [new file with mode: 0644]
src/FDM/flightProperties.hxx [new file with mode: 0644]
src/Instrumentation/HUD/HUD_runway.cxx
src/Main/fg_commands.cxx
src/Main/fg_init.cxx
src/Main/fg_props.cxx
src/Main/main.cxx
src/Main/renderer.cxx
src/Network/AV400.cxx
src/Network/AV400.hxx
src/Network/AV400Sim.cxx
src/Network/AV400Sim.hxx
src/Network/atlas.cxx
src/Network/atlas.hxx
src/Network/garmin.cxx
src/Network/garmin.hxx
src/Network/multiplay.cxx
src/Network/native.cxx
src/Network/native.hxx
src/Network/native_ctrls.cxx
src/Network/native_fdm.cxx
src/Network/native_fdm.hxx
src/Network/native_gui.cxx
src/Network/native_gui.hxx
src/Network/nmea.cxx
src/Network/nmea.hxx
src/Network/opengc.cxx
src/Network/opengc.hxx
src/Network/pve.cxx
src/Network/ray.cxx
src/Network/rul.cxx

index c3514e29afcc75d02f89075efce8e14a4b170c37..91e93b276ba44de7105bfd356dc58572d5b24955 100644 (file)
@@ -44,6 +44,7 @@
 #include <Cockpit/hud.hxx>
 #include <Cockpit/panel_io.hxx>
 #include <Model/acmodel.hxx>
+#include <FDM/flightProperties.hxx>
 
 #include "aircraft.hxx"
 
@@ -57,29 +58,26 @@ fgAIRCRAFT current_aircraft;
 void fgAircraftInit( void ) {
     SG_LOG( SG_AIRCRAFT, SG_INFO, "Initializing Aircraft structure" );
 
-    current_aircraft.fdm_state   = cur_fdm_state;
     current_aircraft.controls = globals->get_controls();
 }
 
 
 // Display various parameters to stdout
 void fgAircraftOutputCurrent(fgAIRCRAFT *a) {
-    FGInterface *f;
-
-    f = a->fdm_state;
+    FlightProperties f;
 
     SG_LOG( SG_FLIGHT, SG_DEBUG,
             "Pos = ("
-           << (f->get_Longitude() * 3600.0 * SGD_RADIANS_TO_DEGREES) << "," 
-           << (f->get_Latitude()  * 3600.0 * SGD_RADIANS_TO_DEGREES) << ","
-           << f->get_Altitude() 
+           << (f.get_Longitude() * 3600.0 * SGD_RADIANS_TO_DEGREES) << "," 
+           << (f.get_Latitude()  * 3600.0 * SGD_RADIANS_TO_DEGREES) << ","
+           << f.get_Altitude() 
            << ")  (Phi,Theta,Psi)=("
-           << f->get_Phi() << "," 
-           << f->get_Theta() << "," 
-           << f->get_Psi() << ")" );
+           << f.get_Phi() << "," 
+           << f.get_Theta() << "," 
+           << f.get_Psi() << ")" );
 
     SG_LOG( SG_FLIGHT, SG_DEBUG,
-           "Kts = " << f->get_V_equiv_kts() 
+           "Kts = " << f.get_V_equiv_kts() 
            << "  Elev = " << globals->get_controls()->get_elevator() 
            << "  Aileron = " << globals->get_controls()->get_aileron() 
            << "  Rudder = " << globals->get_controls()->get_rudder() 
@@ -155,8 +153,8 @@ fgLoadAircraft (const SGPropertyNode * arg)
 
     // TODO:
     //    remove electrical system
-    cur_fdm_state->unbind();
-
+    globals->get_subsystem("flight")->unbind();
+    
     // Save the selected aircraft model since restoreInitialState
     // will obverwrite it.
     //
index 95763b017c0f3326b904ea0c5b08a0632ad3fad8..f28bb4c22275b19008eaebb39423c4b8c9a08b5c 100644 (file)
 #ifndef _AIRCRAFT_HXX
 #define _AIRCRAFT_HXX
                                  
-class FGInterface;
 class FGControls;
 class SGPropertyNode;
 
 // Define a structure containing all the parameters for an aircraft
 typedef struct{
-    FGInterface *fdm_state;
     FGControls *controls;
 } fgAIRCRAFT ;
 
index 21c4a1d44bfd524b0af273b0f22ba67fef0e3bcd..d36275e38cff73bf7808b249c260422292c27cd5 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <simgear/constants.h>
 
-#include <FDM/flight.hxx>
 #include <Main/fg_props.hxx>
 #include <Network/native_ctrls.hxx>
 #include <Network/native_fdm.hxx>
@@ -164,9 +163,10 @@ void FGReplay::update( double dt ) {
     //FGProps2NetFDM( &f, false );
 
     // sanity check, don't collect data if FDM data isn't good
-    if ( !cur_fdm_state->get_inited() ) {
+    if (!fgGetBool("/sim/signals/fdm-initialized", false)) {
         return;
     }
+    
     //FGNetCtrls c;
     //FGProps2NetCtrls( &c, false, false );
     //stamp("point_04ba");
index 967ca992a240e2f8d60550a2383f303f6d4f85a2..07059cc16113c2a39d0729d075207eedf1930862 100644 (file)
 #include "Airports/simple.hxx"
 #include "Airports/runways.hxx"
 
-#include "FDM/flight.hxx" // for getting ground speed
-
 #define RM "/autopilot/route-manager/"
 
-static double get_ground_speed() {
-  // starts in ft/s so we convert to kts
-  static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
-
-  double ft_s = cur_fdm_state->get_V_ground_speed()
-      * speedup_node->getIntValue();
-  double kts = ft_s * SG_FEET_TO_METER * 3600 * SG_METER_TO_NM;
-  return kts;
-}
-
 FGRouteMgr::FGRouteMgr() :
     _route( new SGRoute ),
     input(fgGetNode( RM "input", true )),
@@ -212,7 +200,7 @@ void FGRouteMgr::update( double dt ) {
       return;
     }
     
-    double groundSpeed = get_ground_speed();
+    double groundSpeed = fgGetDouble("/velocities/groundspeed-kt", 0.0);
     if (airborne->getBoolValue()) {
       time_t now = time(NULL);
       elapsedFlightTime->setDoubleValue(difftime(now, _takeoffTime));
@@ -265,14 +253,14 @@ void FGRouteMgr::update( double dt ) {
 
 
 void FGRouteMgr::setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance) {
-    double speed = get_ground_speed();
+    double speed =fgGetDouble("/velocities/groundspeed-kt", 0.0);
     if (speed < 1.0) {
       aProp->setStringValue("--:--");
       return;
     }
   
     char eta_str[64];
-    double eta = aDistance * SG_METER_TO_NM / get_ground_speed();
+    double eta = aDistance * SG_METER_TO_NM / speed;
     if ( eta >= 100.0 ) { 
         eta = 99.999; // clamp
     }
index 0414a0f6a0ae4fb0a15f3cde660c52bde07fbed4..9e1457220f3753544aeee1dd8aa4e72eb4d7a8f8 100644 (file)
@@ -51,6 +51,9 @@
 #include "cockpit.hxx"
 #include "hud.hxx"
 
+// ugly hack, make the raw FDM available here, to support some
+// legacy accessor functions
+extern FGInterface* evil_global_fdm_state;
 
 // The following routines obtain information concerntin the aircraft's
 // current state and return it to calling instrument display routines.
 
 float get_latitude( void )
 {
-    return current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
+    return fgGetDouble("/position/latitude-deg");
 }
 
 float get_lat_min( void )
 {
     double a, d;
 
-    a = current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
+    a = fgGetDouble("/position/latitude-deg");
     if (a < 0.0) {
         a = -a;
     }
@@ -79,7 +82,7 @@ float get_lat_min( void )
 
 float get_longitude( void )
 {
-    return current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
+    return fgGetDouble("/position/longitude-deg");
 }
 
 
@@ -99,7 +102,7 @@ get_formated_gmt_time( void )
 float get_long_min( void )
 {
     double  a, d;
-    a = current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
+    a = fgGetDouble("/position/longitude-deg");
     if (a < 0.0) {
         a = -a;
     }
@@ -139,7 +142,7 @@ float get_speed( void )
 {
     static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
 
-    float speed = current_aircraft.fdm_state->get_V_calibrated_kts()
+    float speed = fgGetDouble("/velocities/airspeed-kt")
         * speedup_node->getIntValue();
 
     return speed;
@@ -147,27 +150,27 @@ float get_speed( void )
 
 float get_mach(void)
 {
-    return current_aircraft.fdm_state->get_Mach_number();
+    return fgGetDouble("/velocities/mach");
 }
 
 float get_aoa( void )
 {
-    return current_aircraft.fdm_state->get_Alpha() * SGD_RADIANS_TO_DEGREES;
+    return fgGetDouble("/orientation/alpha-deg");
 }
 
 float get_roll( void )
 {
-    return current_aircraft.fdm_state->get_Phi();
+    return fgGetDouble("/orientation/roll-deg") * SG_DEGREES_TO_RADIANS;
 }
 
 float get_pitch( void )
 {
-    return current_aircraft.fdm_state->get_Theta();
+    return fgGetDouble("/orientation/pitch-deg") * SG_DEGREES_TO_RADIANS;
 }
 
 float get_heading( void )
 {
-    return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES;
+    return fgGetDouble("/orientation/heading-deg");
 }
 
 float get_altitude( void )
@@ -175,16 +178,11 @@ float get_altitude( void )
     static const SGPropertyNode *startup_units_node
         = fgGetNode("/sim/startup/units");
 
-    float altitude;
-
     if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
-        altitude = current_aircraft.fdm_state->get_Altitude();
+        return fgGetDouble("/position/altitude-ft");
     } else {
-        altitude = (current_aircraft.fdm_state->get_Altitude()
-                    * SG_FEET_TO_METER);
+        return fgGetDouble("/position/altitude-ft") * SG_FEET_TO_METER;
     }
-
-    return altitude;
 }
 
 float get_agl( void )
@@ -192,22 +190,16 @@ float get_agl( void )
     static const SGPropertyNode *startup_units_node
         = fgGetNode("/sim/startup/units");
 
-    float agl;
-
     if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
-        agl = (current_aircraft.fdm_state->get_Altitude()
-               - current_aircraft.fdm_state->get_Runway_altitude());
+        return fgGetDouble("/position/altitude-agl-ft");
     } else {
-        agl = (current_aircraft.fdm_state->get_Altitude()
-               - current_aircraft.fdm_state->get_Runway_altitude()) * SG_FEET_TO_METER;
+        return fgGetDouble("/position/altitude-agl-ft") * SG_FEET_TO_METER;
     }
-
-    return agl;
 }
 
 float get_sideslip( void )
 {
-    return current_aircraft.fdm_state->get_Beta();
+    return fgGetDouble("/orientation/side-slip-rad");
 }
 
 float get_frame_rate( void )
@@ -246,11 +238,11 @@ float get_climb_rate( void )
     static const SGPropertyNode *startup_units_node
         = fgGetNode("/sim/startup/units");
 
-    float climb_rate;
+    float climb_rate = fgGetDouble("/velocities/vertical-speed-fps", 0.0);
     if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
-        climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
+        climb_rate *= 60.0;
     } else {
-        climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * SG_FEET_TO_METER * 60.0;
+        climb_rate *= SG_FEET_TO_METER * 60.0;
     }
 
     return climb_rate;
@@ -259,15 +251,8 @@ float get_climb_rate( void )
 
 float get_view_direction( void )
 {
-    double view_off = SGD_2PI - globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
-    double view = ( current_aircraft.fdm_state->get_Psi() + view_off)
-        * SGD_RADIANS_TO_DEGREES;
-
-    if (view > 360.)
-        view -= 360.;
-    else if (view<0.)
-        view += 360.;
-
+    double view_off = 360.0 - globals->get_current_view()->getHeadingOffset_deg();
+    double view = SGMiscd::normalizeAngle(fgGetDouble("/orientation/heading-deg") + view_off);
     return view;
 }
 
@@ -286,7 +271,7 @@ float get_Vx   ( void )
 {
     // Curt dont comment this and return zero. - Ranga
     // Please remove comments from get_V_..() function in flight.hxx
-    float Vxx = current_aircraft.fdm_state->get_V_north_rel_ground();
+    float Vxx = evil_global_fdm_state->get_V_north_rel_ground();
     return Vxx;
 }
 
@@ -294,7 +279,7 @@ float get_Vy   ( void )
 {
     // Curt dont comment this and return zero. - Ranga
     // Please remove comments from get_V_..() function in flight.hxx
-    float Vyy = current_aircraft.fdm_state->get_V_east_rel_ground();
+    float Vyy = evil_global_fdm_state->get_V_east_rel_ground();
     return Vyy;
 }
 
@@ -302,212 +287,212 @@ float get_Vz   ( void )
 {
     // Curt dont comment this and return zero. - Ranga
     // Please remove comments from get_V_..() function in flight.hxx
-    float Vzz = current_aircraft.fdm_state->get_V_down_rel_ground();
+    float Vzz = evil_global_fdm_state->get_V_down_rel_ground();
     return Vzz;
 }
 
 float get_Ax   ( void )
 {
-    float Ax = current_aircraft.fdm_state->get_V_dot_north();
+    float Ax = evil_global_fdm_state->get_V_dot_north();
     return Ax;
 }
 
 float get_Ay   ( void )
 {
-    float Ay = current_aircraft.fdm_state->get_V_dot_east();
+    float Ay = evil_global_fdm_state->get_V_dot_east();
     return Ay;
 }
 
 float get_Az   ( void )
 {
-    float Az = current_aircraft.fdm_state->get_V_dot_down();
+    float Az = evil_global_fdm_state->get_V_dot_down();
     return Az;
 }
 
 float get_anzg   ( void )
 {
-    float anzg = current_aircraft.fdm_state->get_N_Z_cg();
+    float anzg = evil_global_fdm_state->get_N_Z_cg();
     return anzg;
 }
 
 #ifdef ENABLE_SP_FDM
 int get_iaux1 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_iaux(1);
 }
 
 int get_iaux2 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_iaux(2);
 }
 
 int get_iaux3 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_iaux(3);
 }
 
 int get_iaux4 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_iaux(4);
 }
 
 int get_iaux5 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_iaux(5);
 }
 
 int get_iaux6 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_iaux(6);
 }
 
 int get_iaux7 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_iaux(7);
 }
 
 int get_iaux8 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_iaux(8);
 }
 
 int get_iaux9 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_iaux(9);
 }
 
 int get_iaux10 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_iaux(10);
 }
 
 int get_iaux11 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_iaux(11);
 }
 
 int get_iaux12 (void)
 {
-     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+     FGADA *fdm = (FGADA *)evil_global_fdm_state;
      return fdm->get_iaux(12);
 }
 
 float get_aux1 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_daux(1);
 }
 
 float get_aux2 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_daux(2);
 }
 
 float get_aux3 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_daux(3);
 }
 
 float get_aux4 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_daux(4);
 }
 
 float get_aux5 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_daux(5);
 }
 
 float get_aux6 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_daux(6);
 }
 
 float get_aux7 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_daux(7);
 }
 
 float get_aux8 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_daux(8);
 }
 
 float get_aux9 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_faux(1);
 }
 
 float get_aux10 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_faux(2);
 }
 
 float get_aux11 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_faux(3);
 }
 
 float get_aux12 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_faux(4);
 }
 
 float get_aux13 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_faux(5);
 }
 
 float get_aux14 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_faux(6);
 }
 
 float get_aux15 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_faux(7);
 }
 
 float get_aux16 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_faux(8);
 }
 
 float get_aux17 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_faux(9);
 }
 
 float get_aux18 (void)
 {
-    FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
+    FGADA *fdm = (FGADA *)evil_global_fdm_state;
     return fdm->get_faux(10);
 }
 #endif
index 0f7866619ac7607efc9212312b53aa2c12af93c4..b920bcfc8ebb999fca2658d2e433ce8743961a88 100644 (file)
@@ -185,7 +185,7 @@ FGRunway* runway_instr::get_active_runway()
 
 void runway_instr::get_rwy_points(sgdVec3 *points3d)
 {
-    double alt = current_aircraft.fdm_state->get_Runway_altitude() * SG_FEET_TO_METER;
+    double alt = runway->geod().getElevationM();
     double length = runway->lengthM() * 0.5;
     double width = runway->widthM() * 0.5;
     double frontLat = 0.0, frontLon = 0.0, backLat = 0.0, backLon = 0.0, az = 0.0, tempLat = 0.0, tempLon = 0.0;
index acf20b861ed86f18059c2991cf8401dc874b84a6..a5d76ecfcbe89b4473ecca2b1cf09a5fffab9067 100644 (file)
@@ -90,7 +90,7 @@ FGEnvironmentMgr::init ()
 {
   SG_LOG( SG_GENERAL, SG_INFO, "Initializing environment subsystem");
   SGSubsystemGroup::init();
-  _update_fdm();
+  //_update_fdm();
 }
 
 void
@@ -98,7 +98,7 @@ FGEnvironmentMgr::reinit ()
 {
   SG_LOG( SG_GENERAL, SG_INFO, "Reinitializing environment subsystem");
   SGSubsystemGroup::reinit();
-  _update_fdm();
+  //_update_fdm();
 }
 
 void
@@ -290,20 +290,13 @@ void
 FGEnvironmentMgr::update (double dt)
 {
   SGSubsystemGroup::update(dt);
-
-                               // FIXME: the FDMs should update themselves
-  current_aircraft.fdm_state
-    ->set_Velocities_Local_Airmass(_environment->get_wind_from_north_fps(),
-                                  _environment->get_wind_from_east_fps(),
-                                  _environment->get_wind_from_down_fps());
+  
   _environment->set_elevation_ft(fgGetDouble("/position/altitude-ft"));
   _environment->set_local_weather_lift_fps(fgGetDouble("/local-weather/current/thermal-lift"));
   osg::Vec3 windVec(-_environment->get_wind_from_north_fps(),
                     -_environment->get_wind_from_east_fps(),
                     _environment->get_wind_from_down_fps());
   simgear::Particles::setWindVector(windVec * SG_FEET_TO_METER);
-
-  _update_fdm();
 }
 
 FGEnvironment
@@ -335,27 +328,6 @@ FGEnvironmentMgr::getEnvironment(const SGGeod& aPos) const
 
 }
 
-void
-FGEnvironmentMgr::_update_fdm () const
-{
-  //
-  // Pass atmosphere on to FDM
-  // FIXME: have FDMs read properties directly.
-  //
-  if (fgGetBool("/environment/params/control-fdm-atmosphere")) {
-                               // convert from Rankine to Celsius
-    cur_fdm_state
-      ->set_Static_temperature((9.0/5.0)
-                              * (_environment->get_temperature_degc() + 273.15));
-                               // convert from inHG to PSF
-    cur_fdm_state
-      ->set_Static_pressure(_environment->get_pressure_inhg() * 70.726566);
-                               // keep in slugs/ft^3
-    cur_fdm_state
-      ->set_Density(_environment->get_density_slugft3());
-  }
-}
-
 double
 FGEnvironmentMgr::get_cloud_layer_span_m (int index) const
 {
index ffd75346345067f9d22c353614bea1f1694e8a8e..490340c4aec2a4988313b2c0104b9912fcda734d 100644 (file)
@@ -76,8 +76,6 @@ public:
   virtual FGEnvironment getEnvironment(const SGGeod& aPos) const;
 private:
 
-  void _update_fdm () const;
-
   double get_cloud_layer_span_m (int index) const;
   void set_cloud_layer_span_m (int index, double span_m);
   double get_cloud_layer_elevation_ft (int index) const;
index 2be480971a4bc00768aff3a98f0b5f3aac287ad8..f3c7f291276383a10e2de8126276b2712f82edd8 100644 (file)
@@ -428,47 +428,48 @@ void FGExternalPipe::update_binary( double dt ) {
 
 
 // Process remote FDM "set" commands
-static void process_set_command( const string_list &tokens ) {
+
+void FGExternalPipe::process_set_command( const string_list &tokens ) {
     if ( tokens[1] == "geodetic_position" ) {
         double lat_rad = atof( tokens[2].c_str() );
         double lon_rad = atof( tokens[3].c_str() );
         double alt_m   = atof( tokens[4].c_str() );
-        cur_fdm_state->_updateGeodeticPosition( lat_rad, lon_rad,
+        _updateGeodeticPosition( lat_rad, lon_rad,
                                                 alt_m * SG_METER_TO_FEET );
 
-        double agl_m = alt_m - cur_fdm_state->get_Runway_altitude_m();
-        cur_fdm_state->_set_Altitude_AGL( agl_m * SG_METER_TO_FEET );
+        double agl_m = alt_m - get_Runway_altitude_m();
+        _set_Altitude_AGL( agl_m * SG_METER_TO_FEET );
     } else if ( tokens[1] == "euler_angles" ) {
         double phi_rad   = atof( tokens[2].c_str() );
         double theta_rad = atof( tokens[3].c_str() );
         double psi_rad   = atof( tokens[4].c_str() );
-        cur_fdm_state->_set_Euler_Angles( phi_rad, theta_rad, psi_rad );
+        _set_Euler_Angles( phi_rad, theta_rad, psi_rad );
     } else if ( tokens[1] == "euler_rates" ) {
         double phidot   = atof( tokens[2].c_str() );
         double thetadot = atof( tokens[3].c_str() );
         double psidot   = atof( tokens[4].c_str() );
-        cur_fdm_state->_set_Euler_Rates( phidot, thetadot, psidot );
+        _set_Euler_Rates( phidot, thetadot, psidot );
     } else if ( tokens[1] == "ned" ) {
        double north_fps = atof( tokens[2].c_str() );
        double east_fps = atof( tokens[3].c_str() );
        double down_fps = atof( tokens[4].c_str() );
-       cur_fdm_state->_set_Velocities_Local( north_fps, east_fps, down_fps );
+       _set_Velocities_Local( north_fps, east_fps, down_fps );
     } else if ( tokens[1] == "alpha" ) {
-        cur_fdm_state->_set_Alpha( atof(tokens[2].c_str()) );
+        _set_Alpha( atof(tokens[2].c_str()) );
     } else if ( tokens[1] == "beta" ) {
-        cur_fdm_state->_set_Beta( atof(tokens[2].c_str()) );
+        _set_Beta( atof(tokens[2].c_str()) );
 
 #if 0
-    cur_fdm_state->_set_V_calibrated_kts( net->vcas );
-    cur_fdm_state->_set_Climb_Rate( net->climb_rate );
-    cur_fdm_state->_set_Velocities_Local( net->v_north,
+    _set_V_calibrated_kts( net->vcas );
+    _set_Climb_Rate( net->climb_rate );
+    _set_Velocities_Local( net->v_north,
                                           net->v_east,
                                           net->v_down );
-    cur_fdm_state->_set_Velocities_Wind_Body( net->v_wind_body_north,
+    _set_Velocities_Wind_Body( net->v_wind_body_north,
                                               net->v_wind_body_east,
                                               net->v_wind_body_down );
 
-    cur_fdm_state->_set_Accels_Pilot_Body( net->A_X_pilot,
+    _set_Accels_Pilot_Body( net->A_X_pilot,
                                            net->A_Y_pilot,
                                            net->A_Z_pilot );
 #endif
index d5e03967b11adc2248466153ce254726025ee84e..866967c12e3531aed284f0d47323be7bb5ca6873 100644 (file)
@@ -62,6 +62,7 @@ private:
     void update_binary( double dt );
     void update_property( double dt );
 
+    void process_set_command( const string_list &tokens );
 public:
 
     // Constructor
index 04a2e70bb0f6bcbde1e30a558f9f21db82ff92dc..e9732f772a6c7e66940de058e435adc6d412e5f9 100644 (file)
@@ -977,7 +977,7 @@ void FGJSBsim::set_Altitude(double alt)
     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
     SG_LOG(SG_FLIGHT, SG_INFO,
-          "Terrain elevation: " << cur_fdm_state->get_Runway_altitude() * SG_METER_TO_FEET );
+          "Terrain elevation: " << FGInterface::get_Runway_altitude() * SG_METER_TO_FEET );
     fgic->SetLatitudeRadIC( lat_geoc );
     fgic->SetAltitudeASLFtIC(alt);
     needTrim=true;
diff --git a/src/FDM/fdm_shell.cxx b/src/FDM/fdm_shell.cxx
new file mode 100644 (file)
index 0000000..6c2d095
--- /dev/null
@@ -0,0 +1,242 @@
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <simgear/structure/exception.hxx>
+
+#include <FDM/fdm_shell.hxx>
+#include <FDM/flight.hxx>
+#include <Aircraft/replay.hxx>
+#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
+#include <Scenery/scenery.hxx>
+
+// all the FDMs, since we are the factory method
+#if ENABLE_SP_FDM
+#include <FDM/SP/ADA.hxx>
+#include <FDM/SP/ACMS.hxx>
+#include <FDM/SP/MagicCarpet.hxx>
+#include <FDM/SP/Balloon.h>
+#endif
+#include <FDM/ExternalNet/ExternalNet.hxx>
+#include <FDM/ExternalPipe/ExternalPipe.hxx>
+#include <FDM/JSBSim/JSBSim.hxx>
+#include <FDM/LaRCsim/LaRCsim.hxx>
+#include <FDM/UFO.hxx>
+#include <FDM/NullFDM.hxx>
+#include <FDM/YASim/YASim.hxx>
+
+/*
+ * Evil global variable required by Network/FGNative,
+ * see that class for more information
+ */
+FGInterface* evil_global_fdm_state = NULL;
+
+FDMShell::FDMShell() :
+  _impl(NULL),
+  _dataLogging(false)
+{
+}
+
+FDMShell::~FDMShell()
+{
+  delete _impl;
+}
+
+void FDMShell::init()
+{
+  _props = globals->get_props();
+  createImplementation();
+}
+
+void FDMShell::reinit()
+{
+  if (_impl) {
+    fgSetBool("/sim/signals/fdm-initialized", false);
+    evil_global_fdm_state = NULL;
+    _impl->unbind();
+    delete _impl;
+    _impl = NULL;
+  }
+  
+  init();
+}
+
+void FDMShell::bind()
+{
+  if (_impl && _impl->get_inited()) {
+    if (_impl->get_bound()) {
+      throw sg_exception("FDMShell::bind of bound FGInterface impl");
+    }
+    
+    _impl->bind();
+  }
+}
+
+void FDMShell::unbind()
+{
+  _impl->unbind();
+}
+
+void FDMShell::update(double dt)
+{
+  if (!_impl) {
+    return;
+  }
+  
+  if (!_impl->get_inited()) {
+    // Check for scenery around the aircraft.
+    double lon = fgGetDouble("/sim/presets/longitude-deg");
+    double lat = fgGetDouble("/sim/presets/latitude-deg");
+        
+    double range = 1000.0; // in metres
+    SGGeod geod = SGGeod::fromDeg(lon, lat);
+    if (globals->get_scenery()->scenery_available(geod, range)) {
+        SG_LOG(SG_FLIGHT, SG_INFO, "Scenery loaded, will init FDM");
+        _impl->init();
+        if (_impl->get_bound()) {
+          _impl->unbind();
+        }
+        _impl->bind();
+        
+        evil_global_fdm_state = _impl;
+        fgSetBool("/sim/signals/fdm-initialized", true);
+    }
+  }
+
+  if (!_impl->get_inited()) {
+    return; // still waiting
+  }
+
+// pull environmental data in, since the FDMs are lazy
+  _impl->set_Velocities_Local_Airmass(
+      _props->getDoubleValue("environment/wind-from-north-fps", 0.0),
+                       _props->getDoubleValue("environment/wind-from-east-fps", 0.0),
+                       _props->getDoubleValue("environment/wind-from-down-fps", 0.0));
+
+  if (_props->getBoolValue("environment/params/control-fdm-atmosphere")) {
+    // convert from Rankine to Celsius
+    double tempDegC = _props->getDoubleValue("environment/temperature-degc");
+    _impl->set_Static_temperature((9.0/5.0) * (tempDegC + 273.15));
+    
+    // convert from inHG to PSF
+    double pressureInHg = _props->getDoubleValue("environment/pressure-inhg");
+    _impl->set_Static_pressure(pressureInHg * 70.726566);
+    // keep in slugs/ft^3
+    _impl->set_Density(_props->getDoubleValue("environment/density-slugft3"));
+  }
+
+  bool doLog = _props->getBoolValue("/sim/temp/fdm-data-logging", false);
+  if (doLog != _dataLogging) {
+    _dataLogging = doLog;
+    _impl->ToggleDataLogging(doLog);
+  }
+
+// FIXME - replay manager should handle most of this           
+  int replayState = fgGetInt("/sim/freeze/replay-state", 0);
+  if (replayState == 0) {
+    _impl->update(dt); // normal code path
+  } else if (replayState == 1) {
+    // should be inside FGReplay!
+    SGPropertyNode* replay_time = fgGetNode("/sim/replay/time", true);
+    FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
+    r->replay( replay_time->getDoubleValue() );
+    replay_time->setDoubleValue( replay_time->getDoubleValue()
+                                             + ( dt
+                                                 * fgGetInt("/sim/speed-up") ) );
+  
+  } else if (replayState == 2) {
+    // paused replay, no-op
+  } else {
+    throw sg_range_exception("unknown FGReplay state");
+  }  
+}
+
+void FDMShell::createImplementation()
+{
+  assert(!_impl);
+  
+  double dt = 1.0 / fgGetInt("/sim/model-hz");
+  string model = fgGetString("/sim/flight-model");
+
+    if ( model == "larcsim" ) {
+        _impl = new FGLaRCsim( dt );
+    } else if ( model == "jsb" ) {
+        _impl = new FGJSBsim( dt );
+#if ENABLE_SP_FDM
+    } else if ( model == "ada" ) {
+        _impl = new FGADA( dt );
+    } else if ( model == "acms" ) {
+        _impl = new FGACMS( dt );
+    } else if ( model == "balloon" ) {
+        _impl = new FGBalloonSim( dt );
+    } else if ( model == "magic" ) {
+        _impl = new FGMagicCarpet( dt );
+#endif
+    } else if ( model == "ufo" ) {
+        _impl = new FGUFO( dt );
+    } else if ( model == "external" ) {
+        // external is a synonym for "--fdm=null" and is
+        // maintained here for backwards compatibility
+        _impl = new FGNullFDM( dt );
+    } else if ( model.find("network") == 0 ) {
+        string host = "localhost";
+        int port1 = 5501;
+        int port2 = 5502;
+        int port3 = 5503;
+        string net_options = model.substr(8);
+        string::size_type begin, end;
+        begin = 0;
+        // host
+        end = net_options.find( ",", begin );
+        if ( end != string::npos ) {
+            host = net_options.substr(begin, end - begin);
+            begin = end + 1;
+        }
+        // port1
+        end = net_options.find( ",", begin );
+        if ( end != string::npos ) {
+            port1 = atoi( net_options.substr(begin, end - begin).c_str() );
+            begin = end + 1;
+        }
+        // port2
+        end = net_options.find( ",", begin );
+        if ( end != string::npos ) {
+            port2 = atoi( net_options.substr(begin, end - begin).c_str() );
+            begin = end + 1;
+        }
+        // port3
+        end = net_options.find( ",", begin );
+        if ( end != string::npos ) {
+            port3 = atoi( net_options.substr(begin, end - begin).c_str() );
+            begin = end + 1;
+        }
+        _impl = new FGExternalNet( dt, host, port1, port2, port3 );
+    } else if ( model.find("pipe") == 0 ) {
+        // /* old */ string pipe_path = model.substr(5);
+        // /* old */ _impl = new FGExternalPipe( dt, pipe_path );
+        string pipe_path = "";
+        string pipe_protocol = "";
+        string pipe_options = model.substr(5);
+        string::size_type begin, end;
+        begin = 0;
+        // pipe file path
+        end = pipe_options.find( ",", begin );
+        if ( end != string::npos ) {
+            pipe_path = pipe_options.substr(begin, end - begin);
+            begin = end + 1;
+        }
+        // protocol (last option)
+        pipe_protocol = pipe_options.substr(begin);
+        _impl = new FGExternalPipe( dt, pipe_path, pipe_protocol );
+    } else if ( model == "null" ) {
+        _impl = new FGNullFDM( dt );
+    } else if ( model == "yasim" ) {
+        _impl = new YASim( dt );
+    } else {
+        throw sg_exception(string("Unrecognized flight model '") + model
+               + "', cannot init flight dynamics model.");
+    }
+
+}
+
diff --git a/src/FDM/fdm_shell.hxx b/src/FDM/fdm_shell.hxx
new file mode 100644 (file)
index 0000000..c9b44db
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef FG_FDM_SHELL_HXX
+#define FG_FDM_SHELL_HXX
+
+#include <simgear/structure/subsystem_mgr.hxx>
+
+// forward decls
+class FGInterface;
+
+/**
+ * Wrap an FDM implementation in a subsystem with standard semantics
+ * Notably, deal with the various cases in which update() should not
+ * be called, such as replay or before scenery has loaded
+ *
+ * This class also provides the factory method which creates the
+ * specific FDM class (createImplementation)
+ */
+class FDMShell : public SGSubsystem
+{
+public:
+  FDMShell();
+  ~FDMShell();
+  
+  virtual void init();
+  virtual void reinit();
+  
+  virtual void bind();
+  virtual void unbind();
+  
+  virtual void update(double dt);
+  
+private:
+
+  void createImplementation();
+  
+  FGInterface* _impl;
+  SGPropertyNode* _props; // root property tree for this FDM instance
+  bool _dataLogging;
+};
+
+#endif // of FG_FDM_SHELL_HXX
index 10ce9948a18722f84d4b596a6726c574d70b5f5a..cf4ab9e6a00c7314ce4ea8a66f625284da6327b9 100644 (file)
@@ -44,8 +44,6 @@ static inline void assign(double* ptr, const SGVec3d& vec)
   ptr[2] = vec[2];
 }
 
-FGInterface *cur_fdm_state = 0;
-
 // Constructor
 FGInterface::FGInterface()
 {
@@ -253,7 +251,7 @@ FGInterface::bind ()
         false);
   fgSetArchivable("/position/altitude-ft");
   fgTie("/position/altitude-agl-ft", this,
-        &FGInterface::get_Altitude_AGL); // read-only
+        &FGInterface::get_Altitude_AGL, &FGInterface::set_AltitudeAGL);
   fgSetArchivable("/position/ground-elev-ft");
   fgTie("/position/ground-elev-ft", this,
         &FGInterface::get_Runway_altitude); // read-only
@@ -264,7 +262,8 @@ FGInterface::bind ()
         &FGInterface::get_Runway_altitude_m); // read-only
   fgSetArchivable("/position/sea-level-radius-ft");
   fgTie("/position/sea-level-radius-ft", this,
-        &FGInterface::get_Sea_level_radius); // read-only
+        &FGInterface::get_Sea_level_radius,
+        &FGInterface::_set_Sea_level_radius);
 
                                // Orientation
   fgTie("/orientation/roll-deg", this,
@@ -285,12 +284,16 @@ FGInterface::bind ()
   // Body-axis "euler rates" (rotation speed, but in a funny
   // representation).
   fgTie("/orientation/roll-rate-degps", this,
-       &FGInterface::get_Phi_dot_degps);
+       &FGInterface::get_Phi_dot_degps, &FGInterface::set_Phi_dot_degps);
   fgTie("/orientation/pitch-rate-degps", this,
-       &FGInterface::get_Theta_dot_degps);
+       &FGInterface::get_Theta_dot_degps, &FGInterface::set_Theta_dot_degps);
   fgTie("/orientation/yaw-rate-degps", this,
-       &FGInterface::get_Psi_dot_degps);
+       &FGInterface::get_Psi_dot_degps, &FGInterface::set_Psi_dot_degps);
 
+  fgTie("/orientation/p-body", this, &FGInterface::get_P_body);
+  fgTie("/orientation/q-body", this, &FGInterface::get_Q_body);
+  fgTie("/orientation/r-body", this, &FGInterface::get_R_body);
+  
                                 // Ground speed knots
   fgTie("/velocities/groundspeed-kt", this,
         &FGInterface::get_V_ground_speed_kt);
@@ -301,6 +304,9 @@ FGInterface::bind ()
        &FGInterface::set_V_calibrated_kts,
        false);
 
+    fgTie("/velocities/equivalent-kt", this,
+        &FGInterface::get_V_equiv_kts);
+
                                // Mach number
   fgTie("/velocities/mach", this,
        &FGInterface::get_Mach_number,
@@ -325,11 +331,11 @@ FGInterface::bind ()
                                // LaRCSim are fixed (LaRCSim adds the
                                // earth's rotation to the east velocity).
   fgTie("/velocities/speed-north-fps", this,
-       &FGInterface::get_V_north);
+       &FGInterface::get_V_north, &FGInterface::set_V_north);
   fgTie("/velocities/speed-east-fps", this,
-       &FGInterface::get_V_east);
+       &FGInterface::get_V_east, &FGInterface::set_V_east);
   fgTie("/velocities/speed-down-fps", this,
-       &FGInterface::get_V_down);
+       &FGInterface::get_V_down, &FGInterface::set_V_down);
 
                                // Relative wind
                                // FIXME: temporarily archivable, until
@@ -358,11 +364,11 @@ FGInterface::bind ()
   &FGInterface::get_Gamma_vert_rad,
   &FGInterface::set_Gamma_vert_rad );
   fgTie("/orientation/side-slip-rad", this,
-       &FGInterface::get_Beta); // read-only
+       &FGInterface::get_Beta, &FGInterface::_set_Beta);
   fgTie("/orientation/side-slip-deg", this,
   &FGInterface::get_Beta_deg); // read-only
   fgTie("/orientation/alpha-deg", this,
-  &FGInterface::get_Alpha_deg); // read-only
+  &FGInterface::get_Alpha_deg, &FGInterface::set_Alpha_deg); // read-only
   fgTie("/accelerations/nlf", this,
   &FGInterface::get_Nlf); // read-only
 
@@ -376,11 +382,11 @@ FGInterface::bind ()
 
                                 // Pilot accelerations
   fgTie("/accelerations/pilot/x-accel-fps_sec",
-        this, &FGInterface::get_A_X_pilot);
+        this, &FGInterface::get_A_X_pilot, &FGInterface::set_A_X_pilot);
   fgTie("/accelerations/pilot/y-accel-fps_sec",
-        this, &FGInterface::get_A_Y_pilot);
+        this, &FGInterface::get_A_Y_pilot, &FGInterface::set_A_Y_pilot);
   fgTie("/accelerations/pilot/z-accel-fps_sec",
-        this, &FGInterface::get_A_Z_pilot);
+        this, &FGInterface::get_A_Z_pilot, &FGInterface::set_A_Z_pilot);
 
 }
 
@@ -411,11 +417,15 @@ FGInterface::unbind ()
   fgUntie("/orientation/roll-rate-degps");
   fgUntie("/orientation/pitch-rate-degps");
   fgUntie("/orientation/yaw-rate-degps");
+  fgUntie("/orientation/p-body");
+  fgUntie("/orientation/q-body");
+  fgUntie("/orientation/r-body");
   fgUntie("/orientation/side-slip-rad");
   fgUntie("/orientation/side-slip-deg");
   fgUntie("/orientation/alpha-deg");
   fgUntie("/velocities/airspeed-kt");
   fgUntie("/velocities/groundspeed-kt");
+  fgUntie("/velocities/equivalent-kt");
   fgUntie("/velocities/mach");
   fgUntie("/velocities/speed-north-fps");
   fgUntie("/velocities/speed-east-fps");
@@ -893,6 +903,3 @@ FGInterface::release_wire(void)
   ground_cache.release_wire();
 }
 
-void fgToggleFDMdataLogging(void) {
-  cur_fdm_state->ToggleDataLogging();
-}
index 222df3b546492a29ac427982eda29c3e034f39fa..90859d92178275f90fc0b2b24179be9e27ab9dc5 100644 (file)
@@ -194,6 +194,15 @@ private:
     // the ground cache object itself.
     FGGroundCache ground_cache;
 
+    void set_A_X_pilot(double x)
+    { _set_Accels_Pilot_Body(x, a_pilot_body_v[1], a_pilot_body_v[2]); }
+    
+    void set_A_Y_pilot(double y)
+    { _set_Accels_Pilot_Body(a_pilot_body_v[0], y, a_pilot_body_v[2]); }
+    
+    void set_A_Z_pilot(double z)
+    { _set_Accels_Pilot_Body(a_pilot_body_v[0], a_pilot_body_v[1], z); }
+    
 protected:
 
     int _calc_multiloop (double dt);
@@ -284,6 +293,22 @@ public:
        euler_rates_v[1] = theta;
        euler_rates_v[2] = psi;
     }
+    
+    void set_Phi_dot_degps(double x)
+    {
+      euler_rates_v[0] = x * SG_DEGREES_TO_RADIANS;
+    }
+    
+    void set_Theta_dot_degps(double x)
+    {
+      euler_rates_v[1] = x * SG_DEGREES_TO_RADIANS;
+    }
+    
+    void set_Psi_dot_degps(double x)
+    {
+      euler_rates_v[2] = x * SG_DEGREES_TO_RADIANS;
+    }
+    
     inline void _set_Geocentric_Rates( double lat, double lon, double rad ) {
        geocentric_rates_v[0] = lat;
        geocentric_rates_v[1] = lon;
@@ -328,6 +353,9 @@ public:
     inline void _set_T_Local_to_Body( int i, int j, double value) { }
     inline void _set_Alpha( double a ) { alpha = a; }
     inline void _set_Beta( double b ) { beta = b; }
+    
+    inline void set_Alpha_deg( double a ) { alpha = a * SG_DEGREES_TO_RADIANS; }
+    
     inline void _set_Gamma_vert_rad( double gv ) { gamma_vert_rad = gv; }
     inline void _set_Density( double d ) { density = d; }
     inline void _set_Mach_number( double m ) { mach_number = m; }
@@ -712,10 +740,4 @@ public:
     void release_wire(void);
 };
 
-extern FGInterface * cur_fdm_state;
-
-// Toggle data logging on/off
-void fgToggleFDMdataLogging(void);
-
-
 #endif // _FLIGHT_HXX
diff --git a/src/FDM/flightProperties.cxx b/src/FDM/flightProperties.cxx
new file mode 100644 (file)
index 0000000..2460232
--- /dev/null
@@ -0,0 +1,289 @@
+#include <FDM/flightProperties.hxx>
+
+#include <simgear/props/props.hxx>
+#include <simgear/math/SGMath.hxx>
+
+#include <Main/globals.hxx>
+
+FlightProperties::FlightProperties(SGPropertyNode* root) :
+  _root(root)
+{
+  if (!_root) {
+    _root = globals->get_props();
+  }
+}
+
+FlightProperties::~FlightProperties()
+{
+}
+
+double FlightProperties::get_V_north() const
+{
+  return _root->getDoubleValue("velocities/speed-north-fps", 0.0);
+}
+
+double FlightProperties::get_V_east() const
+{
+  return _root->getDoubleValue("velocities/speed-east-fps", 0.0);
+}
+
+double FlightProperties::get_V_down() const
+{
+  return _root->getDoubleValue("velocities/speed-down-fps", 0.0);
+}
+
+double FlightProperties::get_uBody () const
+{
+  return _root->getDoubleValue("velocities/uBody-fps", 0.0);
+}
+
+double FlightProperties::get_vBody () const
+{
+  return _root->getDoubleValue("velocities/vBody-fps", 0.0);
+}
+
+double FlightProperties::get_wBody () const
+{
+  return _root->getDoubleValue("velocities/wBody-fps", 0.0);
+}
+
+double FlightProperties::get_A_X_pilot() const
+{
+  return _root->getDoubleValue("accelerations/pilot/x-accel-fps_sec", 0.0);
+}
+
+double FlightProperties::get_A_Y_pilot() const
+{
+  return _root->getDoubleValue("/accelerations/pilot/y-accel-fps_sec", 0.0);
+}
+
+double FlightProperties::get_A_Z_pilot() const
+{
+  return _root->getDoubleValue("/accelerations/pilot/z-accel-fps_sec", 0.0);
+}
+
+SGGeod FlightProperties::getPosition() const
+{
+  return SGGeod::fromDegFt(get_Longitude_deg(), get_Latitude_deg(), get_Altitude());
+}
+
+double FlightProperties::get_Latitude() const
+{
+  return get_Latitude_deg() * SG_DEGREES_TO_RADIANS;
+}
+
+double FlightProperties::get_Longitude() const
+{
+  return get_Longitude_deg() * SG_DEGREES_TO_RADIANS;
+}
+
+double FlightProperties::get_Altitude() const
+{
+  return _root->getDoubleValue("position/altitude-ft");
+}
+
+double FlightProperties::get_Altitude_AGL(void) const
+{
+  return _root->getDoubleValue("position/altitude-agl-ft");
+}
+
+double FlightProperties::get_Latitude_deg () const
+{
+  return _root->getDoubleValue("position/latitude-deg");
+}
+
+double FlightProperties::get_Longitude_deg () const
+{
+  return _root->getDoubleValue("position/longitude-deg");
+}
+
+double FlightProperties::get_Track(void) const
+{
+  return _root->getDoubleValue("orientation/track-deg");
+}
+
+double FlightProperties::get_Phi_deg() const
+{
+  return _root->getDoubleValue("orientation/roll-deg");
+}
+
+double FlightProperties::get_Theta_deg() const
+{
+  return _root->getDoubleValue("orientation/pitch-deg");
+}
+
+double FlightProperties::get_Psi_deg() const
+{
+  return _root->getDoubleValue("orientation/heading-deg");
+}
+
+double FlightProperties::get_Phi_dot() const
+{
+  return get_Phi_dot_degps() * SG_DEGREES_TO_RADIANS;
+}
+
+double FlightProperties::get_Theta_dot() const
+{
+   return get_Theta_dot_degps() * SG_DEGREES_TO_RADIANS;
+}
+
+double FlightProperties::get_Psi_dot() const
+{
+   return get_Psi_dot_degps() * SG_DEGREES_TO_RADIANS;
+}
+
+double FlightProperties::get_Alpha() const
+{
+  return _root->getDoubleValue("orientation/alpha-deg") * SG_DEGREES_TO_RADIANS;
+}
+
+double FlightProperties::get_Beta() const
+{
+  return _root->getDoubleValue("orientation/beta-deg") * SG_DEGREES_TO_RADIANS;
+}
+
+double FlightProperties::get_Phi_dot_degps() const
+{
+  return _root->getDoubleValue("orientation/roll-rate-degps");
+}
+
+double FlightProperties::get_Theta_dot_degps() const
+{
+  return _root->getDoubleValue("orientation/pitch-rate-degps");
+}
+
+double FlightProperties::get_Psi_dot_degps() const
+{
+  return _root->getDoubleValue("orientation/yaw-rate-degps");
+}
+  
+double FlightProperties::get_Total_temperature() const
+{
+  return 0.0;
+}
+
+double FlightProperties::get_Total_pressure() const
+{
+  return 0.0;
+}
+
+double FlightProperties::get_Dynamic_pressure() const
+{
+  return 0.0;
+}
+
+void FlightProperties::set_Longitude(double l)
+{
+  _root->setDoubleValue("position/longitude-deg", l * SG_RADIANS_TO_DEGREES);
+}
+
+void FlightProperties::set_Latitude(double l)
+{
+  _root->setDoubleValue("position/latitude-deg", l * SG_RADIANS_TO_DEGREES);
+}
+
+void FlightProperties::set_Altitude(double ft)
+{
+  _root->setDoubleValue("position/altitude-ft", ft);
+}
+
+void FlightProperties::set_Euler_Angles(double phi, double theta, double psi)
+{
+  _root->setDoubleValue("orientation/roll-deg", phi * SG_RADIANS_TO_DEGREES);
+  _root->setDoubleValue("orientation/pitch-deg", theta * SG_RADIANS_TO_DEGREES);
+  _root->setDoubleValue("orientation/heading-deg", psi * SG_RADIANS_TO_DEGREES);
+}
+
+void FlightProperties::set_V_calibrated_kts(double kts)
+{
+  _root->setDoubleValue("velocities/airspeed-kt", kts);
+}
+
+void FlightProperties::set_Climb_Rate(double fps)
+{
+  _root->setDoubleValue("velocities/vertical-speed-fps", fps);
+}
+
+double FlightProperties::get_V_ground_speed() const
+{
+  const double KNOTS_TO_FTS = (SG_NM_TO_METER * SG_METER_TO_FEET)/ 3600.0;
+  return _root->getDoubleValue("velocities/groundspeed-kt") * KNOTS_TO_FTS;
+}
+
+double FlightProperties::get_V_calibrated_kts() const
+{
+  return _root->getDoubleValue("velocities/airspeed-kt");
+}
+
+double FlightProperties::get_V_equiv_kts() const
+{
+  return _root->getDoubleValue("velocities/equivalent-kt");
+}
+
+double FlightProperties::get_Climb_Rate() const
+{
+  return _root->getDoubleValue("velocities/vertical-speed-fps");
+}
+
+double FlightProperties::get_Runway_altitude_m() const
+{
+  return _root->getDoubleValue("environment/ground-elevation-m");
+}
+
+void FlightProperties::set_Accels_Pilot_Body(double x, double y, double z)
+{
+  _root->setDoubleValue("accelerations/pilot/x-accel-fps_sec", x);
+  _root->setDoubleValue("accelerations/pilot/y-accel-fps_sec", y);
+  _root->setDoubleValue("accelerations/pilot/z-accel-fps_sec", z);
+}
+
+void FlightProperties::set_Velocities_Local(double x, double y, double z)
+{
+  _root->setDoubleValue("velocities/speed-north-fps", x);
+  _root->setDoubleValue("velocities/speed-east-fps", y);
+  _root->setDoubleValue("velocities/speed-down-fps", z);
+}
+
+void FlightProperties::set_Velocities_Wind_Body(double x, double y, double z)
+{
+  _root->setDoubleValue("velocities/vBody-fps", x);
+  _root->setDoubleValue("velocities/uBody-fps", y);
+  _root->setDoubleValue("velocities/wBody-fps", z);
+}
+
+void FlightProperties::set_Euler_Rates(double x, double y, double z)
+{
+  _root->setDoubleValue("orientation/roll-rate-degps", x * SG_RADIANS_TO_DEGREES);
+  _root->setDoubleValue("orientation/pitch-rate-degps", y * SG_RADIANS_TO_DEGREES);
+  _root->setDoubleValue("orientation/yaw-rate-degps", z * SG_RADIANS_TO_DEGREES);
+}
+
+void FlightProperties::set_Alpha(double a)
+{
+  _root->setDoubleValue("orientation/alpha-deg", a * SG_RADIANS_TO_DEGREES);
+}
+
+void FlightProperties::set_Beta(double b)
+{
+  _root->setDoubleValue("orientation/side-slip-rad", b);
+}
+
+void FlightProperties::set_Altitude_AGL(double ft)
+{
+  _root->setDoubleValue("position/altitude-agl-ft", ft);
+}
+
+double FlightProperties::get_P_body() const
+{
+  return _root->getDoubleValue("orientation/p-body", 0.0);
+}
+
+double FlightProperties::get_Q_body() const
+{
+  return _root->getDoubleValue("orientation/q-body", 0.0);
+}
+
+double FlightProperties::get_R_body() const
+{
+  return _root->getDoubleValue("orientation/r-body", 0.0);
+}
diff --git a/src/FDM/flightProperties.hxx b/src/FDM/flightProperties.hxx
new file mode 100644 (file)
index 0000000..9df57f3
--- /dev/null
@@ -0,0 +1,102 @@
+#ifndef FG_FLIGHT_PROPERTIES_HXX
+#define FG_FLIGHT_PROPERTIES_HXX
+
+#include <memory>
+#include <simgear/Math/SGMathFwd.hxx> // for SGVec3d 
+#include <simgear/Math/SGMisc.hxx>
+
+// forward decls
+class SGPropertyNode;
+class SGGeoc;
+class SGGeod;
+
+/**
+ * Encapsulate the FDM properties in some getter/setter helpers.
+ * This class intentionally mimics portions of
+ * @FGInterface, to permit easy migration of code outside the FDMs,
+ * to use properties instead of global variables.
+ */
+class FlightProperties
+{
+public:
+  FlightProperties(SGPropertyNode* aRoot = NULL);
+  ~FlightProperties();
+
+  double get_V_north() const;
+  double get_V_east() const;
+  double get_V_down() const;
+  double get_uBody () const;
+  double get_vBody () const;
+  double get_wBody () const;
+  
+  double get_A_X_pilot() const;
+  double get_A_Y_pilot() const;
+  double get_A_Z_pilot() const;
+  
+  double get_P_body() const;
+  double get_Q_body() const;
+  double get_R_body() const;
+    
+  SGGeod getPosition() const;
+
+  double get_Latitude() const;
+  double get_Longitude() const;
+  double get_Altitude() const;
+  
+  double get_Altitude_AGL(void) const;
+  double get_Track(void) const;
+
+  double get_Latitude_deg () const;
+  double get_Longitude_deg () const;
+  
+  double get_Phi_deg() const;
+  double get_Theta_deg() const;
+  double get_Psi_deg() const;
+  
+  double get_Phi() const { return SGMiscd::deg2rad(get_Phi_deg()); }
+  double get_Theta() const { return SGMiscd::deg2rad(get_Theta_deg()); }
+  double get_Psi() const { return SGMiscd::deg2rad(get_Psi_deg()); }
+
+  double get_Phi_dot() const;
+  double get_Theta_dot() const;
+  double get_Psi_dot() const;
+  double get_Alpha() const;
+  double get_Beta() const;
+  
+  double get_Phi_dot_degps() const;
+  double get_Theta_dot_degps() const;
+  double get_Psi_dot_degps() const;
+  
+  double get_V_ground_speed() const; // in feet/s
+  double get_V_equiv_kts() const;
+  double get_V_calibrated_kts() const;
+  double get_Climb_Rate() const;
+  double get_Runway_altitude_m() const;
+  
+  double get_Total_temperature() const;
+  double get_Total_pressure() const;
+  double get_Dynamic_pressure() const;
+  
+  void set_Longitude(double l); // radians
+  void set_Latitude(double l); // radians
+  void set_Altitude(double ft); // feet
+    
+  void set_Euler_Angles(double phi, double theta, double psi);
+  void set_Euler_Rates(double x, double y, double z);
+  
+  void set_Alpha(double a);
+  void set_Beta(double b);
+  
+  void set_Altitude_AGL(double ft);
+  
+  void set_V_calibrated_kts(double kts);
+  void set_Climb_Rate(double fps);
+  
+  void set_Velocities_Local(double x, double y, double z);
+  void set_Velocities_Wind_Body(double x, double y, double z);
+  void set_Accels_Pilot_Body(double x, double y, double z);
+private:
+  SGPropertyNode* _root;
+};
+
+#endif // of FG_FLIGHT_PROPERTIES_HXX
index 8eb443c36ac33371a68c88c79afe617987f6ec67..3e3d5170117f3477dd408c88c82ea47c40f27f02 100644 (file)
@@ -180,7 +180,7 @@ FGRunway* HUD::Runway::get_active_runway()
 
 void HUD::Runway::get_rwy_points(sgdVec3 *_points3d)
 {
-    double alt = current_aircraft.fdm_state->get_Runway_altitude() * SG_FEET_TO_METER;
+    double alt = _runway->geod().getElevationM();
     double length = _runway->lengthM() * 0.5;
     double width = _runway->widthM() * 0.5;
     double frontLat = 0.0, frontLon = 0.0, backLat = 0.0, backLon = 0.0, az = 0.0, tempLat = 0.0, tempLon = 0.0;
index 6131e4795fc2f6796d56702ecd9677075f9ed93b..5e90575dcdda7daa6159c43be3e43a8d846f0bd0 100644 (file)
@@ -1233,7 +1233,7 @@ do_presets_commit (const SGPropertyNode * arg)
     // unbind the current fdm state so property changes
     // don't get lost when we subsequently delete this fdm
     // and create a new one.
-    cur_fdm_state->unbind();
+    globals->get_subsystem("flight")->unbind();
 
     // set position from presets
     fgInitPosition();
index 328c8913c27744d6a48fadd5b98cb7780d81d0c9..72f6849e9be1e5b63e9b34be2d2d68332b018f23 100644 (file)
 #include <Cockpit/panel.hxx>
 #include <Cockpit/panel_io.hxx>
 
-#if ENABLE_SP_FDM
-#include <FDM/SP/ADA.hxx>
-#include <FDM/SP/ACMS.hxx>
-#include <FDM/SP/MagicCarpet.hxx>
-#include <FDM/SP/Balloon.h>
-#endif
-#include <FDM/ExternalNet/ExternalNet.hxx>
-#include <FDM/ExternalPipe/ExternalPipe.hxx>
-#include <FDM/JSBSim/JSBSim.hxx>
-#include <FDM/LaRCsim/LaRCsim.hxx>
-#include <FDM/UFO.hxx>
-#include <FDM/NullFDM.hxx>
-#include <FDM/YASim/YASim.hxx>
 #include <GUI/new_gui.hxx>
 #include <Include/general.hxx>
 #include <Input/input.hxx>
 #include <Time/tmp.hxx>
 #include <Traffic/TrafficMgr.hxx>
 #include <MultiPlayer/multiplaymgr.hxx>
+#include <FDM/fdm_shell.hxx>
 
 #include <Environment/environment_mgr.hxx>
 #include <Environment/ridge_lift.hxx>
@@ -1207,101 +1195,6 @@ bool fgInitGeneral() {
     return true;
 }
 
-
-// Initialize the flight model subsystem.  This just creates the
-// object.  The actual fdm initialization is delayed until we get a
-// proper scenery elevation hit.  This is checked for in main.cxx
-
-void fgInitFDM() {
-
-    if ( cur_fdm_state ) {
-        delete cur_fdm_state;
-        cur_fdm_state = 0;
-    }
-
-    double dt = 1.0 / fgGetInt("/sim/model-hz");
-    string model = fgGetString("/sim/flight-model");
-
-    if ( model == "larcsim" ) {
-        cur_fdm_state = new FGLaRCsim( dt );
-    } else if ( model == "jsb" ) {
-        cur_fdm_state = new FGJSBsim( dt );
-#if ENABLE_SP_FDM
-    } else if ( model == "ada" ) {
-        cur_fdm_state = new FGADA( dt );
-    } else if ( model == "acms" ) {
-        cur_fdm_state = new FGACMS( dt );
-    } else if ( model == "balloon" ) {
-        cur_fdm_state = new FGBalloonSim( dt );
-    } else if ( model == "magic" ) {
-        cur_fdm_state = new FGMagicCarpet( dt );
-#endif
-    } else if ( model == "ufo" ) {
-        cur_fdm_state = new FGUFO( dt );
-    } else if ( model == "external" ) {
-        // external is a synonym for "--fdm=null" and is
-        // maintained here for backwards compatibility
-        cur_fdm_state = new FGNullFDM( dt );
-    } else if ( model.find("network") == 0 ) {
-        string host = "localhost";
-        int port1 = 5501;
-        int port2 = 5502;
-        int port3 = 5503;
-        string net_options = model.substr(8);
-        string::size_type begin, end;
-        begin = 0;
-        // host
-        end = net_options.find( ",", begin );
-        if ( end != string::npos ) {
-            host = net_options.substr(begin, end - begin);
-            begin = end + 1;
-        }
-        // port1
-        end = net_options.find( ",", begin );
-        if ( end != string::npos ) {
-            port1 = atoi( net_options.substr(begin, end - begin).c_str() );
-            begin = end + 1;
-        }
-        // port2
-        end = net_options.find( ",", begin );
-        if ( end != string::npos ) {
-            port2 = atoi( net_options.substr(begin, end - begin).c_str() );
-            begin = end + 1;
-        }
-        // port3
-        end = net_options.find( ",", begin );
-        if ( end != string::npos ) {
-            port3 = atoi( net_options.substr(begin, end - begin).c_str() );
-            begin = end + 1;
-        }
-        cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
-    } else if ( model.find("pipe") == 0 ) {
-        // /* old */ string pipe_path = model.substr(5);
-        // /* old */ cur_fdm_state = new FGExternalPipe( dt, pipe_path );
-        string pipe_path = "";
-        string pipe_protocol = "";
-        string pipe_options = model.substr(5);
-        string::size_type begin, end;
-        begin = 0;
-        // pipe file path
-        end = pipe_options.find( ",", begin );
-        if ( end != string::npos ) {
-            pipe_path = pipe_options.substr(begin, end - begin);
-            begin = end + 1;
-        }
-        // protocol (last option)
-        pipe_protocol = pipe_options.substr(begin);
-        cur_fdm_state = new FGExternalPipe( dt, pipe_path, pipe_protocol );
-    } else if ( model == "null" ) {
-        cur_fdm_state = new FGNullFDM( dt );
-    } else if ( model == "yasim" ) {
-        cur_fdm_state = new YASim( dt );
-    } else {
-        throw sg_exception(string("Unrecognized flight model '") + model
-               + "', cannot init flight dynamics model.");
-    }
-}
-
 // Initialize view parameters
 void fgInitView() {
   // force update of model so that viewer can get some data...
@@ -1513,7 +1406,7 @@ bool fgInitSubsystems() {
     // Initialize the flight model subsystem.
     ////////////////////////////////////////////////////////////////////
 
-    fgInitFDM();
+    globals->add_subsystem("flight", new FDMShell, SGSubsystemMgr::FDM);
         
     // allocates structures so must happen before any of the flight
     // model or control parameters are set
@@ -1539,14 +1432,14 @@ bool fgInitSubsystems() {
     // autopilot.)
     ////////////////////////////////////////////////////////////////////
 
-    globals->add_subsystem("instrumentation", new FGInstrumentMgr);
-    globals->add_subsystem("systems", new FGSystemMgr);
+    globals->add_subsystem("instrumentation", new FGInstrumentMgr, SGSubsystemMgr::FDM);
+    globals->add_subsystem("systems", new FGSystemMgr, SGSubsystemMgr::FDM);
 
     ////////////////////////////////////////////////////////////////////
     // Initialize the XML Autopilot subsystem.
     ////////////////////////////////////////////////////////////////////
 
-    globals->add_subsystem( "xml-autopilot", new FGXMLAutopilotGroup );
+    globals->add_subsystem( "xml-autopilot", new FGXMLAutopilotGroup, SGSubsystemMgr::FDM );
     globals->add_subsystem( "route-manager", new FGRouteMgr );
     
     ////////////////////////////////////////////////////////////////////
@@ -1747,7 +1640,7 @@ void fgReInitSubsystems()
     globals->get_subsystem("ai_model")->reinit();
 
     // Initialize the FDM
-    fgInitFDM();
+    globals->get_subsystem("flight")->reinit();
     
     // allocates structures so must happen before any of the flight
     // model or control parameters are set
@@ -1781,7 +1674,8 @@ void reInit(void)  // from gui_local.cxx -- TODO merge with fgReInitSubsystems()
         master_freeze->setBoolValue(true);
 
     fgSetBool("/sim/signals/reinit", true);
-    cur_fdm_state->unbind();
+
+    globals->get_subsystem("flight")->unbind();
 
     // in case user has changed window size as
     // restoreInitialState() overwrites these
index 787e85ab57de008516347d9a8185b71919d17455..896f713ae9489d932bad80039c9297ff767fcfca 100644 (file)
@@ -34,8 +34,6 @@
 #include <simgear/scene/model/particles.hxx>
 #include <simgear/sound/soundmgr_openal.hxx>
 
-#include <Aircraft/aircraft.hxx>
-#include <FDM/flight.hxx>
 #include <GUI/gui.h>
 
 #include "globals.hxx"
@@ -44,8 +42,6 @@
 
 static bool winding_ccw = true; // FIXME: temporary
 
-static bool fdm_data_logging = false; // FIXME: temporary
-
 static bool frozen = false;    // FIXME: temporary
 
 using std::string;
@@ -308,8 +304,8 @@ setDateString (const char * date_string)
                                // too difficult, by the way.
   long int warp =
     mktime(&new_time) - mktime(current_time) + globals->get_warp();
-  double lon = current_aircraft.fdm_state->get_Longitude();
-  double lat = current_aircraft.fdm_state->get_Latitude();
+  double lon = fgGetDouble("/position/longitude-deg") * SG_DEGREES_TO_RADIANS;
+  double lat = fgGetDouble("/position/latitude-deg") * SG_DEGREES_TO_RADIANS;
   globals->set_warp(warp);
   st->update(lon, lat, cur_time_override->getLongValue(), warp);
 }
@@ -354,7 +350,7 @@ static double
 getHeadingMag ()
 {
   double magheading;
-  magheading = current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES - getMagVar();
+  magheading = fgGetDouble("/orientation/heading-deg") - getMagVar();
   if (magheading < 0) magheading += 360;
   return magheading;
 }
@@ -366,7 +362,7 @@ static double
 getTrackMag ()
 {
   double magtrack;
-  magtrack = current_aircraft.fdm_state->get_Track() - getMagVar();
+  magtrack = fgGetDouble("/orientation/track-deg") - getMagVar();
   if (magtrack < 0) magtrack += 360;
   return magtrack;
 }
@@ -411,22 +407,6 @@ setWindingCCW (bool state)
     glFrontFace ( GL_CW );
 }
 
-static bool
-getFDMDataLogging ()
-{
-  return fdm_data_logging;
-}
-
-static void
-setFDMDataLogging (bool state)
-{
-                               // kludge; no getter or setter available
-  if (state != fdm_data_logging) {
-    fgToggleFDMdataLogging();
-    fdm_data_logging = state;
-  }
-}
-
 static const char *
 getLongitudeString ()
 {
@@ -540,7 +520,6 @@ FGProperties::bind ()
 
                                // Misc. Temporary junk.
   fgTie("/sim/temp/winding-ccw", getWindingCCW, setWindingCCW, false);
-  fgTie("/sim/temp/fdm-data-logging", getFDMDataLogging, setFDMDataLogging);
 }
 
 void
index edf2f84e4a0db5544ace018e994c69e0f317bd89..4ffb1cd031c4326e7da69fb01f3d3c582af23e1f 100644 (file)
@@ -65,7 +65,6 @@
 #include <Sound/beacon.hxx>
 #include <Sound/morse.hxx>
 #include <Sound/fg_fx.hxx>
-#include <FDM/flight.hxx>
 #include <ATCDCL/ATCmgr.hxx>
 #include <ATCDCL/AIMgr.hxx>
 #include <Time/tmp.hxx>
@@ -112,79 +111,6 @@ void fgSetNewSoundDevice(const char *);
 // is initialized.
 extern int _bootstrap_OSInit;
 
-
-
-// Update internal time dependent calculations (i.e. flight model)
-// FIXME: this distinction is obsolete; all subsystems now get delta
-// time on update.
-void fgUpdateTimeDepCalcs() {
-    static bool inited = false;
-
-    static const SGPropertyNode *replay_state
-        = fgGetNode( "/sim/freeze/replay-state", true );
-    static SGPropertyNode *replay_time
-        = fgGetNode( "/sim/replay/time", true );
-    // static const SGPropertyNode *replay_end_time
-    //     = fgGetNode( "/sim/replay/end-time", true );
-
-    //SG_LOG(SG_FLIGHT,SG_INFO, "Updating time dep calcs()");
-
-    // Initialize the FDM here if it hasn't been and if we have a
-    // scenery elevation hit.
-
-    // cout << "cur_fdm_state->get_inited() = " << cur_fdm_state->get_inited() 
-    //      << " cur_elev = " << scenery.get_cur_elev() << endl;
-
-    if (!cur_fdm_state->get_inited()) {
-        // Check for scenery around the aircraft.
-        double lon = fgGetDouble("/sim/presets/longitude-deg");
-        double lat = fgGetDouble("/sim/presets/latitude-deg");
-        // We require just to have 50 meter scenery availabe around
-        // the aircraft.
-        double range = 1000.0;
-        SGGeod geod = SGGeod::fromDeg(lon, lat);
-        if (globals->get_scenery()->scenery_available(geod, range)) {
-            //SG_LOG(SG_FLIGHT, SG_INFO, "Finally initializing fdm");
-            cur_fdm_state->init();
-            if ( cur_fdm_state->get_bound() ) {
-                cur_fdm_state->unbind();
-            }
-            cur_fdm_state->bind();
-        }
-    }
-
-    // conceptually, the following block could be done for each fdm
-    // instance ...
-    if ( cur_fdm_state->get_inited() ) {
-        // we have been inited, and  we are good to go ...
-
-        if ( replay_state->getIntValue() == 0 ) {
-            // replay off, run fdm
-            cur_fdm_state->update( delta_time_sec );
-        } else {
-            FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
-            r->replay( replay_time->getDoubleValue() );
-            if ( replay_state->getIntValue() == 1 ) {
-                // normal playback
-                replay_time->setDoubleValue( replay_time->getDoubleValue()
-                                             + ( delta_time_sec
-                                                 * fgGetInt("/sim/speed-up") ) );
-            } else if ( replay_state->getIntValue() == 2 ) {
-                // paused playback (don't advance replay time)
-            }
-        }
-
-        if ( !inited ) {
-            inited = true;
-            fgSetBool("/sim/signals/fdm-initialized", true);
-        }
-
-    } else {
-        // do nothing, fdm isn't inited yet
-    }
-}
-
-
 // What should we do when we have nothing else to do?  Let's get ready
 // for the next move and update the display?
 static void fgMainLoop( void ) {
@@ -299,6 +225,10 @@ static void fgMainLoop( void ) {
     if (0 < dtMax && dtMax < real_delta_time_sec)
         real_delta_time_sec = dtMax;
 
+    SGSubsystemGroup* fdmGroup = 
+      globals->get_subsystem_mgr()->get_group(SGSubsystemMgr::FDM);
+    fdmGroup->set_fixed_update_time(1.0 / model_hz);
+
     // round the real time down to a multiple of 1/model-hz.
     // this way all systems are updated the _same_ amount of dt.
     static double reminder = 0.0;
@@ -333,21 +263,6 @@ static void fgMainLoop( void ) {
     SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop");
     SG_LOG( SG_ALL, SG_DEBUG, "======= ==== ====");
 
-    // Fix elevation.  I'm just sticking this here for now, it should
-    // probably move eventually
-
-    /* printf("Before - ground = %.2f  runway = %.2f  alt = %.2f\n",
-       scenery.get_cur_elev(),
-       cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
-       cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
-
-    /* printf("Adjustment - ground = %.2f  runway = %.2f  alt = %.2f\n",
-       scenery.get_cur_elev(),
-       cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
-       cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
-
-    // cout << "Warp = " << globals->get_warp() << endl;
-
     // update "time"
     static bool last_clock_freeze = false;
 
@@ -436,17 +351,6 @@ static void fgMainLoop( void ) {
     // multiplayer information is interpreted by an AI model
     if (fgGetBool("/sim/ai-traffic/enabled"))
         globals->get_AI_mgr()->update(delta_time_sec);
-
-    // Run flight model
-    if (0 < global_multi_loop) {
-        // first run the flight model each frame until it is initialized
-        // then continue running each frame only after initial scenery
-        // load is complete.
-        fgUpdateTimeDepCalcs();
-    } else {
-        SG_LOG( SG_ALL, SG_DEBUG,
-                "Elapsed time is zero ... we're zinging" );
-    }
   
     globals->get_aircraft_model()->update(delta_time_sec);
     globals->get_subsystem_mgr()->update(delta_time_sec);
@@ -516,7 +420,7 @@ static void fgMainLoop( void ) {
     // END Tile Manager udpates
 
     if (!scenery_loaded && globals->get_tile_mgr()->isSceneryLoaded()
-        && cur_fdm_state->get_inited()) {
+        && fgGetBool("sim/signals/fdm-initialized")) {
         fgSetBool("sim/sceneryloaded",true);
         if (fgGetBool("/sim/sound/working")) {
             globals->get_soundmgr()->activate();
index 32d7953380b417271fbedd5aead6ba626d1ae3df..d7258df88afa8fe010619a8c08be97c56d3cc2e4 100644 (file)
@@ -630,7 +630,8 @@ FGRenderer::update( bool refresh_camera_settings ) {
     double visibility_meters = fgGetDouble("/environment/visibility-m");
     thesky->set_visibility(visibility_meters);
 
-    thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
+    double altitude_m = fgGetDouble("/position/altitude-ft") * SG_FEET_TO_METER;
+    thesky->modify_vis( altitude_m,
                         ( global_multi_loop * fgGetInt("/sim/speed-up") )
                         / (double)fgGetInt("/sim/model-hz") );
 
@@ -678,26 +679,7 @@ FGRenderer::update( bool refresh_camera_settings ) {
         thesky->reposition( sstate, *globals->get_ephem(), delta_time_sec );
         thesky->repaint( scolor, *globals->get_ephem() );
 
-        /*
-        SG_LOG( SG_GENERAL, SG_BULK,
-                "thesky->reposition( view_pos = " << view_pos[0] << " "
-         << view_pos[1] << " " << view_pos[2] );
-        SG_LOG( SG_GENERAL, SG_BULK,
-                "    zero_elev = " << zero_elev[0] << " "
-         << zero_elev[1] << " " << zero_elev[2]
-         << " lon = " << cur_fdm_state->get_Longitude()
-         << " lat = " << cur_fdm_state->get_Latitude() );
-        SG_LOG( SG_GENERAL, SG_BULK,
-                "    sun_rot = " << l->get_sun_rotation
-         << " gst = " << SGTime::cur_time_params->getGst() );
-        SG_LOG( SG_GENERAL, SG_BULK,
-             "    sun ra = " << globals->get_ephem()->getSunRightAscension()
-          << " sun dec = " << globals->get_ephem()->getSunDeclination()
-          << " moon ra = " << globals->get_ephem()->getMoonRightAscension()
-          << " moon dec = " << globals->get_ephem()->getMoonDeclination() );
-        */
-
-        //OSGFIXME
+            //OSGFIXME
 //         shadows->setupShadows(
 //           current__view->getLongitude_deg(),
 //           current__view->getLatitude_deg(),
index eead2455bbf8b11c8f70d189aa107f41c91f11e3..4b3f368aaf4c602cca2c234c9925c3939c8b198b 100644 (file)
@@ -30,7 +30,6 @@
 #include <simgear/io/iochannel.hxx>
 #include <simgear/timing/sg_time.hxx>
 
-#include <FDM/flight.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 
@@ -80,12 +79,12 @@ bool FGAV400::gen_message() {
     double min;
 
     // create msg_z
-    sprintf( msg_z, "z%05.0f\r\n", cur_fdm_state->get_Altitude() );
+    sprintf( msg_z, "z%05.0f\r\n", fdm.get_Altitude() );
 
     // create msg_A
     sprintf( msg_A, "A");
 
-    double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
+    double latd = fdm.get_Latitude() * SGD_RADIANS_TO_DEGREES;
     if ( latd < 0.0 ) {
        latd = -latd;
        dir = 'S';
@@ -97,7 +96,7 @@ bool FGAV400::gen_message() {
     sprintf( msg_A, "A%c %02d %04.0f\r\n", dir, deg, min);
 
     // create msg_B
-    double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
+    double lond = fdm.get_Longitude() * SGD_RADIANS_TO_DEGREES;
     if ( lond < 0.0 ) {
        lond = -lond;
        dir = 'W';
@@ -262,7 +261,7 @@ bool FGAV400::parse_message() {
                lat *= -1;
            }
 
-           cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
+           fdm.set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lat = " << lat );
 
            // lon val
@@ -291,17 +290,17 @@ bool FGAV400::parse_message() {
                lon *= -1;
            }
 
-           cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
+           fdm.set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lon = " << lon );
 
 #if 0
            double sl_radius, lat_geoc;
-           sgGeodToGeoc( cur_fdm_state->get_Latitude(), 
-                         cur_fdm_state->get_Altitude(), 
+           sgGeodToGeoc( fdm.get_Latitude(), 
+                         fdm.get_Altitude(), 
                          &sl_radius, &lat_geoc );
-           cur_fdm_state->set_Geocentric_Position( lat_geoc, 
-                          cur_fdm_state->get_Longitude(), 
-                          sl_radius + cur_fdm_state->get_Altitude() );
+           fdm.set_Geocentric_Position( lat_geoc, 
+                          fdm.get_Longitude(), 
+                          sl_radius + fdm.get_Altitude() );
 #endif
 
            // speed
@@ -313,8 +312,8 @@ bool FGAV400::parse_message() {
            string speed_str = msg.substr(begin, end - begin);
            begin = end + 1;
            speed = atof( speed_str.c_str() );
-           cur_fdm_state->set_V_calibrated_kts( speed );
-           // cur_fdm_state->set_V_ground_speed( speed );
+           fdm.set_V_calibrated_kts( speed );
+           // fdm.set_V_ground_speed( speed );
            SG_LOG( SG_IO, SG_INFO, "  speed = " << speed );
 
            // heading
@@ -326,8 +325,8 @@ bool FGAV400::parse_message() {
            string hdg_str = msg.substr(begin, end - begin);
            begin = end + 1;
            heading = atof( hdg_str.c_str() );
-           cur_fdm_state->set_Euler_Angles( cur_fdm_state->get_Phi(), 
-                                            cur_fdm_state->get_Theta(), 
+           fdm.set_Euler_Angles( fdm.get_Phi(), 
+                                            fdm.get_Theta(), 
                                             heading * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  heading = " << heading );
        } else if ( sentence == "PGRMZ" ) {
@@ -354,7 +353,7 @@ bool FGAV400::parse_message() {
                altitude *= SG_METER_TO_FEET;
            }
 
-           cur_fdm_state->set_Altitude( altitude );
+           fdm.set_Altitude( altitude );
     
            SG_LOG( SG_IO, SG_INFO, " altitude  = " << altitude );
 
index 02c0fcb0d23c1a93964a0ef01f853d1d45e24c8b..cacfa2051d2339571aad837d42a8f233d9941bc5 100644 (file)
@@ -30,9 +30,7 @@
 #include <string>
 
 #include "protocol.hxx"
-
-using std::string;
-
+#include <FDM/flightProperties.hxx>
 
 class FGAV400 : public FGProtocol {
 
@@ -55,6 +53,8 @@ public:
 
     // close the channel
     bool close();
+    
+  FlightProperties fdm;
 };
 
 
index 2d704a83ebe71b75a8e317818cf796f01d1d1433..3a9fcdf288583bafca961bbbdf83e54ac39fba27 100644 (file)
 #include <simgear/io/iochannel.hxx>
 #include <simgear/timing/sg_time.hxx>
 
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 
 #include "AV400Sim.hxx"
 
 FGAV400Sim::FGAV400Sim() {
+  fdm = new FlightProperties;
 }
 
 FGAV400Sim::~FGAV400Sim() {
+  delete fdm;
 }
 
 
@@ -60,7 +62,7 @@ bool FGAV400Sim::gen_message() {
     double min;
 
     // create msg_a
-    double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
+    double latd = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES;
     if ( latd < 0.0 ) {
        latd = -latd;
        dir = 'S';
@@ -72,7 +74,7 @@ bool FGAV400Sim::gen_message() {
     sprintf( msg_a, "a%c %03d %04.0f\r\n", dir, deg, min);
 
     // create msg_b
-    double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
+    double lond = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES;
     if ( lond < 0.0 ) {
        lond = -lond;
        dir = 'W';
@@ -84,7 +86,7 @@ bool FGAV400Sim::gen_message() {
     sprintf( msg_b, "b%c %03d %04.0f\r\n", dir, deg, min);
 
     // create msg_c
-    double alt = cur_fdm_state->get_Altitude();
+    double alt = fdm->get_Altitude();
     if ( alt > 99999.0 ) { alt = 99999.0; }
     sprintf( msg_c, "c%05.0f\r\n", alt );
 
index ea4493f68bf53998f3c7052fab98ffc470183c08..9a4c45611db5183a3183a24af0b984b47d8c632a 100644 (file)
 
 #include "protocol.hxx"
 
-using std::string;
-
+class FlightProperties;
 
 class FGAV400Sim : public FGProtocol {
 
     char buf[ FG_MAX_MSG_SIZE ];
     int length;
-
+    FlightProperties* fdm;
+    
 public:
 
     FGAV400Sim();
index f0738a12f208e42ed3ab8009a8b11353c4b3861a..20b348569a7546241bcf77f2d0a936dc73056522 100644 (file)
@@ -31,7 +31,7 @@
 
 
 
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/fg_init.hxx>
 
 
 FGAtlas::FGAtlas() {
+  fdm = new FlightProperties;
 }
 
 FGAtlas::~FGAtlas() {
+  delete fdm;
 }
 
 
@@ -65,7 +67,6 @@ static char calc_atlas_cksum(char *sentence) {
     return sum;
 }
 
-
 // generate Atlas message
 bool FGAtlas::gen_message() {
     // cout << "generating atlas message" << endl;
@@ -94,7 +95,7 @@ bool FGAtlas::gen_message() {
             t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec );
 
     char lat[20];
-    double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
+    double latd = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES;
     if ( latd < 0.0 ) {
        latd *= -1.0;
        dir = 'S';
@@ -106,7 +107,7 @@ bool FGAtlas::gen_message() {
     sprintf( lat, "%02d%06.3f,%c", abs(deg), min, dir);
 
     char lon[20];
-    double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
+    double lond = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES;
     if ( lond < 0.0 ) {
        lond *= -1.0;
        dir = 'W';
@@ -118,17 +119,17 @@ bool FGAtlas::gen_message() {
     sprintf( lon, "%03d%06.3f,%c", abs(deg), min, dir);
 
     char speed[10];
-    sprintf( speed, "%05.1f", cur_fdm_state->get_V_equiv_kts() );
+    sprintf( speed, "%05.1f", fdm->get_V_equiv_kts() );
 
     char heading[10];
-    sprintf( heading, "%05.1f", cur_fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES );
+    sprintf( heading, "%05.1f", fdm->get_Psi() * SGD_RADIANS_TO_DEGREES );
 
     char altitude_m[10];
     sprintf( altitude_m, "%02d", 
-            (int)(cur_fdm_state->get_Altitude() * SG_FEET_TO_METER) );
+            (int)(fdm->get_Altitude() * SG_FEET_TO_METER) );
 
     char altitude_ft[10];
-    sprintf( altitude_ft, "%02d", (int)cur_fdm_state->get_Altitude() );
+    sprintf( altitude_ft, "%02d", (int)fdm->get_Altitude() );
 
     char date[10];
     sprintf( date, "%02d%02d%02d", t->getGmt()->tm_mday, 
@@ -275,7 +276,7 @@ bool FGAtlas::parse_message() {
                lat *= -1;
            }
 
-           cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
+           fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lat = " << lat );
 
            // lon val
@@ -304,17 +305,17 @@ bool FGAtlas::parse_message() {
                lon *= -1;
            }
 
-           cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
+           fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lon = " << lon );
 
 #if 0
            double sl_radius, lat_geoc;
-           sgGeodToGeoc( cur_fdm_state->get_Latitude(), 
-                         cur_fdm_state->get_Altitude(), 
+           sgGeodToGeoc( fdm->get_Latitude(), 
+                         fdm->get_Altitude(), 
                          &sl_radius, &lat_geoc );
-           cur_fdm_state->set_Geocentric_Position( lat_geoc, 
-                          cur_fdm_state->get_Longitude(), 
-                          sl_radius + cur_fdm_state->get_Altitude() );
+           fdm->set_Geocentric_Position( lat_geoc, 
+                          fdm->get_Longitude(), 
+                          sl_radius + fdm->get_Altitude() );
 #endif
 
            // speed
@@ -326,8 +327,8 @@ bool FGAtlas::parse_message() {
            string speed_str = msg.substr(begin, end - begin);
            begin = end + 1;
            speed = atof( speed_str.c_str() );
-           cur_fdm_state->set_V_calibrated_kts( speed );
-           // cur_fdm_state->set_V_ground_speed( speed );
+           fdm->set_V_calibrated_kts( speed );
+           // fdm->set_V_ground_speed( speed );
            SG_LOG( SG_IO, SG_INFO, "  speed = " << speed );
 
            // heading
@@ -339,8 +340,8 @@ bool FGAtlas::parse_message() {
            string hdg_str = msg.substr(begin, end - begin);
            begin = end + 1;
            heading = atof( hdg_str.c_str() );
-           cur_fdm_state->set_Euler_Angles( cur_fdm_state->get_Phi(), 
-                                            cur_fdm_state->get_Theta(), 
+           fdm->set_Euler_Angles( fdm->get_Phi(), 
+                                            fdm->get_Theta(), 
                                             heading * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  heading = " << heading );
        } else if ( sentence == "GPGGA" ) {
@@ -380,7 +381,7 @@ bool FGAtlas::parse_message() {
                lat *= -1;
            }
 
-           // cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
+           // fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lat = " << lat );
 
            // lon val
@@ -409,7 +410,7 @@ bool FGAtlas::parse_message() {
                lon *= -1;
            }
 
-           // cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
+           // fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lon = " << lon );
 
            // junk
@@ -465,7 +466,7 @@ bool FGAtlas::parse_message() {
                altitude *= SG_METER_TO_FEET;
            }
 
-           cur_fdm_state->set_Altitude( altitude );
+           fdm->set_Altitude( altitude );
     
            SG_LOG( SG_IO, SG_INFO, " altitude  = " << altitude );
 
index c91355afd6e7cff3bb2776e2872264b228774559..f73a14d7d56a75f157402192e055412ac15a7961 100644 (file)
 
 #include "protocol.hxx"
 
-using std::string;
-
+class FlightProperties;
 
 class FGAtlas : public FGProtocol {
 
     char buf[ FG_MAX_MSG_SIZE ];
     int length;
-
+    FlightProperties* fdm;
+    
 public:
 
     FGAtlas();
index ea6cbbe5e90bb6094df0f4c44dee78e597c04b0b..0bf751bcd5aaf0067f9cf21d26e92a29809439f0 100644 (file)
@@ -31,7 +31,7 @@
 #include <simgear/io/iochannel.hxx>
 #include <simgear/timing/sg_time.hxx>
 
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 
 using std::string;
 
 FGGarmin::FGGarmin() {
+  fdm = new FlightProperties;
 }
 
 FGGarmin::~FGGarmin() {
+  delete fdm;
 }
 
 
@@ -82,7 +84,7 @@ bool FGGarmin::gen_message() {
             t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec );
 
     char rmc_lat[20];
-    double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
+    double latd = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES;
     if ( latd < 0.0 ) {
        latd = -latd;
        dir = 'S';
@@ -94,7 +96,7 @@ bool FGGarmin::gen_message() {
     sprintf( rmc_lat, "%02d%07.4f,%c", abs(deg), min, dir);
 
     char rmc_lon[20];
-    double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
+    double lond = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES;
     if ( lond < 0.0 ) {
        lond = -lond;
        dir = 'W';
@@ -106,14 +108,14 @@ bool FGGarmin::gen_message() {
     sprintf( rmc_lon, "%03d%07.4f,%c", abs(deg), min, dir);
 
     char speed[10];
-    sprintf( speed, "%05.1f", cur_fdm_state->get_V_equiv_kts() );
+    sprintf( speed, "%05.1f", fdm->get_V_equiv_kts() );
 
     char heading[10];
-    sprintf( heading, "%05.1f", cur_fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES );
+    sprintf( heading, "%05.1f", fdm->get_Psi() * SGD_RADIANS_TO_DEGREES );
 
     char altitude_m[10];
     sprintf( altitude_m, "%02d", 
-            (int)(cur_fdm_state->get_Altitude() * SG_FEET_TO_METER) );
+            (int)(fdm->get_Altitude() * SG_FEET_TO_METER) );
 
     char date[10];
     int year = t->getGmt()->tm_year;
@@ -261,7 +263,7 @@ bool FGGarmin::parse_message() {
                lat *= -1;
            }
 
-           cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
+           fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lat = " << lat );
 
            // lon val
@@ -290,17 +292,17 @@ bool FGGarmin::parse_message() {
                lon *= -1;
            }
 
-           cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
+           fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lon = " << lon );
 
 #if 0
            double sl_radius, lat_geoc;
-           sgGeodToGeoc( cur_fdm_state->get_Latitude(), 
-                         cur_fdm_state->get_Altitude(), 
+           sgGeodToGeoc( fdm->get_Latitude(), 
+                         fdm->get_Altitude(), 
                          &sl_radius, &lat_geoc );
-           cur_fdm_state->set_Geocentric_Position( lat_geoc, 
-                          cur_fdm_state->get_Longitude(), 
-                          sl_radius + cur_fdm_state->get_Altitude() );
+           fdm->set_Geocentric_Position( lat_geoc, 
+                          fdm->get_Longitude(), 
+                          sl_radius + fdm->get_Altitude() );
 #endif
 
            // speed
@@ -312,8 +314,8 @@ bool FGGarmin::parse_message() {
            string speed_str = msg.substr(begin, end - begin);
            begin = end + 1;
            speed = atof( speed_str.c_str() );
-           cur_fdm_state->set_V_calibrated_kts( speed );
-           // cur_fdm_state->set_V_ground_speed( speed );
+           fdm->set_V_calibrated_kts( speed );
+           // fdm->set_V_ground_speed( speed );
            SG_LOG( SG_IO, SG_INFO, "  speed = " << speed );
 
            // heading
@@ -325,8 +327,8 @@ bool FGGarmin::parse_message() {
            string hdg_str = msg.substr(begin, end - begin);
            begin = end + 1;
            heading = atof( hdg_str.c_str() );
-           cur_fdm_state->set_Euler_Angles( cur_fdm_state->get_Phi(), 
-                                            cur_fdm_state->get_Theta(), 
+           fdm->set_Euler_Angles( fdm->get_Phi(), 
+                                            fdm->get_Theta(), 
                                             heading * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  heading = " << heading );
        } else if ( sentence == "PGRMZ" ) {
@@ -353,7 +355,7 @@ bool FGGarmin::parse_message() {
                altitude *= SG_METER_TO_FEET;
            }
 
-           cur_fdm_state->set_Altitude( altitude );
+           fdm->set_Altitude( altitude );
     
            SG_LOG( SG_IO, SG_INFO, " altitude  = " << altitude );
 
index 60f2420b66ea1b76fa0e8d51961e2042730e43db..e69d4ab4f868d1088f6fcae17dac8051af6016a5 100644 (file)
 
 #include "protocol.hxx"
 
-using std::string;
-
+class FlightProperties;
 
 class FGGarmin : public FGProtocol {
 
     char buf[ FG_MAX_MSG_SIZE ];
     int length;
-
+    FlightProperties* fdm;
+    
 public:
 
     FGGarmin();
index f6e0e30c7865f2b7000d34edb3b209f992ff31f2..d37c42fdf5040cb98cdf7293e091b74f5a83669e 100644 (file)
@@ -37,7 +37,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/SGMath.hxx>
 
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
 #include <MultiPlayer/mpmessages.hxx>
 
 #include "multiplay.hxx"
@@ -129,7 +129,7 @@ bool FGMultiplay::process() {
 //     if (sim_time < 20)
 //       return true;
 
-    FGInterface *ifce = cur_fdm_state;
+    FlightProperties ifce;
 
     // put together a motion info struct, you will get that later
     // from FGInterface directly ...
@@ -150,10 +150,10 @@ bool FGMultiplay::process() {
 
     // These are for now converted from lat/lon/alt and euler angles.
     // But this should change in FGInterface ...
-    double lon = ifce->get_Longitude();
-    double lat = ifce->get_Latitude();
+    double lon = ifce.get_Longitude();
+    double lat = ifce.get_Latitude();
     // first the aprioriate structure for the geodetic one
-    SGGeod geod = SGGeod::fromRadFt(lon, lat, ifce->get_Altitude());
+    SGGeod geod = SGGeod::fromRadFt(lon, lat, ifce.get_Altitude());
     // Convert to cartesion coordinate
     motionInfo.position = SGVec3d::fromGeod(geod);
     
@@ -161,28 +161,28 @@ bool FGMultiplay::process() {
     // horizontal local frame
     SGQuatf qEc2Hl = SGQuatf::fromLonLatRad((float)lon, (float)lat);
     // The orientation wrt the horizontal local frame
-    float heading = ifce->get_Psi();
-    float pitch = ifce->get_Theta();
-    float roll = ifce->get_Phi();
+    float heading = ifce.get_Psi();
+    float pitch = ifce.get_Theta();
+    float roll = ifce.get_Phi();
     SGQuatf hlOr = SGQuatf::fromYawPitchRoll(heading, pitch, roll);
     // The orientation of the vehicle wrt the earth centered frame
     motionInfo.orientation = qEc2Hl*hlOr;
 
-    if (!ifce->is_suspended()) {
+    if (!globals->get_subsystem("flight")->is_suspended()) {
       // velocities
-      motionInfo.linearVel = SG_FEET_TO_METER*SGVec3f(ifce->get_U_body(),
-                                                      ifce->get_V_body(),
-                                                      ifce->get_W_body());
-      motionInfo.angularVel = SGVec3f(ifce->get_P_body(),
-                                      ifce->get_Q_body(),
-                                      ifce->get_R_body());
+      motionInfo.linearVel = SG_FEET_TO_METER*SGVec3f(ifce.get_uBody(),
+                                                      ifce.get_vBody(),
+                                                      ifce.get_wBody());
+      motionInfo.angularVel = SGVec3f(ifce.get_P_body(),
+                                      ifce.get_Q_body(),
+                                      ifce.get_R_body());
       
       // accels, set that to zero for now.
       // Angular accelerations are missing from the interface anyway,
       // linear accelerations are screwed up at least for JSBSim.
-//  motionInfo.linearAccel = SG_FEET_TO_METER*SGVec3f(ifce->get_U_dot_body(),
-//                                                    ifce->get_V_dot_body(),
-//                                                    ifce->get_W_dot_body());
+//  motionInfo.linearAccel = SG_FEET_TO_METER*SGVec3f(ifce.get_U_dot_body(),
+//                                                    ifce.get_V_dot_body(),
+//                                                    ifce.get_W_dot_body());
       motionInfo.linearAccel = SGVec3f::zeros();
       motionInfo.angularAccel = SGVec3f::zeros();
     } else {
index c627cb15f3f32fd62a19d98c038348165d36784e..0057040537e30b8450a46e80afc373b3fc60efc5 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "native.hxx"
 
+#include <FDM/flight.hxx>
 
 FGNative::FGNative() {
 }
@@ -57,15 +58,21 @@ bool FGNative::open() {
     return true;
 }
 
+/**
+ * The design of FGNative requires direct, memcpy access to FGInterface,
+ * unfortunately. Since this is the only remaining place that does, the
+ * extern lives here, rather than a header file.
+ *
+ */
+extern FGInterface* evil_global_fdm_state;
 
 // process work for this port
 bool FGNative::process() {
     SGIOChannel *io = get_io_channel();
-    int length = sizeof(*cur_fdm_state);
+    int length = sizeof(FGInterface);
 
     if ( get_direction() == SG_IO_OUT ) {
-       // cout << "size of cur_fdm_state = " << length << endl;
-       buf = *cur_fdm_state;
+       buf = *evil_global_fdm_state;
        if ( ! io->write( (char *)(& buf), length ) ) {
            SG_LOG( SG_IO, SG_ALERT, "Error writing data." );
            return false;
@@ -74,12 +81,12 @@ bool FGNative::process() {
        if ( io->get_type() == sgFileType ) {
            if ( io->read( (char *)(& buf), length ) == length ) {
                SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
-               *cur_fdm_state = buf;
+               *evil_global_fdm_state = buf;
            }
        } else {
            while ( io->read( (char *)(& buf), length ) == length ) {
                SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
-               *cur_fdm_state = buf;
+               *evil_global_fdm_state = buf;
            }
        }
     }
index 262ca24920c9a4df87d4f025c2ba5a0426546fa7..66e00830d2e5bab151a0a75480f9874bc205a871 100644 (file)
 
 #include <string>
 
-#include <FDM/flight.hxx>
-
 #include "protocol.hxx"
-
-using std::string;
-
+#include <FDM/flight.hxx>
 
 class FGNative : public FGProtocol {
 
index d7bd3f6bfa4936a5619b64237dcba25667edbea1..2ad871f834f28387b39baebd9cb1eea00661e054 100644 (file)
@@ -29,7 +29,6 @@
 #include <simgear/io/iochannel.hxx>
 #include <simgear/io/lowlevel.hxx> // endian tests
 
-#include <FDM/flight.hxx>
 #include <Main/fg_props.hxx>
 #include <Scenery/scenery.hxx> // ground elevation
 
@@ -205,12 +204,7 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool honor_freezes,
     net->temp_c = fgGetDouble("/environment/temperature-degc");
     net->press_inhg = fgGetDouble("/environment/pressure-sea-level-inhg");
 
-    // cur_fdm_state->get_ground_elev_ft() is what we want ... this
-    // reports the altitude of the aircraft.
-    // "/environment/ground-elevation-m" reports the ground elevation
-    // of the current view point which could change substantially if
-    // the user is switching views.
-    net->hground = cur_fdm_state->get_ground_elev_ft() * SG_FEET_TO_METER;
+    net->hground = fgGetDouble("/position/ground-elev-m");
     net->magvar = fgGetDouble("/environment/magnetic-variation-deg");
 
     net->icing = fgGetBool("/hazards/icing/wing");
@@ -469,7 +463,6 @@ bool FGNativeCtrls::process() {
     int length = sizeof(FGNetCtrls);
 
     if ( get_direction() == SG_IO_OUT ) {
-       // cout << "size of cur_fdm_state = " << length << endl;
 
        FGProps2NetCtrls( &net_ctrls, true, true );
 
index 4fa6275cedd7937179b35feaf855ae69576d0841..bc28f928a6219cc7317449c00f8abb66896947fd 100644 (file)
@@ -30,7 +30,7 @@
 #include <simgear/io/iochannel.hxx>
 #include <simgear/timing/sg_time.hxx>
 
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
 #include <Time/tmp.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
@@ -115,7 +115,9 @@ bool FGNativeFDM::open() {
     set_enabled( true );
 
     // Is this really needed here ????
-    cur_fdm_state->_set_Sea_level_radius( SG_EQUATORIAL_RADIUS_FT );
+    fgSetDouble("/position/sea-level-radius-ft", SG_EQUATORIAL_RADIUS_FT);
+
+    
 
     return true;
 }
@@ -124,37 +126,39 @@ bool FGNativeFDM::open() {
 void FGProps2NetFDM( FGNetFDM *net, bool net_byte_order ) {
     unsigned int i;
 
+    FlightProperties fdm_state;
+
     // Version sanity checking
     net->version = FG_NET_FDM_VERSION;
 
     // Aero parameters
-    net->longitude = cur_fdm_state->get_Longitude();
-    net->latitude = cur_fdm_state->get_Latitude();
-    net->altitude = cur_fdm_state->get_Altitude() * SG_FEET_TO_METER;
-    net->agl = cur_fdm_state->get_Altitude_AGL() * SG_FEET_TO_METER;
-    net->phi = cur_fdm_state->get_Phi();
-    net->theta = cur_fdm_state->get_Theta();
-    net->psi = cur_fdm_state->get_Psi();
-    net->alpha = cur_fdm_state->get_Alpha();
-    net->beta = cur_fdm_state->get_Beta();
-    net->phidot = cur_fdm_state->get_Phi_dot_degps() * SG_DEGREES_TO_RADIANS;
-    net->thetadot = cur_fdm_state->get_Theta_dot_degps()
+    net->longitude = fdm_state.get_Longitude();
+    net->latitude = fdm_state.get_Latitude();
+    net->altitude = fdm_state.get_Altitude() * SG_FEET_TO_METER;
+    net->agl = fdm_state.get_Altitude_AGL() * SG_FEET_TO_METER;
+    net->phi = fdm_state.get_Phi();
+    net->theta = fdm_state.get_Theta();
+    net->psi = fdm_state.get_Psi();
+    net->alpha = fdm_state.get_Alpha();
+    net->beta = fdm_state.get_Beta();
+    net->phidot = fdm_state.get_Phi_dot_degps() * SG_DEGREES_TO_RADIANS;
+    net->thetadot = fdm_state.get_Theta_dot_degps()
         * SG_DEGREES_TO_RADIANS;
-    net->psidot = cur_fdm_state->get_Psi_dot_degps() * SG_DEGREES_TO_RADIANS;
+    net->psidot = fdm_state.get_Psi_dot_degps() * SG_DEGREES_TO_RADIANS;
 
-    net->vcas = cur_fdm_state->get_V_calibrated_kts();
-    net->climb_rate = cur_fdm_state->get_Climb_Rate();
+    net->vcas = fdm_state.get_V_calibrated_kts();
+    net->climb_rate = fdm_state.get_Climb_Rate();
 
-    net->v_north = cur_fdm_state->get_V_north();
-    net->v_east = cur_fdm_state->get_V_east();
-    net->v_down = cur_fdm_state->get_V_down();
-    net->v_wind_body_north = cur_fdm_state->get_uBody();
-    net->v_wind_body_east = cur_fdm_state->get_vBody();
-    net->v_wind_body_down = cur_fdm_state->get_wBody();
+    net->v_north = fdm_state.get_V_north();
+    net->v_east = fdm_state.get_V_east();
+    net->v_down = fdm_state.get_V_down();
+    net->v_wind_body_north = fdm_state.get_uBody();
+    net->v_wind_body_east = fdm_state.get_vBody();
+    net->v_wind_body_down = fdm_state.get_wBody();
 
-    net->A_X_pilot = cur_fdm_state->get_A_X_pilot();
-    net->A_Y_pilot = cur_fdm_state->get_A_Y_pilot();
-    net->A_Z_pilot = cur_fdm_state->get_A_Z_pilot();
+    net->A_X_pilot = fdm_state.get_A_X_pilot();
+    net->A_Y_pilot = fdm_state.get_A_Y_pilot();
+    net->A_Z_pilot = fdm_state.get_A_Z_pilot();
 
     net->stall_warning = fgGetDouble("/sim/alarms/stall-warning", 0.0);
     net->slip_deg
@@ -300,7 +304,8 @@ void FGProps2NetFDM( FGNetFDM *net, bool net_byte_order ) {
 
 void FGNetFDM2Props( FGNetFDM *net, bool net_byte_order ) {
     unsigned int i;
-
+    FlightProperties fdm_state;
+    
     if ( net_byte_order ) {
         // Convert to the net buffer from network format
         net->version = ntohl(net->version);
@@ -379,37 +384,38 @@ void FGNetFDM2Props( FGNetFDM *net, bool net_byte_order ) {
 
     if ( net->version == FG_NET_FDM_VERSION ) {
         // cout << "pos = " << net->longitude << " " << net->latitude << endl;
-        // cout << "sea level rad = " << cur_fdm_state->get_Sea_level_radius()
+        // cout << "sea level rad = " << fdm_state.get_Sea_level_radius()
        //      << endl;
-        cur_fdm_state->_updateGeodeticPosition( net->latitude,
-                                                net->longitude,
-                                                net->altitude
-                                                  * SG_METER_TO_FEET );
+                                      
+      fdm_state.set_Latitude(net->latitude);
+        fdm_state.set_Longitude(net->longitude);
+        fdm_state.set_Altitude(net->altitude * SG_METER_TO_FEET);
+        
        if ( net->agl > -9000 ) {
-           cur_fdm_state->_set_Altitude_AGL( net->agl * SG_METER_TO_FEET );
+           fdm_state.set_Altitude_AGL( net->agl * SG_METER_TO_FEET );
        } else {
            double agl_m = net->altitude
-              - cur_fdm_state->get_Runway_altitude_m();
-           cur_fdm_state->_set_Altitude_AGL( agl_m * SG_METER_TO_FEET );
+              - fdm_state.get_Runway_altitude_m();
+           fdm_state.set_Altitude_AGL( agl_m * SG_METER_TO_FEET );
        }
-        cur_fdm_state->_set_Euler_Angles( net->phi,
+        fdm_state.set_Euler_Angles( net->phi,
                                           net->theta,
                                           net->psi );
-        cur_fdm_state->_set_Alpha( net->alpha );
-        cur_fdm_state->_set_Beta( net->beta );
-        cur_fdm_state->_set_Euler_Rates( net->phidot,
+        fdm_state.set_Alpha( net->alpha );
+        fdm_state.set_Beta( net->beta );
+        fdm_state.set_Euler_Rates( net->phidot,
                                         net->thetadot,
                                         net->psidot );
-        cur_fdm_state->_set_V_calibrated_kts( net->vcas );
-        cur_fdm_state->_set_Climb_Rate( net->climb_rate );
-        cur_fdm_state->_set_Velocities_Local( net->v_north,
+        fdm_state.set_V_calibrated_kts( net->vcas );
+        fdm_state.set_Climb_Rate( net->climb_rate );
+        fdm_state.set_Velocities_Local( net->v_north,
                                               net->v_east,
                                               net->v_down );
-        cur_fdm_state->_set_Velocities_Wind_Body( net->v_wind_body_north,
+        fdm_state.set_Velocities_Wind_Body( net->v_wind_body_north,
                                                   net->v_wind_body_east,
                                                   net->v_wind_body_down );
 
-        cur_fdm_state->_set_Accels_Pilot_Body( net->A_X_pilot,
+        fdm_state.set_Accels_Pilot_Body( net->A_X_pilot,
                                               net->A_Y_pilot,
                                               net->A_Z_pilot );
 
@@ -502,7 +508,7 @@ bool FGNativeFDM::process() {
     int length = sizeof(buf);
 
     if ( get_direction() == SG_IO_OUT ) {
-       // cout << "size of cur_fdm_state = " << length << endl;
+
        FGProps2NetFDM( &buf );
        if ( ! io->write( (char *)(& buf), length ) ) {
            SG_LOG( SG_IO, SG_ALERT, "Error writing data." );
index fd8672bb60b8c24434bf698e408434e7a7d4219c..4a21864c7c8a355ef11edf5ec86af51f1b4d9e17 100644 (file)
 
 #include <simgear/timing/timestamp.hxx>
 
-#include <FDM/flight.hxx>
-
 #include "protocol.hxx"
 #include "net_fdm.hxx"
 
 
-class FGNativeFDM : public FGProtocol, public FGInterface {
+class FGNativeFDM : public FGProtocol {
 
     FGNetFDM buf;
     int length;
-
+    
 public:
 
     FGNativeFDM();
index d7310101a96bd2c91420a8a57398ff39a5883c45..6ddb8349612fbd0d6929a2fa5cd85bbc05781e73 100644 (file)
 #include <simgear/io/iochannel.hxx>
 #include <simgear/timing/sg_time.hxx>
 
-#include <FDM/flight.hxx>
 #include <Time/tmp.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 #include <Scenery/scenery.hxx>
+#include <FDM/flightProperties.hxx>
 
 #include "native_gui.hxx"
 
@@ -116,7 +116,7 @@ bool FGNativeGUI::open() {
 
     set_enabled( true );
 
-    cur_fdm_state->_set_Sea_level_radius( SG_EQUATORIAL_RADIUS_FT );
+    fgSetDouble("/position/sea-level-radius-ft", SG_EQUATORIAL_RADIUS_FT);
     return true;
 }
 
@@ -140,20 +140,22 @@ void FGProps2NetGUI( FGNetGUI *net ) {
        = fgGetNode("/instrumentation/nav/gs-needle-deflection", true);
     unsigned int i;
 
+    static FlightProperties* fdm_state = new FlightProperties;
+
     // Version sanity checking
     net->version = FG_NET_GUI_VERSION;
 
     // Aero parameters
-    net->longitude = cur_fdm_state->get_Longitude();
-    net->latitude = cur_fdm_state->get_Latitude();
-    net->altitude = cur_fdm_state->get_Altitude() * SG_FEET_TO_METER;
-    net->phi = cur_fdm_state->get_Phi();
-    net->theta = cur_fdm_state->get_Theta();
-    net->psi = cur_fdm_state->get_Psi();
+    net->longitude = fdm_state->get_Longitude();
+    net->latitude = fdm_state->get_Latitude();
+    net->altitude = fdm_state->get_Altitude() * SG_FEET_TO_METER;
+    net->phi = fdm_state->get_Phi();
+    net->theta = fdm_state->get_Theta();
+    net->psi = fdm_state->get_Psi();
 
     // Velocities
-    net->vcas = cur_fdm_state->get_V_calibrated_kts();
-    net->climb_rate = cur_fdm_state->get_Climb_Rate();
+    net->vcas = fdm_state->get_V_calibrated_kts();
+    net->climb_rate = fdm_state->get_Climb_Rate();
 
     // Consumables
     net->num_tanks = FGNetGUI::FG_MAX_TANKS;
@@ -165,7 +167,7 @@ void FGProps2NetGUI( FGNetGUI *net ) {
     // Environment
     net->cur_time = globals->get_time_params()->get_cur_time();
     net->warp = globals->get_warp();
-    net->ground_elev = cur_fdm_state->get_Runway_altitude_m();
+    net->ground_elev = fdm_state->get_Runway_altitude_m();
 
     // Approach
     net->tuned_freq = nav_freq->getDoubleValue();
@@ -281,19 +283,22 @@ void FGNetGUI2Props( FGNetGUI *net ) {
 #endif
 
     if ( net->version == FG_NET_GUI_VERSION ) {
+        FlightProperties fdm_state;
+        
         // cout << "pos = " << net->longitude << " " << net->latitude << endl;
-        // cout << "sea level rad = " << cur_fdm_state->get_Sea_level_radius()
+        // cout << "sea level rad = " << fdm_state->get_Sea_level_radius()
        //      << endl;
-        cur_fdm_state->_updateGeodeticPosition( net->latitude,
-                                                net->longitude,
-                                                net->altitude
-                                                  * SG_METER_TO_FEET );
-        cur_fdm_state->_set_Euler_Angles( net->phi,
+  
+        fdm_state.set_Latitude(net->latitude);
+        fdm_state.set_Longitude(net->longitude);
+        fdm_state.set_Altitude(net->altitude * SG_METER_TO_FEET);
+
+        fdm_state.set_Euler_Angles( net->phi,
                                           net->theta,
                                           net->psi );
 
-        cur_fdm_state->_set_V_calibrated_kts( net->vcas );
-        cur_fdm_state->_set_Climb_Rate( net->climb_rate );
+        fdm_state.set_V_calibrated_kts( net->vcas );
+        fdm_state.set_Climb_Rate( net->climb_rate );
 
        for (i = 0; i < net->num_tanks; ++i ) {
            SGPropertyNode * node
@@ -333,7 +338,7 @@ bool FGNativeGUI::process() {
     int length = sizeof(buf);
 
     if ( get_direction() == SG_IO_OUT ) {
-       // cout << "size of cur_fdm_state = " << length << endl;
+       // cout << "size of fdm_state = " << length << endl;
        FGProps2NetGUI( &buf );
        if ( ! io->write( (char *)(& buf), length ) ) {
            SG_LOG( SG_IO, SG_ALERT, "Error writing data." );
index cf5e9de41f72c5bb3fca1ea09d6ed15113905cb8..299a40628b67bb7613459fadf134e53953bc65ae 100644 (file)
 
 #include <simgear/compiler.h>
 
-#include <FDM/flight.hxx>
-
 #include "protocol.hxx"
 #include "net_gui.hxx"
 
-
-class FGNativeGUI : public FGProtocol, public FGInterface {
+class FGNativeGUI : public FGProtocol {
 
     FGNetGUI buf;
     int length;
-
+    
 public:
 
     FGNativeGUI();
index 921f5aa606842aea7a544b8f50e5028faf669ac3..b9d4eb1a4d75dbdfc9f9327cbc4cdb019db944cb 100644 (file)
 #include <simgear/io/iochannel.hxx>
 #include <simgear/timing/sg_time.hxx>
 
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 
 #include "nmea.hxx"
 
 FGNMEA::FGNMEA() {
+  fdm = new FlightProperties();
 }
 
 FGNMEA::~FGNMEA() {
+  delete fdm;
 }
 
 
@@ -79,7 +81,7 @@ bool FGNMEA::gen_message() {
             t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec );
 
     char gga_lat[20], rmc_lat[20];
-    double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
+    double latd = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES;
     if ( latd < 0.0 ) {
        latd = -latd;
        dir = 'S';
@@ -92,7 +94,7 @@ bool FGNMEA::gen_message() {
     sprintf( rmc_lat, "%02d%07.4f,%c", abs(deg), min, dir);
 
     char gga_lon[20], rmc_lon[20];
-    double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
+    double lond = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES;
     if ( lond < 0.0 ) {
        lond = -lond;
        dir = 'W';
@@ -121,7 +123,7 @@ bool FGNMEA::gen_message() {
 
     char altitude_m[10];
     sprintf( altitude_m, "%.1f", 
-            cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
+            fdm->get_Altitude() * SG_FEET_TO_METER );
 
     char date[10];
     int year = t->getGmt()->tm_year;
@@ -272,7 +274,7 @@ bool FGNMEA::parse_message() {
                lat *= -1;
            }
 
-           cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
+           fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lat = " << lat );
 
            // lon val
@@ -301,17 +303,17 @@ bool FGNMEA::parse_message() {
                lon *= -1;
            }
 
-           cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
+           fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lon = " << lon );
 
 #if 0
            double sl_radius, lat_geoc;
-           sgGeodToGeoc( cur_fdm_state->get_Latitude(), 
-                         cur_fdm_state->get_Altitude(), 
+           sgGeodToGeoc( fdm->get_Latitude(), 
+                         fdm->get_Altitude(), 
                          &sl_radius, &lat_geoc );
-           cur_fdm_state->set_Geocentric_Position( lat_geoc, 
-                          cur_fdm_state->get_Longitude(), 
-                          sl_radius + cur_fdm_state->get_Altitude() );
+           fdm->set_Geocentric_Position( lat_geoc, 
+                          fdm->get_Longitude(), 
+                          sl_radius + fdm->get_Altitude() );
 #endif
 
            // speed
@@ -323,8 +325,8 @@ bool FGNMEA::parse_message() {
            string speed_str = msg.substr(begin, end - begin);
            begin = end + 1;
            speed = atof( speed_str.c_str() );
-           cur_fdm_state->set_V_calibrated_kts( speed );
-           // cur_fdm_state->set_V_ground_speed( speed );
+           fdm->set_V_calibrated_kts( speed );
+           // fdm->set_V_ground_speed( speed );
            SG_LOG( SG_IO, SG_INFO, "  speed = " << speed );
 
            // heading
@@ -336,8 +338,8 @@ bool FGNMEA::parse_message() {
            string hdg_str = msg.substr(begin, end - begin);
            begin = end + 1;
            heading = atof( hdg_str.c_str() );
-           cur_fdm_state->set_Euler_Angles( cur_fdm_state->get_Phi(), 
-                                            cur_fdm_state->get_Theta(), 
+           fdm->set_Euler_Angles( fdm->get_Phi(), 
+                                            fdm->get_Theta(), 
                                             heading * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  heading = " << heading );
        } else if ( sentence == "GPGGA" ) {
@@ -377,7 +379,7 @@ bool FGNMEA::parse_message() {
                lat *= -1;
            }
 
-           // cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
+           // fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lat = " << lat );
 
            // lon val
@@ -406,7 +408,7 @@ bool FGNMEA::parse_message() {
                lon *= -1;
            }
 
-           // cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
+           // fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lon = " << lon );
 
            // junk
@@ -462,7 +464,7 @@ bool FGNMEA::parse_message() {
                altitude *= SG_METER_TO_FEET;
            }
 
-           cur_fdm_state->set_Altitude( altitude );
+           fdm->set_Altitude( altitude );
     
            SG_LOG( SG_IO, SG_INFO, " altitude  = " << altitude );
 
index 0549b70145f5ce05bd8b033a33b4ad5282b38d5a..38a266e7e6e7227a1735ca7444d671cc9e05334d 100644 (file)
 
 #include "protocol.hxx"
 
-using std::string;
-
+class FlightProperties;
 
 class FGNMEA : public FGProtocol {
 
     char buf[ FG_MAX_MSG_SIZE ];
     int length;
-
+    FlightProperties* fdm;
 public:
 
     FGNMEA();
index 6cdb5a4f55566fa6344739eef2a8f46774a4f398..687df7a04c6e2ed15c0fc1301e636021ecb99561 100644 (file)
@@ -38,7 +38,7 @@
 #include <vector>
 
 #include "opengc.hxx"
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 
@@ -101,9 +101,11 @@ FGOpenGC::FGOpenGC() :
        p_alphadot(fgGetNode("/fdm/jsbsim/aero/alphadot-rad_sec[0]", true)),
        p_betadot(fgGetNode("/fdm/jsbsim/aero/betadot-rad_sec[0]", true))
 {
+  fdm = new FlightProperties;
 }
 
 FGOpenGC::~FGOpenGC() {
+  delete fdm;
 }
 
 // open hailing frequencies
@@ -127,7 +129,7 @@ bool FGOpenGC::open() {
 }
 
 //static void collect_data( const FGInterface *fdm, ogcFGData *data ) {
-void FGOpenGC::collect_data( const FGInterface *fdm, ogcFGData *data ) {       
+void FGOpenGC::collect_data(ogcFGData *data ) {        
                                                                                        
     data->version_id = OGC_VERSION;
     
@@ -144,16 +146,16 @@ void FGOpenGC::collect_data( const FGInterface *fdm, ogcFGData *data ) {
    
     data->vvi = p_vvi->getDoubleValue();
     data->mach = p_mach->getDoubleValue();
-    data->groundspeed = cur_fdm_state->get_V_ground_speed();
-    data->v_keas = cur_fdm_state->get_V_equiv_kts();
+    data->groundspeed = fdm->get_V_ground_speed();
+    data->v_keas = fdm->get_V_equiv_kts();
     data->v_kcas = vel_kcas->getDoubleValue();
  
 
-    data->phi_dot = cur_fdm_state->get_Phi_dot();
-    data->theta_dot = cur_fdm_state->get_Theta_dot();
-    data->psi_dot = cur_fdm_state->get_Psi_dot();
+    data->phi_dot = fdm->get_Phi_dot();
+    data->theta_dot = fdm->get_Theta_dot();
+    data->psi_dot = fdm->get_Psi_dot();
 
-    data->alpha = cur_fdm_state->get_Alpha();
+    data->alpha = fdm->get_Alpha();
     data->beta = p_yaw->getDoubleValue();
     data->alpha_dot = p_alphadot->getDoubleValue();
     data->beta_dot = p_yaw_rate->getDoubleValue();
@@ -272,9 +274,9 @@ void FGOpenGC::collect_data( const FGInterface *fdm, ogcFGData *data ) {
                data->x_feed_valve[2] = x_feed2_node->getBoolValue(); 
                data->x_feed_valve[3] = x_feed3_node->getBoolValue(); 
                **********/                     
-    data->total_temperature = cur_fdm_state->get_Total_temperature();
-    data->total_pressure = cur_fdm_state->get_Total_pressure();
-    data->dynamic_pressure = cur_fdm_state->get_Dynamic_pressure();
+    data->total_temperature = fdm->get_Total_temperature();
+    data->total_pressure = fdm->get_Total_pressure();
+    data->dynamic_pressure = fdm->get_Dynamic_pressure();
     
     data->static_pressure = press_node->getDoubleValue();
     data->static_temperature = temp_node->getDoubleValue();
@@ -283,7 +285,7 @@ void FGOpenGC::collect_data( const FGInterface *fdm, ogcFGData *data ) {
     data->sea_level_pressure = fgGetDouble("/environment/sea-level-pressure-inhg");
 }
 
-static void distribute_data( const ogcFGData *data, FGInterface *chunk ) {
+static void distribute_data( const ogcFGData *data ) {
     // just a place holder until the CDU is developed
        
 }
@@ -294,7 +296,7 @@ bool FGOpenGC::process() {
     int length = sizeof(buf);
 
     if ( get_direction() == SG_IO_OUT ) {
-        collect_data( cur_fdm_state, &buf );
+        collect_data( &buf );
        //collect_data( &buf );
        if ( ! io->write( (char *)(& buf), length ) ) {
            SG_LOG( SG_IO, SG_ALERT, "Error writing data." );
@@ -304,12 +306,12 @@ bool FGOpenGC::process() {
        if ( io->get_type() == sgFileType ) {
            if ( io->read( (char *)(& buf), length ) == length ) {
                SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
-               distribute_data( &buf, cur_fdm_state );
+               distribute_data( &buf );
            }
        } else {
            while ( io->read( (char *)(& buf), length ) == length ) {
                SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
-               distribute_data( &buf, cur_fdm_state );
+               distribute_data( &buf );
            }
        }
     }
index 0f7ad4c385765b7f7dcf1e0f7b9cd6caa4cfcde4..6371e1d0ae98bf91f3e4a2ac0fe313c22cdff95b 100644 (file)
 
 #include <string>
 
-#include <FDM/flight.hxx>
 #include <Main/fg_props.hxx>
 
 #include "protocol.hxx"
 #include "opengc_data.hxx"
 
-class FGOpenGC : public FGProtocol, public FGInterface {
+class FlightProperties;
+
+class FGOpenGC : public FGProtocol
+{
 
     ogcFGData buf;
+    FlightProperties* fdm;
     
     // Environment
     SGPropertyNode_ptr press_node;
@@ -154,7 +157,7 @@ public:
     // close the channel
     bool close();
 
-    void collect_data( const FGInterface *fdm, ogcFGData *data );
+    void collect_data(ogcFGData *data );
 };
 
 #endif // _FG_OPENGC_HXX
index b497120ca9deaceabfa4c7e9ad385d8584d8402a..c78422eb627536298e6a955ac0a636b496e3ac89 100644 (file)
@@ -30,7 +30,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/io/iochannel.hxx>
 
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
 
 #include "pve.hxx"
 
@@ -55,10 +55,10 @@ FGPVE::~FGPVE() {
 
 bool FGPVE::gen_message() {
     // cout << "generating pve message" << endl;
-    FGInterface *f = cur_fdm_state;
+    FlightProperties f;
 
     // get roll and pitch, convert to degrees
-    double roll_deg = f->get_Phi() * SGD_RADIANS_TO_DEGREES;
+    double roll_deg = f.get_Phi() * SGD_RADIANS_TO_DEGREES;
     while ( roll_deg <= -180.0 ) {
        roll_deg += 360.0;
     }
@@ -66,7 +66,7 @@ bool FGPVE::gen_message() {
        roll_deg -= 360.0;
     }
 
-    double pitch_deg = f->get_Theta() * SGD_RADIANS_TO_DEGREES;
+    double pitch_deg = f.get_Theta() * SGD_RADIANS_TO_DEGREES;
     while ( pitch_deg <= -180.0 ) {
        pitch_deg += 360.0;
     }
@@ -74,7 +74,7 @@ bool FGPVE::gen_message() {
        pitch_deg -= 360.0;
     }
 
-    short int heave = (int)(f->get_W_body() * 128.0);
+    short int heave = (int)(f.get_wBody() * 128.0);
 
     // scale roll and pitch to output format (1 - 255)
     // straight && level == (128, 128)
index 97a0c1262e83ff2052cb40150da0a5e5d1aa528a..b85831087d68c83e8998b0483de4dd71506fb89f 100644 (file)
@@ -28,7 +28,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/io/iochannel.hxx>
 
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
 
 #include "ray.hxx"
 
@@ -66,7 +66,8 @@ FGRAY::~FGRAY() {
 
 bool FGRAY::gen_message() {
     // cout << "generating RayWoodworth message" << endl;
-    FGInterface *f = cur_fdm_state;
+    FlightProperties f;
+    
     int axis, subaxis;
     const double fullscale[6] = { -0.5, -0.5, -0.5, /* radians */
                                  -0.3, -0.3, -0.15  /* meters */ };
@@ -76,7 +77,7 @@ bool FGRAY::gen_message() {
 
     /* get basic information about gravity */
     double grav_acc = -9.81;
-    double vert_acc = f->get_A_Z_pilot() * 0.3;
+    double vert_acc = f.get_A_Z_pilot() * 0.3;
     if ( -3.0 < vert_acc )
        vert_acc = -3.0;
 
@@ -89,13 +90,13 @@ bool FGRAY::gen_message() {
 
        /* Retrieve the desired components */
        switch ( axis ) {
-       case 0: ang_pos = f->get_Phi();
-               lin_acc = f->get_A_Y_pilot() * 0.3;
+       case 0: ang_pos = f.get_Phi();
+               lin_acc = f.get_A_Y_pilot() * 0.3;
                break;
-       case 1: ang_pos = f->get_Theta();
-               lin_acc = f->get_A_X_pilot() * 0.3;
+       case 1: ang_pos = f.get_Theta();
+               lin_acc = f.get_A_X_pilot() * 0.3;
                break;
-       case 2: ang_pos = f->get_Psi();
+       case 2: ang_pos = f.get_Psi();
                lin_acc = grav_acc - vert_acc;
                break;
        default:
index a55a897f2a02194c371804e4485db1cdf4d81c99..9945163069f0d684248d70a64a91aad455e2a951 100644 (file)
@@ -31,7 +31,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/io/iochannel.hxx>
 
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
 
 #include "rul.hxx"
 
@@ -61,10 +61,10 @@ FGRUL::~FGRUL() {
 
 bool FGRUL::gen_message() {
     // cout << "generating rul message" << endl;
-    FGInterface *f = cur_fdm_state;
+    FlightProperties f;
 
     // get roll and pitch, convert to degrees
-    double roll_deg = f->get_Phi() * SGD_RADIANS_TO_DEGREES;
+    double roll_deg = f.get_Phi() * SGD_RADIANS_TO_DEGREES;
     while ( roll_deg < -180.0 ) {
        roll_deg += 360.0;
     }
@@ -72,7 +72,7 @@ bool FGRUL::gen_message() {
        roll_deg -= 360.0;
     }
 
-    double pitch_deg = f->get_Theta() * SGD_RADIANS_TO_DEGREES;
+    double pitch_deg = f.get_Theta() * SGD_RADIANS_TO_DEGREES;
     while ( pitch_deg < -180.0 ) {
        pitch_deg += 360.0;
     }