Difference between revisions of "Linux Joysticks and Gamepads"

From Elite Wiki
(Updating BB links)
(Major update for modern distros)
Line 1: Line 1:
 
[[File:PS3 Controller.jpeg|right|320px]]
 
[[File:PS3 Controller.jpeg|right|320px]]
== Setting up a Joystick or Gamepad in Oolite ==
+
== Overview ==
<br>
 
Linux distributions, nowadays, have many joystick and gamepad drivers built in. However, even if they work out of the box, they offer limited configuration options. An alternative to the xpad kernel driver is the [[http://pingus.seul.org/~grumbel/xboxdrv/ XBoxDrv]]. It is a user-space driver, giving a variety of configuration options for all controllers. For XBox controllers, this alternative works without the need of having a Linux distribution with XBox controller support.<br><br>
 
  
The instructions below describe how to set up XBoxDrv for use with an XBox 360 controller on Ubuntu Lucid, nevertheless, the XBoxDrv author has extended it to also work with non-XBox controllers. If anyone gets it to work with a non-XBox controller, feel free to expand this wiki page with any information helpful to others trying to do the same.<br>
+
Generally speaking, Linux is quite good with joystick and gamepad detection and support, but sometimes things can go wrong. Failing to detect a joystick at all is fairly uncommon, and most reported problems revolve around button detection/assignment, and/or axis range. This article provides information on setting up game controllers so that they work well in Oolite Linux.
''(quote from xboxdrv changelog: support for reading from evdev, this allows the use of regular PC joysticks or the Playstation 3 controllers with xboxdrv, useful if you need configurability or joy2key-like functionality, but don't have a Xbox360 gamepad.)''<br><br>
 
  
1. Install [[http://pingus.seul.org/~grumbel/xboxdrv/ XBoxDrv]] - for Ubuntu there is a binary package. Installation instructions are [[http://github.com/Grumbel/xboxdrv/blob/master/README here]].<br><br>
+
== Calibrating a Joystick or Gamepad ==
2. Don't worry about all the stuff about sudo modprobe uinput and changing permissions on /dev/uinput etc.<br><br>
 
3. Download [[http://www.box.com/shared/koxvusxtap runxboxdrv]], a wrapper I wrote to make using xboxdrv very simple. Hopefully, this will be included in a future release of XBoxDrv.<br><br>
 
4. Also in the download are an Oolite configuration for xboxdrv: oolite.ini and a key configuration for Oolite to go with it: [[Oolite_Keyboard_Controls|keyconfig.plist]]<br><br>
 
5. Extract them to your home folder and move keyconfig.plist to ~/.Oolite/Addons<br><br>
 
6. Make runxboxdrv executable:
 
$ chmod +x ~/runxboxdrv
 
<br>
 
7. Execute the following to get the oolite executable path: ''(the oolite executable path may vary depending to your installation)''
 
$ which oolite
 
/usr/bin/oolite
 
$
 
and then execute:  ''(for the sake of this tutorial we will assume the path /usr/bin/oolite.)''
 
$ ~/runxboxdrv --config=~/oolite.ini /usr/bin/oolite
 
<br>
 
8. The only joystick setup needed in Oolite is to set up the axes. The left hand analog stick left-right should be roll. The right hand stick is up, down, left, right.<br><br>
 
9. Open oolite.ini in a text editor to see the mappings of everything else. Descriptions of the option names can be found at [[http://pingus.seul.org/~grumbel/xboxdrv/xboxdrv.html xboxdrv manpage]]<br><br>
 
10. The left shoulder button acts like a shift key and effectively almost doubles the number of buttons.<br><br>
 
  
If you have any problems, post on the [[https://bb.oolite.space/viewforum.php?f=9 Oolite Linux Forum]].
+
Although Oolite provides options to set up dead zones, a full calibration within the game is not possible. The best way to calibrate game controllers on Linux is using a utility such as [[https://github.com/Grumbel/jstest-gtk jstest-gtk]] which will probably be present in your distribution's Software Manager. Launch the ''jstest-gtk'' gui (it will probably be located in the System Menu) and, underneath the name of your joystick, it will list the device details, such as "Device:/dev/input/js0". Keep a record of this device information.
 +
 
 +
After calibrating and before closing the gui, execute the following command to store the calibration information:
 +
 +
sudo jscal-store /dev/input/js0
 +
 
 +
Ensure you use the device information you recorded earlier.
 +
 
 +
== Button Detection & Axis Range Problems ==
 +
 
 +
For unknown reasons, it appears that sometimes SDL ([https://www.libsdl.org/ Simple DirectMedia Layer]) (which is used by Oolite) takes raw input from the evdev device drivers, instead of using the correct joystick device. If this happens, then the calibration will be ignored. By adding the appropriate environment variable to either the ''/etc/environment'' file, or the ''.bashrc'' startup script, you can force SDL to use the "real" joystick driver for input.
 +
 
 +
[https://help.ubuntu.com/community/EnvironmentVariables Officially speaking], ''/etc/environment'' is the correct place for system-wide environment variables. To add the environment variable to the ''/etc/environment'' file, '''as root''', open ''/etc/environment'' in your text editor, add the following (on a new line) to the file, and save:
 +
 
 +
SDL_JOYSTICK_DEVICE="/dev/input/js0"
 +
 
 +
Again, use the device information you recorded earlier.
 +
 
 +
For the change to 'take', you then need to log out and back in again. Rebooting is unnecessary.
 +
 
 +
If you prefer changing the ''.bashrc'' startup script instead, you should add the above line to ''.bashrc'' in your ''Home'' folder. As the dot in front of the filename indicates, this is a hidden file, so you may need to set the view in your file browser to "Show Hidden Files" before it will become visible. Once done, save the file and log out, then back in.
 +
 
 +
== Using Saved Calibration ==
 +
 
 +
The calibration will be forgotten after rebooting, so to ensure the saved calibration is used, make a bash script called for example ''run_oolite'' with:
 +
 
 +
#!/bin/bash
 +
jscal-restore /dev/input/js0
 +
cd ${1%/*}
 +
$1
 +
 
 +
Make that script executable and then you can run Oolite assuming ''run_oolite"" is in your path, using:
 +
 
 +
run_oolite PATH_TO_OOLITE
 +
 
 +
PATH_TO_OOLITE can be something like ''/home/USERNAME/GNUstep/Applications/Oolite/oolite''
 +
 
 +
If you are using the [[https://github.com/OoliteProject/OoliteStarter Oolite Starter]] then replace PATH_TO_OOLITE with PATH_TO_OOLITE_STARTER (which may look something like: /opt/oolitestarter-innocuous/bin/OoliteStarter_innocuous)
 +
 
 +
== Mapping Axes and Buttons to Keyboard Key Presses ==
 +
 
 +
Sometimes it is desirable to have an axis act more like a keyboard key press, for example to increase and decrease speed. This can be achieved with the utility [[https://github.com/AntiMicroX/antimicrox AntiMicroX]], a graphical program used to map gamepad keys to keyboard, mouse, scripts and macros. More information on keyboard controls can be found [[https://wiki.alioth.net/index.php/Oolite_Keyboard_Controls here]]. Once you have set up AntiMicroX the way you want, you can use your configuration by modifying the ''run_oolite"" script described earlier:
 +
 
 +
#!/bin/bash
 +
jscal-restore /dev/input/js0
 +
antimicrox --tray &
 +
cd ${1%/*}
 +
$1
 +
 
 +
== Other problems ==
 +
 
 +
Should you require further guidance in creating or editing the above files, or the methods given above fail to resolve, or don't address your particular problem, please don't hesitate to post a thread detailing the issue, and your attempts to fix it, to the [https://bb.oolite.space/viewforum.php?f=9 Oolite-Linux forum]. The forum has several Linux gurus available, who would be more than happy to assist.
  
 
== Links ==
 
== Links ==
*[https://bb.oolite.space/viewtopic.php?p=218983#p218983 Original discussion]
 
*[[Joystick problems (Linux)]]
 
 
*[[Joysticks and Gamepads]]
 
*[[Joysticks and Gamepads]]
 
*[[Joysticks: Guide to Setting Up]]
 
*[[Joysticks: Guide to Setting Up]]

Revision as of 05:16, 14 July 2025

PS3 Controller.jpeg

Overview

Generally speaking, Linux is quite good with joystick and gamepad detection and support, but sometimes things can go wrong. Failing to detect a joystick at all is fairly uncommon, and most reported problems revolve around button detection/assignment, and/or axis range. This article provides information on setting up game controllers so that they work well in Oolite Linux.

Calibrating a Joystick or Gamepad

Although Oolite provides options to set up dead zones, a full calibration within the game is not possible. The best way to calibrate game controllers on Linux is using a utility such as [jstest-gtk] which will probably be present in your distribution's Software Manager. Launch the jstest-gtk gui (it will probably be located in the System Menu) and, underneath the name of your joystick, it will list the device details, such as "Device:/dev/input/js0". Keep a record of this device information.

After calibrating and before closing the gui, execute the following command to store the calibration information:

sudo jscal-store /dev/input/js0

Ensure you use the device information you recorded earlier.

Button Detection & Axis Range Problems

For unknown reasons, it appears that sometimes SDL (Simple DirectMedia Layer) (which is used by Oolite) takes raw input from the evdev device drivers, instead of using the correct joystick device. If this happens, then the calibration will be ignored. By adding the appropriate environment variable to either the /etc/environment file, or the .bashrc startup script, you can force SDL to use the "real" joystick driver for input.

Officially speaking, /etc/environment is the correct place for system-wide environment variables. To add the environment variable to the /etc/environment file, as root, open /etc/environment in your text editor, add the following (on a new line) to the file, and save:

SDL_JOYSTICK_DEVICE="/dev/input/js0"

Again, use the device information you recorded earlier.

For the change to 'take', you then need to log out and back in again. Rebooting is unnecessary.

If you prefer changing the .bashrc startup script instead, you should add the above line to .bashrc in your Home folder. As the dot in front of the filename indicates, this is a hidden file, so you may need to set the view in your file browser to "Show Hidden Files" before it will become visible. Once done, save the file and log out, then back in.

Using Saved Calibration

The calibration will be forgotten after rebooting, so to ensure the saved calibration is used, make a bash script called for example run_oolite with:

#!/bin/bash
jscal-restore /dev/input/js0
cd ${1%/*}
$1

Make that script executable and then you can run Oolite assuming run_oolite"" is in your path, using:

run_oolite PATH_TO_OOLITE

PATH_TO_OOLITE can be something like /home/USERNAME/GNUstep/Applications/Oolite/oolite

If you are using the [Oolite Starter] then replace PATH_TO_OOLITE with PATH_TO_OOLITE_STARTER (which may look something like: /opt/oolitestarter-innocuous/bin/OoliteStarter_innocuous)

Mapping Axes and Buttons to Keyboard Key Presses

Sometimes it is desirable to have an axis act more like a keyboard key press, for example to increase and decrease speed. This can be achieved with the utility [AntiMicroX], a graphical program used to map gamepad keys to keyboard, mouse, scripts and macros. More information on keyboard controls can be found [here]. Once you have set up AntiMicroX the way you want, you can use your configuration by modifying the run_oolite"" script described earlier:

#!/bin/bash
jscal-restore /dev/input/js0
antimicrox --tray &
cd ${1%/*}
$1

Other problems

Should you require further guidance in creating or editing the above files, or the methods given above fail to resolve, or don't address your particular problem, please don't hesitate to post a thread detailing the issue, and your attempts to fix it, to the Oolite-Linux forum. The forum has several Linux gurus available, who would be more than happy to assist.

Links