# Joystick axis not read using Gamepad function

**URL:** <https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250>\
**Category:** Hardware\
**Tags:** linux\
**Created:** [February 16, 2022, 1:34pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250 "2022-02-16T13:34:18Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![antonicc](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@antonicc](https://psychtoolbox.discourse.group/u/antonicc)\
**Post date:** [February 16, 2022, 1:34pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/1 "2022-02-16T13:34:18Z")

</div>

Hi,

I would like to read a joystick in PTB 3.0.17 on Ubuntu 18.04 with Matlab 2020a. It is a Current Design grip device that is presented as a joystick to the system by its 932 interface.

I followed the instructions in the Gamepad() documentation, installed the xorg joystick package, and set up the 52-MyJoystick.conf file. Using jstest on the command line, I can read the joystick correctly, and it is recognized by PTB (as Gamepad(‘GetGamepadNamesFromIndices’, …) returns the device name). However, when I read the axes with Gamepad(‘GetAxis’, …) it always returns Inf.

I tested this configuration and my script on a different computer (Ubuntu 20.04, Matlab 2021a, PTB 3.0.18) and it works fine. Unfortunately, I cannot update the computer where we would like to read the device.

Do you have any pointers for me, on how I could solve this problem and read the axis? Any advice is highly appreciated!

Thanks,  
Antonius

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [February 16, 2022, 3:49pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/2 "2022-02-16T15:49:39Z")

</div>

Hi Antonius,

given that on Linux, a gamepad is currently indistinguishable from a mouse for PTB – `GetGamePadIndices` returns all mice, touchpads, joysticks etc., maybe you are querying the wrong “gamepad” ie. a mouse or touchpad.

Try this:

`[index, name] = GetGamePadIndices`

Find the name of your grip device in the `name` list. Then, in your code, e.g., if the name was ‘Curdesgrip’, use:

`index = Gamepad ('GetGamepadindicesfromnames', 'Curdesgrip');`

What’s the output of

`v = Gamepad(‘GetAxis’, index, 1);`?

What happens if you follow the approach of `Gamepad GetAxisRawMapping?` ?

Note though that Ubuntu 18.04-LTS and PTB 3.0.17 are no longer officially supported, and any further diagnostic will have to be paid by `help PsychPaidSupportAndServices`, unless the problem and solution is apparent to me within 30 seconds of receiving your reply. Buying one of these would be appreciated anyway, as i’ve already spent two dozen minutes reviewing your case.

-mario

---

<div class="post-metadata">

**Author:** ![antonicc](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@antonicc](https://psychtoolbox.discourse.group/u/antonicc)\
**Post date:** [February 17, 2022, 12:07pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/3 "2022-02-17T12:07:28Z")

</div>

Hi Mario,

thanks for your help, I appreciate it.

Thank you for your suggestion, that’s what I did!

This is the code I use:

`joystickName = 'Current Designs, Inc. 932';`

`numGamepads = Gamepad('GetNumGamepads');`  
`gamepadName = Gamepad('GetGamepadNamesFromIndices', 1:numGamepads);`

`gamepadIndices = Gamepad('GetGamepadIndicesFromNames', joystickName); `  
`gamepadIndices = max(gamepadIndices); `

`numAxes = Gamepad('GetNumAxes', gamepadIndices);`  
`axesIndices = max(numAxes); % usually the last one, but tested all of them`

`% Test 1: Gamepad`  
`axisState = Gamepad('GetAxis', gamepadIndices, axesIndices); % one time before to initialize the function`

`while 1`  
` axisState = Gamepad('GetAxis', gamepadIndices, axesIndices);`  
` fprintf('%i\n', -axisState);`  
`end`

`% Test 2: GetMouse`  
`% This is supposed to be faster, but it is not, according to my test`  
`handles = Gamepad('GetAxisRawMapping', gamepadIndices, axesIndices);`

`while 1`  
` [d1,d2,d3,d4,v] = GetMouse([], handles(1));`  
` rawState = v(handles(2));`  
` fprintf('%i\n', -rawState);`  
`end`

I tested all the axis, with always the same return of Inf. I’ll manually recheck the indexing, maybe there is something I missed.

Is there anything else that comes to your mind, except a device/axis index problem?

Thanks again for your help.

Best,  
Antonius

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [February 17, 2022, 5:10pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/4 "2022-02-17T17:10:25Z")

</div>

> [@mariokleiner](#):
>
> `help PsychPaidSupportAndServices`

for up to a maximum of one hour more of my brain-time. If it works on Ubuntu 20.04-LTS as you already mentioned, then it is not something for me to spend more time on for free on a unsupported old OS and PTB.

---

<div class="post-metadata">

**Author:** ![antonicc](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@antonicc](https://psychtoolbox.discourse.group/u/antonicc)\
**Post date:** [June 9, 2022, 9:10pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/5 "2022-06-09T21:10:46Z")

</div>

Hi Mario,

I wanted to return to this, as I could reproduce the problem under Ubuntu 20.04, Matlab R2021a, and the latest PTB from neurodebian (3.0.18).

We have two computers with this setup and the Current Design 932 interface with a joystick connected.  
On both computers, `jstest /dev/input/js0 ` is correctly reading the axis on bash.

However, `Gamepad('GetNumGamepads')` and `Gamepad('GetGamepadNamesFromIndices'` return on one computer only one device with the name _Current Designs, Inc. 932_, while on the other computer three devices. Weirdly, the third device can be read correctly by `Gamepad('GetAxis')`.

I would be happy to dig into this further, but I would need some pointers on how PTB is determining the names and accessing the devices, also given that it is connected on both computers to `/dev/input/js0 `.

Thank you so much for your help and we really appreciate the work you are doing with Psychtoolbox!

Thanks,  
Antonius

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [June 9, 2022, 10:08pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/6 "2022-06-09T22:08:58Z")

</div>

As mentioned before, `help PsychPaidSupportAndServices` will tell you how to buy some work time from me for further advice. Getting a paid support membership is the best way to express how much labs “really appreciate my work” in a way that is actually helpful for PTB’s continued maintenance.

However, pricing has changed since mid-May, as currently 150 Euro + tax now only buy you 30 minutes, not up 60 minutes anymore. Iow. rates have doubled and we have a discount program to reward labs for demonstrating actual supportive behavior instead of the more popular lip service.

Edit: I should also mention that if you participate in our currently running user survey (see announcements category of the forum), you will get a discount code after survey completion for a slightly reduced price for such a support membership.

Best,  
-mario

---

<div class="post-metadata">

**Author:** ![antonicc](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@antonicc](https://psychtoolbox.discourse.group/u/antonicc)\
**Post date:** [July 1, 2022, 8:35pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/7 "2022-07-01T20:35:39Z")

</div>

Hi Mario,

it would be great if you have an advice for us. The activation key is  
NTTCZCXE-202271223333:c18cab4ebed475e27cd92bd96575732329f70e368a26c566e3f28f4b57e0c0b9

Thank you!

Antonius

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [July 4, 2022, 5:15pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/8 "2022-07-04T17:15:21Z")

</div>

Ok, your license key is now confirmed as activated. This can take up to 10 business days, and i am not in control of that process, so always good to have a valid paid membership available instead of buying it the moment you need support.

Unfortunately there was a long gap of multiple months since you asked for support first until you bought a paid membership, and my memory is not that good, so i had to reread all your posts and reacquaint myself with the issues, starting at zero. Long story short, this has already used up 52 minutes of work time, 22 minutes more than paid for by your purchase, so even before me giving any answers, we are already out of time for this.

I’ll give you 8 more minutes of my time, otherwise you’d have to buy an extra hour packages for 300 Euros + sales tax for every started batch of 60 more minutes of work time, ofc. with no guaranteed success - you pay for my time trying, not for successful resolution of the issue. As your lab doesn’t have any long-running support membership, you are unfortunately also not eligible for a discount.

Nothing obvious stands out in your posts so far that would point to a clear reason for the problems, but lets go on hunches:

I need full output for all machines tested, both the 18.04-LTS, the working 20.04-LTS and the non-working 20.04-LTS.

What is the full output of the `.local/share/xorg/Xorg.0.log` on the two Ubuntu 20.04 LTS machines? I think `/var/log/Xorg.0.log` would be the right location on Ubuntu 18.04 if there isn’t a Xorg.0.log at the same location as on Ubuntu 20.04. My own last 18.04 machine died a few weeks ago, so i can’t test on 18.04 anymore…

What is the full output of the `xinput list --long` command in a terminal on all machines?  
What is the full output of `PsychHID('Devices', 3)` and separately for `PsychHID('Devices', 5)`?

The way joystick queries in Psychtoolbox work, is to treat them as special “weirdo” mouse devices instead of using the low-level kernel joystick driver that is used by the `jstest /dev/input/js0` command. This because it saves a lot of extra implementation work for myself and as a bonus allows us to use all the keyboard queue features we have for keyboards and mice also for joysticks, e.g., automatic timestamped recording of button presses or axis value trajectories.

So we know that your grip devices get correctly recognized and handled by the kernel due to the successfull jstest, but something seems to go wrong on some machines on the way from kernel through X-Server to PsychHID. Although i don’t have a clue yet as to what that would be.

[52 minutes used of 30 minutes paid - Membership license more than used up]  
-mario

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [July 5, 2022, 1:04pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/9 "2022-07-05T13:04:21Z")

</div>

Also, please respond quickly. If i forget all the thoughts i had about the topic and have to spend time to reread everything again, i can’t give you the few bonus minutes and you’d have to buy the expensive 1 hour package for sure for further help. Context switching in at least my brain is expensive.

-mario

---

<div class="post-metadata">

**Author:** ![antonicc](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@antonicc](https://psychtoolbox.discourse.group/u/antonicc)\
**Post date:** [July 5, 2022, 10:51pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/10 "2022-07-05T22:51:33Z")

</div>

Hi,

thanks for these hints. I don’t have regular access to the machines and no admin access on all of them (no installation possible of xinput on the not working machine), so I could only get part of the info you requested.

I uploaded the log files and PsychHID output here:  
[https://www.dropbox.com/s/6ax7d2l0csq3pal/PTBGamepadDebugOutput.zip?dl=1](https://www.dropbox.com/s/6ax7d2l0csq3pal/PTBGamepadDebugOutput.zip?dl=1)

Ubuntu 20.04 is the output of the working Thinkpad, and Ubuntu18.04 is the output of the not working Dell tower.

Thanks,  
Antonius

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [July 6, 2022, 3:35am UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/11 "2022-07-06T03:35:06Z")

</div>

So the good news is i think i know pretty well why it doesn’t work on Ubuntu 18.04. The bad news is that reading through logs etc. took me not 8 minutes, but 1 hour 15 minutes. I give you the 15 minutes for free, but not the additional 1hour, that’s too much.

So you will need to buy one 1 hour extra package for currently 300 Euros + tax for the information. This can be bought under the following link:

> **[Psychtoolbox Paid Support](https://www.digistore24.com/product/433025)**
>
> This product allows you to purchase extra support hours, to receive further suppor …

Post the Order number / license key here, and once we have receipt of payment, I can tell you what i learned. That should hopefully get you unstuck. If not, or for related followup questions, another hour of support would need to be purchased for another 300 Euros + tax to pay for additional work time beyond what i did already.

Best,  
-mario

---

<div class="post-metadata">

**Author:** ![antonicc](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@antonicc](https://psychtoolbox.discourse.group/u/antonicc)\
**Post date:** [July 6, 2022, 1:29pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/12 "2022-07-06T13:29:43Z")

</div>

Hi Mario,

That’s great news, thank you! We will need some time to get the funds, please save the solution for the moment until we get back to this.

Thanks,  
Antonius

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [July 7, 2022, 4:30pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/13 "2022-07-07T16:30:54Z")

</div>

Just don’t wait too long. I took some notes about problem and likely solution, but if i forget the details and my notes would turn out insufficient to jog my memory, or if we’d need more work time to refine/tweak/iterate and I’d have to look at this again from the start, you’d be out for at least another 300 Euros + sales tax for a 2nd extra hour support package…

-mario

---

<div class="post-metadata">

**Author:** ![antonicc](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@antonicc](https://psychtoolbox.discourse.group/u/antonicc)\
**Post date:** [July 26, 2022, 2:17pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/14 "2022-07-26T14:17:07Z")

</div>

Hello,

The new key:

`V5EKCEW6-2022726161342:7620c4caec38787418d8141a5b14d2a7498b8ec66d11c3056e37b21a46ecdb04`

Thanks

Antonius

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [July 26, 2022, 6:27pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/15 "2022-07-26T18:27:26Z")

</div>

Great. Confirmed and accounted as more than used up with over 15 minutes of free work time included. I hope the following information from my notes and memory will be sufficient, otherwise another 300 Euro + tax payment for the next hour would be needed:

Likely reason for failure - user error - and steps to fix:

Your Ubuntu 18.04-LTS machine **does not** have the xorg joystick driver installed, contrary to what you told me, so something must have been missed or gone wrong without you noticing. The clue was these lines in the XOrg.0.log file (file “XOrg\_Ubuntu18.04.log”) you sent me:

[427.370] (\*\*) Current Designs, Inc. 932: Applying InputClass “My Joystick configuration”  
[427.370] (II) LoadModule: “joystick”  
[427.370] (WW) Warning, couldn’t open module joystick  
[427.370] (II) UnloadModule: “joystick”  
[427.370] (II) Unloading joystick  
[427.370] (EE) Failed to load module “joystick” (module does not exist, 0)  
[427.370] (EE) No input driver matching `joystick' [427.370] (II) Falling back to input driver `libinput’  
[427.370] (II) Using input driver ‘libinput’ for ‘Current Designs, Inc. 932’

→ “module does not exist” → No such driver installed → Then it falls back to the standard libinput driver, which doesn’t treat your joystick in a useable way. → Game over!

You can see the different behaviour in the log when searching for “joystick” on the machine where it worked.

I made some additional refinements to joystick matching in an improved GetGamepadIndices.m file, based on your results and some testing with a X-Box game controller here.

So steps to resolve this on your Ubuntu 18.04-LTS machine:

1. `sudo apt-get install xserver-xorg-input-joystick`
2. Make sure you don’t get errors, make sure the custom joystick config file from Psychtoolbox Psychtoolbox/PsychContributed/52-MyLinuxJoystick.conf is properly installed in /etc/X11/xorg.conf.d/ then logout and login again.
3. Download the new/refined GetGamepadIndices.m file from:  
[https://raw.githubusercontent.com/kleinerm/Psychtoolbox-3/master/Psychtoolbox/PsychHardware/GetGamepadIndices.m](https://raw.githubusercontent.com/kleinerm/Psychtoolbox-3/master/Psychtoolbox/PsychHardware/GetGamepadIndices.m)
4. Put it into the Psychtoolbox/PsychHardware/ subfolder as a replacement for the original. This should do better device filtering and only return true joystick devices (ie. controllers with at least one axis).
5. GetGamepadIndices should return exactly the right joystick device, and Gamepad should be able to deal with it.

Using the new GetGamepadIndices.m for your Ubuntu 20.04 machines will also make things more easy/foolproof. This file will be included in future PTB releases.

Hope it helps. Otherwise you now know how to buy the next extra hour.

Best,  
-mario

[Paid support fully exhausted]

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [August 13, 2022, 5:37pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/16 "2022-08-13T17:37:53Z")

</div>

After 18 days without a response I assume the problem was successfully resolved and will soon delete my notes wrt. this issue.

---

<div class="post-metadata">

**Author:** ![antonicc](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@antonicc](https://psychtoolbox.discourse.group/u/antonicc)\
**Post date:** [September 15, 2022, 11:27am UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/17 "2022-09-15T11:27:54Z")

</div>

Hello,

I don’t have regular access to the machine and I only could test this now. I can confirm that installing the package and using the updated function solved the problem.

Best,  
Antonius

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [September 27, 2022, 1:46pm UTC](https://psychtoolbox.discourse.group/t/joystick-axis-not-read-using-gamepad-function/4250/18 "2022-09-27T13:46:50Z")

</div>

Great. Case closed.  
-mario
