1
0
Fork 0

Merge branch 'topics/mainloop' into next

This commit is contained in:
James Turner 2010-06-26 15:30:00 +01:00
commit a0588272dc
58 changed files with 1288 additions and 951 deletions

View file

@ -3485,6 +3485,14 @@
RelativePath="..\..\..\src\Environment\ridge_lift.hxx"
>
</File>
<File
RelativePath="..\..\..\src\Environment\ephemeris.cxx"
>
</File>
<File
RelativePath="..\..\..\src\Environment\ephemeris.hxx"
>
</File>
</Filter>
<Filter
Name="Lib_Model"

View file

@ -44,6 +44,7 @@
#include <Cockpit/hud.hxx>
#include <Cockpit/panel_io.hxx>
#include <Model/acmodel.hxx>
#include <FDM/flightProperties.hxx>
#include "aircraft.hxx"
@ -57,29 +58,26 @@ fgAIRCRAFT current_aircraft;
void fgAircraftInit( void ) {
SG_LOG( SG_AIRCRAFT, SG_INFO, "Initializing Aircraft structure" );
current_aircraft.fdm_state = cur_fdm_state;
current_aircraft.controls = globals->get_controls();
}
// Display various parameters to stdout
void fgAircraftOutputCurrent(fgAIRCRAFT *a) {
FGInterface *f;
f = a->fdm_state;
FlightProperties f;
SG_LOG( SG_FLIGHT, SG_DEBUG,
"Pos = ("
<< (f->get_Longitude() * 3600.0 * SGD_RADIANS_TO_DEGREES) << ","
<< (f->get_Latitude() * 3600.0 * SGD_RADIANS_TO_DEGREES) << ","
<< f->get_Altitude()
<< (f.get_Longitude() * 3600.0 * SGD_RADIANS_TO_DEGREES) << ","
<< (f.get_Latitude() * 3600.0 * SGD_RADIANS_TO_DEGREES) << ","
<< f.get_Altitude()
<< ") (Phi,Theta,Psi)=("
<< f->get_Phi() << ","
<< f->get_Theta() << ","
<< f->get_Psi() << ")" );
<< f.get_Phi() << ","
<< f.get_Theta() << ","
<< f.get_Psi() << ")" );
SG_LOG( SG_FLIGHT, SG_DEBUG,
"Kts = " << f->get_V_equiv_kts()
"Kts = " << f.get_V_equiv_kts()
<< " Elev = " << globals->get_controls()->get_elevator()
<< " Aileron = " << globals->get_controls()->get_aileron()
<< " Rudder = " << globals->get_controls()->get_rudder()
@ -155,7 +153,7 @@ 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.
@ -204,13 +202,7 @@ fgLoadAircraft (const SGPropertyNode * arg)
globals->get_current_panel()->update(0);
}
// Load the new 3D model
//
globals->get_aircraft_model()->unbind();
delete globals->get_aircraft_model();
globals->set_aircraft_model(new FGAircraftModel);
globals->get_aircraft_model()->init();
globals->get_aircraft_model()->bind();
globals->get_aircraft_model()->reinit();
// TODO:
// load new electrical system
@ -227,11 +219,7 @@ fgLoadAircraft (const SGPropertyNode * arg)
t = fgInitTime();
globals->set_time_params( t );
globals->get_viewmgr()->reinit();
globals->get_controls()->reset_all();
globals->get_aircraft_model()->reinit();
globals->get_subsystem("xml-autopilot")->reinit();
fgReInitSubsystems();
if ( !freeze ) {

View file

@ -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 ;

View file

@ -26,7 +26,6 @@
#include <simgear/constants.h>
#include <FDM/flight.hxx>
#include <Main/fg_props.hxx>
#include <Network/native_ctrls.hxx>
#include <Network/native_fdm.hxx>
@ -164,9 +163,10 @@ void FGReplay::update( double dt ) {
//FGProps2NetFDM( &f, false );
// sanity check, don't collect data if FDM data isn't good
if ( !cur_fdm_state->get_inited() ) {
if (!fgGetBool("/sim/signals/fdm-initialized", false)) {
return;
}
//FGNetCtrls c;
//FGProps2NetCtrls( &c, false, false );
//stamp("point_04ba");

View file

@ -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
}

View file

@ -38,9 +38,7 @@
#include <Aircraft/aircraft.hxx>
#include <Include/general.hxx>
#ifdef ENABLE_SP_FDM
#include <FDM/SP/ADA.hxx>
#endif
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Main/viewmgr.hxx>
@ -51,7 +49,6 @@
#include "cockpit.hxx"
#include "hud.hxx"
// The following routines obtain information concerntin the aircraft's
// current state and return it to calling instrument display routines.
// They should eventually be member functions of the aircraft.
@ -59,14 +56,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 +76,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 +96,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 +136,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 +144,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 +172,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 +184,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 +232,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 +245,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;
}
@ -280,235 +259,103 @@ float get_dme( void )
return dme_node->getFloatValue();
}
// $$$ begin - added, VS Renganathan 13 Oct 2K
// #ifdef FIGHTER_HUD
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();
return Vxx;
}
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();
return Vyy;
}
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();
return Vzz;
}
float get_Ax ( void )
{
float Ax = current_aircraft.fdm_state->get_V_dot_north();
return Ax;
}
float get_Ay ( void )
{
float Ay = current_aircraft.fdm_state->get_V_dot_east();
return Ay;
}
float get_Az ( void )
{
float Az = current_aircraft.fdm_state->get_V_dot_down();
return Az;
return fgGetDouble("/accelerations/ned/north-accel-fps_sec", 0.0);
}
float get_anzg ( void )
{
float anzg = current_aircraft.fdm_state->get_N_Z_cg();
return anzg;
return fgGetDouble("/accelerations/n-z-cg-fps_sec", 0.0);
}
#ifdef ENABLE_SP_FDM
int get_iaux1 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_iaux(1);
}
int get_iaux2 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_iaux(2);
}
int get_iaux3 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_iaux(3);
}
int get_iaux4 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_iaux(4);
}
int get_iaux5 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_iaux(5);
}
int get_iaux6 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_iaux(6);
}
int get_iaux7 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_iaux(7);
}
int get_iaux8 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_iaux(8);
}
int get_iaux9 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_iaux(9);
}
int get_iaux10 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_iaux(10);
}
int get_iaux11 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_iaux(11);
}
int get_iaux12 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_iaux(12);
}
float get_aux1 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_daux(1);
return fgGetDouble("/fdm-ada/ship-lat", 0.0);
}
float get_aux2 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_daux(2);
return fgGetDouble("/fdm-ada/ship-lon", 0.0);
}
float get_aux3 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_daux(3);
return fgGetDouble("/fdm-ada/ship-alt", 0.0);
}
float get_aux4 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_daux(4);
return fgGetDouble("/fdm-ada/skijump-dist", 0.0);
}
float get_aux5 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_daux(5);
return fgGetDouble("/fdm-ada/aux5", 0.0);
}
float get_aux6 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_daux(6);
return fgGetDouble("/fdm-ada/aux6", 0.0);
}
float get_aux7 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_daux(7);
return fgGetDouble("/fdm-ada/aux7", 0.0);
}
float get_aux8 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_daux(8);
}
return fgGetDouble("/fdm-ada/aux8", 0.0);}
float get_aux9 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_faux(1);
}
return fgGetDouble("/fdm-ada/aux9", 0.0);}
float get_aux10 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_faux(2);
return fgGetDouble("/fdm-ada/aux10", 0.0);
}
float get_aux11 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_faux(3);
return fgGetDouble("/fdm-ada/aux11", 0.0);
}
float get_aux12 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_faux(4);
return fgGetDouble("/fdm-ada/aux12", 0.0);
}
float get_aux13 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_faux(5);
return fgGetDouble("/fdm-ada/aux13", 0.0);
}
float get_aux14 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_faux(6);
return fgGetDouble("/fdm-ada/aux14", 0.0);
}
float get_aux15 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_faux(7);
return fgGetDouble("/fdm-ada/aux15", 0.0);
}
float get_aux16 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_faux(8);
return fgGetDouble("/fdm-ada/aux16", 0.0);
}
float get_aux17 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_faux(9);
return fgGetDouble("/fdm-ada/aux17", 0.0);
}
float get_aux18 (void)
{
FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
return fdm->get_faux(10);
return fgGetDouble("/fdm-ada/aux18", 0.0);
}
#endif

View file

@ -134,46 +134,6 @@ extern float get_mach( void );
extern char *coord_format_lat(float);
extern char *coord_format_lon(float);
// $$$ begin - added, VS Renganathan, 13 Oct 2K
extern float get_anzg (void);
extern float get_Vx (void);
extern float get_Vy (void);
extern float get_Vz (void);
extern float get_Ax (void);
extern float get_Ay (void);
extern float get_Az (void);
extern int get_iaux1 (void);
extern int get_iaux2 (void);
extern int get_iaux3 (void);
extern int get_iaux4 (void);
extern int get_iaux5 (void);
extern int get_iaux6 (void);
extern int get_iaux7 (void);
extern int get_iaux8 (void);
extern int get_iaux9 (void);
extern int get_iaux10 (void);
extern int get_iaux11 (void);
extern int get_iaux12 (void);
extern float get_aux1(void);
extern float get_aux2(void);
extern float get_aux3(void);
extern float get_aux4(void);
extern float get_aux5 (void);
extern float get_aux6 (void);
extern float get_aux7 (void);
extern float get_aux8(void);
extern float get_aux9(void);
extern float get_aux10(void);
extern float get_aux11(void);
extern float get_aux12(void);
extern float get_aux13(void);
extern float get_aux14(void);
extern float get_aux15(void);
extern float get_aux16(void);
extern float get_aux17(void);
extern float get_aux18(void);
// $$$ end - added, VS Renganathan, 13 Oct 2K
extern char *get_formated_gmt_time( void );
enum hudinstype{ HUDno_instr,

View file

@ -96,11 +96,11 @@ void HudLadder::draw(void)
#ifdef ENABLE_SP_FDM
int lgear, wown, wowm, ilcanclaw, ihook;
ilcanclaw = get_iaux2();
lgear = get_iaux3();
wown = get_iaux4();
wowm = get_iaux5();
ihook = get_iaux6();
ilcanclaw = fgGetInt("/fdm-ada/iaux2", 0);
lgear = fgGetInt("/fdm-ada/iaux3", 0);
wown = fgGetInt("/fdm-ada/iaux4", 0);
wowm = fgGetInt("/fdm-ada/iaux5", 0);;
ihook = fgGetInt("/fdm-ada/iaux6", 0);
#endif
float pitch_value = current_ch1() * SGD_RADIANS_TO_DEGREES;
@ -159,12 +159,12 @@ void HudLadder::draw(void)
//****************************************************************
//velocity vector reticle - computations
if (velocity_vector) {
Vxx = get_Vx();
Vyy = get_Vy();
Vzz = get_Vz();
Axx = get_Ax();
Ayy = get_Ay();
Azz = get_Az();
Vxx = fgGetDouble("/velocities/north-relground-fps", 0.0);
Vyy = fgGetDouble("/velocities/east-relground-fps", 0.0);
Vzz = fgGetDouble("/velocities/down-relground-fps", 0.0);
Axx = fgGetDouble("/accelerations/ned/north-accel-fps_sec", 0.0);
Ayy = fgGetDouble("/accelerations/ned/east-accel-fps_sec", 0.0);
Azz = fgGetDouble("/accelerations/ned/down-accel-fps_sec", 0.0);
psi = get_heading();
if (psi > 180.0)
@ -597,8 +597,8 @@ void HudLadder::draw(void)
fromwp_lon = get_longitude() * SGD_DEGREES_TO_RADIANS;
fromwp_lat = get_latitude() * SGD_DEGREES_TO_RADIANS;
towp_lon = get_aux2() * SGD_DEGREES_TO_RADIANS;
towp_lat = get_aux1() * SGD_DEGREES_TO_RADIANS;
towp_lon = fgGetDouble("/fdm-ada/ship-lon", 0.0) * SGD_DEGREES_TO_RADIANS;
towp_lat = fgGetDouble("/fdm-ada/ship-lat", 0.0) * SGD_DEGREES_TO_RADIANS;
dist = acos(sin(fromwp_lat) * sin(towp_lat) + cos(fromwp_lat)
* cos(towp_lat) * cos(fabs(fromwp_lon - towp_lon)));

View file

@ -185,7 +185,7 @@ FGRunway* runway_instr::get_active_runway()
void runway_instr::get_rwy_points(sgdVec3 *points3d)
{
double alt = current_aircraft.fdm_state->get_Runway_altitude() * SG_FEET_TO_METER;
double alt = runway->geod().getElevationM();
double length = runway->lengthM() * 0.5;
double width = runway->widthM() * 0.5;
double frontLat = 0.0, frontLon = 0.0, backLat = 0.0, backLon = 0.0, az = 0.0, tempLat = 0.0, tempLon = 0.0;

View file

@ -12,6 +12,7 @@ libEnvironment_a_SOURCES = \
fgwind.cxx fgwind.hxx \
atmosphere.cxx atmosphere.hxx \
precipitation_mgr.cxx precipitation_mgr.hxx \
ridge_lift.cxx ridge_lift.hxx
ridge_lift.cxx ridge_lift.hxx \
ephemeris.cxx ephemeris.hxx
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src

View file

@ -90,7 +90,7 @@ FGEnvironmentMgr::init ()
{
SG_LOG( SG_GENERAL, SG_INFO, "Initializing environment subsystem");
SGSubsystemGroup::init();
_update_fdm();
//_update_fdm();
}
void
@ -98,7 +98,7 @@ FGEnvironmentMgr::reinit ()
{
SG_LOG( SG_GENERAL, SG_INFO, "Reinitializing environment subsystem");
SGSubsystemGroup::reinit();
_update_fdm();
//_update_fdm();
}
void
@ -291,19 +291,12 @@ 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
{

View file

@ -76,8 +76,6 @@ public:
virtual FGEnvironment getEnvironment(const SGGeod& aPos) const;
private:
void _update_fdm () const;
double get_cloud_layer_span_m (int index) const;
void set_cloud_layer_span_m (int index, double span_m);
double get_cloud_layer_elevation_ft (int index) const;

View file

@ -0,0 +1,62 @@
#include <Environment/ephemeris.hxx>
#include <simgear/timing/sg_time.hxx>
#include <simgear/ephemeris/ephemeris.hxx>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
Ephemeris::Ephemeris() :
_impl(NULL),
_latProp(NULL)
{
}
Ephemeris::~Ephemeris()
{
delete _impl;
}
void Ephemeris::init()
{
if (_impl) {
return;
}
SGPath ephem_data_path(globals->get_fg_root());
ephem_data_path.append("Astro");
_impl = new SGEphemeris(ephem_data_path.c_str());
globals->set_ephem(_impl);
}
void Ephemeris::postinit()
{
update(0.0);
}
static void tieStar(const char* prop, Star* s, double (Star::*getter)() const)
{
fgGetNode(prop, true)->tie(SGRawValueMethods<Star, double>(*s, getter, NULL));
}
void Ephemeris::bind()
{
_latProp = fgGetNode("/position/latitude-deg", true);
tieStar("/ephemeris/sun/xs", _impl->get_sun(), &Star::getxs);
tieStar("/ephemeris/sun/ys", _impl->get_sun(), &Star::getys);
tieStar("/ephemeris/sun/ze", _impl->get_sun(), &Star::getze);
tieStar("/ephemeris/sun/ye", _impl->get_sun(), &Star::getye);
tieStar("/ephemeris/sun/lat-deg", _impl->get_sun(), &Star::getLat);
}
void Ephemeris::unbind()
{
}
void Ephemeris::update(double)
{
SGTime* st = globals->get_time_params();
_impl->update(st->getMjd(), st->getLst(), _latProp->getDoubleValue());
}

View file

@ -0,0 +1,31 @@
#ifndef FG_ENVIRONMENT_EPHEMERIS_HXX
#define FG_ENVIRONMENT_EPHEMERIS_HXX
#include <simgear/structure/subsystem_mgr.hxx>
class SGEphemeris;
class SGPropertyNode;
/**
* Wrap SGEphemeris in a susbsytem/property interface
*/
class Ephemeris : public SGSubsystem
{
public:
Ephemeris();
~Ephemeris();
virtual void bind();
virtual void unbind();
virtual void update(double dt);
virtual void init();
virtual void postinit();
private:
SGEphemeris* _impl;
SGPropertyNode* _latProp;
};
#endif // of FG_ENVIRONMENT_EPHEMERIS_HXX

View file

@ -428,47 +428,48 @@ void FGExternalPipe::update_binary( double dt ) {
// Process remote FDM "set" commands
static void process_set_command( const string_list &tokens ) {
void FGExternalPipe::process_set_command( const string_list &tokens ) {
if ( tokens[1] == "geodetic_position" ) {
double lat_rad = atof( tokens[2].c_str() );
double lon_rad = atof( tokens[3].c_str() );
double alt_m = atof( tokens[4].c_str() );
cur_fdm_state->_updateGeodeticPosition( lat_rad, lon_rad,
_updateGeodeticPosition( lat_rad, lon_rad,
alt_m * SG_METER_TO_FEET );
double agl_m = alt_m - cur_fdm_state->get_Runway_altitude_m();
cur_fdm_state->_set_Altitude_AGL( agl_m * SG_METER_TO_FEET );
double agl_m = alt_m - get_Runway_altitude_m();
_set_Altitude_AGL( agl_m * SG_METER_TO_FEET );
} else if ( tokens[1] == "euler_angles" ) {
double phi_rad = atof( tokens[2].c_str() );
double theta_rad = atof( tokens[3].c_str() );
double psi_rad = atof( tokens[4].c_str() );
cur_fdm_state->_set_Euler_Angles( phi_rad, theta_rad, psi_rad );
_set_Euler_Angles( phi_rad, theta_rad, psi_rad );
} else if ( tokens[1] == "euler_rates" ) {
double phidot = atof( tokens[2].c_str() );
double thetadot = atof( tokens[3].c_str() );
double psidot = atof( tokens[4].c_str() );
cur_fdm_state->_set_Euler_Rates( phidot, thetadot, psidot );
_set_Euler_Rates( phidot, thetadot, psidot );
} else if ( tokens[1] == "ned" ) {
double north_fps = atof( tokens[2].c_str() );
double east_fps = atof( tokens[3].c_str() );
double down_fps = atof( tokens[4].c_str() );
cur_fdm_state->_set_Velocities_Local( north_fps, east_fps, down_fps );
_set_Velocities_Local( north_fps, east_fps, down_fps );
} else if ( tokens[1] == "alpha" ) {
cur_fdm_state->_set_Alpha( atof(tokens[2].c_str()) );
_set_Alpha( atof(tokens[2].c_str()) );
} else if ( tokens[1] == "beta" ) {
cur_fdm_state->_set_Beta( atof(tokens[2].c_str()) );
_set_Beta( atof(tokens[2].c_str()) );
#if 0
cur_fdm_state->_set_V_calibrated_kts( net->vcas );
cur_fdm_state->_set_Climb_Rate( net->climb_rate );
cur_fdm_state->_set_Velocities_Local( net->v_north,
_set_V_calibrated_kts( net->vcas );
_set_Climb_Rate( net->climb_rate );
_set_Velocities_Local( net->v_north,
net->v_east,
net->v_down );
cur_fdm_state->_set_Velocities_Wind_Body( net->v_wind_body_north,
_set_Velocities_Wind_Body( net->v_wind_body_north,
net->v_wind_body_east,
net->v_wind_body_down );
cur_fdm_state->_set_Accels_Pilot_Body( net->A_X_pilot,
_set_Accels_Pilot_Body( net->A_X_pilot,
net->A_Y_pilot,
net->A_Z_pilot );
#endif

View file

@ -62,6 +62,7 @@ private:
void update_binary( double dt );
void update_property( double dt );
void process_set_command( const string_list &tokens );
public:
// Constructor

View file

@ -977,7 +977,7 @@ void FGJSBsim::set_Altitude(double alt)
_set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET );
fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
SG_LOG(SG_FLIGHT, SG_INFO,
"Terrain elevation: " << cur_fdm_state->get_Runway_altitude() * SG_METER_TO_FEET );
"Terrain elevation: " << FGInterface::get_Runway_altitude() * SG_METER_TO_FEET );
fgic->SetLatitudeRadIC( lat_geoc );
fgic->SetAltitudeASLFtIC(alt);
needTrim=true;

View file

@ -11,6 +11,8 @@ noinst_LIBRARIES = libFlight.a
libFlight_a_SOURCES = \
flight.cxx flight.hxx \
fdm_shell.cxx fdm_shell.hxx \
flightProperties.cxx flightProperties.hxx \
groundcache.cxx groundcache.hxx \
UFO.cxx UFO.hxx \
NullFDM.cxx NullFDM.hxx

View file

@ -261,14 +261,15 @@ bool FGADA::copy_from_FGADA() {
_set_Velocities_Local( V_north, V_east, V_down ); //same as UVW_local in fps
//Positions and attitude for ship
_set_daux(1,sixdof_to_visuals.aux1);//ship lat
_set_daux(2,sixdof_to_visuals.aux2);//ship lon
_set_daux(3,sixdof_to_visuals.aux3);//ship alt+heave
_set_daux(4,sixdof_to_visuals.aux4);//distance of a/c from ski-jump exit
_set_faux(1,sixdof_to_visuals.aux9);//ship pitch
_set_faux(2,sixdof_to_visuals.aux10);//ship roll
_set_faux(3,sixdof_to_visuals.aux11);//ship yaw
_set_iaux(1,sixdof_to_visuals.iaux1);//flag for drawing ship
fgSetDouble("/fdm-ada/ship-lat", sixdof_to_visuals.aux1);
fgSetDouble("/fdm-ada/ship-lon", sixdof_to_visuals.aux2);
fgSetDouble("/fdm-ada/ship-alt", sixdof_to_visuals.aux3);
fgSetDouble("/fdm-ada/skijump-dist", sixdof_to_visuals.aux4);
fgSetDouble("/fdm-ada/ship-pitch", sixdof_to_visuals.aux9); // faux1
fgSetDouble("/fdm-ada/ship-roll", sixdof_to_visuals.aux10); // faux2
fgSetDouble("/fdm-ada/ship-yaw", sixdof_to_visuals.aux11); // faux3
fgSetInt("/fdm-ada/draw-ship", sixdof_to_visuals.iaux1);
// controls
globals->get_controls()->set_throttle(0,throttle/131.0);
@ -284,30 +285,30 @@ bool FGADA::copy_from_FGADA() {
_set_Mach_number( Machno);
_set_Climb_Rate( W_local*SG_METER_TO_FEET ); //pressure alt in feet for lca(navy)
_set_iaux(2,sixdof_to_visuals.iaux2);//control law mode switch posn
_set_iaux(3,sixdof_to_visuals.iaux3);//ldg gear posn
_set_iaux(4,sixdof_to_visuals.iaux4);// wow nose status
_set_iaux(5,sixdof_to_visuals.iaux5);// wow main status
_set_iaux(6,sixdof_to_visuals.iaux6);// arrester hook posn
_set_iaux(7,sixdof_to_visuals.iaux7);
_set_iaux(8,sixdof_to_visuals.iaux8);
_set_iaux(9,sixdof_to_visuals.iaux9);
_set_iaux(10,sixdof_to_visuals.iaux10);
_set_iaux(11,sixdof_to_visuals.iaux11);
_set_iaux(12,sixdof_to_visuals.iaux12);
fgSetInt("/fdm-ada/iaux2", sixdof_to_visuals.iaux2); //control law mode switch posn
fgSetInt("/fdm-ada/iaux3", sixdof_to_visuals.iaux3); //ldg gear posn
fgSetInt("/fdm-ada/iaux4", sixdof_to_visuals.iaux4); // wow nose status
fgSetInt("/fdm-ada/iaux5", sixdof_to_visuals.iaux5); // wow main status
fgSetInt("/fdm-ada/iaux6", sixdof_to_visuals.iaux6); // arrester hook posn
fgSetInt("/fdm-ada/iaux7", sixdof_to_visuals.iaux7);
fgSetInt("/fdm-ada/iaux8", sixdof_to_visuals.iaux8);
fgSetInt("/fdm-ada/iaux9", sixdof_to_visuals.iaux9);
fgSetInt("/fdm-ada/iaux10", sixdof_to_visuals.iaux10);
fgSetInt("/fdm-ada/iaux11", sixdof_to_visuals.iaux11);
fgSetInt("/fdm-ada/iaux12", sixdof_to_visuals.iaux12);
_set_daux(5,sixdof_to_visuals.aux5);
_set_daux(6,sixdof_to_visuals.aux6);
_set_daux(7,sixdof_to_visuals.aux7);
_set_daux(8,sixdof_to_visuals.aux8);
fgSetDouble("/fdm-ada/aux5", sixdof_to_visuals.aux5);
fgSetDouble("/fdm-ada/aux6", sixdof_to_visuals.aux6);
fgSetDouble("/fdm-ada/aux7", sixdof_to_visuals.aux7);
fgSetDouble("/fdm-ada/aux8", sixdof_to_visuals.aux8);
_set_faux(4,sixdof_to_visuals.aux12);
_set_faux(5,sixdof_to_visuals.aux13);
_set_faux(6,sixdof_to_visuals.aux14);
_set_faux(7,sixdof_to_visuals.aux15);
_set_faux(8,sixdof_to_visuals.aux16);
_set_faux(9,sixdof_to_visuals.aux17);
_set_faux(10,sixdof_to_visuals.aux18);
fgSetDouble("/fdm-ada/aux12", sixdof_to_visuals.aux12);
fgSetDouble("/fdm-ada/aux13", sixdof_to_visuals.aux13);
fgSetDouble("/fdm-ada/aux14", sixdof_to_visuals.aux14);
fgSetDouble("/fdm-ada/aux15", sixdof_to_visuals.aux15);
fgSetDouble("/fdm-ada/aux16", sixdof_to_visuals.aux16);
fgSetDouble("/fdm-ada/aux17", sixdof_to_visuals.aux17);
fgSetDouble("/fdm-ada/aux18", sixdof_to_visuals.aux18);
// Angular rates
_set_Omega_Body( P_body, Q_body, R_body );

242
src/FDM/fdm_shell.cxx Normal file
View file

@ -0,0 +1,242 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <simgear/structure/exception.hxx>
#include <FDM/fdm_shell.hxx>
#include <FDM/flight.hxx>
#include <Aircraft/replay.hxx>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Scenery/scenery.hxx>
// all the FDMs, since we are the factory method
#if ENABLE_SP_FDM
#include <FDM/SP/ADA.hxx>
#include <FDM/SP/ACMS.hxx>
#include <FDM/SP/MagicCarpet.hxx>
#include <FDM/SP/Balloon.h>
#endif
#include <FDM/ExternalNet/ExternalNet.hxx>
#include <FDM/ExternalPipe/ExternalPipe.hxx>
#include <FDM/JSBSim/JSBSim.hxx>
#include <FDM/LaRCsim/LaRCsim.hxx>
#include <FDM/UFO.hxx>
#include <FDM/NullFDM.hxx>
#include <FDM/YASim/YASim.hxx>
/*
* Evil global variable required by Network/FGNative,
* see that class for more information
*/
FGInterface* evil_global_fdm_state = NULL;
FDMShell::FDMShell() :
_impl(NULL),
_dataLogging(false)
{
}
FDMShell::~FDMShell()
{
delete _impl;
}
void FDMShell::init()
{
_props = globals->get_props();
createImplementation();
}
void FDMShell::reinit()
{
if (_impl) {
fgSetBool("/sim/signals/fdm-initialized", false);
evil_global_fdm_state = NULL;
_impl->unbind();
delete _impl;
_impl = NULL;
}
init();
}
void FDMShell::bind()
{
if (_impl && _impl->get_inited()) {
if (_impl->get_bound()) {
throw sg_exception("FDMShell::bind of bound FGInterface impl");
}
_impl->bind();
}
}
void FDMShell::unbind()
{
_impl->unbind();
}
void FDMShell::update(double dt)
{
if (!_impl) {
return;
}
if (!_impl->get_inited()) {
// Check for scenery around the aircraft.
double lon = fgGetDouble("/sim/presets/longitude-deg");
double lat = fgGetDouble("/sim/presets/latitude-deg");
double range = 1000.0; // in metres
SGGeod geod = SGGeod::fromDeg(lon, lat);
if (globals->get_scenery()->scenery_available(geod, range)) {
SG_LOG(SG_FLIGHT, SG_INFO, "Scenery loaded, will init FDM");
_impl->init();
if (_impl->get_bound()) {
_impl->unbind();
}
_impl->bind();
evil_global_fdm_state = _impl;
fgSetBool("/sim/signals/fdm-initialized", true);
}
}
if (!_impl->get_inited()) {
return; // still waiting
}
// pull environmental data in, since the FDMs are lazy
_impl->set_Velocities_Local_Airmass(
_props->getDoubleValue("environment/wind-from-north-fps", 0.0),
_props->getDoubleValue("environment/wind-from-east-fps", 0.0),
_props->getDoubleValue("environment/wind-from-down-fps", 0.0));
if (_props->getBoolValue("environment/params/control-fdm-atmosphere")) {
// convert from Rankine to Celsius
double tempDegC = _props->getDoubleValue("environment/temperature-degc");
_impl->set_Static_temperature((9.0/5.0) * (tempDegC + 273.15));
// convert from inHG to PSF
double pressureInHg = _props->getDoubleValue("environment/pressure-inhg");
_impl->set_Static_pressure(pressureInHg * 70.726566);
// keep in slugs/ft^3
_impl->set_Density(_props->getDoubleValue("environment/density-slugft3"));
}
bool doLog = _props->getBoolValue("/sim/temp/fdm-data-logging", false);
if (doLog != _dataLogging) {
_dataLogging = doLog;
_impl->ToggleDataLogging(doLog);
}
// FIXME - replay manager should handle most of this
int replayState = fgGetInt("/sim/freeze/replay-state", 0);
if (replayState == 0) {
_impl->update(dt); // normal code path
} else if (replayState == 1) {
// should be inside FGReplay!
SGPropertyNode* replay_time = fgGetNode("/sim/replay/time", true);
FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
r->replay( replay_time->getDoubleValue() );
replay_time->setDoubleValue( replay_time->getDoubleValue()
+ ( dt
* fgGetInt("/sim/speed-up") ) );
} else if (replayState == 2) {
// paused replay, no-op
} else {
throw sg_range_exception("unknown FGReplay state");
}
}
void FDMShell::createImplementation()
{
assert(!_impl);
double dt = 1.0 / fgGetInt("/sim/model-hz");
string model = fgGetString("/sim/flight-model");
if ( model == "larcsim" ) {
_impl = new FGLaRCsim( dt );
} else if ( model == "jsb" ) {
_impl = new FGJSBsim( dt );
#if ENABLE_SP_FDM
} else if ( model == "ada" ) {
_impl = new FGADA( dt );
} else if ( model == "acms" ) {
_impl = new FGACMS( dt );
} else if ( model == "balloon" ) {
_impl = new FGBalloonSim( dt );
} else if ( model == "magic" ) {
_impl = new FGMagicCarpet( dt );
#endif
} else if ( model == "ufo" ) {
_impl = new FGUFO( dt );
} else if ( model == "external" ) {
// external is a synonym for "--fdm=null" and is
// maintained here for backwards compatibility
_impl = new FGNullFDM( dt );
} else if ( model.find("network") == 0 ) {
string host = "localhost";
int port1 = 5501;
int port2 = 5502;
int port3 = 5503;
string net_options = model.substr(8);
string::size_type begin, end;
begin = 0;
// host
end = net_options.find( ",", begin );
if ( end != string::npos ) {
host = net_options.substr(begin, end - begin);
begin = end + 1;
}
// port1
end = net_options.find( ",", begin );
if ( end != string::npos ) {
port1 = atoi( net_options.substr(begin, end - begin).c_str() );
begin = end + 1;
}
// port2
end = net_options.find( ",", begin );
if ( end != string::npos ) {
port2 = atoi( net_options.substr(begin, end - begin).c_str() );
begin = end + 1;
}
// port3
end = net_options.find( ",", begin );
if ( end != string::npos ) {
port3 = atoi( net_options.substr(begin, end - begin).c_str() );
begin = end + 1;
}
_impl = new FGExternalNet( dt, host, port1, port2, port3 );
} else if ( model.find("pipe") == 0 ) {
// /* old */ string pipe_path = model.substr(5);
// /* old */ _impl = new FGExternalPipe( dt, pipe_path );
string pipe_path = "";
string pipe_protocol = "";
string pipe_options = model.substr(5);
string::size_type begin, end;
begin = 0;
// pipe file path
end = pipe_options.find( ",", begin );
if ( end != string::npos ) {
pipe_path = pipe_options.substr(begin, end - begin);
begin = end + 1;
}
// protocol (last option)
pipe_protocol = pipe_options.substr(begin);
_impl = new FGExternalPipe( dt, pipe_path, pipe_protocol );
} else if ( model == "null" ) {
_impl = new FGNullFDM( dt );
} else if ( model == "yasim" ) {
_impl = new YASim( dt );
} else {
throw sg_exception(string("Unrecognized flight model '") + model
+ "', cannot init flight dynamics model.");
}
}

40
src/FDM/fdm_shell.hxx Normal file
View file

@ -0,0 +1,40 @@
#ifndef FG_FDM_SHELL_HXX
#define FG_FDM_SHELL_HXX
#include <simgear/structure/subsystem_mgr.hxx>
// forward decls
class FGInterface;
/**
* Wrap an FDM implementation in a subsystem with standard semantics
* Notably, deal with the various cases in which update() should not
* be called, such as replay or before scenery has loaded
*
* This class also provides the factory method which creates the
* specific FDM class (createImplementation)
*/
class FDMShell : public SGSubsystem
{
public:
FDMShell();
~FDMShell();
virtual void init();
virtual void reinit();
virtual void bind();
virtual void unbind();
virtual void update(double dt);
private:
void createImplementation();
FGInterface* _impl;
SGPropertyNode* _props; // root property tree for this FDM instance
bool _dataLogging;
};
#endif // of FG_FDM_SHELL_HXX

View file

@ -44,8 +44,6 @@ static inline void assign(double* ptr, const SGVec3d& vec)
ptr[2] = vec[2];
}
FGInterface *cur_fdm_state = 0;
// Constructor
FGInterface::FGInterface()
{
@ -253,7 +251,7 @@ FGInterface::bind ()
false);
fgSetArchivable("/position/altitude-ft");
fgTie("/position/altitude-agl-ft", this,
&FGInterface::get_Altitude_AGL); // read-only
&FGInterface::get_Altitude_AGL, &FGInterface::set_AltitudeAGL);
fgSetArchivable("/position/ground-elev-ft");
fgTie("/position/ground-elev-ft", this,
&FGInterface::get_Runway_altitude); // read-only
@ -264,7 +262,8 @@ FGInterface::bind ()
&FGInterface::get_Runway_altitude_m); // read-only
fgSetArchivable("/position/sea-level-radius-ft");
fgTie("/position/sea-level-radius-ft", this,
&FGInterface::get_Sea_level_radius); // read-only
&FGInterface::get_Sea_level_radius,
&FGInterface::_set_Sea_level_radius);
// Orientation
fgTie("/orientation/roll-deg", this,
@ -285,11 +284,15 @@ 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,
@ -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,19 @@ 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);
fgTie("/velocities/north-relground-fps", this,
&FGInterface::get_V_north_rel_ground);
fgTie("/velocities/east-relground-fps", this,
&FGInterface::get_V_east_rel_ground);
fgTie("/velocities/down-relground-fps", this,
&FGInterface::get_V_down_rel_ground);
// Relative wind
// FIXME: temporarily archivable, until
@ -358,11 +372,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 +390,13 @@ 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);
fgTie("/accelerations/n-z-cg-fps_sec", this, &FGInterface::get_N_Z_cg);
}
@ -411,15 +427,22 @@ 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");
fgUntie("/velocities/speed-down-fps");
fgUntie("/velocities/north-relground-fps");
fgUntie("/velocities/east-relground-fps");
fgUntie("/velocities/down-relground-fps");
fgUntie("/velocities/uBody-fps");
fgUntie("/velocities/vBody-fps");
fgUntie("/velocities/wBody-fps");
@ -432,6 +455,7 @@ FGInterface::unbind ()
fgUntie("/accelerations/ned/north-accel-fps_sec");
fgUntie("/accelerations/ned/east-accel-fps_sec");
fgUntie("/accelerations/ned/down-accel-fps_sec");
fgUntie("/accelerations/n-z-cg-fps_sec");
}
/**
@ -893,6 +917,3 @@ FGInterface::release_wire(void)
ground_cache.release_wire();
}
void fgToggleFDMdataLogging(void) {
cur_fdm_state->ToggleDataLogging();
}

View file

@ -187,13 +187,18 @@ private:
double altitude_agl;
double track;
double daux[16]; // auxilliary doubles
float faux[16]; // auxilliary floats
int iaux[16]; // auxilliary ints
// 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 +289,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 +349,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; }
@ -339,10 +363,6 @@ public:
inline void _set_Runway_altitude( double alt ) { runway_altitude = alt; }
inline void _set_Climb_Rate(double rate) { climb_rate = rate; }
inline void _set_daux( int n, double value ) { daux[n] = value; }
inline void _set_faux( int n, float value ) { faux[n] = value; }
inline void _set_iaux( int n, int value ) { iaux[n] = value; }
public:
FGInterface();
@ -623,11 +643,6 @@ public:
inline double get_Climb_Rate() const { return climb_rate; }
// Auxilliary variables
inline double get_daux( int n ) const { return daux[n]; }
inline float get_faux( int n ) const { return faux[n]; }
inline int get_iaux( int n ) const { return iaux[n]; }
// Note that currently this is the "same" value runway altitude...
inline double get_ground_elev_ft() const { return runway_altitude; }
@ -712,10 +727,4 @@ public:
void release_wire(void);
};
extern FGInterface * cur_fdm_state;
// Toggle data logging on/off
void fgToggleFDMdataLogging(void);
#endif // _FLIGHT_HXX

View file

@ -0,0 +1,289 @@
#include <FDM/flightProperties.hxx>
#include <simgear/props/props.hxx>
#include <simgear/math/SGMath.hxx>
#include <Main/globals.hxx>
FlightProperties::FlightProperties(SGPropertyNode* root) :
_root(root)
{
if (!_root) {
_root = globals->get_props();
}
}
FlightProperties::~FlightProperties()
{
}
double FlightProperties::get_V_north() const
{
return _root->getDoubleValue("velocities/speed-north-fps", 0.0);
}
double FlightProperties::get_V_east() const
{
return _root->getDoubleValue("velocities/speed-east-fps", 0.0);
}
double FlightProperties::get_V_down() const
{
return _root->getDoubleValue("velocities/speed-down-fps", 0.0);
}
double FlightProperties::get_uBody () const
{
return _root->getDoubleValue("velocities/uBody-fps", 0.0);
}
double FlightProperties::get_vBody () const
{
return _root->getDoubleValue("velocities/vBody-fps", 0.0);
}
double FlightProperties::get_wBody () const
{
return _root->getDoubleValue("velocities/wBody-fps", 0.0);
}
double FlightProperties::get_A_X_pilot() const
{
return _root->getDoubleValue("accelerations/pilot/x-accel-fps_sec", 0.0);
}
double FlightProperties::get_A_Y_pilot() const
{
return _root->getDoubleValue("/accelerations/pilot/y-accel-fps_sec", 0.0);
}
double FlightProperties::get_A_Z_pilot() const
{
return _root->getDoubleValue("/accelerations/pilot/z-accel-fps_sec", 0.0);
}
SGGeod FlightProperties::getPosition() const
{
return SGGeod::fromDegFt(get_Longitude_deg(), get_Latitude_deg(), get_Altitude());
}
double FlightProperties::get_Latitude() const
{
return get_Latitude_deg() * SG_DEGREES_TO_RADIANS;
}
double FlightProperties::get_Longitude() const
{
return get_Longitude_deg() * SG_DEGREES_TO_RADIANS;
}
double FlightProperties::get_Altitude() const
{
return _root->getDoubleValue("position/altitude-ft");
}
double FlightProperties::get_Altitude_AGL(void) const
{
return _root->getDoubleValue("position/altitude-agl-ft");
}
double FlightProperties::get_Latitude_deg () const
{
return _root->getDoubleValue("position/latitude-deg");
}
double FlightProperties::get_Longitude_deg () const
{
return _root->getDoubleValue("position/longitude-deg");
}
double FlightProperties::get_Track(void) const
{
return _root->getDoubleValue("orientation/track-deg");
}
double FlightProperties::get_Phi_deg() const
{
return _root->getDoubleValue("orientation/roll-deg");
}
double FlightProperties::get_Theta_deg() const
{
return _root->getDoubleValue("orientation/pitch-deg");
}
double FlightProperties::get_Psi_deg() const
{
return _root->getDoubleValue("orientation/heading-deg");
}
double FlightProperties::get_Phi_dot() const
{
return get_Phi_dot_degps() * SG_DEGREES_TO_RADIANS;
}
double FlightProperties::get_Theta_dot() const
{
return get_Theta_dot_degps() * SG_DEGREES_TO_RADIANS;
}
double FlightProperties::get_Psi_dot() const
{
return get_Psi_dot_degps() * SG_DEGREES_TO_RADIANS;
}
double FlightProperties::get_Alpha() const
{
return _root->getDoubleValue("orientation/alpha-deg") * SG_DEGREES_TO_RADIANS;
}
double FlightProperties::get_Beta() const
{
return _root->getDoubleValue("orientation/beta-deg") * SG_DEGREES_TO_RADIANS;
}
double FlightProperties::get_Phi_dot_degps() const
{
return _root->getDoubleValue("orientation/roll-rate-degps");
}
double FlightProperties::get_Theta_dot_degps() const
{
return _root->getDoubleValue("orientation/pitch-rate-degps");
}
double FlightProperties::get_Psi_dot_degps() const
{
return _root->getDoubleValue("orientation/yaw-rate-degps");
}
double FlightProperties::get_Total_temperature() const
{
return 0.0;
}
double FlightProperties::get_Total_pressure() const
{
return 0.0;
}
double FlightProperties::get_Dynamic_pressure() const
{
return 0.0;
}
void FlightProperties::set_Longitude(double l)
{
_root->setDoubleValue("position/longitude-deg", l * SG_RADIANS_TO_DEGREES);
}
void FlightProperties::set_Latitude(double l)
{
_root->setDoubleValue("position/latitude-deg", l * SG_RADIANS_TO_DEGREES);
}
void FlightProperties::set_Altitude(double ft)
{
_root->setDoubleValue("position/altitude-ft", ft);
}
void FlightProperties::set_Euler_Angles(double phi, double theta, double psi)
{
_root->setDoubleValue("orientation/roll-deg", phi * SG_RADIANS_TO_DEGREES);
_root->setDoubleValue("orientation/pitch-deg", theta * SG_RADIANS_TO_DEGREES);
_root->setDoubleValue("orientation/heading-deg", psi * SG_RADIANS_TO_DEGREES);
}
void FlightProperties::set_V_calibrated_kts(double kts)
{
_root->setDoubleValue("velocities/airspeed-kt", kts);
}
void FlightProperties::set_Climb_Rate(double fps)
{
_root->setDoubleValue("velocities/vertical-speed-fps", fps);
}
double FlightProperties::get_V_ground_speed() const
{
const double KNOTS_TO_FTS = (SG_NM_TO_METER * SG_METER_TO_FEET)/ 3600.0;
return _root->getDoubleValue("velocities/groundspeed-kt") * KNOTS_TO_FTS;
}
double FlightProperties::get_V_calibrated_kts() const
{
return _root->getDoubleValue("velocities/airspeed-kt");
}
double FlightProperties::get_V_equiv_kts() const
{
return _root->getDoubleValue("velocities/equivalent-kt");
}
double FlightProperties::get_Climb_Rate() const
{
return _root->getDoubleValue("velocities/vertical-speed-fps");
}
double FlightProperties::get_Runway_altitude_m() const
{
return _root->getDoubleValue("environment/ground-elevation-m");
}
void FlightProperties::set_Accels_Pilot_Body(double x, double y, double z)
{
_root->setDoubleValue("accelerations/pilot/x-accel-fps_sec", x);
_root->setDoubleValue("accelerations/pilot/y-accel-fps_sec", y);
_root->setDoubleValue("accelerations/pilot/z-accel-fps_sec", z);
}
void FlightProperties::set_Velocities_Local(double x, double y, double z)
{
_root->setDoubleValue("velocities/speed-north-fps", x);
_root->setDoubleValue("velocities/speed-east-fps", y);
_root->setDoubleValue("velocities/speed-down-fps", z);
}
void FlightProperties::set_Velocities_Wind_Body(double x, double y, double z)
{
_root->setDoubleValue("velocities/vBody-fps", x);
_root->setDoubleValue("velocities/uBody-fps", y);
_root->setDoubleValue("velocities/wBody-fps", z);
}
void FlightProperties::set_Euler_Rates(double x, double y, double z)
{
_root->setDoubleValue("orientation/roll-rate-degps", x * SG_RADIANS_TO_DEGREES);
_root->setDoubleValue("orientation/pitch-rate-degps", y * SG_RADIANS_TO_DEGREES);
_root->setDoubleValue("orientation/yaw-rate-degps", z * SG_RADIANS_TO_DEGREES);
}
void FlightProperties::set_Alpha(double a)
{
_root->setDoubleValue("orientation/alpha-deg", a * SG_RADIANS_TO_DEGREES);
}
void FlightProperties::set_Beta(double b)
{
_root->setDoubleValue("orientation/side-slip-rad", b);
}
void FlightProperties::set_Altitude_AGL(double ft)
{
_root->setDoubleValue("position/altitude-agl-ft", ft);
}
double FlightProperties::get_P_body() const
{
return _root->getDoubleValue("orientation/p-body", 0.0);
}
double FlightProperties::get_Q_body() const
{
return _root->getDoubleValue("orientation/q-body", 0.0);
}
double FlightProperties::get_R_body() const
{
return _root->getDoubleValue("orientation/r-body", 0.0);
}

View file

@ -0,0 +1,102 @@
#ifndef FG_FLIGHT_PROPERTIES_HXX
#define FG_FLIGHT_PROPERTIES_HXX
#include <memory>
#include <simgear/Math/SGMathFwd.hxx> // for SGVec3d
#include <simgear/Math/SGMisc.hxx>
// forward decls
class SGPropertyNode;
class SGGeoc;
class SGGeod;
/**
* Encapsulate the FDM properties in some getter/setter helpers.
* This class intentionally mimics portions of
* @FGInterface, to permit easy migration of code outside the FDMs,
* to use properties instead of global variables.
*/
class FlightProperties
{
public:
FlightProperties(SGPropertyNode* aRoot = NULL);
~FlightProperties();
double get_V_north() const;
double get_V_east() const;
double get_V_down() const;
double get_uBody () const;
double get_vBody () const;
double get_wBody () const;
double get_A_X_pilot() const;
double get_A_Y_pilot() const;
double get_A_Z_pilot() const;
double get_P_body() const;
double get_Q_body() const;
double get_R_body() const;
SGGeod getPosition() const;
double get_Latitude() const;
double get_Longitude() const;
double get_Altitude() const;
double get_Altitude_AGL(void) const;
double get_Track(void) const;
double get_Latitude_deg () const;
double get_Longitude_deg () const;
double get_Phi_deg() const;
double get_Theta_deg() const;
double get_Psi_deg() const;
double get_Phi() const { return SGMiscd::deg2rad(get_Phi_deg()); }
double get_Theta() const { return SGMiscd::deg2rad(get_Theta_deg()); }
double get_Psi() const { return SGMiscd::deg2rad(get_Psi_deg()); }
double get_Phi_dot() const;
double get_Theta_dot() const;
double get_Psi_dot() const;
double get_Alpha() const;
double get_Beta() const;
double get_Phi_dot_degps() const;
double get_Theta_dot_degps() const;
double get_Psi_dot_degps() const;
double get_V_ground_speed() const; // in feet/s
double get_V_equiv_kts() const;
double get_V_calibrated_kts() const;
double get_Climb_Rate() const;
double get_Runway_altitude_m() const;
double get_Total_temperature() const;
double get_Total_pressure() const;
double get_Dynamic_pressure() const;
void set_Longitude(double l); // radians
void set_Latitude(double l); // radians
void set_Altitude(double ft); // feet
void set_Euler_Angles(double phi, double theta, double psi);
void set_Euler_Rates(double x, double y, double z);
void set_Alpha(double a);
void set_Beta(double b);
void set_Altitude_AGL(double ft);
void set_V_calibrated_kts(double kts);
void set_Climb_Rate(double fps);
void set_Velocities_Local(double x, double y, double z);
void set_Velocities_Wind_Body(double x, double y, double z);
void set_Accels_Pilot_Body(double x, double y, double z);
private:
SGPropertyNode* _root;
};
#endif // of FG_FLIGHT_PROPERTIES_HXX

View file

@ -180,7 +180,7 @@ FGRunway* HUD::Runway::get_active_runway()
void HUD::Runway::get_rwy_points(sgdVec3 *_points3d)
{
double alt = current_aircraft.fdm_state->get_Runway_altitude() * SG_FEET_TO_METER;
double alt = _runway->geod().getElevationM();
double length = _runway->lengthM() * 0.5;
double width = _runway->widthM() * 0.5;
double frontLat = 0.0, frontLon = 0.0, backLat = 0.0, backLon = 0.0, az = 0.0, tempLat = 0.0, tempLon = 0.0;

View file

@ -1233,7 +1233,7 @@ do_presets_commit (const SGPropertyNode * arg)
// unbind the current fdm state so property changes
// don't get lost when we subsequently delete this fdm
// and create a new one.
cur_fdm_state->unbind();
globals->get_subsystem("flight")->unbind();
// set position from presets
fgInitPosition();

View file

@ -89,19 +89,6 @@
#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>
@ -123,6 +110,7 @@
#include <Time/tmp.hxx>
#include <Traffic/TrafficMgr.hxx>
#include <MultiPlayer/multiplaymgr.hxx>
#include <FDM/fdm_shell.hxx>
#include <Environment/environment_mgr.hxx>
#include <Environment/ridge_lift.hxx>
@ -1207,101 +1195,6 @@ bool fgInitGeneral() {
return true;
}
// Initialize the flight model subsystem. This just creates the
// object. The actual fdm initialization is delayed until we get a
// proper scenery elevation hit. This is checked for in main.cxx
void fgInitFDM() {
if ( cur_fdm_state ) {
delete cur_fdm_state;
cur_fdm_state = 0;
}
double dt = 1.0 / fgGetInt("/sim/model-hz");
string model = fgGetString("/sim/flight-model");
if ( model == "larcsim" ) {
cur_fdm_state = new FGLaRCsim( dt );
} else if ( model == "jsb" ) {
cur_fdm_state = new FGJSBsim( dt );
#if ENABLE_SP_FDM
} else if ( model == "ada" ) {
cur_fdm_state = new FGADA( dt );
} else if ( model == "acms" ) {
cur_fdm_state = new FGACMS( dt );
} else if ( model == "balloon" ) {
cur_fdm_state = new FGBalloonSim( dt );
} else if ( model == "magic" ) {
cur_fdm_state = new FGMagicCarpet( dt );
#endif
} else if ( model == "ufo" ) {
cur_fdm_state = new FGUFO( dt );
} else if ( model == "external" ) {
// external is a synonym for "--fdm=null" and is
// maintained here for backwards compatibility
cur_fdm_state = new FGNullFDM( dt );
} else if ( model.find("network") == 0 ) {
string host = "localhost";
int port1 = 5501;
int port2 = 5502;
int port3 = 5503;
string net_options = model.substr(8);
string::size_type begin, end;
begin = 0;
// host
end = net_options.find( ",", begin );
if ( end != string::npos ) {
host = net_options.substr(begin, end - begin);
begin = end + 1;
}
// port1
end = net_options.find( ",", begin );
if ( end != string::npos ) {
port1 = atoi( net_options.substr(begin, end - begin).c_str() );
begin = end + 1;
}
// port2
end = net_options.find( ",", begin );
if ( end != string::npos ) {
port2 = atoi( net_options.substr(begin, end - begin).c_str() );
begin = end + 1;
}
// port3
end = net_options.find( ",", begin );
if ( end != string::npos ) {
port3 = atoi( net_options.substr(begin, end - begin).c_str() );
begin = end + 1;
}
cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
} else if ( model.find("pipe") == 0 ) {
// /* old */ string pipe_path = model.substr(5);
// /* old */ cur_fdm_state = new FGExternalPipe( dt, pipe_path );
string pipe_path = "";
string pipe_protocol = "";
string pipe_options = model.substr(5);
string::size_type begin, end;
begin = 0;
// pipe file path
end = pipe_options.find( ",", begin );
if ( end != string::npos ) {
pipe_path = pipe_options.substr(begin, end - begin);
begin = end + 1;
}
// protocol (last option)
pipe_protocol = pipe_options.substr(begin);
cur_fdm_state = new FGExternalPipe( dt, pipe_path, pipe_protocol );
} else if ( model == "null" ) {
cur_fdm_state = new FGNullFDM( dt );
} else if ( model == "yasim" ) {
cur_fdm_state = new YASim( dt );
} else {
throw sg_exception(string("Unrecognized flight model '") + model
+ "', cannot init flight dynamics model.");
}
}
// Initialize view parameters
void fgInitView() {
// force update of model so that viewer can get some data...
@ -1513,7 +1406,7 @@ bool fgInitSubsystems() {
// Initialize the flight model subsystem.
////////////////////////////////////////////////////////////////////
fgInitFDM();
globals->add_subsystem("flight", new FDMShell, SGSubsystemMgr::FDM);
// allocates structures so must happen before any of the flight
// model or control parameters are set
@ -1539,14 +1432,14 @@ bool fgInitSubsystems() {
// autopilot.)
////////////////////////////////////////////////////////////////////
globals->add_subsystem("instrumentation", new FGInstrumentMgr);
globals->add_subsystem("systems", new FGSystemMgr);
globals->add_subsystem("instrumentation", new FGInstrumentMgr, SGSubsystemMgr::FDM);
globals->add_subsystem("systems", new FGSystemMgr, SGSubsystemMgr::FDM);
////////////////////////////////////////////////////////////////////
// Initialize the XML Autopilot subsystem.
////////////////////////////////////////////////////////////////////
globals->add_subsystem( "xml-autopilot", new FGXMLAutopilotGroup );
globals->add_subsystem( "xml-autopilot", new FGXMLAutopilotGroup, SGSubsystemMgr::FDM );
globals->add_subsystem( "route-manager", new FGRouteMgr );
////////////////////////////////////////////////////////////////////
@ -1747,7 +1640,7 @@ void fgReInitSubsystems()
globals->get_subsystem("ai_model")->reinit();
// Initialize the FDM
fgInitFDM();
globals->get_subsystem("flight")->reinit();
// allocates structures so must happen before any of the flight
// model or control parameters are set
@ -1781,7 +1674,8 @@ void reInit(void) // from gui_local.cxx -- TODO merge with fgReInitSubsystems()
master_freeze->setBoolValue(true);
fgSetBool("/sim/signals/reinit", true);
cur_fdm_state->unbind();
globals->get_subsystem("flight")->unbind();
// in case user has changed window size as
// restoreInitialState() overwrites these

View file

@ -34,8 +34,6 @@
#include <simgear/scene/model/particles.hxx>
#include <simgear/sound/soundmgr_openal.hxx>
#include <Aircraft/aircraft.hxx>
#include <FDM/flight.hxx>
#include <GUI/gui.h>
#include "globals.hxx"
@ -44,8 +42,6 @@
static bool winding_ccw = true; // FIXME: temporary
static bool fdm_data_logging = false; // FIXME: temporary
static bool frozen = false; // FIXME: temporary
using std::string;
@ -308,8 +304,8 @@ setDateString (const char * date_string)
// too difficult, by the way.
long int warp =
mktime(&new_time) - mktime(current_time) + globals->get_warp();
double lon = current_aircraft.fdm_state->get_Longitude();
double lat = current_aircraft.fdm_state->get_Latitude();
double lon = fgGetDouble("/position/longitude-deg") * SG_DEGREES_TO_RADIANS;
double lat = fgGetDouble("/position/latitude-deg") * SG_DEGREES_TO_RADIANS;
globals->set_warp(warp);
st->update(lon, lat, cur_time_override->getLongValue(), warp);
}
@ -354,7 +350,7 @@ static double
getHeadingMag ()
{
double magheading;
magheading = current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES - getMagVar();
magheading = fgGetDouble("/orientation/heading-deg") - getMagVar();
if (magheading < 0) magheading += 360;
return magheading;
}
@ -366,7 +362,7 @@ static double
getTrackMag ()
{
double magtrack;
magtrack = current_aircraft.fdm_state->get_Track() - getMagVar();
magtrack = fgGetDouble("/orientation/track-deg") - getMagVar();
if (magtrack < 0) magtrack += 360;
return magtrack;
}
@ -411,22 +407,6 @@ setWindingCCW (bool state)
glFrontFace ( GL_CW );
}
static bool
getFDMDataLogging ()
{
return fdm_data_logging;
}
static void
setFDMDataLogging (bool state)
{
// kludge; no getter or setter available
if (state != fdm_data_logging) {
fgToggleFDMdataLogging();
fdm_data_logging = state;
}
}
static const char *
getLongitudeString ()
{
@ -540,7 +520,6 @@ FGProperties::bind ()
// Misc. Temporary junk.
fgTie("/sim/temp/winding-ccw", getWindingCCW, setWindingCCW, false);
fgTie("/sim/temp/fdm-data-logging", getFDMDataLogging, setFDMDataLogging);
}
void

View file

@ -131,7 +131,6 @@ FGGlobals::~FGGlobals()
delete subsystem_mgr;
delete event_mgr;
delete time_params;
delete ephem;
delete mag;
delete matlib;
delete route_mgr;

View file

@ -41,7 +41,6 @@
#include <osgDB/Registry>
// Class references
#include <simgear/ephemeris/ephemeris.hxx>
#include <simgear/scene/model/modellib.hxx>
#include <simgear/scene/material/matlib.hxx>
#include <simgear/scene/model/animation.hxx>
@ -66,11 +65,11 @@
#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>
#include <Environment/environment_mgr.hxx>
#include <Environment/ephemeris.hxx>
#include <GUI/new_gui.hxx>
#include <MultiPlayer/multiplaymgr.hxx>
@ -112,87 +111,6 @@ void fgSetNewSoundDevice(const char *);
// is initialized.
extern int _bootstrap_OSInit;
// Update internal time dependent calculations (i.e. flight model)
// FIXME: this distinction is obsolete; all subsystems now get delta
// time on update.
void fgUpdateTimeDepCalcs() {
static bool inited = false;
static const SGPropertyNode *replay_state
= fgGetNode( "/sim/freeze/replay-state", true );
static SGPropertyNode *replay_time
= fgGetNode( "/sim/replay/time", true );
// static const SGPropertyNode *replay_end_time
// = fgGetNode( "/sim/replay/end-time", true );
//SG_LOG(SG_FLIGHT,SG_INFO, "Updating time dep calcs()");
// Initialize the FDM here if it hasn't been and if we have a
// scenery elevation hit.
// cout << "cur_fdm_state->get_inited() = " << cur_fdm_state->get_inited()
// << " cur_elev = " << scenery.get_cur_elev() << endl;
if (!cur_fdm_state->get_inited()) {
// Check for scenery around the aircraft.
double lon = fgGetDouble("/sim/presets/longitude-deg");
double lat = fgGetDouble("/sim/presets/latitude-deg");
// We require just to have 50 meter scenery availabe around
// the aircraft.
double range = 1000.0;
SGGeod geod = SGGeod::fromDeg(lon, lat);
if (globals->get_scenery()->scenery_available(geod, range)) {
//SG_LOG(SG_FLIGHT, SG_INFO, "Finally initializing fdm");
cur_fdm_state->init();
if ( cur_fdm_state->get_bound() ) {
cur_fdm_state->unbind();
}
cur_fdm_state->bind();
}
}
// conceptually, the following block could be done for each fdm
// instance ...
if ( cur_fdm_state->get_inited() ) {
// we have been inited, and we are good to go ...
if ( replay_state->getIntValue() == 0 ) {
// replay off, run fdm
cur_fdm_state->update( delta_time_sec );
} else {
FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
r->replay( replay_time->getDoubleValue() );
if ( replay_state->getIntValue() == 1 ) {
// normal playback
replay_time->setDoubleValue( replay_time->getDoubleValue()
+ ( delta_time_sec
* fgGetInt("/sim/speed-up") ) );
} else if ( replay_state->getIntValue() == 2 ) {
// paused playback (don't advance replay time)
}
}
if ( !inited ) {
inited = true;
fgSetBool("/sim/signals/fdm-initialized", true);
}
} else {
// do nothing, fdm isn't inited yet
}
globals->get_aircraft_model()->update(delta_time_sec);
// Update solar system
globals->get_ephem()->update( globals->get_time_params()->getMjd(),
globals->get_time_params()->getLst(),
cur_fdm_state->get_Latitude() );
}
// 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 ) {
@ -307,6 +225,10 @@ static void fgMainLoop( void ) {
if (0 < dtMax && dtMax < real_delta_time_sec)
real_delta_time_sec = dtMax;
SGSubsystemGroup* fdmGroup =
globals->get_subsystem_mgr()->get_group(SGSubsystemMgr::FDM);
fdmGroup->set_fixed_update_time(1.0 / model_hz);
// round the real time down to a multiple of 1/model-hz.
// this way all systems are updated the _same_ amount of dt.
static double reminder = 0.0;
@ -341,21 +263,6 @@ static void fgMainLoop( void ) {
SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop");
SG_LOG( SG_ALL, SG_DEBUG, "======= ==== ====");
// Fix elevation. I'm just sticking this here for now, it should
// probably move eventually
/* printf("Before - ground = %.2f runway = %.2f alt = %.2f\n",
scenery.get_cur_elev(),
cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
/* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n",
scenery.get_cur_elev(),
cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
// cout << "Warp = " << globals->get_warp() << endl;
// update "time"
static bool last_clock_freeze = false;
@ -445,18 +352,9 @@ static void fgMainLoop( void ) {
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_subsystem_mgr()->update(delta_time_sec);
globals->get_aircraft_model()->update(delta_time_sec);
//
// Tile Manager updates - see if we need to load any new scenery tiles.
@ -523,7 +421,7 @@ static void fgMainLoop( void ) {
// END Tile Manager udpates
if (!scenery_loaded && globals->get_tile_mgr()->isSceneryLoaded()
&& cur_fdm_state->get_inited()) {
&& fgGetBool("sim/signals/fdm-initialized")) {
fgSetBool("sim/sceneryloaded",true);
if (fgGetBool("/sim/sound/working")) {
globals->get_soundmgr()->activate();
@ -697,9 +595,11 @@ static void fgIdleFunction ( void ) {
// Initialize the 3D aircraft model subsystem (has a dependency on
// the scenery subsystem.)
////////////////////////////////////////////////////////////////////
globals->set_aircraft_model(new FGAircraftModel);
globals->get_aircraft_model()->init();
globals->get_aircraft_model()->bind();
FGAircraftModel* acm = new FGAircraftModel;
globals->set_aircraft_model(acm);
//globals->add_subsystem("aircraft-model", acm);
acm->init();
acm->bind();
////////////////////////////////////////////////////////////////////
// Initialize the view manager subsystem.
@ -714,13 +614,10 @@ static void fgIdleFunction ( void ) {
} else if ( idle_state == 6 ) {
idle_state++;
// Initialize the sky
SGPath ephem_data_path( globals->get_fg_root() );
ephem_data_path.append( "Astro" );
SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() );
ephem->update( globals->get_time_params()->getMjd(),
globals->get_time_params()->getLst(),
0.0 );
globals->set_ephem( ephem );
Ephemeris* eph = new Ephemeris;
globals->add_subsystem("ephmeris", eph);
eph->init(); // FIXME - remove this once SGSky code below is also a subsystem
// TODO: move to environment mgr
thesky = new SGSky;

View file

@ -630,7 +630,8 @@ FGRenderer::update( bool refresh_camera_settings ) {
double visibility_meters = fgGetDouble("/environment/visibility-m");
thesky->set_visibility(visibility_meters);
thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
double altitude_m = fgGetDouble("/position/altitude-ft") * SG_FEET_TO_METER;
thesky->modify_vis( altitude_m,
( global_multi_loop * fgGetInt("/sim/speed-up") )
/ (double)fgGetInt("/sim/model-hz") );
@ -678,25 +679,6 @@ FGRenderer::update( bool refresh_camera_settings ) {
thesky->reposition( sstate, *globals->get_ephem(), delta_time_sec );
thesky->repaint( scolor, *globals->get_ephem() );
/*
SG_LOG( SG_GENERAL, SG_BULK,
"thesky->reposition( view_pos = " << view_pos[0] << " "
<< view_pos[1] << " " << view_pos[2] );
SG_LOG( SG_GENERAL, SG_BULK,
" zero_elev = " << zero_elev[0] << " "
<< zero_elev[1] << " " << zero_elev[2]
<< " lon = " << cur_fdm_state->get_Longitude()
<< " lat = " << cur_fdm_state->get_Latitude() );
SG_LOG( SG_GENERAL, SG_BULK,
" sun_rot = " << l->get_sun_rotation
<< " gst = " << SGTime::cur_time_params->getGst() );
SG_LOG( SG_GENERAL, SG_BULK,
" sun ra = " << globals->get_ephem()->getSunRightAscension()
<< " sun dec = " << globals->get_ephem()->getSunDeclination()
<< " moon ra = " << globals->get_ephem()->getMoonRightAscension()
<< " moon dec = " << globals->get_ephem()->getMoonDeclination() );
*/
//OSGFIXME
// shadows->setupShadows(
// current__view->getLongitude_deg(),

View file

@ -55,10 +55,7 @@ FGAircraftModel::FGAircraftModel ()
FGAircraftModel::~FGAircraftModel ()
{
osg::Node* node = _aircraft->getSceneGraph();
globals->get_scenery()->get_aircraft_branch()->removeChild(node);
delete _aircraft;
deinit();
}
void
@ -83,6 +80,27 @@ FGAircraftModel::init ()
globals->get_scenery()->get_aircraft_branch()->addChild(node);
}
void
FGAircraftModel::reinit()
{
deinit();
init();
}
void
FGAircraftModel::deinit()
{
if (!_aircraft) {
return;
}
osg::Node* node = _aircraft->getSceneGraph();
globals->get_scenery()->get_aircraft_branch()->removeChild(node);
delete _aircraft;
_aircraft = NULL;
}
void
FGAircraftModel::bind ()
{

View file

@ -6,16 +6,6 @@
#ifndef __ACMODEL_HXX
#define __ACMODEL_HXX 1
#ifndef __cplusplus
# error This library requires C++
#endif
#include <vector>
#include <string>
using std::string;
using std::vector;
#include <osg/ref_ptr>
#include <osg/Group>
#include <osg/Switch>
@ -35,6 +25,7 @@ public:
virtual ~FGAircraftModel ();
virtual void init ();
virtual void reinit ();
virtual void bind ();
virtual void unbind ();
virtual void update (double dt);
@ -42,6 +33,7 @@ public:
virtual SGVec3d& getVelocity() { return _velocity; }
private:
void deinit ();
SGModelPlacement * _aircraft;
SGVec3d _velocity;

View file

@ -30,7 +30,6 @@
#include <simgear/io/iochannel.hxx>
#include <simgear/timing/sg_time.hxx>
#include <FDM/flight.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
@ -80,12 +79,12 @@ bool FGAV400::gen_message() {
double min;
// create msg_z
sprintf( msg_z, "z%05.0f\r\n", cur_fdm_state->get_Altitude() );
sprintf( msg_z, "z%05.0f\r\n", fdm.get_Altitude() );
// create msg_A
sprintf( msg_A, "A");
double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
double latd = fdm.get_Latitude() * SGD_RADIANS_TO_DEGREES;
if ( latd < 0.0 ) {
latd = -latd;
dir = 'S';
@ -97,7 +96,7 @@ bool FGAV400::gen_message() {
sprintf( msg_A, "A%c %02d %04.0f\r\n", dir, deg, min);
// create msg_B
double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
double lond = fdm.get_Longitude() * SGD_RADIANS_TO_DEGREES;
if ( lond < 0.0 ) {
lond = -lond;
dir = 'W';
@ -262,7 +261,7 @@ bool FGAV400::parse_message() {
lat *= -1;
}
cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
fdm.set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " lat = " << lat );
// lon val
@ -291,17 +290,17 @@ bool FGAV400::parse_message() {
lon *= -1;
}
cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
fdm.set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " lon = " << lon );
#if 0
double sl_radius, lat_geoc;
sgGeodToGeoc( cur_fdm_state->get_Latitude(),
cur_fdm_state->get_Altitude(),
sgGeodToGeoc( fdm.get_Latitude(),
fdm.get_Altitude(),
&sl_radius, &lat_geoc );
cur_fdm_state->set_Geocentric_Position( lat_geoc,
cur_fdm_state->get_Longitude(),
sl_radius + cur_fdm_state->get_Altitude() );
fdm.set_Geocentric_Position( lat_geoc,
fdm.get_Longitude(),
sl_radius + fdm.get_Altitude() );
#endif
// speed
@ -313,8 +312,8 @@ bool FGAV400::parse_message() {
string speed_str = msg.substr(begin, end - begin);
begin = end + 1;
speed = atof( speed_str.c_str() );
cur_fdm_state->set_V_calibrated_kts( speed );
// cur_fdm_state->set_V_ground_speed( speed );
fdm.set_V_calibrated_kts( speed );
// fdm.set_V_ground_speed( speed );
SG_LOG( SG_IO, SG_INFO, " speed = " << speed );
// heading
@ -326,8 +325,8 @@ bool FGAV400::parse_message() {
string hdg_str = msg.substr(begin, end - begin);
begin = end + 1;
heading = atof( hdg_str.c_str() );
cur_fdm_state->set_Euler_Angles( cur_fdm_state->get_Phi(),
cur_fdm_state->get_Theta(),
fdm.set_Euler_Angles( fdm.get_Phi(),
fdm.get_Theta(),
heading * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " heading = " << heading );
} else if ( sentence == "PGRMZ" ) {
@ -354,7 +353,7 @@ bool FGAV400::parse_message() {
altitude *= SG_METER_TO_FEET;
}
cur_fdm_state->set_Altitude( altitude );
fdm.set_Altitude( altitude );
SG_LOG( SG_IO, SG_INFO, " altitude = " << altitude );

View file

@ -30,9 +30,7 @@
#include <string>
#include "protocol.hxx"
using std::string;
#include <FDM/flightProperties.hxx>
class FGAV400 : public FGProtocol {
@ -55,6 +53,8 @@ public:
// close the channel
bool close();
FlightProperties fdm;
};

View file

@ -34,16 +34,18 @@
#include <simgear/io/iochannel.hxx>
#include <simgear/timing/sg_time.hxx>
#include <FDM/flight.hxx>
#include <FDM/flightProperties.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include "AV400Sim.hxx"
FGAV400Sim::FGAV400Sim() {
fdm = new FlightProperties;
}
FGAV400Sim::~FGAV400Sim() {
delete fdm;
}
@ -60,7 +62,7 @@ bool FGAV400Sim::gen_message() {
double min;
// create msg_a
double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
double latd = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES;
if ( latd < 0.0 ) {
latd = -latd;
dir = 'S';
@ -72,7 +74,7 @@ bool FGAV400Sim::gen_message() {
sprintf( msg_a, "a%c %03d %04.0f\r\n", dir, deg, min);
// create msg_b
double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
double lond = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES;
if ( lond < 0.0 ) {
lond = -lond;
dir = 'W';
@ -84,7 +86,7 @@ bool FGAV400Sim::gen_message() {
sprintf( msg_b, "b%c %03d %04.0f\r\n", dir, deg, min);
// create msg_c
double alt = cur_fdm_state->get_Altitude();
double alt = fdm->get_Altitude();
if ( alt > 99999.0 ) { alt = 99999.0; }
sprintf( msg_c, "c%05.0f\r\n", alt );

View file

@ -35,13 +35,13 @@
#include "protocol.hxx"
using std::string;
class FlightProperties;
class FGAV400Sim : public FGProtocol {
char buf[ FG_MAX_MSG_SIZE ];
int length;
FlightProperties* fdm;
public:

View file

@ -31,7 +31,7 @@
#include <FDM/flight.hxx>
#include <FDM/flightProperties.hxx>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Main/fg_init.hxx>
@ -40,9 +40,11 @@
FGAtlas::FGAtlas() {
fdm = new FlightProperties;
}
FGAtlas::~FGAtlas() {
delete fdm;
}
@ -65,7 +67,6 @@ static char calc_atlas_cksum(char *sentence) {
return sum;
}
// generate Atlas message
bool FGAtlas::gen_message() {
// cout << "generating atlas message" << endl;
@ -94,7 +95,7 @@ bool FGAtlas::gen_message() {
t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec );
char lat[20];
double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
double latd = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES;
if ( latd < 0.0 ) {
latd *= -1.0;
dir = 'S';
@ -106,7 +107,7 @@ bool FGAtlas::gen_message() {
sprintf( lat, "%02d%06.3f,%c", abs(deg), min, dir);
char lon[20];
double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
double lond = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES;
if ( lond < 0.0 ) {
lond *= -1.0;
dir = 'W';
@ -118,17 +119,17 @@ bool FGAtlas::gen_message() {
sprintf( lon, "%03d%06.3f,%c", abs(deg), min, dir);
char speed[10];
sprintf( speed, "%05.1f", cur_fdm_state->get_V_equiv_kts() );
sprintf( speed, "%05.1f", fdm->get_V_equiv_kts() );
char heading[10];
sprintf( heading, "%05.1f", cur_fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES );
sprintf( heading, "%05.1f", fdm->get_Psi() * SGD_RADIANS_TO_DEGREES );
char altitude_m[10];
sprintf( altitude_m, "%02d",
(int)(cur_fdm_state->get_Altitude() * SG_FEET_TO_METER) );
(int)(fdm->get_Altitude() * SG_FEET_TO_METER) );
char altitude_ft[10];
sprintf( altitude_ft, "%02d", (int)cur_fdm_state->get_Altitude() );
sprintf( altitude_ft, "%02d", (int)fdm->get_Altitude() );
char date[10];
sprintf( date, "%02d%02d%02d", t->getGmt()->tm_mday,
@ -275,7 +276,7 @@ bool FGAtlas::parse_message() {
lat *= -1;
}
cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " lat = " << lat );
// lon val
@ -304,17 +305,17 @@ bool FGAtlas::parse_message() {
lon *= -1;
}
cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " lon = " << lon );
#if 0
double sl_radius, lat_geoc;
sgGeodToGeoc( cur_fdm_state->get_Latitude(),
cur_fdm_state->get_Altitude(),
sgGeodToGeoc( fdm->get_Latitude(),
fdm->get_Altitude(),
&sl_radius, &lat_geoc );
cur_fdm_state->set_Geocentric_Position( lat_geoc,
cur_fdm_state->get_Longitude(),
sl_radius + cur_fdm_state->get_Altitude() );
fdm->set_Geocentric_Position( lat_geoc,
fdm->get_Longitude(),
sl_radius + fdm->get_Altitude() );
#endif
// speed
@ -326,8 +327,8 @@ bool FGAtlas::parse_message() {
string speed_str = msg.substr(begin, end - begin);
begin = end + 1;
speed = atof( speed_str.c_str() );
cur_fdm_state->set_V_calibrated_kts( speed );
// cur_fdm_state->set_V_ground_speed( speed );
fdm->set_V_calibrated_kts( speed );
// fdm->set_V_ground_speed( speed );
SG_LOG( SG_IO, SG_INFO, " speed = " << speed );
// heading
@ -339,8 +340,8 @@ bool FGAtlas::parse_message() {
string hdg_str = msg.substr(begin, end - begin);
begin = end + 1;
heading = atof( hdg_str.c_str() );
cur_fdm_state->set_Euler_Angles( cur_fdm_state->get_Phi(),
cur_fdm_state->get_Theta(),
fdm->set_Euler_Angles( fdm->get_Phi(),
fdm->get_Theta(),
heading * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " heading = " << heading );
} else if ( sentence == "GPGGA" ) {
@ -380,7 +381,7 @@ bool FGAtlas::parse_message() {
lat *= -1;
}
// cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
// fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " lat = " << lat );
// lon val
@ -409,7 +410,7 @@ bool FGAtlas::parse_message() {
lon *= -1;
}
// cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
// fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " lon = " << lon );
// junk
@ -465,7 +466,7 @@ bool FGAtlas::parse_message() {
altitude *= SG_METER_TO_FEET;
}
cur_fdm_state->set_Altitude( altitude );
fdm->set_Altitude( altitude );
SG_LOG( SG_IO, SG_INFO, " altitude = " << altitude );

View file

@ -31,13 +31,13 @@
#include "protocol.hxx"
using std::string;
class FlightProperties;
class FGAtlas : public FGProtocol {
char buf[ FG_MAX_MSG_SIZE ];
int length;
FlightProperties* fdm;
public:

View file

@ -31,7 +31,7 @@
#include <simgear/io/iochannel.hxx>
#include <simgear/timing/sg_time.hxx>
#include <FDM/flight.hxx>
#include <FDM/flightProperties.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
@ -40,9 +40,11 @@
using std::string;
FGGarmin::FGGarmin() {
fdm = new FlightProperties;
}
FGGarmin::~FGGarmin() {
delete fdm;
}
@ -82,7 +84,7 @@ bool FGGarmin::gen_message() {
t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec );
char rmc_lat[20];
double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
double latd = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES;
if ( latd < 0.0 ) {
latd = -latd;
dir = 'S';
@ -94,7 +96,7 @@ bool FGGarmin::gen_message() {
sprintf( rmc_lat, "%02d%07.4f,%c", abs(deg), min, dir);
char rmc_lon[20];
double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
double lond = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES;
if ( lond < 0.0 ) {
lond = -lond;
dir = 'W';
@ -106,14 +108,14 @@ bool FGGarmin::gen_message() {
sprintf( rmc_lon, "%03d%07.4f,%c", abs(deg), min, dir);
char speed[10];
sprintf( speed, "%05.1f", cur_fdm_state->get_V_equiv_kts() );
sprintf( speed, "%05.1f", fdm->get_V_equiv_kts() );
char heading[10];
sprintf( heading, "%05.1f", cur_fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES );
sprintf( heading, "%05.1f", fdm->get_Psi() * SGD_RADIANS_TO_DEGREES );
char altitude_m[10];
sprintf( altitude_m, "%02d",
(int)(cur_fdm_state->get_Altitude() * SG_FEET_TO_METER) );
(int)(fdm->get_Altitude() * SG_FEET_TO_METER) );
char date[10];
int year = t->getGmt()->tm_year;
@ -261,7 +263,7 @@ bool FGGarmin::parse_message() {
lat *= -1;
}
cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " lat = " << lat );
// lon val
@ -290,17 +292,17 @@ bool FGGarmin::parse_message() {
lon *= -1;
}
cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " lon = " << lon );
#if 0
double sl_radius, lat_geoc;
sgGeodToGeoc( cur_fdm_state->get_Latitude(),
cur_fdm_state->get_Altitude(),
sgGeodToGeoc( fdm->get_Latitude(),
fdm->get_Altitude(),
&sl_radius, &lat_geoc );
cur_fdm_state->set_Geocentric_Position( lat_geoc,
cur_fdm_state->get_Longitude(),
sl_radius + cur_fdm_state->get_Altitude() );
fdm->set_Geocentric_Position( lat_geoc,
fdm->get_Longitude(),
sl_radius + fdm->get_Altitude() );
#endif
// speed
@ -312,8 +314,8 @@ bool FGGarmin::parse_message() {
string speed_str = msg.substr(begin, end - begin);
begin = end + 1;
speed = atof( speed_str.c_str() );
cur_fdm_state->set_V_calibrated_kts( speed );
// cur_fdm_state->set_V_ground_speed( speed );
fdm->set_V_calibrated_kts( speed );
// fdm->set_V_ground_speed( speed );
SG_LOG( SG_IO, SG_INFO, " speed = " << speed );
// heading
@ -325,8 +327,8 @@ bool FGGarmin::parse_message() {
string hdg_str = msg.substr(begin, end - begin);
begin = end + 1;
heading = atof( hdg_str.c_str() );
cur_fdm_state->set_Euler_Angles( cur_fdm_state->get_Phi(),
cur_fdm_state->get_Theta(),
fdm->set_Euler_Angles( fdm->get_Phi(),
fdm->get_Theta(),
heading * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " heading = " << heading );
} else if ( sentence == "PGRMZ" ) {
@ -353,7 +355,7 @@ bool FGGarmin::parse_message() {
altitude *= SG_METER_TO_FEET;
}
cur_fdm_state->set_Altitude( altitude );
fdm->set_Altitude( altitude );
SG_LOG( SG_IO, SG_INFO, " altitude = " << altitude );

View file

@ -31,13 +31,13 @@
#include "protocol.hxx"
using std::string;
class FlightProperties;
class FGGarmin : public FGProtocol {
char buf[ FG_MAX_MSG_SIZE ];
int length;
FlightProperties* fdm;
public:

View file

@ -37,7 +37,7 @@
#include <simgear/debug/logstream.hxx>
#include <simgear/math/SGMath.hxx>
#include <FDM/flight.hxx>
#include <FDM/flightProperties.hxx>
#include <MultiPlayer/mpmessages.hxx>
#include "multiplay.hxx"
@ -129,7 +129,7 @@ bool FGMultiplay::process() {
// if (sim_time < 20)
// return true;
FGInterface *ifce = cur_fdm_state;
FlightProperties ifce;
// put together a motion info struct, you will get that later
// from FGInterface directly ...
@ -150,10 +150,10 @@ bool FGMultiplay::process() {
// These are for now converted from lat/lon/alt and euler angles.
// But this should change in FGInterface ...
double lon = ifce->get_Longitude();
double lat = ifce->get_Latitude();
double lon = ifce.get_Longitude();
double lat = ifce.get_Latitude();
// first the aprioriate structure for the geodetic one
SGGeod geod = SGGeod::fromRadFt(lon, lat, ifce->get_Altitude());
SGGeod geod = SGGeod::fromRadFt(lon, lat, ifce.get_Altitude());
// Convert to cartesion coordinate
motionInfo.position = SGVec3d::fromGeod(geod);
@ -161,28 +161,28 @@ bool FGMultiplay::process() {
// horizontal local frame
SGQuatf qEc2Hl = SGQuatf::fromLonLatRad((float)lon, (float)lat);
// The orientation wrt the horizontal local frame
float heading = ifce->get_Psi();
float pitch = ifce->get_Theta();
float roll = ifce->get_Phi();
float heading = ifce.get_Psi();
float pitch = ifce.get_Theta();
float roll = ifce.get_Phi();
SGQuatf hlOr = SGQuatf::fromYawPitchRoll(heading, pitch, roll);
// The orientation of the vehicle wrt the earth centered frame
motionInfo.orientation = qEc2Hl*hlOr;
if (!ifce->is_suspended()) {
if (!globals->get_subsystem("flight")->is_suspended()) {
// velocities
motionInfo.linearVel = SG_FEET_TO_METER*SGVec3f(ifce->get_U_body(),
ifce->get_V_body(),
ifce->get_W_body());
motionInfo.angularVel = SGVec3f(ifce->get_P_body(),
ifce->get_Q_body(),
ifce->get_R_body());
motionInfo.linearVel = SG_FEET_TO_METER*SGVec3f(ifce.get_uBody(),
ifce.get_vBody(),
ifce.get_wBody());
motionInfo.angularVel = SGVec3f(ifce.get_P_body(),
ifce.get_Q_body(),
ifce.get_R_body());
// accels, set that to zero for now.
// Angular accelerations are missing from the interface anyway,
// linear accelerations are screwed up at least for JSBSim.
// motionInfo.linearAccel = SG_FEET_TO_METER*SGVec3f(ifce->get_U_dot_body(),
// ifce->get_V_dot_body(),
// ifce->get_W_dot_body());
// motionInfo.linearAccel = SG_FEET_TO_METER*SGVec3f(ifce.get_U_dot_body(),
// ifce.get_V_dot_body(),
// ifce.get_W_dot_body());
motionInfo.linearAccel = SGVec3f::zeros();
motionInfo.angularAccel = SGVec3f::zeros();
} else {

View file

@ -29,6 +29,7 @@
#include "native.hxx"
#include <FDM/flight.hxx>
FGNative::FGNative() {
}
@ -57,15 +58,21 @@ bool FGNative::open() {
return true;
}
/**
* The design of FGNative requires direct, memcpy access to FGInterface,
* unfortunately. Since this is the only remaining place that does, the
* extern lives here, rather than a header file.
*
*/
extern FGInterface* evil_global_fdm_state;
// process work for this port
bool FGNative::process() {
SGIOChannel *io = get_io_channel();
int length = sizeof(*cur_fdm_state);
int length = sizeof(FGInterface);
if ( get_direction() == SG_IO_OUT ) {
// cout << "size of cur_fdm_state = " << length << endl;
buf = *cur_fdm_state;
buf = *evil_global_fdm_state;
if ( ! io->write( (char *)(& buf), length ) ) {
SG_LOG( SG_IO, SG_ALERT, "Error writing data." );
return false;
@ -74,12 +81,12 @@ bool FGNative::process() {
if ( io->get_type() == sgFileType ) {
if ( io->read( (char *)(& buf), length ) == length ) {
SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
*cur_fdm_state = buf;
*evil_global_fdm_state = buf;
}
} else {
while ( io->read( (char *)(& buf), length ) == length ) {
SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
*cur_fdm_state = buf;
*evil_global_fdm_state = buf;
}
}
}

View file

@ -29,12 +29,8 @@
#include <string>
#include <FDM/flight.hxx>
#include "protocol.hxx"
using std::string;
#include <FDM/flight.hxx>
class FGNative : public FGProtocol {

View file

@ -29,7 +29,6 @@
#include <simgear/io/iochannel.hxx>
#include <simgear/io/lowlevel.hxx> // endian tests
#include <FDM/flight.hxx>
#include <Main/fg_props.hxx>
#include <Scenery/scenery.hxx> // ground elevation
@ -205,12 +204,7 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool honor_freezes,
net->temp_c = fgGetDouble("/environment/temperature-degc");
net->press_inhg = fgGetDouble("/environment/pressure-sea-level-inhg");
// cur_fdm_state->get_ground_elev_ft() is what we want ... this
// reports the altitude of the aircraft.
// "/environment/ground-elevation-m" reports the ground elevation
// of the current view point which could change substantially if
// the user is switching views.
net->hground = cur_fdm_state->get_ground_elev_ft() * SG_FEET_TO_METER;
net->hground = fgGetDouble("/position/ground-elev-m");
net->magvar = fgGetDouble("/environment/magnetic-variation-deg");
net->icing = fgGetBool("/hazards/icing/wing");
@ -469,7 +463,6 @@ bool FGNativeCtrls::process() {
int length = sizeof(FGNetCtrls);
if ( get_direction() == SG_IO_OUT ) {
// cout << "size of cur_fdm_state = " << length << endl;
FGProps2NetCtrls( &net_ctrls, true, true );

View file

@ -30,7 +30,7 @@
#include <simgear/io/iochannel.hxx>
#include <simgear/timing/sg_time.hxx>
#include <FDM/flight.hxx>
#include <FDM/flightProperties.hxx>
#include <Time/tmp.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
@ -115,7 +115,9 @@ bool FGNativeFDM::open() {
set_enabled( true );
// Is this really needed here ????
cur_fdm_state->_set_Sea_level_radius( SG_EQUATORIAL_RADIUS_FT );
fgSetDouble("/position/sea-level-radius-ft", SG_EQUATORIAL_RADIUS_FT);
return true;
}
@ -124,37 +126,39 @@ bool FGNativeFDM::open() {
void FGProps2NetFDM( FGNetFDM *net, bool net_byte_order ) {
unsigned int i;
FlightProperties fdm_state;
// Version sanity checking
net->version = FG_NET_FDM_VERSION;
// Aero parameters
net->longitude = cur_fdm_state->get_Longitude();
net->latitude = cur_fdm_state->get_Latitude();
net->altitude = cur_fdm_state->get_Altitude() * SG_FEET_TO_METER;
net->agl = cur_fdm_state->get_Altitude_AGL() * SG_FEET_TO_METER;
net->phi = cur_fdm_state->get_Phi();
net->theta = cur_fdm_state->get_Theta();
net->psi = cur_fdm_state->get_Psi();
net->alpha = cur_fdm_state->get_Alpha();
net->beta = cur_fdm_state->get_Beta();
net->phidot = cur_fdm_state->get_Phi_dot_degps() * SG_DEGREES_TO_RADIANS;
net->thetadot = cur_fdm_state->get_Theta_dot_degps()
net->longitude = fdm_state.get_Longitude();
net->latitude = fdm_state.get_Latitude();
net->altitude = fdm_state.get_Altitude() * SG_FEET_TO_METER;
net->agl = fdm_state.get_Altitude_AGL() * SG_FEET_TO_METER;
net->phi = fdm_state.get_Phi();
net->theta = fdm_state.get_Theta();
net->psi = fdm_state.get_Psi();
net->alpha = fdm_state.get_Alpha();
net->beta = fdm_state.get_Beta();
net->phidot = fdm_state.get_Phi_dot_degps() * SG_DEGREES_TO_RADIANS;
net->thetadot = fdm_state.get_Theta_dot_degps()
* SG_DEGREES_TO_RADIANS;
net->psidot = cur_fdm_state->get_Psi_dot_degps() * SG_DEGREES_TO_RADIANS;
net->psidot = fdm_state.get_Psi_dot_degps() * SG_DEGREES_TO_RADIANS;
net->vcas = cur_fdm_state->get_V_calibrated_kts();
net->climb_rate = cur_fdm_state->get_Climb_Rate();
net->vcas = fdm_state.get_V_calibrated_kts();
net->climb_rate = fdm_state.get_Climb_Rate();
net->v_north = cur_fdm_state->get_V_north();
net->v_east = cur_fdm_state->get_V_east();
net->v_down = cur_fdm_state->get_V_down();
net->v_wind_body_north = cur_fdm_state->get_uBody();
net->v_wind_body_east = cur_fdm_state->get_vBody();
net->v_wind_body_down = cur_fdm_state->get_wBody();
net->v_north = fdm_state.get_V_north();
net->v_east = fdm_state.get_V_east();
net->v_down = fdm_state.get_V_down();
net->v_wind_body_north = fdm_state.get_uBody();
net->v_wind_body_east = fdm_state.get_vBody();
net->v_wind_body_down = fdm_state.get_wBody();
net->A_X_pilot = cur_fdm_state->get_A_X_pilot();
net->A_Y_pilot = cur_fdm_state->get_A_Y_pilot();
net->A_Z_pilot = cur_fdm_state->get_A_Z_pilot();
net->A_X_pilot = fdm_state.get_A_X_pilot();
net->A_Y_pilot = fdm_state.get_A_Y_pilot();
net->A_Z_pilot = fdm_state.get_A_Z_pilot();
net->stall_warning = fgGetDouble("/sim/alarms/stall-warning", 0.0);
net->slip_deg
@ -300,6 +304,7 @@ void FGProps2NetFDM( FGNetFDM *net, bool net_byte_order ) {
void FGNetFDM2Props( FGNetFDM *net, bool net_byte_order ) {
unsigned int i;
FlightProperties fdm_state;
if ( net_byte_order ) {
// Convert to the net buffer from network format
@ -379,37 +384,38 @@ void FGNetFDM2Props( FGNetFDM *net, bool net_byte_order ) {
if ( net->version == FG_NET_FDM_VERSION ) {
// cout << "pos = " << net->longitude << " " << net->latitude << endl;
// cout << "sea level rad = " << cur_fdm_state->get_Sea_level_radius()
// cout << "sea level rad = " << fdm_state.get_Sea_level_radius()
// << endl;
cur_fdm_state->_updateGeodeticPosition( net->latitude,
net->longitude,
net->altitude
* SG_METER_TO_FEET );
fdm_state.set_Latitude(net->latitude);
fdm_state.set_Longitude(net->longitude);
fdm_state.set_Altitude(net->altitude * SG_METER_TO_FEET);
if ( net->agl > -9000 ) {
cur_fdm_state->_set_Altitude_AGL( net->agl * SG_METER_TO_FEET );
fdm_state.set_Altitude_AGL( net->agl * SG_METER_TO_FEET );
} else {
double agl_m = net->altitude
- cur_fdm_state->get_Runway_altitude_m();
cur_fdm_state->_set_Altitude_AGL( agl_m * SG_METER_TO_FEET );
- fdm_state.get_Runway_altitude_m();
fdm_state.set_Altitude_AGL( agl_m * SG_METER_TO_FEET );
}
cur_fdm_state->_set_Euler_Angles( net->phi,
fdm_state.set_Euler_Angles( net->phi,
net->theta,
net->psi );
cur_fdm_state->_set_Alpha( net->alpha );
cur_fdm_state->_set_Beta( net->beta );
cur_fdm_state->_set_Euler_Rates( net->phidot,
fdm_state.set_Alpha( net->alpha );
fdm_state.set_Beta( net->beta );
fdm_state.set_Euler_Rates( net->phidot,
net->thetadot,
net->psidot );
cur_fdm_state->_set_V_calibrated_kts( net->vcas );
cur_fdm_state->_set_Climb_Rate( net->climb_rate );
cur_fdm_state->_set_Velocities_Local( net->v_north,
fdm_state.set_V_calibrated_kts( net->vcas );
fdm_state.set_Climb_Rate( net->climb_rate );
fdm_state.set_Velocities_Local( net->v_north,
net->v_east,
net->v_down );
cur_fdm_state->_set_Velocities_Wind_Body( net->v_wind_body_north,
fdm_state.set_Velocities_Wind_Body( net->v_wind_body_north,
net->v_wind_body_east,
net->v_wind_body_down );
cur_fdm_state->_set_Accels_Pilot_Body( net->A_X_pilot,
fdm_state.set_Accels_Pilot_Body( net->A_X_pilot,
net->A_Y_pilot,
net->A_Z_pilot );
@ -502,7 +508,7 @@ bool FGNativeFDM::process() {
int length = sizeof(buf);
if ( get_direction() == SG_IO_OUT ) {
// cout << "size of cur_fdm_state = " << length << endl;
FGProps2NetFDM( &buf );
if ( ! io->write( (char *)(& buf), length ) ) {
SG_LOG( SG_IO, SG_ALERT, "Error writing data." );

View file

@ -29,13 +29,11 @@
#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;

View file

@ -30,11 +30,11 @@
#include <simgear/io/iochannel.hxx>
#include <simgear/timing/sg_time.hxx>
#include <FDM/flight.hxx>
#include <Time/tmp.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include <Scenery/scenery.hxx>
#include <FDM/flightProperties.hxx>
#include "native_gui.hxx"
@ -116,7 +116,7 @@ bool FGNativeGUI::open() {
set_enabled( true );
cur_fdm_state->_set_Sea_level_radius( SG_EQUATORIAL_RADIUS_FT );
fgSetDouble("/position/sea-level-radius-ft", SG_EQUATORIAL_RADIUS_FT);
return true;
}
@ -140,20 +140,22 @@ void FGProps2NetGUI( FGNetGUI *net ) {
= fgGetNode("/instrumentation/nav/gs-needle-deflection", true);
unsigned int i;
static FlightProperties* fdm_state = new FlightProperties;
// Version sanity checking
net->version = FG_NET_GUI_VERSION;
// Aero parameters
net->longitude = cur_fdm_state->get_Longitude();
net->latitude = cur_fdm_state->get_Latitude();
net->altitude = cur_fdm_state->get_Altitude() * SG_FEET_TO_METER;
net->phi = cur_fdm_state->get_Phi();
net->theta = cur_fdm_state->get_Theta();
net->psi = cur_fdm_state->get_Psi();
net->longitude = fdm_state->get_Longitude();
net->latitude = fdm_state->get_Latitude();
net->altitude = fdm_state->get_Altitude() * SG_FEET_TO_METER;
net->phi = fdm_state->get_Phi();
net->theta = fdm_state->get_Theta();
net->psi = fdm_state->get_Psi();
// Velocities
net->vcas = cur_fdm_state->get_V_calibrated_kts();
net->climb_rate = cur_fdm_state->get_Climb_Rate();
net->vcas = fdm_state->get_V_calibrated_kts();
net->climb_rate = fdm_state->get_Climb_Rate();
// Consumables
net->num_tanks = FGNetGUI::FG_MAX_TANKS;
@ -165,7 +167,7 @@ void FGProps2NetGUI( FGNetGUI *net ) {
// Environment
net->cur_time = globals->get_time_params()->get_cur_time();
net->warp = globals->get_warp();
net->ground_elev = cur_fdm_state->get_Runway_altitude_m();
net->ground_elev = fdm_state->get_Runway_altitude_m();
// Approach
net->tuned_freq = nav_freq->getDoubleValue();
@ -281,19 +283,22 @@ void FGNetGUI2Props( FGNetGUI *net ) {
#endif
if ( net->version == FG_NET_GUI_VERSION ) {
FlightProperties fdm_state;
// cout << "pos = " << net->longitude << " " << net->latitude << endl;
// cout << "sea level rad = " << cur_fdm_state->get_Sea_level_radius()
// cout << "sea level rad = " << fdm_state->get_Sea_level_radius()
// << endl;
cur_fdm_state->_updateGeodeticPosition( net->latitude,
net->longitude,
net->altitude
* SG_METER_TO_FEET );
cur_fdm_state->_set_Euler_Angles( net->phi,
fdm_state.set_Latitude(net->latitude);
fdm_state.set_Longitude(net->longitude);
fdm_state.set_Altitude(net->altitude * SG_METER_TO_FEET);
fdm_state.set_Euler_Angles( net->phi,
net->theta,
net->psi );
cur_fdm_state->_set_V_calibrated_kts( net->vcas );
cur_fdm_state->_set_Climb_Rate( net->climb_rate );
fdm_state.set_V_calibrated_kts( net->vcas );
fdm_state.set_Climb_Rate( net->climb_rate );
for (i = 0; i < net->num_tanks; ++i ) {
SGPropertyNode * node
@ -333,7 +338,7 @@ bool FGNativeGUI::process() {
int length = sizeof(buf);
if ( get_direction() == SG_IO_OUT ) {
// cout << "size of cur_fdm_state = " << length << endl;
// cout << "size of fdm_state = " << length << endl;
FGProps2NetGUI( &buf );
if ( ! io->write( (char *)(& buf), length ) ) {
SG_LOG( SG_IO, SG_ALERT, "Error writing data." );

View file

@ -27,13 +27,10 @@
#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;

View file

@ -29,16 +29,18 @@
#include <simgear/io/iochannel.hxx>
#include <simgear/timing/sg_time.hxx>
#include <FDM/flight.hxx>
#include <FDM/flightProperties.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include "nmea.hxx"
FGNMEA::FGNMEA() {
fdm = new FlightProperties();
}
FGNMEA::~FGNMEA() {
delete fdm;
}
@ -79,7 +81,7 @@ bool FGNMEA::gen_message() {
t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec );
char gga_lat[20], rmc_lat[20];
double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
double latd = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES;
if ( latd < 0.0 ) {
latd = -latd;
dir = 'S';
@ -92,7 +94,7 @@ bool FGNMEA::gen_message() {
sprintf( rmc_lat, "%02d%07.4f,%c", abs(deg), min, dir);
char gga_lon[20], rmc_lon[20];
double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
double lond = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES;
if ( lond < 0.0 ) {
lond = -lond;
dir = 'W';
@ -121,7 +123,7 @@ bool FGNMEA::gen_message() {
char altitude_m[10];
sprintf( altitude_m, "%.1f",
cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
fdm->get_Altitude() * SG_FEET_TO_METER );
char date[10];
int year = t->getGmt()->tm_year;
@ -272,7 +274,7 @@ bool FGNMEA::parse_message() {
lat *= -1;
}
cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " lat = " << lat );
// lon val
@ -301,17 +303,17 @@ bool FGNMEA::parse_message() {
lon *= -1;
}
cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " lon = " << lon );
#if 0
double sl_radius, lat_geoc;
sgGeodToGeoc( cur_fdm_state->get_Latitude(),
cur_fdm_state->get_Altitude(),
sgGeodToGeoc( fdm->get_Latitude(),
fdm->get_Altitude(),
&sl_radius, &lat_geoc );
cur_fdm_state->set_Geocentric_Position( lat_geoc,
cur_fdm_state->get_Longitude(),
sl_radius + cur_fdm_state->get_Altitude() );
fdm->set_Geocentric_Position( lat_geoc,
fdm->get_Longitude(),
sl_radius + fdm->get_Altitude() );
#endif
// speed
@ -323,8 +325,8 @@ bool FGNMEA::parse_message() {
string speed_str = msg.substr(begin, end - begin);
begin = end + 1;
speed = atof( speed_str.c_str() );
cur_fdm_state->set_V_calibrated_kts( speed );
// cur_fdm_state->set_V_ground_speed( speed );
fdm->set_V_calibrated_kts( speed );
// fdm->set_V_ground_speed( speed );
SG_LOG( SG_IO, SG_INFO, " speed = " << speed );
// heading
@ -336,8 +338,8 @@ bool FGNMEA::parse_message() {
string hdg_str = msg.substr(begin, end - begin);
begin = end + 1;
heading = atof( hdg_str.c_str() );
cur_fdm_state->set_Euler_Angles( cur_fdm_state->get_Phi(),
cur_fdm_state->get_Theta(),
fdm->set_Euler_Angles( fdm->get_Phi(),
fdm->get_Theta(),
heading * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " heading = " << heading );
} else if ( sentence == "GPGGA" ) {
@ -377,7 +379,7 @@ bool FGNMEA::parse_message() {
lat *= -1;
}
// cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
// fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " lat = " << lat );
// lon val
@ -406,7 +408,7 @@ bool FGNMEA::parse_message() {
lon *= -1;
}
// cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
// fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " lon = " << lon );
// junk
@ -462,7 +464,7 @@ bool FGNMEA::parse_message() {
altitude *= SG_METER_TO_FEET;
}
cur_fdm_state->set_Altitude( altitude );
fdm->set_Altitude( altitude );
SG_LOG( SG_IO, SG_INFO, " altitude = " << altitude );

View file

@ -31,14 +31,13 @@
#include "protocol.hxx"
using std::string;
class FlightProperties;
class FGNMEA : public FGProtocol {
char buf[ FG_MAX_MSG_SIZE ];
int length;
FlightProperties* fdm;
public:
FGNMEA();

View file

@ -38,7 +38,7 @@
#include <vector>
#include "opengc.hxx"
#include <FDM/flight.hxx>
#include <FDM/flightProperties.hxx>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
@ -101,9 +101,11 @@ FGOpenGC::FGOpenGC() :
p_alphadot(fgGetNode("/fdm/jsbsim/aero/alphadot-rad_sec[0]", true)),
p_betadot(fgGetNode("/fdm/jsbsim/aero/betadot-rad_sec[0]", true))
{
fdm = new FlightProperties;
}
FGOpenGC::~FGOpenGC() {
delete fdm;
}
// open hailing frequencies
@ -127,7 +129,7 @@ bool FGOpenGC::open() {
}
//static void collect_data( const FGInterface *fdm, ogcFGData *data ) {
void FGOpenGC::collect_data( const FGInterface *fdm, ogcFGData *data ) {
void FGOpenGC::collect_data(ogcFGData *data ) {
data->version_id = OGC_VERSION;
@ -144,16 +146,16 @@ void FGOpenGC::collect_data( const FGInterface *fdm, ogcFGData *data ) {
data->vvi = p_vvi->getDoubleValue();
data->mach = p_mach->getDoubleValue();
data->groundspeed = cur_fdm_state->get_V_ground_speed();
data->v_keas = cur_fdm_state->get_V_equiv_kts();
data->groundspeed = fdm->get_V_ground_speed();
data->v_keas = fdm->get_V_equiv_kts();
data->v_kcas = vel_kcas->getDoubleValue();
data->phi_dot = cur_fdm_state->get_Phi_dot();
data->theta_dot = cur_fdm_state->get_Theta_dot();
data->psi_dot = cur_fdm_state->get_Psi_dot();
data->phi_dot = fdm->get_Phi_dot();
data->theta_dot = fdm->get_Theta_dot();
data->psi_dot = fdm->get_Psi_dot();
data->alpha = cur_fdm_state->get_Alpha();
data->alpha = fdm->get_Alpha();
data->beta = p_yaw->getDoubleValue();
data->alpha_dot = p_alphadot->getDoubleValue();
data->beta_dot = p_yaw_rate->getDoubleValue();
@ -272,9 +274,9 @@ void FGOpenGC::collect_data( const FGInterface *fdm, ogcFGData *data ) {
data->x_feed_valve[2] = x_feed2_node->getBoolValue();
data->x_feed_valve[3] = x_feed3_node->getBoolValue();
**********/
data->total_temperature = cur_fdm_state->get_Total_temperature();
data->total_pressure = cur_fdm_state->get_Total_pressure();
data->dynamic_pressure = cur_fdm_state->get_Dynamic_pressure();
data->total_temperature = fdm->get_Total_temperature();
data->total_pressure = fdm->get_Total_pressure();
data->dynamic_pressure = fdm->get_Dynamic_pressure();
data->static_pressure = press_node->getDoubleValue();
data->static_temperature = temp_node->getDoubleValue();
@ -283,7 +285,7 @@ void FGOpenGC::collect_data( const FGInterface *fdm, ogcFGData *data ) {
data->sea_level_pressure = fgGetDouble("/environment/sea-level-pressure-inhg");
}
static void distribute_data( const ogcFGData *data, FGInterface *chunk ) {
static void distribute_data( const ogcFGData *data ) {
// just a place holder until the CDU is developed
}
@ -294,7 +296,7 @@ bool FGOpenGC::process() {
int length = sizeof(buf);
if ( get_direction() == SG_IO_OUT ) {
collect_data( cur_fdm_state, &buf );
collect_data( &buf );
//collect_data( &buf );
if ( ! io->write( (char *)(& buf), length ) ) {
SG_LOG( SG_IO, SG_ALERT, "Error writing data." );
@ -304,12 +306,12 @@ bool FGOpenGC::process() {
if ( io->get_type() == sgFileType ) {
if ( io->read( (char *)(& buf), length ) == length ) {
SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
distribute_data( &buf, cur_fdm_state );
distribute_data( &buf );
}
} else {
while ( io->read( (char *)(& buf), length ) == length ) {
SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
distribute_data( &buf, cur_fdm_state );
distribute_data( &buf );
}
}
}

View file

@ -30,15 +30,18 @@
#include <string>
#include <FDM/flight.hxx>
#include <Main/fg_props.hxx>
#include "protocol.hxx"
#include "opengc_data.hxx"
class FGOpenGC : public FGProtocol, public FGInterface {
class FlightProperties;
class FGOpenGC : public FGProtocol
{
ogcFGData buf;
FlightProperties* fdm;
// Environment
SGPropertyNode_ptr press_node;
@ -154,7 +157,7 @@ public:
// close the channel
bool close();
void collect_data( const FGInterface *fdm, ogcFGData *data );
void collect_data(ogcFGData *data );
};
#endif // _FG_OPENGC_HXX

View file

@ -30,7 +30,7 @@
#include <simgear/debug/logstream.hxx>
#include <simgear/io/iochannel.hxx>
#include <FDM/flight.hxx>
#include <FDM/flightProperties.hxx>
#include "pve.hxx"
@ -55,10 +55,10 @@ FGPVE::~FGPVE() {
bool FGPVE::gen_message() {
// cout << "generating pve message" << endl;
FGInterface *f = cur_fdm_state;
FlightProperties f;
// get roll and pitch, convert to degrees
double roll_deg = f->get_Phi() * SGD_RADIANS_TO_DEGREES;
double roll_deg = f.get_Phi() * SGD_RADIANS_TO_DEGREES;
while ( roll_deg <= -180.0 ) {
roll_deg += 360.0;
}
@ -66,7 +66,7 @@ bool FGPVE::gen_message() {
roll_deg -= 360.0;
}
double pitch_deg = f->get_Theta() * SGD_RADIANS_TO_DEGREES;
double pitch_deg = f.get_Theta() * SGD_RADIANS_TO_DEGREES;
while ( pitch_deg <= -180.0 ) {
pitch_deg += 360.0;
}
@ -74,7 +74,7 @@ bool FGPVE::gen_message() {
pitch_deg -= 360.0;
}
short int heave = (int)(f->get_W_body() * 128.0);
short int heave = (int)(f.get_wBody() * 128.0);
// scale roll and pitch to output format (1 - 255)
// straight && level == (128, 128)

View file

@ -28,7 +28,7 @@
#include <simgear/debug/logstream.hxx>
#include <simgear/io/iochannel.hxx>
#include <FDM/flight.hxx>
#include <FDM/flightProperties.hxx>
#include "ray.hxx"
@ -66,7 +66,8 @@ FGRAY::~FGRAY() {
bool FGRAY::gen_message() {
// cout << "generating RayWoodworth message" << endl;
FGInterface *f = cur_fdm_state;
FlightProperties f;
int axis, subaxis;
const double fullscale[6] = { -0.5, -0.5, -0.5, /* radians */
-0.3, -0.3, -0.15 /* meters */ };
@ -76,7 +77,7 @@ bool FGRAY::gen_message() {
/* get basic information about gravity */
double grav_acc = -9.81;
double vert_acc = f->get_A_Z_pilot() * 0.3;
double vert_acc = f.get_A_Z_pilot() * 0.3;
if ( -3.0 < vert_acc )
vert_acc = -3.0;
@ -89,13 +90,13 @@ bool FGRAY::gen_message() {
/* Retrieve the desired components */
switch ( axis ) {
case 0: ang_pos = f->get_Phi();
lin_acc = f->get_A_Y_pilot() * 0.3;
case 0: ang_pos = f.get_Phi();
lin_acc = f.get_A_Y_pilot() * 0.3;
break;
case 1: ang_pos = f->get_Theta();
lin_acc = f->get_A_X_pilot() * 0.3;
case 1: ang_pos = f.get_Theta();
lin_acc = f.get_A_X_pilot() * 0.3;
break;
case 2: ang_pos = f->get_Psi();
case 2: ang_pos = f.get_Psi();
lin_acc = grav_acc - vert_acc;
break;
default:

View file

@ -31,7 +31,7 @@
#include <simgear/debug/logstream.hxx>
#include <simgear/io/iochannel.hxx>
#include <FDM/flight.hxx>
#include <FDM/flightProperties.hxx>
#include "rul.hxx"
@ -61,10 +61,10 @@ FGRUL::~FGRUL() {
bool FGRUL::gen_message() {
// cout << "generating rul message" << endl;
FGInterface *f = cur_fdm_state;
FlightProperties f;
// get roll and pitch, convert to degrees
double roll_deg = f->get_Phi() * SGD_RADIANS_TO_DEGREES;
double roll_deg = f.get_Phi() * SGD_RADIANS_TO_DEGREES;
while ( roll_deg < -180.0 ) {
roll_deg += 360.0;
}
@ -72,7 +72,7 @@ bool FGRUL::gen_message() {
roll_deg -= 360.0;
}
double pitch_deg = f->get_Theta() * SGD_RADIANS_TO_DEGREES;
double pitch_deg = f.get_Theta() * SGD_RADIANS_TO_DEGREES;
while ( pitch_deg < -180.0 ) {
pitch_deg += 360.0;
}

View file

@ -31,10 +31,10 @@
#include <ctime>
#include <simgear/math/SGMath.hxx>
#include <simgear/ephemeris/ephemeris.hxx>
#include <simgear/timing/sg_time.hxx>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include "tmp.hxx"
#include "sunsolver.hxx"
@ -56,12 +56,14 @@ void fgSunPositionGST(double gst, double *lon, double *lat) {
double alpha, delta;
double tmp;
double beta = globals->get_ephem()->get_sun()->getLat();
SGPropertyNode* sun = fgGetNode("/ephemeris/sun");
assert(sun);
double beta = sun->getDoubleValue("lat-deg");
// double r = globals->get_ephem()->get_sun()->getDistance();
double xs = globals->get_ephem()->get_sun()->getxs();
double ys = globals->get_ephem()->get_sun()->getys();
double ye = globals->get_ephem()->get_sun()->getye();
double ze = globals->get_ephem()->get_sun()->getze();
double xs = sun->getDoubleValue("xs");
double ys = sun->getDoubleValue("ys");
double ye = sun->getDoubleValue("ye");
double ze = sun->getDoubleValue("ze");
alpha = atan2(ys - tan(beta)*ze/ys, xs);
delta = asin(sin(beta)*ye/ys + cos(beta)*ze);