[Home]A New Approach For Using Joypads With LinuxCNC

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

A new approach for using joypads with LinuxCNC

One interesting feature is to do manual jogging under LinuxCNC with normal inexpensive joysticks or joypads. Some time ago Manfredi wrote an interesting article in this linux wiki. At that time some effort has to be spent, since there were no "easy to use" hal-components available with the standard distribution. Since then, times have changed, because as there are now newer and easier means of connect to joypads.

In this article, another means will be explained in more detail.

Joysticks / joypads can be coupled to LinuxCNC via two different hal-components: hal_joystick and hal_input. The hal_joystick component was used by Manfredi. Here I will show the use of the hal_input component. Compared to hal_joystick it has some advantages:

+ Seamless integration when loaded in a hal file (race condition avoided)
+ Handle calibrated and uncalibrated joypads
+ Ability to couple to additional input devices like mice or keybords
+ Automatic detection of the input pins of a device
+ Extended parameters like scales, hysteresis, etc.
- More difficult to install

For installation and getting your device name please also look at the manpages (man hal_input) as I only give an example, which worked for me.

As a prerequisite you need a rule in the udevs (dynamic device management) rules folder (/etc/udev/rules.d, use sudo). In my case it is a file called emc_joy.rules (the name can be chosen freely). There must be a line either for the use of various input devices or for a certain device. I used the variant for all devices (see manpages):

SUBSYSTEM="input", mode="0660", group="plugdev"

A file to do this is here: upload:50-input-permissions.rules

Download the file, then open a shell and run `sudo cp <wherever you downloaded it> /etc/udev/rules.d`. If you have already plugged your device in, unplug it and plug it back in so the new rule will take effect.

If I only want to connect my SAITEK P880 joypad, I take the line

SYSFS{idProduct}=="0109", SYSFS{idVendor}=="06a3", MODE="0660", GROUP="plugdev"

Unplug your joypad and plug it in again. Identify the name of your joypad with less /proc/bus/input/devices. In my case it is the SAITEK P880 joypad.

Now set up a hal-file (for example joypad_v3.hal). Write in the line:

loadusr -W hal_input -KRAL SAITEK

(taking a part of the name of the joypad will work, also other input definitions, see manpages)

The -W option is important, as it forces LinuxCNC to wait until this userspace component is fully loaded (hal_ready()). Otherwise it would't find the pins later used in the hal-file, because they are not exported by hal_input at that time.

Set the hal-filename in the ini-files [HAL] section:

HALFILE = joypad_v3.hal

If you start AXIS now and look at the hal you should find the component as "input" or "hal_input" in the components section, and the pins and parameters at the corresponding sections. Note the axes and buttons names you want to use for the hal-file (from hal or hal-meter). Of course you can also use the terminal to find out:

loadusr -W hal_input -KRAL SAITEK
show pin

Before you set up your appropriate hal-file, I want to introduce to you the new hal-component joyhandle that I wrote to further improve the behavior of my joypad. It gives the possibility to set scales, deadbands (hal_input can do that as well) and a nonlinearity in the movement. Thus the axes can be driven very precisely at low speed without losing the full velocity range. The following diagram shows this behavior and the parameters of joyhandle in more detail:


The joyhandle component is of course not limited to joypads but may also serve for other applications.

To use the joyhandle component, compile and install it:

 sudo comp --install joyhandle.comp
this requires that you have previously installed the build-essential and linuxcnc-dev packages (see ContributedComponents for more information)

Now setting up the halfile is straight forward. If you do not want to use joyhandle, please delete or uncomment the corresponding lines. We also use (different to Manfredis approach) the new halui components for manual jogging (set HALUI = halui) in the [HAL] section of the ini-file). Use the names for your pins and axes, you found out earlier.

Please have a look at the joypad_v3.hal file below.

That's it. Optimize the parameter for your needs.

Acknowledgement: I want to thank Jeff Epler for the useful discussion about realtime hal-components and race conditions.

Files: joyhandle.comp, joypad_v3.hal



For suggestions and experiences please contact me under [1].

(I would appreciate, if somebody is going to check the mathematics in the joyhandle-component.)

Note: The joyhandle component is now included when building from source (2.4.0~pre).

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited January 3, 2017 6:07 am by KimK (diff)
Published under a Creative Commons License