Redid the Makefile system so it is simpler and more robust.
+David Luff <david.luff@nottingham.ac.uk>
+ Contributed heavily to the IO360 piston engine model.
+
+
Christian Mayer <flightgear@christianmayer.de>
Working on a multi-lingual conversion tools for fgfs
as a demonstration of technology ;-)
#include "LaRCsim.hxx"
-#define USE_NEW_ENGINE_CODE 1
-FGEngine eng;
-
-
// Initialize the LaRCsim flight model, dt is the time increment for
// each subsequent iteration through the EOM
int FGLaRCsim::init( double dt ) {
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
// cout << "FGLaRCsim::init()" << endl;
// cout << "FGLaRCsim::update()" << endl;
#ifdef USE_NEW_ENGINE_CODE
- // update simple engine model
+ // 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 );
eng.set_Mixture_Lever_Pos( 80 );
+
+ // 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 = " << 80;
#define _LARCSIM_HXX
+#include "IO360.hxx"
#include "flight.hxx"
+#define USE_NEW_ENGINE_CODE 1
+
+
class FGLaRCsim: public FGInterface {
+#ifdef USE_NEW_ENGINE_CODE
+ FGEngine eng;
+#endif
+
public:
// copy FDM state to LaRCsim structures
#include <math.h>
#include <list>
+#include <vector>
#include <Time/timestamp.hxx>
FG_USING_STD(list);
+FG_USING_STD(vector);
typedef double FG_VECTOR_3[3];
+class FGEngInterface {
+
+private:
+
+ // inputs
+ double Throttle;
+ double Mixture;
+ double Prop_Advance;
+
+ // outputs
+ double RPM;
+ double Manifold_Pressure;
+ double MaxHP;
+ double Percentage_Power;
+ double EGT;
+ double prop_thrust;
+
+public:
+
+ inline double get_Throttle() const { return Throttle; }
+ inline double get_Mixture() const { return Mixture; }
+ inline double get_Prop_Advance() const { return Prop_Advance; }
+ inline double get_RPM() const { return RPM; }
+ inline double get_Manifold_Pressure() const { return Manifold_Pressure; }
+ inline double get_MaxHP() const { return MaxHP; }
+ inline double get_Percentage_Power() const { return Percentage_Power; }
+ inline double get_EGT() const { return EGT; }
+ inline double get_prop_thrust() const { return prop_thrust; }
+
+ inline void set_Throttle( double t ) { Throttle = t; }
+ inline void set_Mixture( double m ) { Mixture = m; }
+ inline void set_Prop_Advance( double p ) { Prop_Advance = p; }
+ inline void set_RPM( double r ) { RPM = r; }
+ inline void set_Manifold_Pressure( double mp ) { Manifold_Pressure = mp; }
+ inline void set_MaxHP( double hp ) { MaxHP = hp; }
+ inline void set_Percentage_Power( double p ) { Percentage_Power = p; }
+ inline void set_EGT( double e ) { EGT = e; }
+ inline void set_prop_thrust( double t ) { prop_thrust = t; }
+
+};
+
+typedef vector < FGEngInterface > engine_list;
+
+
// This is based heavily on LaRCsim/ls_generic.h
class FGInterface {
double sin_longitude, cos_longitude;
double sin_latitude, cos_latitude;
+ // Engine list
+ engine_list engines;
+
FGTimeStamp valid_stamp; // time this record is valid
FGTimeStamp next_stamp; // time this record is valid
inline double get_cos_latitude(void) const {
return cos_latitude;
}
+
+ // engines
+ inline double get_num_engines() const {
+ return engines.size();
+ }
+
+ inline FGEngInterface* get_engine( int i ) {
+ return &engines[i];
+ }
+
+ inline void add_engine( FGEngInterface e ) {
+ return engines.push_back( e );
+ }
};
// $Id$
-#define MICHAEL_JOHNSON_EXPERIMENTAL_ENGINE_AUDIO
+#define USE_NEW_ENGINE_CODE
+#undef MICHAEL_JOHNSON_EXPERIMENTAL_ENGINE_AUDIO
#ifdef HAVE_CONFIG_H
#ifdef ENABLE_AUDIO_SUPPORT
if ( current_options.get_sound() && !audio_sched->not_working() ) {
-# ifdef MICHAEL_JOHNSON_EXPERIMENTAL_ENGINE_AUDIO
+# if defined(MICHAEL_JOHNSON_EXPERIMENTAL_ENGINE_AUDIO)
static double kts_to_fts = NM_TO_METER * METER_TO_FEET / 3600.0;
double pitch = log((controls.get_throttle(0) * 14.0) + 1.0);
//fprintf(stderr, "pitch1: %f ", pitch);
- // if (controls.get_throttle(0) > 0.0 ||
+ // 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());
pitch_envelope.setStep ( 0, 0.01, pitch );
volume_envelope.setStep ( 0, 0.01, volume );
+# elif defined(USE_NEW_ENGINE_CODE)
+
+ // pitch corresponds to rpm
+ // volume corresponds to manifold pressure
+
+ double rpm_factor = cur_fdm_state->get_engine(0)->get_RPM() / 2500.0;
+ cout << "rpm = " << cur_fdm_state->get_engine(0)->get_RPM() << endl;
+
+ double pitch = 0.3 + rpm_factor * 3.0;
+
+ // don't run at absurdly slow rates -- not realistic
+ // and sounds bad to boot. :-)
+ if (pitch < 0.7) { pitch = 0.7; }
+ if (pitch > 5.0) { pitch = 5.0; }
+ cout << "pitch = " << pitch << endl;
+
+ double mp_factor =
+ cur_fdm_state->get_engine(0)->get_Manifold_Pressure() / 28;
+ cout << "mp = " << cur_fdm_state->get_engine(0)->get_Manifold_Pressure()
+ << endl;
+
+ double volume = mp_factor;
+
+ if ( volume < 0.3 ) { volume = 0.3; }
+ if ( volume > 2.0 ) { volume = 2.0; }
+ cout << "volume = " << volume << endl;
+
+ pitch_envelope.setStep ( 0, 0.01, pitch );
+ volume_envelope.setStep ( 0, 0.01, volume );
+
# else
double param = controls.get_throttle( 0 ) * 2.0 + 1.0;