1
0
Fork 0

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. ;-)
This commit is contained in:
curt 2000-05-19 16:29:23 +00:00
parent 2f22748275
commit 9835072241
7 changed files with 43 additions and 40 deletions

View 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++ ) {

View 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++ ) {

View 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 {

View 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() !=

View 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();

View 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" ) {

View 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; }