Difference between revisions of "Linux Joysticks and Gamepads"

From Elite Wiki
m (Setting up a Joystick or Gamepad in Oolite)
m
 
(16 intermediate revisions by 6 users not shown)
Line 1: Line 1:
== Setting up a Joystick or Gamepad in Oolite ==
+
[[File:PS3 Controller.jpeg|right|320px]]
<br>
+
== Overview ==
Linux distributions such as Ubuntu Lucid have many joystick and gamepad drivers built in. While they work out of the box, they offer limited configurability. Here I will outline a better alternative which gives far greater configurability for all controllers. For XBox controllers, the alternative works irrespective of whether your Linux distribution includes XBox controller support.<br><br>
 
  
The instructions below describe how to set up a userspace driver called xboxdrv for use with an XBox 360 controller. The author of xboxdrv has extended it to also work with non-XBox controllers, so if anyone tries this with a non-XBox controller and gets it to work, please expand this wiki page with any information helpful to others trying to do the same. (xboxdrv author wrote: 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>
+
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.
  
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.net/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: keyconfig.plist<br><br>
 
5. Extract them to your home folder and move keyconfig.plist to ~/.Oolite/Addons<br><br>
 
6. Make runxboxdrv executable eg. chmod +x ~/runxboxdrv<br><br>
 
7. Run from a menu icon or shell using: ~/runxboxdrv --config=~/oolite.ini /usr/bin/oolite<br><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 [[http://www.aegidian.org/bb/viewforum.php?f=3 Forums]].
+
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.
  
[[Category:Oolite]]
+
After calibrating and before closing the gui, execute the following command in a shell to store the calibration information:
 +
 +
sudo jscal-store /dev/input/js0
 +
 
 +
Ensure you use the device information you recorded earlier in place of ''/dev/input/js0''.
 +
 
 +
== Button Detection & Axis Range Problems ==
 +
 
 +
If your calibration is ignored, then you need to do the following: add the appropriate environment variable to either the ''/etc/environment'' file, or the ''.bashrc'' startup script.
 +
 
 +
[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.
 +
 
 +
Explanation: Oolite uses [https://www.libsdl.org/ Simple DirectMedia Layer (SDL)]. For unknown reasons, it appears that sometimes SDL takes raw input from the evdev device drivers, instead of using the correct joystick device. This fix forces SDL to use the "real" joystick driver for input.
 +
 
 +
== Using Saved Calibration ==
 +
 
 +
The calibration will be forgotten after rebooting, so to ensure the saved calibration is used, make a file called for example ''run_oolite'' with the following contents:
 +
 
 +
#!/bin/bash
 +
jscal-restore /dev/input/js0
 +
cd ${1%/*}
 +
$1
 +
 
 +
Again, use the device information you recorded earlier. Save the file (which is a bash script) in a folder which is in your system's ''PATH'' or you can save it in the same folder as the ''oolite'' executable. The ''oolite'' executable is located in a folder like this: ''/home/USERNAME/GNUstep/Applications/Oolite/'' which hereafter we'll call ''OOLITE_FOLDER''. Make that file executable (which can usually be done in your distro's file explorer by right clicking on the file and choosing to edit Permissions). Then you can run Oolite in a shell using:
 +
 
 +
OOLITE_FOLDER/run_oolite OOLITE_FOLDER/oolite
 +
 
 +
The first ''OOLITE_FOLDER'' in the command above should be removed if ''run_oolite'' is in your system's ''PATH''.
 +
 
 +
If you are using the [https://github.com/OoliteProject/OoliteStarter Oolite Starter] then replace ''OOLITE_FOLDER/oolite'' with the path to Oolite Starter which will 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 joystick and gamepad controls to keyboard, mouse, scripts and macros. More information on Oolite's default 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
 +
 
 +
Again, use the device information you recorded earlier.
 +
 
 +
== 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 ==
 +
*[[Joysticks and Gamepads]]
 +
*[[Joysticks: Guide to Setting Up]]
 +
*[[Dizzy's guide to Setting up Joystick Axis Profiles]]
 +
*[[Keyboard Issues]]
 +
 
 +
[[Category:Oolite]][[Category:Help pages]]

Latest revision as of 22:12, 15 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 in a shell to store the calibration information:

sudo jscal-store /dev/input/js0

Ensure you use the device information you recorded earlier in place of /dev/input/js0.

Button Detection & Axis Range Problems

If your calibration is ignored, then you need to do the following: add the appropriate environment variable to either the /etc/environment file, or the .bashrc startup script.

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.

Explanation: Oolite uses Simple DirectMedia Layer (SDL). For unknown reasons, it appears that sometimes SDL takes raw input from the evdev device drivers, instead of using the correct joystick device. This fix forces SDL to use the "real" joystick driver for input.

Using Saved Calibration

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

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

Again, use the device information you recorded earlier. Save the file (which is a bash script) in a folder which is in your system's PATH or you can save it in the same folder as the oolite executable. The oolite executable is located in a folder like this: /home/USERNAME/GNUstep/Applications/Oolite/ which hereafter we'll call OOLITE_FOLDER. Make that file executable (which can usually be done in your distro's file explorer by right clicking on the file and choosing to edit Permissions). Then you can run Oolite in a shell using:

OOLITE_FOLDER/run_oolite OOLITE_FOLDER/oolite

The first OOLITE_FOLDER in the command above should be removed if run_oolite is in your system's PATH.

If you are using the Oolite Starter then replace OOLITE_FOLDER/oolite with the path to Oolite Starter which will 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 joystick and gamepad controls to keyboard, mouse, scripts and macros. More information on Oolite's default 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

Again, use the device information you recorded earlier.

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