1
0
Fork 0

Some tweaks relating to engines and the various LaRCsim related fdm's

This commit is contained in:
curt 2000-10-10 20:31:20 +00:00
parent 0fc90cfc56
commit 7c38f172d9
5 changed files with 75 additions and 125 deletions

View file

@ -39,7 +39,7 @@
// each subsequent iteration through the EOM
int FGLaRCsim::init( double dt ) {
#ifdef USE_NEW_ENGINE_CODE
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
@ -48,7 +48,7 @@ int FGLaRCsim::init( double dt ) {
// update the engines interface
FGEngInterface e;
add_engine( e );
#endif
}
// cout << "FGLaRCsim::init()" << endl;
@ -87,7 +87,7 @@ int FGLaRCsim::init( double dt ) {
int FGLaRCsim::update( int multiloop ) {
// cout << "FGLaRCsim::update()" << endl;
#ifdef USE_NEW_ENGINE_CODE
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 );
@ -126,7 +126,7 @@ int FGLaRCsim::update( int multiloop ) {
#endif
F_X_engine = eng.get_prop_thrust_SI() * 0.07;
#endif // USE_NEW_ENGINE_CODE
}
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 );

View file

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

View file

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

View file

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

View file

@ -21,10 +21,6 @@
// $Id$
#define USE_NEW_ENGINE_CODE
#undef MICHAEL_JOHNSON_EXPERIMENTAL_ENGINE_AUDIO
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
@ -102,6 +98,8 @@
# include <Weather/weather.hxx>
#endif
#include "version.h"
#include "bfi.hxx"
#include "fg_init.hxx"
#include "fg_io.hxx"
@ -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 =
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
@ -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();