]> git.mxchange.org Git - flightgear.git/commitdiff
Working on putting engine data on "the bus"
authorcurt <curt>
Fri, 29 Sep 2000 03:27:21 +0000 (03:27 +0000)
committercurt <curt>
Fri, 29 Sep 2000 03:27:21 +0000 (03:27 +0000)
Thanks
src/FDM/LaRCsim.cxx
src/FDM/LaRCsim.hxx
src/FDM/flight.hxx
src/Main/main.cxx

diff --git a/Thanks b/Thanks
index d4d20de4f64a1fa00c7fa44f359f32ce4f7f07a1..c8d67d40e300a04a233d7b2286077d8918775d81 100644 (file)
--- a/Thanks
+++ b/Thanks
@@ -177,6 +177,10 @@ Bob Kuehne <rpk@who.net>
   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 ;-)
index 35fcb9d58e28c07aecd3f0fac347f5b3462616ea..0188276ef795f07e7ae83af4c487a54564c030e4 100644 (file)
 #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 ) {
@@ -48,6 +44,10 @@ 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;
@@ -88,13 +88,27 @@ int FGLaRCsim::update( int multiloop ) {
     // 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;
index d08db68b3bad57c2841c5da74191e260ffd36a55..068cb8f21efe6d81737af64fb4236de2683b5fea 100644 (file)
 #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
index 727ecbfab680560af08dfefdf55d8d104e143bbf..99e916b8043198a25665fd4af422357eb80960c2 100644 (file)
 #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 {
 
@@ -186,6 +232,9 @@ private:
     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
 
@@ -889,6 +938,19 @@ public:
     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 );
+    }
 };
 
 
index 7f09e45f909aefe872033856b13c63cb0db9e32d..987eb13e5b0e89ff2e10e43a26286777c8663bd0 100644 (file)
@@ -21,7 +21,8 @@
 // $Id$
 
 
-#define MICHAEL_JOHNSON_EXPERIMENTAL_ENGINE_AUDIO
+#define USE_NEW_ENGINE_CODE
+#undef MICHAEL_JOHNSON_EXPERIMENTAL_ENGINE_AUDIO
 
 
 #ifdef HAVE_CONFIG_H
@@ -896,7 +897,7 @@ static void fgMainLoop( void ) {
 #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;
 
@@ -912,7 +913,7 @@ static void fgMainLoop( void ) {
 
        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());
@@ -953,6 +954,36 @@ static void fgMainLoop( void ) {
        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;