Input device: Difference between revisions

Jump to navigation Jump to search
m
Robot: Cosmetic changes
m (Language link)
m (Robot: Cosmetic changes)
Line 5: Line 5:
Unfortunately, given the several combinations of operating systems supported by FlightGear (possibly in foreign languages) and joysticks available, chances are your joystick does not work out of the box. Basically, there are two alternative approaches to get it going, with the first one being preferred.
Unfortunately, given the several combinations of operating systems supported by FlightGear (possibly in foreign languages) and joysticks available, chances are your joystick does not work out of the box. Basically, there are two alternative approaches to get it going, with the first one being preferred.


==Built-in joystick support==
== Built-in joystick support ==


===General remarks===
=== General remarks ===
In order for joystick auto-detection to work, a joystick bindings xml file must exist for each joystick. This file describes what axes and buttons are to be used to control which functions in FlightGear. The associations between functions and axes or buttons are called “bindings”. This bindings file can have any name as long as a corresponding entry exists in the joysticks description file  
In order for joystick auto-detection to work, a joystick bindings xml file must exist for each joystick. This file describes what axes and buttons are to be used to control which functions in FlightGear. The associations between functions and axes or buttons are called “bindings”. This bindings file can have any name as long as a corresponding entry exists in the joysticks description file  


Line 20: Line 20:
for a file that might work for your joystick. If such a file exists and your joystick is working with other applications, then it should work with FlightGear the first time you run it. If such a file does not exist, then we will discuss in a later section how to create such a file by cutting and pasting bindings from the examples that are included with FlightGear.
for a file that might work for your joystick. If such a file exists and your joystick is working with other applications, then it should work with FlightGear the first time you run it. If such a file does not exist, then we will discuss in a later section how to create such a file by cutting and pasting bindings from the examples that are included with FlightGear.


===Verifying your joystick is working===
=== Verifying your joystick is working ===
Does your computer see your joystick? One way to answer this question under Linux is to reboot your system and immediately enter on the [[command line]]  
Does your computer see your joystick? One way to answer this question under Linux is to reboot your system and immediately enter on the [[command line]]  


Line 31: Line 31:
This line tells us that a joystick has identified itself as SAITEK CYBORG 3D USB to the operating system. It does not tell us that the joystick driver sees your joystick. If you are working under Windows, the method above does not work. Go to <tt>Start > Controlpanel > Game Controller</tt> instead and see whether the dialog displays (and responses) on your joystick.  
This line tells us that a joystick has identified itself as SAITEK CYBORG 3D USB to the operating system. It does not tell us that the joystick driver sees your joystick. If you are working under Windows, the method above does not work. Go to <tt>Start > Controlpanel > Game Controller</tt> instead and see whether the dialog displays (and responses) on your joystick.  


===Confirming that the driver recognizes your joystick===
=== Confirming that the driver recognizes your joystick ===
FlightGear ships with a utility called js_demo. It will report the number of joysticks attached to a system, their respective “names”, and their capabilities. Under Linux, you can run js_demo from the folder /FlightGear/bin as follows:  
FlightGear ships with a utility called js_demo. It will report the number of joysticks attached to a system, their respective “names”, and their capabilities. Under Linux, you can run js_demo from the folder /FlightGear/bin as follows:  


Line 43: Line 43:
  js_demo.exe  
  js_demo.exe  


