From 7c38f172d936bc073288ac35428d5eb97c7d4c1c Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 10 Oct 2000 20:31:20 +0000 Subject: [PATCH] Some tweaks relating to engines and the various LaRCsim related fdm's --- src/FDM/LaRCsim.cxx | 101 +++++++++++++++++----------------- src/FDM/LaRCsim.hxx | 5 -- src/FDM/LaRCsim/c172_engine.c | 2 +- src/FDM/LaRCsim/ls_generic.h | 3 + src/Main/main.cxx | 95 ++++++++------------------------ 5 files changed, 78 insertions(+), 128 deletions(-) diff --git a/src/FDM/LaRCsim.cxx b/src/FDM/LaRCsim.cxx index 7d32831e3..568913cc3 100644 --- a/src/FDM/LaRCsim.cxx +++ b/src/FDM/LaRCsim.cxx @@ -39,16 +39,16 @@ // each subsequent iteration through the EOM int FGLaRCsim::init( double dt ) { -#ifdef USE_NEW_ENGINE_CODE - // Initialize our little engine that hopefully might - eng.init(dt); - // dcl - in passing dt to init rather than update I am assuming - // that the LaRCsim dt is fixed at one value (yes it is 120hz CLO) - - // update the engines interface - FGEngInterface e; - add_engine( e ); -#endif + if ( current_options.get_aircraft() == "c172" ) { + // Initialize our little engine that hopefully might + eng.init(dt); + // dcl - in passing dt to init rather than update I am assuming + // that the LaRCsim dt is fixed at one value (yes it is 120hz CLO) + + // update the engines interface + FGEngInterface e; + add_engine( e ); + } // cout << "FGLaRCsim::init()" << endl; @@ -87,46 +87,46 @@ int FGLaRCsim::init( double dt ) { int FGLaRCsim::update( int multiloop ) { // cout << "FGLaRCsim::update()" << endl; -#ifdef USE_NEW_ENGINE_CODE - // set control inputs - eng.set_IAS( V_calibrated_kts ); - eng.set_Throttle_Lever_Pos( controls.get_throttle( 0 ) * 100.0 ); - eng.set_Propeller_Lever_Pos( 100 ); - if ( controls.get_mixture( 0 ) > 0.60 ) { - eng.set_Mixture_Lever_Pos( controls.get_mixture( 0 ) * 100.0 ); - } else { - eng.set_Mixture_Lever_Pos( 60.0 ); - } - - // update engine model - eng.update(); - - // copy engine state values onto "bus" - FGEngInterface *e = get_engine( 0 ); - e->set_Throttle( controls.get_throttle( 0 ) * 100.0 ); - e->set_Mixture( 80 ); - e->set_Prop_Advance( 100 ); - e->set_RPM( eng.get_RPM() ); - e->set_Manifold_Pressure( eng.get_Manifold_Pressure() ); - e->set_MaxHP( eng.get_MaxHP() ); - e->set_Percentage_Power( eng.get_Percentage_Power() ); - e->set_EGT( eng.get_EGT() ); - e->set_prop_thrust( eng.get_prop_thrust_SI() ); + if ( current_options.get_aircraft() == "c172" ) { + // set control inputs + eng.set_IAS( V_calibrated_kts ); + eng.set_Throttle_Lever_Pos( controls.get_throttle( 0 ) * 100.0 ); + eng.set_Propeller_Lever_Pos( 100 ); + if ( controls.get_mixture( 0 ) > 0.60 ) { + eng.set_Mixture_Lever_Pos( controls.get_mixture( 0 ) * 100.0 ); + } else { + eng.set_Mixture_Lever_Pos( 60.0 ); + } + + // update engine model + eng.update(); + + // copy engine state values onto "bus" + FGEngInterface *e = get_engine( 0 ); + e->set_Throttle( controls.get_throttle( 0 ) * 100.0 ); + e->set_Mixture( 80 ); + e->set_Prop_Advance( 100 ); + e->set_RPM( eng.get_RPM() ); + e->set_Manifold_Pressure( eng.get_Manifold_Pressure() ); + e->set_MaxHP( eng.get_MaxHP() ); + e->set_Percentage_Power( eng.get_Percentage_Power() ); + e->set_EGT( eng.get_EGT() ); + e->set_prop_thrust( eng.get_prop_thrust_SI() ); #if 0 - cout << "Throttle = " << controls.get_throttle( 0 ) * 100.0; - cout << " Mixture = " << controls.get_mixture( 0 ) * 100.0; - cout << " RPM = " << eng.get_RPM(); - cout << " MP = " << eng.get_Manifold_Pressure(); - cout << " HP = " << ( eng.get_MaxHP() * eng.get_Percentage_Power() + cout << "Throttle = " << controls.get_throttle( 0 ) * 100.0; + cout << " Mixture = " << controls.get_mixture( 0 ) * 100.0; + cout << " RPM = " << eng.get_RPM(); + cout << " MP = " << eng.get_Manifold_Pressure(); + cout << " HP = " << ( eng.get_MaxHP() * eng.get_Percentage_Power() / 100.0 ); - cout << " EGT = " << eng.get_EGT(); - cout << " Thrust (N) " << eng.get_prop_thrust_SI(); // Thrust in Newtons - cout << '\n'; + cout << " EGT = " << eng.get_EGT(); + cout << " Thrust (N) " << eng.get_prop_thrust_SI(); // Thrust in Newtons + cout << '\n'; #endif - F_X_engine = eng.get_prop_thrust_SI() * 0.07; -#endif // USE_NEW_ENGINE_CODE + F_X_engine = eng.get_prop_thrust_SI() * 0.07; + } double save_alt = 0.0; double time_step = (1.0 / current_options.get_model_hz()) * multiloop; @@ -144,11 +144,14 @@ int FGLaRCsim::update( int multiloop ) { Long_trim = controls.get_elevator_trim(); Rudder_pedal = controls.get_rudder() / current_options.get_speed_up(); Flap_handle = 30.0 * controls.get_flaps(); -#ifdef USE_NEW_ENGINE_CODE - Throttle_pct = -1.0; // tells engine model to use propellor thrust -#else + + if ( current_options.get_aircraft() == "c172" ) { + Use_External_Engine = 1; + } else { + Use_External_Engine = 0; + } + Throttle_pct = controls.get_throttle( 0 ) * 1.0; -#endif Brake_pct[0] = controls.get_brake( 1 ); Brake_pct[1] = controls.get_brake( 0 ); diff --git a/src/FDM/LaRCsim.hxx b/src/FDM/LaRCsim.hxx index 068cb8f21..5007409e6 100644 --- a/src/FDM/LaRCsim.hxx +++ b/src/FDM/LaRCsim.hxx @@ -31,14 +31,9 @@ #include "flight.hxx" -#define USE_NEW_ENGINE_CODE 1 - - class FGLaRCsim: public FGInterface { -#ifdef USE_NEW_ENGINE_CODE FGEngine eng; -#endif public: diff --git a/src/FDM/LaRCsim/c172_engine.c b/src/FDM/LaRCsim/c172_engine.c index 4b3f784a6..64632a2d1 100644 --- a/src/FDM/LaRCsim/c172_engine.c +++ b/src/FDM/LaRCsim/c172_engine.c @@ -77,7 +77,7 @@ void c172_engine( SCALAR dt, int init ) { Throttle[3] = Throttle_pct; - if ( Throttle_pct >= 0 ) { + if ( ! Use_External_Engine ) { /* do a crude engine power calc based on throttle position */ v=V_rel_wind; h=Altitude; diff --git a/src/FDM/LaRCsim/ls_generic.h b/src/FDM/LaRCsim/ls_generic.h index 6059cce1e..3a4b1f6cb 100644 --- a/src/FDM/LaRCsim/ls_generic.h +++ b/src/FDM/LaRCsim/ls_generic.h @@ -128,6 +128,9 @@ typedef struct { #define F_Y_engine generic_.f_engine_v[1] #define F_Z_engine generic_.f_engine_v[2] + int use_external_engine; +#define Use_External_Engine generic_.use_external_engine + VECTOR_3 f_gear_v; #define F_gear_v generic_.f_gear_v #define F_X_gear generic_.f_gear_v[0] diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 8274269ef..7ef6ab223 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -21,10 +21,6 @@ // $Id$ -#define USE_NEW_ENGINE_CODE -#undef MICHAEL_JOHNSON_EXPERIMENTAL_ENGINE_AUDIO - - #ifdef HAVE_CONFIG_H # include #endif @@ -102,6 +98,8 @@ # include #endif +#include "version.h" + #include "bfi.hxx" #include "fg_init.hxx" #include "fg_io.hxx" @@ -174,7 +172,7 @@ sgMat4 copy_of_ssgOpenGLAxisSwapMatrix = { 0.0f, 0.0f, 0.0f, 1.0f } } ; -// The following defines flight gear options. Because glutlib will also +// The following defines flightgear options. Because glutlib will also // want to parse its own options, those options must not be included here // or they will get parsed by the main program option parser. Hence case // is significant for any option added that might be in conflict with @@ -897,71 +895,16 @@ static void fgMainLoop( void ) { #ifdef ENABLE_AUDIO_SUPPORT if ( current_options.get_sound() && !audio_sched->not_working() ) { -# if defined(MICHAEL_JOHNSON_EXPERIMENTAL_ENGINE_AUDIO) - - static double kts_to_fts = NM_TO_METER * METER_TO_FEET / 3600.0; - - // note: all these factors are relative to the sample. our - // sample format should really contain a conversion factor so - // that we can get prop speed right for arbitrary samples. - // Note that for normal-size props, there is a point at which - // the prop tips approach the speed of sound; that is a pretty - // strong limit to how fast the prop can go. - - // multiplication factor is prime pitch control; add some log - // component for verisimilitude - - double pitch = log((controls.get_throttle(0) * 14.0) + 1.0); - //fprintf(stderr, "pitch1: %f ", pitch); - // if (controls.get_throttle(0) > 0.0 || - // cur_fdm_state->get_V_calibrated_kts() > 40.0) { - - //fprintf(stderr, "rel_wind: %f ", cur_fdm_state->get_V_calibrated_kts()); - // only add relative wind and AoA if prop is moving - // or we're really flying at idle throttle - if (pitch < 5.4) { // this needs tuning - // prop tips not breaking sound barrier - pitch += log(cur_fdm_state->get_V_calibrated_kts() * kts_to_fts + 0.8)/2; - } else { - // prop tips breaking sound barrier - pitch += log(cur_fdm_state->get_V_calibrated_kts() * kts_to_fts + 0.8)/10; - } - //fprintf(stderr, "pitch2: %f ", pitch); - //fprintf(stderr, "AoA: %f ", FG_Gamma_vert_rad); - - // Angle of Attack next... -x^3(e^x) is my best guess Just - // need to calculate some reasonable scaling factor and - // then clamp it on the positive aoa (neg adj) side - double aoa = cur_fdm_state->get_Gamma_vert_rad() * 2.2; - double tmp = 3.0; - double aoa_adj = pow(-aoa, tmp) * pow(M_E, aoa); - if (aoa_adj < -0.8) aoa_adj = -0.8; - pitch += aoa_adj; - //fprintf(stderr, "pitch3: %f ", pitch); - - // don't run at absurdly slow rates -- not realistic - // and sounds bad to boot. :-) - if (pitch < 0.8) pitch = 0.8; - // } - // fprintf(stderr, "pitch4: %f\n", pitch); - - double volume = controls.get_throttle(0) * 0.1 + 0.3 + - log(cur_fdm_state->get_V_calibrated_kts() * kts_to_fts + 1.0)/14.0; - if ( volume > 1.0 ) { volume = 1.0; } - - // fprintf(stderr, "volume: %f\n", volume); - - pitch_envelope.setStep ( 0, 0.01, pitch ); - volume_envelope.setStep ( 0, 0.01, volume ); - -# elif defined(USE_NEW_ENGINE_CODE) - - if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) { + if ( current_options.get_aircraft() == "c172" ) { // pitch corresponds to rpm // volume corresponds to manifold pressure - double rpm_factor = cur_fdm_state->get_engine(0)->get_RPM() / - 2500.0; + double rpm_factor; + if ( cur_fdm_state->get_engine(0) != NULL ) { + rpm_factor = cur_fdm_state->get_engine(0)->get_RPM() / 2500.0; + } else { + rpm_factor = 1.0; + } // cout << "rpm = " << cur_fdm_state->get_engine(0)->get_RPM() // << endl; @@ -973,8 +916,13 @@ static void fgMainLoop( void ) { if (pitch > 5.0) { pitch = 5.0; } // cout << "pitch = " << pitch << endl; - double mp_factor = - cur_fdm_state->get_engine(0)->get_Manifold_Pressure() / 28; + double mp_factor; + if ( cur_fdm_state->get_engine(0) != NULL ) { + mp_factor = + cur_fdm_state->get_engine(0)->get_Manifold_Pressure() / 28; + } else { + mp_factor = 1.0; + } // cout << "mp = " // << cur_fdm_state->get_engine(0)->get_Manifold_Pressure() // << endl; @@ -992,7 +940,7 @@ static void fgMainLoop( void ) { pitch_envelope.setStep ( 0, 0.01, param ); volume_envelope.setStep ( 0, 0.01, param ); } -# endif + audio_sched -> update(); } #endif @@ -1054,7 +1002,7 @@ static void fgIdleFunction ( void ) { } else if ( idle_state == 3 ) { // This is the top level init routine which calls all the // other subsystem initialization routines. If you are adding - // a subsystem to flight gear, its initialization call should + // a subsystem to flightgear, its initialization call should // located in this routine. if( !fgInitSubsystems()) { FG_LOG( FG_GENERAL, FG_ALERT, @@ -1214,7 +1162,7 @@ int fgGlutInit( int *argc, char **argv ) { // Initialize windows if ( current_options.get_game_mode() == 0 ) { // Open the regular window - glutCreateWindow("Flight Gear"); + glutCreateWindow("FlightGear"); #ifndef GLUT_WRONG_VERSION } else { // Open the cool new 'game mode' window @@ -1324,7 +1272,8 @@ int main( int argc, char **argv ) { // set default log levels fglog().setLogLevels( FG_ALL, FG_INFO ); - FG_LOG( FG_GENERAL, FG_INFO, "Flight Gear: Version " << VERSION << endl ); + FG_LOG( FG_GENERAL, FG_INFO, "FlightGear: Version " + << FLIGHTGEAR_VERSION << endl ); // seed the random number generater fg_srandom(); -- 2.39.5