#include <Cockpit/hud.hxx>
#include <Cockpit/panel_io.hxx>
#include <Model/acmodel.hxx>
+#include <FDM/flightProperties.hxx>
#include "aircraft.hxx"
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()
// TODO:
// remove electrical system
- cur_fdm_state->unbind();
-
+ globals->get_subsystem("flight")->unbind();
+
// Save the selected aircraft model since restoreInitialState
// will obverwrite it.
//
#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 ;
#include <simgear/constants.h>
-#include <FDM/flight.hxx>
#include <Main/fg_props.hxx>
#include <Network/native_ctrls.hxx>
#include <Network/native_fdm.hxx>
//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");
#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 )),
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));
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
}
#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;
}
float get_longitude( void )
{
- return current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
+ return fgGetDouble("/position/longitude-deg");
}
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;
}
{
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;
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 )
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 )
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 )
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;
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;
}
{
// 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;
}
{
// 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;
}
{
// 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
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;
{
SG_LOG( SG_GENERAL, SG_INFO, "Initializing environment subsystem");
SGSubsystemGroup::init();
- _update_fdm();
+ //_update_fdm();
}
void
{
SG_LOG( SG_GENERAL, SG_INFO, "Reinitializing environment subsystem");
SGSubsystemGroup::reinit();
- _update_fdm();
+ //_update_fdm();
}
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
}
-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
{
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;
// 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
void update_binary( double dt );
void update_property( double dt );
+ void process_set_command( const string_list &tokens );
public:
// Constructor
_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;
--- /dev/null
+#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.");
+ }
+
+}
+
--- /dev/null
+#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
ptr[2] = vec[2];
}
-FGInterface *cur_fdm_state = 0;
-
// Constructor
FGInterface::FGInterface()
{
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
&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,
// 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);
&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,
// 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
&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
// 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);
}
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");
ground_cache.release_wire();
}
-void fgToggleFDMdataLogging(void) {
- cur_fdm_state->ToggleDataLogging();
-}
// 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);
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;
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; }
void release_wire(void);
};
-extern FGInterface * cur_fdm_state;
-
-// Toggle data logging on/off
-void fgToggleFDMdataLogging(void);
-
-
#endif // _FLIGHT_HXX
--- /dev/null
+#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);
+}
--- /dev/null
+#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
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;
// 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();
#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>
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...
// 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
// 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 );
////////////////////////////////////////////////////////////////////
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
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
#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"
static bool winding_ccw = true; // FIXME: temporary
-static bool fdm_data_logging = false; // FIXME: temporary
-
static bool frozen = false; // FIXME: temporary
using std::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);
}
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;
}
getTrackMag ()
{
double magtrack;
- magtrack = current_aircraft.fdm_state->get_Track() - getMagVar();
+ magtrack = fgGetDouble("/orientation/track-deg") - getMagVar();
if (magtrack < 0) magtrack += 360;
return magtrack;
}
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 ()
{
// Misc. Temporary junk.
fgTie("/sim/temp/winding-ccw", getWindingCCW, setWindingCCW, false);
- fgTie("/sim/temp/fdm-data-logging", getFDMDataLogging, setFDMDataLogging);
}
void
#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>
// 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 ) {
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;
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;
// 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);
// 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();
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") );
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(),
#include <simgear/io/iochannel.hxx>
#include <simgear/timing/sg_time.hxx>
-#include <FDM/flight.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
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';
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';
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
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
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
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" ) {
altitude *= SG_METER_TO_FEET;
}
- cur_fdm_state->set_Altitude( altitude );
+ fdm.set_Altitude( altitude );
SG_LOG( SG_IO, SG_INFO, " altitude = " << altitude );
#include <string>
#include "protocol.hxx"
-
-using std::string;
-
+#include <FDM/flightProperties.hxx>
class FGAV400 : public FGProtocol {
// close the channel
bool close();
+
+ FlightProperties fdm;
};
#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;
}
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';
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';
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 );
#include "protocol.hxx"
-using std::string;
-
+class FlightProperties;
class FGAV400Sim : public FGProtocol {
char buf[ FG_MAX_MSG_SIZE ];
int length;
-
+ FlightProperties* fdm;
+
public:
FGAV400Sim();
-#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;
}
return sum;
}
-
// generate Atlas message
bool FGAtlas::gen_message() {
// cout << "generating atlas message" << endl;
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';
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';
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,
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
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
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
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" ) {
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
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
altitude *= SG_METER_TO_FEET;
}
- cur_fdm_state->set_Altitude( altitude );
+ fdm->set_Altitude( altitude );
SG_LOG( SG_IO, SG_INFO, " altitude = " << altitude );
#include "protocol.hxx"
-using std::string;
-
+class FlightProperties;
class FGAtlas : public FGProtocol {
char buf[ FG_MAX_MSG_SIZE ];
int length;
-
+ FlightProperties* fdm;
+
public:
FGAtlas();
#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;
}
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';
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';
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;
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
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
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
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" ) {
altitude *= SG_METER_TO_FEET;
}
- cur_fdm_state->set_Altitude( altitude );
+ fdm->set_Altitude( altitude );
SG_LOG( SG_IO, SG_INFO, " altitude = " << altitude );
#include "protocol.hxx"
-using std::string;
-
+class FlightProperties;
class FGGarmin : public FGProtocol {
char buf[ FG_MAX_MSG_SIZE ];
int length;
-
+ FlightProperties* fdm;
+
public:
FGGarmin();
#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"
// 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 ...
// 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);
// 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 {
#include "native.hxx"
+#include <FDM/flight.hxx>
FGNative::FGNative() {
}
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;
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;
}
}
}
#include <string>
-#include <FDM/flight.hxx>
-
#include "protocol.hxx"
-
-using std::string;
-
+#include <FDM/flight.hxx>
class FGNative : public FGProtocol {
#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
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");
int length = sizeof(FGNetCtrls);
if ( get_direction() == SG_IO_OUT ) {
- // cout << "size of cur_fdm_state = " << length << endl;
FGProps2NetCtrls( &net_ctrls, true, true );
#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>
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;
}
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
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);
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 );
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." );
#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();
#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"
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;
}
= 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;
// 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();
#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
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." );
#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();
#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;
}
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';
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';
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;
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
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
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
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" ) {
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
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
altitude *= SG_METER_TO_FEET;
}
- cur_fdm_state->set_Altitude( altitude );
+ fdm->set_Altitude( altitude );
SG_LOG( SG_IO, SG_INFO, " altitude = " << altitude );
#include "protocol.hxx"
-using std::string;
-
+class FlightProperties;
class FGNMEA : public FGProtocol {
char buf[ FG_MAX_MSG_SIZE ];
int length;
-
+ FlightProperties* fdm;
public:
FGNMEA();
#include <vector>
#include "opengc.hxx"
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
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
}
//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;
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();
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();
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
}
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." );
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 );
}
}
}
#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;
// close the channel
bool close();
- void collect_data( const FGInterface *fdm, ogcFGData *data );
+ void collect_data(ogcFGData *data );
};
#endif // _FG_OPENGC_HXX
#include <simgear/debug/logstream.hxx>
#include <simgear/io/iochannel.hxx>
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
#include "pve.hxx"
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;
}
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;
}
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)
#include <simgear/debug/logstream.hxx>
#include <simgear/io/iochannel.hxx>
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
#include "ray.hxx"
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 */ };
/* 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;
/* 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:
#include <simgear/debug/logstream.hxx>
#include <simgear/io/iochannel.hxx>
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
#include "rul.hxx"
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;
}
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;
}