From 85be9be1e05c76a2d5fde5086a4122f79529e015 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 16 Jun 2010 08:31:59 +0100 Subject: [PATCH] Initial work on FDM shell, and removal of cur_fdm_state --- src/Aircraft/aircraft.cxx | 24 +- src/Aircraft/aircraft.hxx | 2 - src/Aircraft/replay.cxx | 4 +- src/Autopilot/route_mgr.cxx | 18 +- src/Cockpit/cockpit.cxx | 135 +++++------- src/Cockpit/hud_rwy.cxx | 2 +- src/Environment/environment_mgr.cxx | 34 +-- src/Environment/environment_mgr.hxx | 2 - src/FDM/ExternalPipe/ExternalPipe.cxx | 29 +-- src/FDM/ExternalPipe/ExternalPipe.hxx | 1 + src/FDM/JSBSim/JSBSim.cxx | 2 +- src/FDM/fdm_shell.cxx | 242 +++++++++++++++++++++ src/FDM/fdm_shell.hxx | 40 ++++ src/FDM/flight.cxx | 43 ++-- src/FDM/flight.hxx | 34 ++- src/FDM/flightProperties.cxx | 289 +++++++++++++++++++++++++ src/FDM/flightProperties.hxx | 102 +++++++++ src/Instrumentation/HUD/HUD_runway.cxx | 2 +- src/Main/fg_commands.cxx | 2 +- src/Main/fg_init.cxx | 122 +---------- src/Main/fg_props.cxx | 29 +-- src/Main/main.cxx | 106 +-------- src/Main/renderer.cxx | 24 +- src/Network/AV400.cxx | 31 ++- src/Network/AV400.hxx | 6 +- src/Network/AV400Sim.cxx | 10 +- src/Network/AV400Sim.hxx | 6 +- src/Network/atlas.cxx | 45 ++-- src/Network/atlas.hxx | 6 +- src/Network/garmin.cxx | 38 ++-- src/Network/garmin.hxx | 6 +- src/Network/multiplay.cxx | 36 +-- src/Network/native.cxx | 17 +- src/Network/native.hxx | 6 +- src/Network/native_ctrls.cxx | 9 +- src/Network/native_fdm.cxx | 94 ++++---- src/Network/native_fdm.hxx | 6 +- src/Network/native_gui.cxx | 45 ++-- src/Network/native_gui.hxx | 7 +- src/Network/nmea.cxx | 38 ++-- src/Network/nmea.hxx | 5 +- src/Network/opengc.cxx | 32 +-- src/Network/opengc.hxx | 9 +- src/Network/pve.cxx | 10 +- src/Network/ray.cxx | 17 +- src/Network/rul.cxx | 8 +- 46 files changed, 1095 insertions(+), 680 deletions(-) create mode 100644 src/FDM/fdm_shell.cxx create mode 100644 src/FDM/fdm_shell.hxx create mode 100644 src/FDM/flightProperties.cxx create mode 100644 src/FDM/flightProperties.hxx diff --git a/src/Aircraft/aircraft.cxx b/src/Aircraft/aircraft.cxx index c3514e29a..91e93b276 100644 --- a/src/Aircraft/aircraft.cxx +++ b/src/Aircraft/aircraft.cxx @@ -44,6 +44,7 @@ #include #include #include +#include #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. // diff --git a/src/Aircraft/aircraft.hxx b/src/Aircraft/aircraft.hxx index 95763b017..f28bb4c22 100644 --- a/src/Aircraft/aircraft.hxx +++ b/src/Aircraft/aircraft.hxx @@ -26,13 +26,11 @@ #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 ; diff --git a/src/Aircraft/replay.cxx b/src/Aircraft/replay.cxx index 21c4a1d44..d36275e38 100644 --- a/src/Aircraft/replay.cxx +++ b/src/Aircraft/replay.cxx @@ -26,7 +26,6 @@ #include -#include #include
#include #include @@ -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"); diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index 967ca992a..07059cc16 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -51,20 +51,8 @@ #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 } diff --git a/src/Cockpit/cockpit.cxx b/src/Cockpit/cockpit.cxx index 0414a0f6a..9e1457220 100644 --- a/src/Cockpit/cockpit.cxx +++ b/src/Cockpit/cockpit.cxx @@ -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. @@ -59,14 +62,14 @@ 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 diff --git a/src/Cockpit/hud_rwy.cxx b/src/Cockpit/hud_rwy.cxx index 0f7866619..b920bcfc8 100644 --- a/src/Cockpit/hud_rwy.cxx +++ b/src/Cockpit/hud_rwy.cxx @@ -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; diff --git a/src/Environment/environment_mgr.cxx b/src/Environment/environment_mgr.cxx index acf20b861..a5d76ecfc 100644 --- a/src/Environment/environment_mgr.cxx +++ b/src/Environment/environment_mgr.cxx @@ -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 { diff --git a/src/Environment/environment_mgr.hxx b/src/Environment/environment_mgr.hxx index ffd753463..490340c4a 100644 --- a/src/Environment/environment_mgr.hxx +++ b/src/Environment/environment_mgr.hxx @@ -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; diff --git a/src/FDM/ExternalPipe/ExternalPipe.cxx b/src/FDM/ExternalPipe/ExternalPipe.cxx index 2be480971..f3c7f2912 100644 --- a/src/FDM/ExternalPipe/ExternalPipe.cxx +++ b/src/FDM/ExternalPipe/ExternalPipe.cxx @@ -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 diff --git a/src/FDM/ExternalPipe/ExternalPipe.hxx b/src/FDM/ExternalPipe/ExternalPipe.hxx index d5e03967b..866967c12 100644 --- a/src/FDM/ExternalPipe/ExternalPipe.hxx +++ b/src/FDM/ExternalPipe/ExternalPipe.hxx @@ -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 diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index 04a2e70bb..e9732f772 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -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 index 000000000..6c2d09537 --- /dev/null +++ b/src/FDM/fdm_shell.cxx @@ -0,0 +1,242 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include +#include +#include +#include
+#include
+#include + +// all the FDMs, since we are the factory method +#if ENABLE_SP_FDM +#include +#include +#include +#include +#endif +#include +#include +#include +#include +#include +#include +#include + +/* + * 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 index 000000000..c9b44db70 --- /dev/null +++ b/src/FDM/fdm_shell.hxx @@ -0,0 +1,40 @@ +#ifndef FG_FDM_SHELL_HXX +#define FG_FDM_SHELL_HXX + +#include + +// 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 diff --git a/src/FDM/flight.cxx b/src/FDM/flight.cxx index 10ce9948a..cf4ab9e6a 100644 --- a/src/FDM/flight.cxx +++ b/src/FDM/flight.cxx @@ -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(); -} diff --git a/src/FDM/flight.hxx b/src/FDM/flight.hxx index 222df3b54..90859d921 100644 --- a/src/FDM/flight.hxx +++ b/src/FDM/flight.hxx @@ -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 index 000000000..24602325c --- /dev/null +++ b/src/FDM/flightProperties.cxx @@ -0,0 +1,289 @@ +#include + +#include +#include + +#include
+ +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 index 000000000..9df57f345 --- /dev/null +++ b/src/FDM/flightProperties.hxx @@ -0,0 +1,102 @@ +#ifndef FG_FLIGHT_PROPERTIES_HXX +#define FG_FLIGHT_PROPERTIES_HXX + +#include +#include // for SGVec3d +#include + +// 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 diff --git a/src/Instrumentation/HUD/HUD_runway.cxx b/src/Instrumentation/HUD/HUD_runway.cxx index 8eb443c36..3e3d51701 100644 --- a/src/Instrumentation/HUD/HUD_runway.cxx +++ b/src/Instrumentation/HUD/HUD_runway.cxx @@ -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; diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 6131e4795..5e90575dc 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -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(); diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 328c8913c..72f6849e9 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -89,19 +89,6 @@ #include #include -#if ENABLE_SP_FDM -#include -#include -#include -#include -#endif -#include -#include -#include -#include -#include -#include -#include #include #include #include @@ -123,6 +110,7 @@ #include