This post, written at Stuart's request, is meant to answer two of the forum's frequently asked questions, regarding joystick configuration in Flightgear.
Q1: Why does my joystick seem messed up? I run Flightgear on Windows [XP / Vista].
Q2: How can I change the controls assigned to each button on my joystick?
(EDIT: Even if you are reading this for Q2 and not Q1, you should still read most of it, as the explanation will give you the knowledge necessary to create your own customized controls.)
1. How Flightgear handles joysticks.
In layman's terms, Flightgear firsts attempts to detect whether a joystick is connected, and if so, what it is called. After checking /Flightgear/data/joysticks.xml for any instructions to the contrary, it will then scan through all of the various XML files under /Flightgear/data/Input/Joysticks looking for an XML file which defines "bindings" (i.e. command or control assignments for each axis and button) for that particular joystick. For example, if the stick is being reported as a "Saitek ST290 Pro", Flightgear will come across the file /Flightgear/data/Input/Joysticks/Saitek/ST290-Pro.xml which contains the tags:
- Code: Select all
<name>Saitek ST290 Pro</name>
<name>SAITEK Saitek ST290 Pro</name>
... and it will use the control assignments found in that file to assign functions to each axis and button.
If it doesn't find an XML file for your particular joystick, it will substitute a "generic" one (/Flightgear/data/Input/Joysticks/Default/) which only maps the basic functions of elevator, aileron, rudder (if available), throttle, brakes, and elevator trim. Those assignments may or may not end up in logical-seeming places for your joystick.
2. The problem, as "caused" by Windows XP/Vista.
It seems as if Windows XP and/or Vista tend to report all joystick names as "Microsoft PC-Joystick Driver" regardless of what they are. This may or may not hold true if the user has taken the time to install the manufacturer's specific driver for that device; all feedback we have received so far seems to indicate that Windows defaults to a "generic" MS driver regardless, but your mileage may vary.
If the name is being mis-reported, this then prevents Flightgear from automatically assigning controls logically (using one of its many pre-defined XML bindings files) based on how the various axis numbers are assigned and how the buttons are laid out. Flightgear will then revert to the "generic" (aka default) bindings. For some joysticks the default file might make perfect sense; for others, it might cause odd behavior.
3. The solution; several different approaches.
There are three main solutions to this issue; however, both are similar in that they involve modifying one or more of the .xml files contained under /Flightgear/data/, and that they are both "temporary" solutions which are only good as long as you continue to use the same joystick. If you should change joysticks, you will have to re-employ this solution to allow Flightgear to assign the appropriate "new" XML bindings.
Wordpad is the recommended Windows application with which to do the modification, although Notepad or any other text-based editor usually suffices. Wordpad is usually a better choice because of a difference in the way line-feeds and carriage-returns are represented in one versus the other, but aside from some formatting issues, Notepad should work out okay.
a. Force the Name issue.
The first solution to this issue is to add the name "Microsoft PC-Joystick Driver" to whichever XML bindings file you wish to use. In the above example, you have a Saitek ST290 Pro joystick and would like to use the bindings file which Flightgear provides. In /Flightgear/data/Input/Joysticks/Saitek/ST290-Pro.xml, where you see the following:
- Code: Select all
<name>Saitek ST290 Pro</name>
<name>SAITEK Saitek ST290 Pro</name>
... you would want to add a third <name> tag, the result reading as thus:
- Code: Select all
<name>Saitek ST290 Pro</name>
<name>SAITEK Saitek ST290 Pro</name>
<name>Microsoft PC-Joystick Driver</name>
Thereafter, when Flightgear reads your joystick name as "Microsoft PC-Joystick Driver" and finds the tag <name>Microsoft PC-Joystick Driver</name> in /Flightgear/data/Input/Joysticks/Saitek/ST290-Pro.xml, it will then use that file to assign controls.
b. Override the automatic selection.
Recall in the initial explanation that before Flightgear begins scanning through XML files in /Flightgear/data/Input/Joysticks/, it first checks /Flightgear/data/joysticks.xml for any overriding instructions? This is where you can manually supersede its automatic assignment with a manually-specified filename. You will need to know which virtual position your joystick is in; js_demo will tell you, but if not, you can usually assume "0" and then try other values if the results don't seem to work out. To specify the joystick in position "0" is a Saitek ST-290 Pro, and that you wish to use the XML bindings file Flightgear provides for that model, you would add the following to /Flightgear/data/joysticks.xml, in between the <PropertyList> tags:
- Code: Select all
<PropertyList>
<js n="0" include="Input/Joysticks/Saitek/ST290-Pro.xml"/>
</PropertyList>
EDIT: ... just make sure that the <!-- and --> tags (which tell the program to ignore what's between, as a "comment" or "example") are removed. You want that section of code to be considered "live" code by the program, not a "comment" or "example."
c. Create your own custom control assignments.
My preferred way to deal with joystick axis and button assignments has been to create my own customized bindings file and point js n="0" to it using the method shown above. I start by opening the bindings file for my model of joystick and then re-saving it as /Flightgear/data/Input/Joysticks/custom.xml, and then changing /Flightgear/data/joysticks.xml to read as follows (and you can remove EVERYTHING except what's shown here):
- Code: Select all
<PropertyList>
<js n="0" include="Input/Joysticks/custom.xml"/>
</PropertyList>
In that custom.xml file, I then take note of what controls are currently assigned to each axis and button and make notes as to where each one is physically located. (NOTE: some joysticks have numbers printed on each button; however, those numbers do not necessarily correspond to the numbers that the software assigns to them. The ST290 Pro is an excellent example of this.) Alternately I could use js_demo.exe, if available, to determine which axis and which button are given what numbers.
Then, I use the existing XML file as a template, but modify what appears between each set of <binding></binding> tags to suit my needs. There are many examples of how to accomplish each desired action, and these may be found in the other included XML joystick binding files, or also here on the forums. I personally have borrowed (and further adapted) many ideas I have discovered here on the forums, as well as exploring some of my own, to create what I believe to be a very high-functioning set of controls for the ST290 Pro, even though it has a very limited number of buttons. Here are some I've created or seen in the forum, some of which I have used and some I have not:
- For joysticks that have no rudder control (twist axis), I've seen (a) a binding which automatically changes the left/right stick movement to control the rudder instead of the ailerons when on the ground, as well as (b) a binding that allowed for "auto-coordination" of aileron and rudder controls ONLY while a certain button was depressed (again, to improve ground steering).
For joysticks which have the rudder on twist but don't have the ability to command left- and right-hand wheelbrakes independently (i.e. the wheelbrakes are only available in an on-off mode), I personally have a script with a formula so that when I am simultaneously braking and steering with rudder, the wheelbrakes are applied differentially to assist in ground steering.
For use with FGCOM (voice communication add-on), I have personally mapped the push-to-talk onto the joystick trigger.
For gear-up and down, I personally have a binding which coordinates this with the arrestor hook used in aircraft carrier operations. I also include a ground-altitude check, so that the gear cannot be commanded "up" via joystick when the aircraft is on the ground.
I have seen a binding for a button which, while depressed momentarily, allows the pilot view (cockpit view) to "glance down" at the instrument panel -- a very useful function in aircraft where certain critical gauges are below the default field-of-view.
I have even seen a very complex set of bindings which turn one or more buttons into "Alternate" command buttons -- meaning, that the other buttons have one set of effects if the "Alternate" button is not pressed, versus different effects if it is!
Please feel free to search the forum for, or else ask for, help in using any of the above ideas or any others of your own which you would like to implement. Virtually any command can be mapped to a joystick button, and virtually any "conditional test" can be added to make that button carry out or not carry out that action, depending, or carry out a different action, or even more than one action, as a result.
4. Further information.
To get additional information or help with joysticks, please see the following:
- http://www.flightgear.org/Docs/getstart/getstartch3.html#x8-360003.6
http://wiki.flightgear.org/index.php/Joystick
/Flightgear/data/joysticks.xml (comments section)
viewtopic.php?f=11&t=2402
viewtopic.php?f=11&t=2183
viewtopic.php?f=2&t=2155
viewtopic.php?f=11&t=1708
viewtopic.php?f=11&t=1691
viewtopic.php?f=11&t=1660
viewtopic.php?f=2&t=1114
viewtopic.php?f=2&t=642