#include <simgear/compiler.h>
-#ifdef FG_MATH_EXCEPTION_CLASH
+#ifdef SG_MATH_EXCEPTION_CLASH
# include <math.h>
#endif
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
-#include <simgear/math/fg_geodesy.hxx>
-#include <simgear/misc/fgpath.hxx>
+#include <simgear/math/sg_geodesy.hxx>
+#include <simgear/misc/sg_path.hxx>
#include <Aircraft/aircraft.hxx>
#include <Controls/controls.hxx>
-#include <Main/options.hxx>
+#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
#include "Balloon.h"
/****************************************************************************/
+FGBalloonSim::FGBalloonSim( double dt ) {
+ //set the dt of the model
+ current_balloon.set_dt(dt);
+}
+
+
+FGBalloonSim::~FGBalloonSim() {
+}
+
+
// Initialize the BalloonSim flight model, dt is the time increment for
// each subsequent iteration through the EOM
-int FGBalloonSim::init( double dt ) {
- sgVec3 temp;
+void FGBalloonSim::init() {
+
+ //do init common to all the FDM's
+ common_init();
+
+ //now do init specific to the Balloon
- FG_LOG( FG_FLIGHT, FG_INFO, "Starting initializing BalloonSim" );
+ sgVec3 temp;
- FG_LOG( FG_FLIGHT, FG_INFO, " created a balloon" );
+ SG_LOG( SG_FLIGHT, SG_INFO, "Starting initializing BalloonSim" );
- //set the dt of the model
- current_balloon.set_dt(dt);
+ SG_LOG( SG_FLIGHT, SG_INFO, " created a balloon" );
//set position
sgSetVec3( temp,
get_Latitude(),
get_Longitude(),
- get_Altitude() * FEET_TO_METER);
+ get_Altitude() * SG_FEET_TO_METER);
current_balloon.setPosition( temp );
//set Euler angles (?)
//set velocities
sgSetVec3( temp,
- current_options.get_uBody(),
- current_options.get_vBody(),
- current_options.get_wBody() );
+ fgGetDouble("/velocities/uBody-fps"),
+ fgGetDouble("/velocities/vBody-fps"),
+ fgGetDouble("/velocities/wBody-fps") );
current_balloon.setVelocity( temp );
- FG_LOG( FG_FLIGHT, FG_INFO, "Finished initializing BalloonSim" );
-
- return 1;
+ SG_LOG( SG_FLIGHT, SG_INFO, "Finished initializing BalloonSim" );
}
// Run an iteration of the EOM (equations of motion)
-int FGBalloonSim::update( int multiloop ) {
+void FGBalloonSim::update( double dt ) {
double save_alt = 0.0;
+ if (is_suspended())
+ return;
+
+ int multiloop = _calc_multiloop(dt);
+
// lets try to avoid really screwing up the BalloonSim model
if ( get_Altitude() < -9000 ) {
save_alt = get_Altitude();
}
// set control positions
- current_balloon.set_burner_strength ( controls.get_throttle(0) );
+ current_balloon.set_burner_strength ( globals->get_controls()->get_throttle(0) );
//not more implemented yet
// Inform BalloonSim of the local terrain altitude
- current_balloon.setGroundLevel ( get_Runway_altitude() * FEET_TO_METER);
+ current_balloon.setGroundLevel ( get_Runway_altitude() * SG_FEET_TO_METER);
// old -- FGInterface_2_JSBsim() not needed except for Init()
// translate FG to JSBsim structure
/*sgVec3 temp, temp2;
current_balloon.getPosition( temp );
current_balloon.getVelocity( temp2 );
- FG_LOG( FG_FLIGHT, FG_INFO, "T: " << current_balloon.getTemperature() <<
+ SG_LOG( SG_FLIGHT, SG_INFO, "T: " << current_balloon.getTemperature() <<
" alt: " << temp[2] <<
" gr_alt: " << get_Runway_altitude() <<
" burner: " << controls.get_elevator() <<
if ( save_alt < -9000.0 ) {
set_Altitude( save_alt );
}
-
- return 1;
}
// Convert from the FGInterface struct to the BalloonSim
-int FGBalloonSim::copy_to_BalloonSim() {
- return 1;
+bool FGBalloonSim::copy_to_BalloonSim() {
+ return true;
}
// Convert from the BalloonSim to the FGInterface struct
-int FGBalloonSim::copy_from_BalloonSim() {
+bool FGBalloonSim::copy_from_BalloonSim() {
sgVec3 temp;
// Velocities
current_balloon.getVelocity( temp );
- set_Velocities_Local( temp[0], temp[1], temp[2] );
+ _set_Velocities_Local( temp[0], temp[1], temp[2] );
- /* ***FIXME*** */ set_V_equiv_kts( sgLengthVec3 ( temp ) );
+ /* ***FIXME*** */ _set_V_equiv_kts( sgLengthVec3 ( temp ) );
- set_Omega_Body( 0.0, 0.0, 0.0 );
+ _set_Omega_Body( 0.0, 0.0, 0.0 );
// Positions
current_balloon.getPosition( temp );
- double lat_geoc = temp[0];
- double lon = temp[1];
- double alt = temp[2] * METER_TO_FEET;
-
- double lat_geod, tmp_alt, sl_radius1, sl_radius2, tmp_lat_geoc;
- fgGeocToGeod( lat_geoc, EQUATORIAL_RADIUS_M + alt * FEET_TO_METER,
- &lat_geod, &tmp_alt, &sl_radius1 );
- fgGeodToGeoc( lat_geod, alt * FEET_TO_METER, &sl_radius2, &tmp_lat_geoc );
-
- FG_LOG( FG_FLIGHT, FG_DEBUG, "lon = " << lon << " lat_geod = " << lat_geod
- << " lat_geoc = " << lat_geoc
- << " alt = " << alt << " tmp_alt = " << tmp_alt * METER_TO_FEET
- << " sl_radius1 = " << sl_radius1 * METER_TO_FEET
- << " sl_radius2 = " << sl_radius2 * METER_TO_FEET
- << " Equator = " << EQUATORIAL_RADIUS_FT );
-
- set_Geocentric_Position( lat_geoc, lon,
- sl_radius2 * METER_TO_FEET + alt );
- set_Geodetic_Position( lat_geod, lon, alt );
+ //temp[0]: geocentric latitude
+ //temp[1]: longitude
+ //temp[2]: altitude (meters)
+ _updateGeocentricPosition( temp[0], temp[1], temp[2] * SG_METER_TO_FEET );
+
current_balloon.getHPR( temp );
set_Euler_Angles( temp[0], temp[1], temp[2] );
- set_Euler_Rates(0,0,0);
-
- set_Alpha( 0.0/*FDMExec.GetTranslation()->Getalpha()*/ );
- set_Beta( 0.0/*FDMExec.GetTranslation()->Getbeta()*/ );
-
- /* **FIXME*** */ set_Sea_level_radius( sl_radius2 * METER_TO_FEET );
- /* **FIXME*** */ set_Earth_position_angle( 0.0 );
-
- /* ***FIXME*** */ set_Runway_altitude( 0.0 );
-
- set_sin_lat_geocentric( lat_geoc );
- set_cos_lat_geocentric( lat_geoc );
- set_sin_cos_longitude( lon );
- set_sin_cos_latitude( lat_geod );
-
- return 0;
+
+ return true;
}