]> git.mxchange.org Git - flightgear.git/commitdiff
From Tony Peden:
authorcurt <curt>
Fri, 19 May 2000 16:29:23 +0000 (16:29 +0000)
committercurt <curt>
Fri, 19 May 2000 16:29:23 +0000 (16:29 +0000)
This set of changes cleans up my previous ones quite a bit:
[tony@valkyrie FlightGear]$ tar -ztf tp_changes.tgz
src/Controls/controls.cxx
src/Controls/controls.hxx
src/FDM/JSBsim.cxx
src/Main/fg_init.cxx
src/Main/options.cxx
src/Main/options.hxx
src/Joystick/joystick.cxx

controls.[ch]xx:  removed the trimmed_throttle stuff.  This undoes the
                  changes I submitted last time.

JSBsim.cxx:       updates for the removal of the trimmed_throttle stuff

fg_init.cxx:      removed the autothrottle logic.  The autothrottle is now
off
                  by default.

options.[ch]xx:   Sets trim_mode to false by default.  It is enabled only
                  when --notrim is not used and JSBsim is the FDM.

joystick.cxx:     Added logic for syncing the throttle lever.  This is
                  only enabled when trim_mode is enabled.   The way I
                  did it is, I hope, a good way of going about it.

I tested:
fgfs --fdm=larcsim
fgfs --fdm=jsb --aircraft=c172 --vc=100 --altitude=500
fgfs --notrim --fdm=jsb --aircraft=c172 --vc=100 --altitude=500

All work as intended, at least for me.

Make sure your joystick is calibrated and give:
fgfs --fdm=jsb --aircraft=c172 --vc=100 --altitude=500
a try, I think you just might be impressed.

I am. ;-)

src/Controls/controls.cxx
src/Controls/controls.hxx
src/FDM/JSBSim.cxx
src/Joystick/joystick.cxx
src/Main/fg_init.cxx
src/Main/options.cxx
src/Main/options.hxx

index e10e1a8609b24b441e7bb22e7fd10cea5e87a50d..ff097a4ab89fb79690a67ec210ca8aa3591d6e69 100644 (file)
@@ -36,7 +36,6 @@ FGControls::FGControls() :
 {
     for ( int engine = 0; engine < MAX_ENGINES; engine++ ) {
        throttle[engine] = 0.0;
-       trimmed_throttle[engine]=0.0;
     }
 
     for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
index ea859bb9913bcd1a46fa747f2259a5da8121e723..08f840950941050133a43417096d5bc6c5c80ac5 100644 (file)
@@ -57,7 +57,6 @@ private:
     double rudder;
     double flaps;
     double throttle[MAX_ENGINES];
-    double trimmed_throttle[MAX_ENGINES];
     double brake[MAX_WHEELS];
 
     inline void CLAMP(double *x, double min, double max ) {
@@ -81,9 +80,6 @@ public:
     inline double get_flaps() const { return flaps; }
     inline double get_throttle(int engine) const { return throttle[engine]; }
     inline double get_brake(int wheel) const { return brake[wheel]; }
-    inline double get_trimmed_throttle(int engine) const {
-       return trimmed_throttle[engine];
-    }
 
     // Update functions
     inline void set_aileron( double pos ) {
@@ -153,19 +149,6 @@ public:
            }
        }
     }
-    inline void set_trimmed_throttle( int engine, double pos ) {
-       if ( engine == ALL_ENGINES ) {
-           for ( int i = 0; i < MAX_ENGINES; i++ ) {
-               trimmed_throttle[i] = pos;
-               CLAMP( &trimmed_throttle[i], 0.0, 1.0 );
-           }
-       } else {
-           if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
-               trimmed_throttle[engine] = pos;
-               CLAMP( &trimmed_throttle[engine], 0.0, 1.0 );
-           }
-       }
-    }
     inline void move_throttle( int engine, double amt ) {
        if ( engine == ALL_ENGINES ) {
            for ( int i = 0; i < MAX_ENGINES; i++ ) {
index 183669eada360e811873c816b202b6fc9cd8acc9..0714817c7e2f7abfdb52c01d1b876311fbef36d3 100644 (file)
@@ -120,7 +120,8 @@ int FGJSBsim::init( double dt ) {
   FG_LOG( FG_FLIGHT, FG_INFO, "  lat: " <<  get_Latitude() );
   FG_LOG( FG_FLIGHT, FG_INFO, "  lon: " <<  get_Longitude() );
   FG_LOG( FG_FLIGHT, FG_INFO, "  alt: " <<  get_Altitude() );
-
+  
+  //must check > 0, != 0 will give bad result if --notrim set
   if(current_options.get_trim_mode() == true) {
     FG_LOG( FG_FLIGHT, FG_INFO, "  Starting trim..." );
     FGTrimLong *fgtrim=new FGTrimLong(&FDMExec,fgic);
@@ -129,13 +130,9 @@ int FGJSBsim::init( double dt ) {
     fgtrim->TrimStats();
     fgtrim->ReportState();
 
-    controls.set_elevator_trim(FDMExec.GetFCS()->GetDeCmd());
-    controls.set_trimmed_throttle(FGControls::ALL_ENGINES,FDMExec.GetFCS()->GetThrottleCmd(0)/100);
-    //the trimming routine only knows how to get 1 value for throttle
-
-    //for(int i=0;i<FDMExec.GetAircraft()->GetNumEngines();i++) {
-    //  controls.set_throttle(i,FDMExec.GetFCS()->GetThrottleCmd(i)/100);
-    //}
+    controls.set_elevator_trim(FDMExec.GetFCS()->GetPitchTrimCmd());
+    controls.set_throttle(FGControls::ALL_ENGINES,FDMExec.GetFCS()->GetThrottleCmd(0)/100);
+    
     delete fgtrim;
     FG_LOG( FG_FLIGHT, FG_INFO, "  Trim complete." );
   } else {
index 8b2256cca60dc2a4cf0e2544969772d2048bca08..cc828053a7c5f7911b40e98f93f05d7045a4bae9 100644 (file)
@@ -54,6 +54,12 @@ static jsJoystick *js1;
 // these will hold the values of the axes
 static float *js_ax0, *js_ax1;
 
+static bool sync_throttle=false;
+
+static float throttle_tmp=0;
+
+#define SYNC_TOLERANCE 0.02
+
 #elif defined( ENABLE_GLUT_JOYSTICK )
 
 // Do we want these user settable ??
@@ -176,6 +182,12 @@ int fgJoystickInit( void ) {
     {
        current_options.set_auto_coordination(fgOPTIONS::FG_AUTO_COORD_ENABLED);
     }
+    
+    if(current_options.get_trim_mode() > 0) {
+        FG_LOG(FG_INPUT, FG_INFO,
+              "  Waiting for user to synchronize throttle lever...");
+        sync_throttle=true;
+    }
 
 
 #elif defined( ENABLE_GLUT_JOYSTICK )
@@ -205,8 +217,19 @@ int fgJoystickRead( void ) {
 
        //  Added by William Riley -- riley@technologist.com
        if ( js0->getNumAxes() >= 3 ) {
-           controls.set_throttle( FGControls::ALL_ENGINES,
-                                  ((-js_ax0[2] + 1) / 2) );
+           throttle_tmp=(-js_ax0[2] + 1) / 2;
+        
+           if(sync_throttle == true) {
+               if (fabs(controls.get_throttle(0)-throttle_tmp)
+                   < SYNC_TOLERANCE)
+               {
+                   FG_LOG(FG_INPUT, FG_INFO, "  Throttle lever synchronized.");
+                   controls.set_throttle(FGControls::ALL_ENGINES,throttle_tmp);
+                   sync_throttle=false;
+               }    
+           } else {
+               controls.set_throttle( FGControls::ALL_ENGINES,throttle_tmp );
+           }
        } 
        if ( js0->getNumAxes() > 3 ) {
            if ( current_options.get_auto_coordination() !=
index 0d5857387eff13e8471881f618f41b2f97d22b13..d0953e7f3b0f4bfbec01aa13601499b31b04e022 100644 (file)
@@ -544,13 +544,6 @@ bool fgInitSubsystems( void ) {
     // Autopilot init
     current_autopilot = new FGAutopilot;
     current_autopilot->init();
-    
-    if((current_options.get_trim_mode() == true) && (current_options.get_flight_model() == FGInterface::FG_JSBSIM) ) {
-       current_autopilot->set_AutoThrottleEnabled(
-             ! current_autopilot->get_AutoThrottleEnabled()  );
-       current_autopilot->AutoThrottleAdjust( 
-                 controls.get_trimmed_throttle(0) );
-   } 
 
     // initialize the gui parts of the autopilot
     NewTgtAirportInit();
index 684392ffdf0da9fcd70f3e74c537549256ac3bb9..2eac4f9a416a8bd73461dba1d33aeb6788b1ed02 100644 (file)
@@ -169,7 +169,7 @@ fgOPTIONS::fgOPTIONS() :
     aircraft( "c172" ),
     model_hz( NEW_DEFAULT_MODEL_HZ ),
     speed_up( 1 ),
-    trim(true),
+    trim(0),
 
     // Rendering options
     fog(FG_FOG_NICEST),  // nicest
@@ -681,6 +681,11 @@ int fgOPTIONS::parse_option( const string& arg ) {
        fg_root = arg.substr( 10 );
     } else if ( arg.find( "--fdm=" ) != string::npos ) {
        flight_model = parse_fdm( arg.substr(6) );
+    if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
+       set_trim_mode(1);
+    } else {
+       set_trim_mode(0);
+    }        
     } else if ( arg.find( "--aircraft=" ) != string::npos ) {
        aircraft = arg.substr(11);
     } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
@@ -690,7 +695,7 @@ int fgOPTIONS::parse_option( const string& arg ) {
     } else if ( arg.find( "--speed=" ) != string::npos ) {
        speed_up = atoi( arg.substr(8) );
     } else if ( arg.find( "--notrim") != string::npos) {
-       trim=false;
+       trim=-1;
     } else if ( arg == "--fog-disable" ) {
        fog = FG_FOG_DISABLED;  
     } else if ( arg == "--fog-fastest" ) {
index 2e5672333b879848a00fb96fc2130da16bddeabb..01d3c6e951313a4307503fe420dfab48699ebb6d 100644 (file)
@@ -162,7 +162,10 @@ private:
     string aircraft;    // Aircraft to model
     int model_hz;       // number of FDM iterations per second
     int speed_up;       // Sim mechanics run this much faster than normal speed
-    bool trim;          // use the FDM trimming routine during init
+    int trim;           // use the FDM trimming routine during init
+                        // <0 --notrim set, 0 no trim, >0 trim
+                        // default behavior is to enable trimming for jsbsim
+                        // disable for all other fdm's
 
     // Rendering options
     fgFogKind fog;      // Fog nicest/fastest/disabled
@@ -256,7 +259,7 @@ public:
     inline int get_model_hz() const { return model_hz; }
     inline int get_speed_up() const { return speed_up; }
     inline void set_speed_up( int speed ) { speed_up = speed; }
-    inline bool get_trim_mode(void) { return trim; }
+    inline int get_trim_mode(void) { return trim; }
        
     inline bool fog_enabled() const { return fog != FG_FOG_DISABLED; }
     inline fgFogKind get_fog() const { return fog; }
@@ -313,7 +316,7 @@ public:
     inline void set_flight_model (int value) { flight_model = value; }
     inline void set_aircraft (const string &ac) { aircraft = ac; }
     inline void set_model_hz (int value) { model_hz = value; }
-    inline void set_trim_mode(bool bb) { trim=bb; }
+    inline void set_trim_mode(int value) { trim = value; }
     inline void set_fog (fgFogKind value) { fog = value; }
     inline void set_clouds( bool value ) { clouds = value; }
     inline void set_clouds_asl( double value ) { clouds_asl = value; }