From 9c4953490780e9fa3436201213d43e416498bf28 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 12 Jan 2004 17:39:41 +0000 Subject: [PATCH] Attempt #1 to sort out confusion between left / right / parking brake controls in the cockpit vs. which wheels they apply to. FlightGear now sets /controls/gear/brake-left, /controls/gear/brake-right, and /controls/gear/brake-parking. It should be up to the FDM to sort out which wheels under which circumstances are affected by these controls and ultimately what happens to the physical motion of the aircraft. --- docs-mini/README.properties | 5 +- scripts/perl/web/mkindex.pl | 8 +-- scripts/python/FlightGear.py | 2 +- src/Autopilot/newauto.cxx | 16 ++++-- src/Controls/controls.cxx | 101 ++++++++++++++++++----------------- src/Controls/controls.hxx | 18 ++++--- src/FDM/JSBSim/JSBSim.cxx | 8 +-- src/FDM/LaRCsim/LaRCsim.cxx | 4 +- src/FDM/MagicCarpet.cxx | 4 +- src/FDM/UFO.cxx | 4 +- src/GUI/mouse.cxx | 3 +- src/Input/fgjs.cxx | 16 +++--- src/Network/atc610x.cxx | 6 +-- src/Network/native_ctrls.cxx | 43 ++++++--------- src/Network/net_ctrls.hxx | 7 +-- src/Replay/replay.cxx | 10 ++-- 16 files changed, 132 insertions(+), 123 deletions(-) diff --git a/docs-mini/README.properties b/docs-mini/README.properties index a4cdc672f..a64ebac2c 100644 --- a/docs-mini/README.properties +++ b/docs-mini/README.properties @@ -52,13 +52,14 @@ Fuel Gear ---- -/controls/gear/parking-brake +/controls/gear/brake-left +/controls/gear/brake-right +/controls/gear/brake-parking /controls/gear/steering /controls/gear/gear-down /controls/gear/antiskid /controls/gear/tailhook /controls/gear/tailwheel-lock -/controls/gear/wheel[%d]/brake /controls/gear/wheel[%d]/alternate-extension Anti-Ice diff --git a/scripts/perl/web/mkindex.pl b/scripts/perl/web/mkindex.pl index 9f89388a9..a1376ddee 100755 --- a/scripts/perl/web/mkindex.pl +++ b/scripts/perl/web/mkindex.pl @@ -289,9 +289,7 @@ while ( ) { print OUT "\n"; if ( -f "$mdir/$linkname.txt" ) { - if ( $twidth < $swidth ) { - print OUT "
\n"; - } + print OUT "
\n"; print OUT "\n"; open( IN, "<$mdir/$linkname.txt" ); while ( ) { @@ -300,9 +298,7 @@ while ( ) { close( IN ); print OUT "\n"; } else { - if ( $twidth < $swidth ) { - print OUT "
\n"; - } + print OUT "
\n"; print OUT "\n"; print OUT "$linkname\n"; print OUT "\n"; diff --git a/scripts/python/FlightGear.py b/scripts/python/FlightGear.py index 4b02a05df..9b71d57da 100644 --- a/scripts/python/FlightGear.py +++ b/scripts/python/FlightGear.py @@ -87,7 +87,7 @@ class FlightGear: # Connect to flightgear telnet server. fg = FlightGear('myhost', 5500) # parking brake on - fg['/controls/parking-brake'] = 1 + fg['/controls/gear/brake-parking'] = 1 # Get current heading heading = fg['/orientation/heading-deg'] diff --git a/src/Autopilot/newauto.cxx b/src/Autopilot/newauto.cxx index 81708ff2a..b699c8c9d 100644 --- a/src/Autopilot/newauto.cxx +++ b/src/Autopilot/newauto.cxx @@ -756,15 +756,23 @@ FGAutopilot::update (double dt) double current_angle = atan2( y, x ) * SGD_RADIANS_TO_DEGREES; double target_angle = current_radiostack->get_navcom1()->get_nav_target_gs(); - double gs_diff = target_angle - current_angle; // convert desired vertical path angle into a climb rate double des_angle = current_angle - 10 * gs_diff; - // convert to meter/min - double horiz_vel = cur_fdm_state->get_V_ground_speed() - * SG_FEET_TO_METER * 60.0; + // estimate horizontal speed towards ILS in meters per minute + static double horiz_vel = 0.0; + static double last_x = 0.0; + double dist = last_x - x; + last_x = x; + double new_vel = ( dist / dt ) * 60.0; + horiz_vel = 0.75 * horiz_vel + 0.25 * new_vel; + // double horiz_vel = cur_fdm_state->get_V_ground_speed() + // * SG_FEET_TO_METER * 60.0; + // double horiz_vel = airspeed_node->getFloatValue() + // * SG_FEET_TO_METER * 60.0; + climb_rate = -sin( des_angle * SGD_DEGREES_TO_RADIANS ) * horiz_vel; /* climb_error_accum += gs_diff * 2.0; */ /* climb_rate = gs_diff * 200.0 + climb_error_accum; */ diff --git a/src/Controls/controls.cxx b/src/Controls/controls.cxx index 58d91fe7f..c66088873 100644 --- a/src/Controls/controls.cxx +++ b/src/Controls/controls.cxx @@ -72,7 +72,9 @@ FGControls::FGControls() : drag_chute( false ), throttle_idle( true ), dump_valve( false ), - parking_brake( 0.0 ), + brake_left( 0.0 ), + brake_right( 0.0 ), + brake_parking( 0.0 ), steering( 0.0 ), gear_down( true ), antiskid( true ), @@ -202,8 +204,8 @@ FGControls::init () condition[engine] = 0; } + brake_left = brake_right = brake_parking = 0.0; for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) { - brake[wheel] = 0.0; alternate_extension[wheel] = false; } @@ -420,10 +422,20 @@ FGControls::bind () } // gear - fgTie("/controls/gear/parking-brake", this, - &FGControls::get_parking_brake, - &FGControls::set_parking_brake); - fgSetArchivable("/controls/gear/parking-brake"); + fgTie("/controls/gear/brake-left", this, + &FGControls::get_brake_left, + &FGControls::set_brake_left); + fgSetArchivable("/controls/gear/brake-left"); + + fgTie("/controls/gear/brake-right", this, + &FGControls::get_brake_right, + &FGControls::set_brake_right); + fgSetArchivable("/controls/gear/brake-right"); + + fgTie("/controls/gear/brake-parking", this, + &FGControls::get_brake_parking, + &FGControls::set_brake_parking); + fgSetArchivable("/controls/gear/brake-parking"); fgTie("/controls/gear/steering", this, &FGControls::get_steering, &FGControls::set_steering); @@ -448,11 +460,6 @@ FGControls::bind () for (index = 0; index < MAX_WHEELS; index++) { char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, "/controls/gear/wheel[%d]/brake", index); - fgTie(name, this, index, - &FGControls::get_brake, &FGControls::set_brake); - fgSetArchivable(name); - snprintf(name, MAX_NAME_LEN, "/controls/gear/wheel[%d]/alternate-extension", index); fgTie(name, this, index, @@ -868,7 +875,9 @@ void FGControls::unbind () fgUntie(name); } } - fgUntie("/controls/gear/parking_brake"); + fgUntie("/controls/gear/brake-left"); + fgUntie("/controls/gear/brake-right"); + fgUntie("/controls/gear/brake-parking"); fgUntie("/controls/gear/steering"); fgUntie("/controls/gear/gear_down"); fgUntie("/controls/gear/antiskid"); @@ -876,8 +885,6 @@ void FGControls::unbind () fgUntie("/controls/gear/tailwheel-lock"); for (index = 0; index < MAX_WHEELS; index++) { char name[MAX_NAME_LEN]; - snprintf(name, MAX_NAME_LEN, "/controls/gear/wheel[%d]/brakes", index); - fgUntie(name); snprintf(name, MAX_NAME_LEN, "/controls/gear/wheel[%d]/alternate-extension", index); fgUntie(name); @@ -1594,10 +1601,38 @@ FGControls::set_boost_pump( int index, bool val ) void -FGControls::set_parking_brake( double pos ) +FGControls::set_brake_left( double pos ) +{ + brake_left = pos; + CLAMP(&brake_left, 0.0, 1.0); +} + +void +FGControls::move_brake_left( double amt ) +{ + brake_left += amt; + CLAMP( &brake_left, 0.0, 1.0 ); +} + +void +FGControls::set_brake_right( double pos ) +{ + brake_right = pos; + CLAMP(&brake_right, 0.0, 1.0); +} + +void +FGControls::move_brake_right( double amt ) +{ + brake_right += amt; + CLAMP( &brake_right, 0.0, 1.0 ); +} + +void +FGControls::set_brake_parking( double pos ) { - parking_brake = pos; - CLAMP(&parking_brake, 0.0, 1.0); + brake_parking = pos; + CLAMP(&brake_parking, 0.0, 1.0); } void @@ -1639,38 +1674,6 @@ FGControls::set_tailwheel_lock( bool state ) } -void -FGControls::set_brake( int wheel, double pos ) -{ - if ( wheel == ALL_WHEELS ) { - for ( int i = 0; i < MAX_WHEELS; i++ ) { - brake[i] = pos; - CLAMP( &brake[i], 0.0, 1.0 ); - } - } else { - if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) { - brake[wheel] = pos; - CLAMP( &brake[wheel], 0.0, 1.0 ); - } - } -} - -void -FGControls::move_brake( int wheel, double amt ) -{ - if ( wheel == ALL_WHEELS ) { - for ( int i = 0; i < MAX_WHEELS; i++ ) { - brake[i] += amt; - CLAMP( &brake[i], 0.0, 1.0 ); - } - } else { - if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) { - brake[wheel] += amt; - CLAMP( &brake[wheel], 0.0, 1.0 ); - } - } -} - void FGControls::set_alternate_extension( int wheel, bool val ) { diff --git a/src/Controls/controls.hxx b/src/Controls/controls.hxx index ad7e3085c..e55c4c38b 100644 --- a/src/Controls/controls.hxx +++ b/src/Controls/controls.hxx @@ -154,7 +154,9 @@ private: bool boost_pump[MAX_TANKS * MAX_BOOSTPUMPS]; // controls/gear/ - double parking_brake; + double brake_left; + double brake_right; + double brake_parking; double steering; bool gear_down; bool antiskid; @@ -162,7 +164,6 @@ private: bool tailwheel_lock; // controls/gear/wheel[n]/ - double brake[MAX_WHEELS]; bool alternate_extension[MAX_WHEELS]; // controls/anti-ice/ @@ -333,7 +334,9 @@ public: } // controls/gear/ - inline double get_parking_brake() const { return parking_brake; } + inline double get_brake_left() const { return brake_left; } + inline double get_brake_right() const { return brake_right; } + inline double get_brake_parking() const { return brake_parking; } inline double get_steering() const { return steering; } inline bool get_gear_down() const { return gear_down; } inline bool get_antiskid() const { return antiskid; } @@ -341,7 +344,6 @@ public: inline bool get_tailwheel_lock() const { return tailwheel_lock; } // controls/gear/wheel[n]/ - inline double get_brake(int wheel) const { return brake[wheel]; } inline bool get_alternate_extension(int wheel) const { return alternate_extension[wheel]; } @@ -513,7 +515,11 @@ public: void set_boost_pump( int index, bool val ); // controls/gear/ - void set_parking_brake( double pos ); + void set_brake_left( double pos ); + void move_brake_left( double amt ); + void set_brake_right( double pos ); + void move_brake_right( double amt ); + void set_brake_parking( double pos ); void set_steering( double pos ); void move_steering( double amt ); void set_gear_down( bool gear ); @@ -522,8 +528,6 @@ public: void set_tailwheel_lock( bool val ); // controls/gear/wheel[n]/ - void set_brake( int wheel, double pos ); - void move_brake( int wheel, double amt ); void set_alternate_extension( int wheel, bool val ); // controls/anti-ice/ diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index e893c58b0..34f2af9a9 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -413,10 +413,10 @@ bool FGJSBsim::copy_to_JSBsim() { // Parking brake sets minimum braking // level for mains. - double parking_brake = globals->get_controls()->get_parking_brake(); - FCS->SetLBrake(FMAX(globals->get_controls()->get_brake(0), parking_brake)); - FCS->SetRBrake(FMAX(globals->get_controls()->get_brake(1), parking_brake)); - FCS->SetCBrake( globals->get_controls()->get_brake(2) ); + double parking_brake = globals->get_controls()->get_brake_parking(); + FCS->SetLBrake(FMAX(globals->get_controls()->get_brake_left(), parking_brake)); + FCS->SetRBrake(FMAX(globals->get_controls()->get_brake_right(), parking_brake)); + FCS->SetCBrake( 0.0 ); FCS->SetGearCmd( globals->get_controls()->get_gear_down()); for (i = 0; i < Propulsion->GetNumEngines(); i++) { diff --git a/src/FDM/LaRCsim/LaRCsim.cxx b/src/FDM/LaRCsim/LaRCsim.cxx index 5683feb48..f69bd9939 100644 --- a/src/FDM/LaRCsim/LaRCsim.cxx +++ b/src/FDM/LaRCsim/LaRCsim.cxx @@ -281,8 +281,8 @@ void FGLaRCsim::update( double dt ) { Throttle_pct = globals->get_controls()->get_throttle( 0 ) * 1.0; - Brake_pct[0] = globals->get_controls()->get_brake( 1 ); - Brake_pct[1] = globals->get_controls()->get_brake( 0 ); + Brake_pct[0] = globals->get_controls()->get_brake_right(); + Brake_pct[1] = globals->get_controls()->get_brake_left(); // Inform LaRCsim of the local terrain altitude // Runway_altitude = get_Runway_altitude(); diff --git a/src/FDM/MagicCarpet.cxx b/src/FDM/MagicCarpet.cxx index 8450c45b3..885d69cc0 100644 --- a/src/FDM/MagicCarpet.cxx +++ b/src/FDM/MagicCarpet.cxx @@ -61,7 +61,9 @@ void FGMagicCarpet::update( double dt ) { // speed and distance traveled double speed = globals->get_controls()->get_throttle( 0 ) * 2000; // meters/sec - if ( globals->get_controls()->get_brake( 0 ) ) { + if ( globals->get_controls()->get_brake_left() > 0.0 + || globals->get_controls()->get_brake_right() > 0.0 ) + { speed = -speed; } diff --git a/src/FDM/UFO.cxx b/src/FDM/UFO.cxx index e2c1366db..65e9fb2c4 100644 --- a/src/FDM/UFO.cxx +++ b/src/FDM/UFO.cxx @@ -68,7 +68,9 @@ void FGUFO::update( double dt ) { // read the throttle double th = globals->get_controls()->get_throttle( 0 ); - if (globals->get_controls()->get_brake(0)) { + if ( globals->get_controls()->get_brake_left() > 0.0 + || globals->get_controls()->get_brake_right() > 0.0 ) + { th = -th; } Throttle = th * throttle_damp + Throttle * (1 - throttle_damp); diff --git a/src/GUI/mouse.cxx b/src/GUI/mouse.cxx index 10290f7d3..b4b612ac9 100644 --- a/src/GUI/mouse.cxx +++ b/src/GUI/mouse.cxx @@ -198,7 +198,8 @@ static inline float get_goal_view_offset() { } static inline void move_brake(float offset) { - globals->get_controls()->move_brake(FGControls::ALL_WHEELS, offset); + globals->get_controls()->move_brake_left(offset); + globals->get_controls()->move_brake_right(offset); } static inline void move_throttle(float offset) { diff --git a/src/Input/fgjs.cxx b/src/Input/fgjs.cxx index c4cd037d9..8cce19be7 100644 --- a/src/Input/fgjs.cxx +++ b/src/Input/fgjs.cxx @@ -48,22 +48,24 @@ string axes_propnames[8]={ "/controls/flight/elevator","/controls/flight/aileron bool half_range[8]={ false,false,false,true,true,true,false,false }; -string button_humannames[7]= { "apply all brakes", "apply left brake", +string button_humannames[6]= { "apply left brake", "apply right brake", "step flaps up", "step flaps down","apply nose-up trim", "apply nose-down trim" }; -string button_propnames[7]={ "/controls/gear/wheel[-1]/brake", "/controls/gear/wheel[0]/brake", - "/controls/gear/wheel[1]/brake", "/controls/flight/flaps", - "/controls/flight/flaps","/controls/flight/elevator-trim", +string button_propnames[6]={ "/controls/gear/brake-left", + "/controls/gear/brake-right", + "/controls/flight/flaps", + "/controls/flight/flaps", + "/controls/flight/elevator-trim", "/controls/flight/elevator-trim" }; -float button_step[7]={ 1.0, 1.0, 1.0, 0.34, -0.34, 0.001, -0.001 }; +float button_step[6]={ 1.0, 1.0, 0.34, -0.34, 0.001, -0.001 }; -string button_repeat[7]={ "false", "false", "false", "false", "false", +string button_repeat[6]={ "false", "false", "false", "false", "true", "true" }; @@ -166,7 +168,7 @@ int main(void) { cout << endl; } - for(control=0;control<=6;control++) { + for(control=0;control<=5;control++) { cout << "Press the button you wish to use to " << button_humannames[control] << endl; diff --git a/src/Network/atc610x.cxx b/src/Network/atc610x.cxx index 174c6e504..7b604bd6e 100644 --- a/src/Network/atc610x.cxx +++ b/src/Network/atc610x.cxx @@ -744,11 +744,11 @@ bool FGATC610x::do_analog_in() { tmp = scale( brake_left_min->getIntValue(), brake_left_max->getIntValue(), analog_in_data[20] ); - fgSetFloat( "/controls/gear/wheel[0]/brake", tmp ); + fgSetFloat( "/controls/gear/brake-left", tmp ); tmp = scale( brake_right_min->getIntValue(), brake_right_max->getIntValue(), analog_in_data[21] ); - fgSetFloat( "/controls/gear/wheel[1]/brake", tmp ); + fgSetFloat( "/controls/gear/brake-right", tmp ); } // nav1 volume @@ -1888,7 +1888,7 @@ bool FGATC610x::do_switches() { fgSetBool( "/controls/circuit-breakers/annunciators", true ); #endif - fgSetDouble( "/controls/gear/parking-brake", + fgSetDouble( "/controls/gear/brake-parking", switch_matrix[board][7][3] ); fgSetDouble( "/radios/marker-beacon/power-btn", switch_matrix[board][6][1] ); diff --git a/src/Network/native_ctrls.cxx b/src/Network/native_ctrls.cxx index 89a4ef0bb..5261d339a 100644 --- a/src/Network/native_ctrls.cxx +++ b/src/Network/native_ctrls.cxx @@ -164,21 +164,10 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool honor_freezes, net->fuel_selector[i] = false; } } - net->num_wheels = FGNetCtrls::FG_MAX_WHEELS; - tempnode = fgGetNode("/controls/gear", true); - for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) { - node = fgGetNode("/controls/gear/wheel", i); - if ( node != NULL && node->getChild("brake") != NULL ) { - if ( tempnode->getChild("parking-brake")->getDoubleValue() > 0.0 ) { - net->brake[i] = 1.0; - } else { - net->brake[i] - = node->getChild("brake")->getDoubleValue(); - } - } else { - net->brake[i] = 0.0; - } - } + node = fgGetNode("/controls/gear", true); + net->brake_left = node->getChild("brake-left")->getDoubleValue(); + net->brake_right = node->getChild("brake-right")->getDoubleValue(); + net->brake_parking = node->getChild("brake-parking")->getDoubleValue(); node = fgGetNode("/controls/switches", true); tempnode = node->getChild("master-bat"); @@ -252,10 +241,9 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool honor_freezes, net->fuel_selector[i] = htonl(net->fuel_selector[i]); } net->num_tanks = htonl(net->num_tanks); - for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) { - htond(net->brake[i]); - } - net->num_wheels = htonl(net->num_wheels); + htond(net->brake_left); + htond(net->brake_right); + htond(net->brake_parking); net->gear_handle = htonl(net->gear_handle); net->master_bat = htonl(net->master_bat); net->master_alt = htonl(net->master_alt); @@ -310,10 +298,9 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes, for ( i = 0; i < net->num_tanks; ++i ) { net->fuel_selector[i] = htonl(net->fuel_selector[i]); } - net->num_wheels = htonl(net->num_wheels); - for ( i = 0; i < net->num_wheels; ++i ) { - htond(net->brake[i]); - } + htond(net->brake_left); + htond(net->brake_right); + htond(net->brake_parking); net->gear_handle = htonl(net->gear_handle); net->master_bat = htonl(net->master_bat); net->master_alt = htonl(net->master_alt); @@ -377,11 +364,11 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes, node->getChild( "fuel_selector" ) ->setBoolValue( net->fuel_selector[i] ); } - for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) { - node = fgGetNode( "/controls/gear/wheel", i ); - if ( node != NULL ) { - node->getChild( "brake" )->setDoubleValue( net->brake[i] ); - } + node = fgGetNode( "/controls/gear" ); + if ( node != NULL ) { + node->getChild( "brake-left" )->setDoubleValue( net->brake_left ); + node->getChild( "brake-right" )->setDoubleValue( net->brake_right ); + node->getChild( "brake-parking" )->setDoubleValue( net->brake_parking ); } node = fgGetNode( "/controls/gear", true ); diff --git a/src/Network/net_ctrls.hxx b/src/Network/net_ctrls.hxx index 58f646bee..26b3bc62a 100644 --- a/src/Network/net_ctrls.hxx +++ b/src/Network/net_ctrls.hxx @@ -16,7 +16,7 @@ # error This library requires C++ #endif -const int FG_NET_CTRLS_VERSION = 18; +const int FG_NET_CTRLS_VERSION = 19; // Define a structure containing the control parameters @@ -66,8 +66,9 @@ public: bool fuel_selector[FG_MAX_TANKS]; // false = off, true = on // Brake controls - int num_wheels; // number of valid wheels - double brake[FG_MAX_WHEELS]; // 0 ... 1 + double brake_left; + double brake_right; + double brake_parking; // Landing Gear bool gear_handle; // true=gear handle down; false= gear handle up diff --git a/src/Replay/replay.cxx b/src/Replay/replay.cxx index 38ebe9e25..0395dc7b6 100644 --- a/src/Replay/replay.cxx +++ b/src/Replay/replay.cxx @@ -343,10 +343,12 @@ static FGReplayData interpolate( double time, FGReplayData f1, FGReplayData f2 ) } // Brake controls - for ( i = 0; i < ctrls1.num_wheels; ++i ) { - result.ctrls.brake[i] - = weight( ctrls1.brake[i], ctrls2.brake[i], ratio ); - } + result.ctrls.brake_left + = weight( ctrls1.brake_left, ctrls2.brake_right, ratio ); + result.ctrls.brake_right + = weight( ctrls1.brake_right, ctrls2.brake_right, ratio ); + result.ctrls.brake_parking + = weight( ctrls1.brake_parking, ctrls2.brake_parking, ratio ); // Landing Gear result.ctrls.gear_handle = ctrls1.gear_handle; -- 2.39.5