If js_demo.exe is not included in your version, download it [http://fgfs.beggabaur.de/forum/js_demo.exe here].
If js_demo.exe is not included in your version, download it [http://fgfs.beggabaur.de/forum/js_demo.exe here].


On our system, the first few lines of output are (stop the program with C if it is quickly scrolling past your window!) as follows:  
On our system, the first few lines of output are (stop the program with C if it is quickly scrolling past your window!) as follows:  
Line 64: Line 64:
First note that js demo reports which number is assigned to each joystick recognized by the driver. Also, note that the “name” each joystick reports is also included between quotes. We will need the names for each bindings file when we begin writing the binding xml files for each joystick.
First note that js demo reports which number is assigned to each joystick recognized by the driver. Also, note that the “name” each joystick reports is also included between quotes. We will need the names for each bindings file when we begin writing the binding xml files for each joystick.


===Identifying the numbering of axes and buttons===
=== Identifying the numbering of axes and buttons ===
Axis and button numbers can be identified using js demo as follows. By observing the output of js demo while working your joystick axes and buttons you can determine what axis and button numbers are assigned to each joystick axis and button. It should be noted that numbering generally starts with zero.  
Axis and button numbers can be identified using js demo as follows. By observing the output of js demo while working your joystick axes and buttons you can determine what axis and button numbers are assigned to each joystick axis and button. It should be noted that numbering generally starts with zero.  


Line 93: Line 93:
When you move any control, the numbers change after the axis number corresponding to that moving control and when you depress any button, the “off” after the button number corresponding to the button pressed changes to “on”. In this way, you can quickly write down the axes numbers and button numbers for each function without messing with binary.
When you move any control, the numbers change after the axis number corresponding to that moving control and when you depress any button, the “off” after the button number corresponding to the button pressed changes to “on”. In this way, you can quickly write down the axes numbers and button numbers for each function without messing with binary.


===Writing or editing joystick binding xml files===
=== Writing or editing joystick binding xml files ===
At this point, you have confirmed that the operating system and the joystick driver both recognize your joystick(s). You also know of several ways to identify the joystick “name” your joystick reports to the driver and operating system. You will need a written list of what control functions you wish to have assigned to which axis and button and the corresponding numbers.  
At this point, you have confirmed that the operating system and the joystick driver both recognize your joystick(s). You also know of several ways to identify the joystick “name” your joystick reports to the driver and operating system. You will need a written list of what control functions you wish to have assigned to which axis and button and the corresponding numbers.  


Line 182: Line 182:
Several users have reported that the numbers of axes and buttons assigned to functions may be different with the same joystick under Windows and Linux. The above procedure should allow one to easily change a binding xml file created for a different operating system for use by their operating system.
Several users have reported that the numbers of axes and buttons assigned to functions may be different with the same joystick under Windows and Linux. The above procedure should allow one to easily change a binding xml file created for a different operating system for use by their operating system.


===Telling FlightGear about your new bindings xml file===
=== Telling FlightGear about your new bindings xml file ===
Before FlightGear can use your new xml file, you need to edit the file  
Before FlightGear can use your new xml file, you need to edit the file  


Line 193: Line 193:
You can tell how FlightGear has interpretted your joystick setup by selecting Help -> Joystick Information from the Menu.
You can tell how FlightGear has interpretted your joystick setup by selecting Help -> Joystick Information from the Menu.


===Some hints for Windows users===
=== Some hints for Windows users ===
Basically, the procedures described above should work for Windows as well. If your joystick/yoke/pedals work out of the box or if you get it to work using the methods above, fine. Unfortunately there may be a few problems.  
Basically, the procedures described above should work for Windows as well. If your joystick/yoke/pedals work out of the box or if you get it to work using the methods above, fine. Unfortunately there may be a few problems.  


Line 206: Line 206:
Unfortunately, we did not find a way to get the pedals to work, too, that way. Thus, in cases like this one (and others) you may want to try an alternative method of assigning joystick controls.
Unfortunately, we did not find a way to get the pedals to work, too, that way. Thus, in cases like this one (and others) you may want to try an alternative method of assigning joystick controls.


==Joystick support via .fgfsrc entries==
== Joystick support via .fgfsrc entries ==
Fortunately, there is a tool available now, which takes most of the burden from the average user who, maybe, is not that experienced with XML, the language which these files are written in.  
Fortunately, there is a tool available now, which takes most of the burden from the average user who, maybe, is not that experienced with XML, the language which these files are written in.  


Line 281: Line 281:
You should be able to at least get your joystick working along these lines. Concerning all the finer points, for instance, getting the joystick buttons working, John Check has written a very useful README being included in the base package to be found under '''FlightGear/Docs/Readme/Joystick.html'''. In case of any trouble with your input device, it is highly recommended to have a look into this document.
You should be able to at least get your joystick working along these lines. Concerning all the finer points, for instance, getting the joystick buttons working, John Check has written a very useful README being included in the base package to be found under '''FlightGear/Docs/Readme/Joystick.html'''. In case of any trouble with your input device, it is highly recommended to have a look into this document.


==More about programming joystick XML files==
== More about programming joystick XML files ==
===General tips===
=== General tips ===
* When testing a new xml file it is best to start FlightGear via a command window (rather than the GUI interface). Any error messages will then be displayed in the terminal. Error messages will give both a message and a line number, helping you pinpoint any errors.
* When testing a new xml file it is best to start FlightGear via a command window (rather than the GUI interface). Any error messages will then be displayed in the terminal. Error messages will give both a message and a line number, helping you pinpoint any errors.


* Errors can be detected on initial startup or at runtime. Both types of errors will be displayed in the terminal.
* Errors can be detected on initial startup or at runtime. Both types of errors will be displayed in the terminal.


* One of the most common errors is including a character that makes XML choke. Such characters include  
* One of the most common errors is including a character that makes XML choke. Such characters include  
  & < --
  & < --


Line 294: Line 294:
* If your scripts contain any of these characters, you have to enclose the scripts in <script><![CDATA[...]]></script>. Alternatively, you can 'escape' the characters, ie "<" becomes "&lt;".
* If your scripts contain any of these characters, you have to enclose the scripts in <script><![CDATA[...]]></script>. Alternatively, you can 'escape' the characters, ie "<" becomes "&lt;".


* Note that as of ver 1.9.1 there appears to be no way to tell FlightGear to reload joystick files at runtime. So to test any changes to your file you must exit FlightGear and re-start, a somewhat time-consuming process.
* Note that as of ver 1.9.1 there appears to be no way to tell FlightGear to reload joystick files at runtime. So to test any changes to your file you must exit FlightGear and re-start, a somewhat time-consuming process.


* You can find many examples of different ways to program joysticks simply by examining the joystick xml files that are packaged with FlightGear. See the directory FlightGear/data/input/joysticks
* You can find many examples of different ways to program joysticks simply by examining the joystick xml files that are packaged with FlightGear. See the directory FlightGear/data/input/joysticks


* Many advanced functions can be programmed using the Nasal scripting language. These scripts are enclosed in <script></script> tags in the XML file. Helpful:
* Many advanced functions can be programmed using the Nasal scripting language. These scripts are enclosed in <script></script> tags in the XML file. Helpful:
** A guide to the [[Nasal scripting language]] in FlightGear  
** A guide to the [[Nasal scripting language]] in FlightGear  
** [[Nasal FAQ]]
** [[Nasal FAQ]]
Line 309: Line 309:
* All Nasal code shares a common namespace, so it's possible to set a variable in one nasal binding, and to read it in another.
* All Nasal code shares a common namespace, so it's possible to set a variable in one nasal binding, and to read it in another.


===Useful hints for scripts===
=== Useful hints for scripts ===
Some particularly useful ideas for programming scripts within joystick XML files:
Some particularly useful ideas for programming scripts within joystick XML files:
* getprop and setprop can be used for getting & setting properties from the internal properties tree:
* getprop and setprop can be used for getting & setting properties from the internal properties tree:
Line 323: Line 323:
  print("Just", " a ", "test");
  print("Just", " a ", "test");


* You can display info in FlightGear via a popup. This is useful for giving the user feedback about changes that may not be obvious via the panel. It can also be useful for debugging. Example:
* You can display info in FlightGear via a popup. This is useful for giving the user feedback about changes that may not be obvious via the panel. It can also be useful for debugging. Example:


  gui.popupTip("Parking Brake ON");
  gui.popupTip("Parking Brake ON");
Line 344: Line 344:
Note that "var" creates variables that are local in scope, which may cause problems if you are intending to use a variable globally among all different bindings in your joystick XML file.
Note that "var" creates variables that are local in scope, which may cause problems if you are intending to use a variable globally among all different bindings in your joystick XML file.


* You can include a section of script that runs on startup to initialize variables, create functions, etc. Example:
* You can include a section of script that runs on startup to initialize variables, create functions, etc. Example:
  <PropertyList>
  <PropertyList>
   <name type="string">My joystick name</name>
   <name type="string">My joystick name</name>
Line 360: Line 360:
* Sample code for firing weapons with the joystick is found on the [[Gun Effects]] page.
* Sample code for firing weapons with the joystick is found on the [[Gun Effects]] page.


==Resource==
== Resource ==
* [http://www.flightgear.org/Docs/getstart/getstartch3.html#x8-360003.6 The FlightGear Manual]
* [http://www.flightgear.org/Docs/getstart/getstartch3.html#x8-360003.6 The FlightGear Manual]
== External Links ==
== External Links ==

Navigation menu