From 98350722416c1a8629352fcecd9d1f9c35d1c071 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 19 May 2000 16:29:23 +0000 Subject: [PATCH] From Tony Peden: 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 | 1 - src/Controls/controls.hxx | 17 ----------------- src/FDM/JSBSim.cxx | 13 +++++-------- src/Joystick/joystick.cxx | 27 +++++++++++++++++++++++++-- src/Main/fg_init.cxx | 7 ------- src/Main/options.cxx | 9 +++++++-- src/Main/options.hxx | 9 ++++++--- 7 files changed, 43 insertions(+), 40 deletions(-) diff --git a/src/Controls/controls.cxx b/src/Controls/controls.cxx index e10e1a860..ff097a4ab 100644 --- a/src/Controls/controls.cxx +++ b/src/Controls/controls.cxx @@ -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++ ) { diff --git a/src/Controls/controls.hxx b/src/Controls/controls.hxx index ea859bb99..08f840950 100644 --- a/src/Controls/controls.hxx +++ b/src/Controls/controls.hxx @@ -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++ ) { diff --git a/src/FDM/JSBSim.cxx b/src/FDM/JSBSim.cxx index 183669ead..0714817c7 100644 --- a/src/FDM/JSBSim.cxx +++ b/src/FDM/JSBSim.cxx @@ -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;iGetNumEngines();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 { diff --git a/src/Joystick/joystick.cxx b/src/Joystick/joystick.cxx index 8b2256cca..cc828053a 100644 --- a/src/Joystick/joystick.cxx +++ b/src/Joystick/joystick.cxx @@ -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() != diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 0d5857387..d0953e7f3 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -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(); diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 684392ffd..2eac4f9a4 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -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" ) { diff --git a/src/Main/options.hxx b/src/Main/options.hxx index 2e5672333..01d3c6e95 100644 --- a/src/Main/options.hxx +++ b/src/Main/options.hxx @@ -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; } -- 2.39.5