[Flightgear-devel] RFC: Apply throttle axis changes only to selected engines
Hi all! Currently the joystick throttle axis and the mouse throttle control apply any throttle change to all engines. In my work on LZ-129 Hindenburg I discovered that I need to be able to quickly control the engines individually or in (sub)groups - and I think this ability would be useful also for other multi-engine aircraft. I propose the following changes to controls.nas: 1. throttleMouse(), throttleAxis() and incThrottle() only change the throttle setting for the selected engines, i.e. those that have /sim/input/selected/engine[i] == true 2. A new function controls.selectEngineToo(e_no) adds engine number e_no to the set of active engines. The existing selectEngine() is mutually exclusive - it deselects all other engines. (I hope somebody can come up with a better name than selectEngineToo..) 3. Mixture and propeller controls seem to honour engine selection already. On my system I have mapped controls.selectEngineToo() to shift+ctrl+, which I find convenient and easy to work with. E.g. shift+1 and then shift+ctrl+2 selects engine 1 and 2. Aircraft like Dornier Do X or Convair B-36 could add their own keyboard shortcuts to select engine groups.. :) Here is a patch for Nasal/controls.nas that implements the changes: http://www.gidenstam.org/FlightGear/misc/controls.nas_individual_throttles.diff Suggestions and comments are welcome! Cheers, Anders -- --- Anders Gidenstam mail: anders(at)gidenstam.org WWW: http://www.gidenstam.org/FlightGear/JSBSim-LTA/Index: Nasal/controls.nas === RCS file: /var/cvs/FlightGear-0.9/data/Nasal/controls.nas,v retrieving revision 1.21 diff -u -p -u -r1.21 controls.nas --- Nasal/controls.nas 22 Jun 2007 18:49:38 - 1.21 +++ Nasal/controls.nas 6 Jul 2007 22:31:28 - @@ -27,6 +27,10 @@ selectEngine = func { foreach(node; sel) { node.setBoolValue(node.getIndex() == arg[0]); } } +selectEngineToo = func { +setprop("/sim/input/selected/engine["~arg[0]~"]", 1); +} + selectAllEngines = func { sel = props.globals.getNode("/sim/input/selected").getChildren("engine"); foreach(node; sel) { node.setBoolValue(1); } @@ -53,10 +57,16 @@ centerFlightControls = func { throttleMouse = func { if(!getprop("/devices/status/mice/mouse[0]/button[1]")) { return; } -val = (cmdarg().getNode("offset").getValue() * -4 - + getprop("/controls/engines/engine/throttle")); -if(size(arg) > 0) { val = -val; } -props.setAll("/controls/engines/engine", "throttle", val); +sel = props.globals.getNode("/sim/input/selected").getChildren("engine"); +foreach(node; sel) { + if (node.getValue()) { +val = (cmdarg().getNode("offset").getValue() * -4 + + getprop("/controls/engines/engine["~node.getIndex()~"]/throttle")); +if(size(arg) > 0) { val = -val; } +setprop("/controls/engines/engine["~node.getIndex()~"]/throttle", +val); + } +} } # Joystick axis handlers (uses cmdarg). Shouldn't be called from @@ -64,7 +74,13 @@ throttleMouse = func { throttleAxis = func { val = cmdarg().getNode("setting").getValue(); if(size(arg) > 0) { val = -val; } -props.setAll("/controls/engines/engine", "throttle", (1 - val)/2); +sel = props.globals.getNode("/sim/input/selected").getChildren("engine"); +foreach(node; sel) { +if (node.getValue()) { +setprop("/controls/engines/engine["~node.getIndex()~"]/throttle", +(1 - val)/2); +} +} } mixtureAxis = func { val = cmdarg().getNode("setting").getValue(); @@ -218,16 +234,19 @@ adjEngControl = func { # arg[1] is the auto-throttle target speed increment incThrottle = func { auto = props.globals.getNode("/autopilot/locks/speed", 1); +selected = props.globals.getNode("/sim/input/selected"); if ( !auto.getValue() ) { engs = props.globals.getNode("/controls/engines").getChildren("engine"); foreach(e; engs) { -node = e.getNode("throttle", 1); -node.setValue(node.getValue() + arg[0]); -if ( node.getValue() < -1.0 ) { - node.setValue( -1.0 ); -} -if ( node.getValue() > 1.0 ) { - node.setValue( 1.0 ); +if(selected.getChild("engine", e.getIndex(), 1).getBoolValue()) { + node = e.getNode("throttle", 1); + node.setValue(node.getValue() + arg[0]); + if ( node.getValue() < -1.0 ) { +node.setValue( -1.0 ); + } + if ( node.getValue() > 1.0 ) { +node.setValue( 1.0 ); + } } } } else { - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http:/
Re: [Flightgear-devel] RFC: Apply throttle axis changes only to selected engines
* Anders Gidenstam -- Saturday 07 July 2007: > In my work on LZ-129 Hindenburg I discovered that I need to be able > to quickly control the engines individually or in (sub)groups I've thought in the past that the throttle should really respect the selected engines. > 1. throttleMouse(), throttleAxis() and incThrottle() only change the > throttle setting for the selected engines, i.e. those that have > /sim/input/selected/engine[i] == true You shouldn't have things in the loop that don't change, though it's certainly not a big performance problem. For example the cmdarg().getNode("offset").getValue() * -4. This code sets the same value for all selected engines to the js/mouse value. But if they weren't all at the same level, this would mean that some make abrupt jumps. Applying the same delta to all selected engines would be nicer, but has its own problems ... :-/ > 2. A new function controls.selectEngineToo(e_no) adds engine number e_no > to the set of active engines. The existing selectEngine() is mutually > exclusive - it deselects all other engines. I'd rather make a function something like this: var selectEngines = func(state, engines...) { var sel = props.globals.getNode("/sim/input/selected"); if(size(engines)) { foreach(var e; engines) sel.getChild("engine", e, 1).setBoolValue(state); } else { foreach(var e; sel.getChildren("engine")) e.setBoolValue(state); } } One could then say selectEngines(1);# select all engines selectEngines(0);# unselect all engines selectEngines(1, 3, 5, 7); # select engines 3, 5, and 7 selectEngines(0, 4); # unselect engine 4 That is: the first argument decides whether to select or unselect, followed by a list of engine indices, to which the operation applies (for example, all engines on the left of an airship). If no engines are listed, then all of them are used. (Maybe a bit overengineered. ;-) m. - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] RFC: Apply throttle axis changes only to selected engines
On Sat, 7 Jul 2007, Melchior FRANZ wrote: > This code sets the same value for all selected engines to the js/mouse > value. But if they weren't all at the same level, this would mean that > some make abrupt jumps. Applying the same delta to all selected engines > would be nicer, but has its own problems ... :-/ Actually, throttleMouse applies a delta while throttleAxis sets an absolute value (unless I misread the code). That behaviour at least makes some kind of sense.. :) > I'd rather make a function something like this: > > var selectEngines = func(state, engines...) { ... > } Ah, yes that is much nicer. I hadn't grasped the argument list possibility. Thanks for the code review! Updated diff: http://www.gidenstam.org/FlightGear/misc/controls.nas_individual_throttles.diff Cheers, Anders -- --- Anders Gidenstam mail: anders(at)gidenstam.org WWW: http://www.gidenstam.org/FlightGear/JSBSim-LTA/ - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] RFC: Apply throttle axis changes only to selected engines
Hi again, There hasn't been too many comments on this proposal (but OTOH also no objections :) To summarize the proposed changes again: - Change controls.nas so throttle input to only affect the selected engines. The input is handled as follows: i) Page up/down changes the selected throttles one step up/down, i.e. if the original throttle settings were x steps apart they remain x steps apart (unless the boundary is reached). ii) Mouse + MMB drag changes the selected throttles by the delta amount (length of drag). iii) The throttleAxis() wrapper for joysticks sets the selected throttles to correspond to the joystick's axis position. I.e. all selected engines will get the same throttle setting. Since most joystick throttles are positional devices I think this behaviour is more logical than using a relative adjustment in this case. Note that if all engines are selected (and have the same initial throttle setting) the behaviour is identical to the present. - Add the possibility to select subsets of the engines via the new controls.selectEngines(). For this functionality to be accessible a keyboard binding also needs to be added - my suggestion is shift+ctrl+<#key> to select engine #key+1 in addition to the already selected engine(s). Diff for Nasal/controls.nas: http://www.gidenstam.org/FlightGear/misc/controls.nas_individual_throttles.diff I think this type of throttle control is desired and needed in FG, e.g. for proper control of the Boeing 314A on water. Cheers, Anders -- --- Anders Gidenstam mail: anders(at)gidenstam.org WWW: http://www.gidenstam.org/FlightGear/JSBSim-LTA/ - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] RFC: Apply throttle axis changes only to selected engines
* Anders Gidenstam -- Tuesday 17 July 2007: > - Change controls.nas so throttle input to only affect the selected engines. This has been committed. Thanks. I've only made some minor changes, that have made your code actually *less* consistent with the existing controls.nas code. This is because I want to convert the rest of it in the next time, too. (No, it's not about changing the coding style of that file, but to use Nasal features and and improvements that weren't available when the file was started, such as consequent use of the "var" keyword, += operators etc.) m. - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel