Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Xbox 360 controller: invalid axis values (linux)  (Read 3906 times)

0 Members and 1 Guest are viewing this topic.

frosty

  • Newbie
  • *
  • Posts: 13
    • View Profile
Xbox 360 controller: invalid axis values (linux)
« on: February 03, 2015, 05:22:26 pm »
Hello,

I started digging into coding gamepad support for my game, but ran into some issues, particularly with getting seemingly bad values from the axis inputs on my (brand new) Xbox 360 wired controller.

When I compile and start my program, I see the following printed to stdout:

Quote
Unable to get joystick attribute. Could not find USB device for joystick at index 0.
Unable to get joystick attribute. Could not find USB device for joystick at index 0.

When I query the values of sf::Joystick::getIdentification(0), I get the following:

Quote
name: Microsoft X-Box 360 pad
vendorId: 0
productId: 0

I am able to see input occurring from all of the buttons and axis, however the state of the axis appear to be incorrect. In the resting/center position, either of the axis will return values anywhere across the spectrum, from -1 to 1.

For example:

sf::Joystick::update()
float x = sf::Joystick::getAxisPosition(0, sf::Joystick::X);
float y = sf::Joystick::getAxisPosition(0, sf::Joystick::Y);

sf::Vector2f normalized = normalize(x, y);

Output at resting/center position (not touching the controller):

Quote
x: -0.977409
y: 0.211355

If I move the controller around and then release it back to the resting state, it will give a totally different set of nonzero values. At least one of the x/y axis is typically pegged at around 0.9 (or -0.9).

Interestingly, I plugged in another generic controller with a similar layout (an old Belkin Nostromo N45) and it works fine with the same code, giving zero values in the center position and normal/expected values throughout it's movement range (although SFML outputs the same warning message about not finding the USB device).

However, the Xbox gamepad works great and behaves as expected in all other games on my system, so I don't think it's faulty controller hardware.

I'm running the latest SFML (built from github source) on Archlinux x86_64. The xpad driver module is automatically loaded.
« Last Edit: February 03, 2015, 05:29:47 pm by frosty »

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: Xbox 360 controller: invalid axis values (linux)
« Reply #1 on: February 03, 2015, 05:46:29 pm »
Maybe related to this? I get weird results in Ubuntu with the 360 controller too.

frosty

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Xbox 360 controller: invalid axis values (linux)
« Reply #2 on: February 03, 2015, 08:45:43 pm »
Maybe related to this? I get weird results in Ubuntu with the 360 controller too.

It does sound like a similar issue. However it sounds like you are getting random values from a phantom controller that isn't actually connected? Whereas my controller is connected except it's getting nonsensical values from the axis control.

The error message displayed at the console is the same however.

I'll post a comment over there as well just in case.
« Last Edit: February 03, 2015, 08:54:37 pm by frosty »

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: Xbox 360 controller: invalid axis values (linux)
« Reply #3 on: February 03, 2015, 09:22:04 pm »
I think the problem I mentioned is related to the linux switch to xcb. Do you still have the problem if you use an older version of sfml? (I think the 2.2 tag is pre-xcb). Also do the random values change as you move the controller axis as if it is reading the controller, but wrongly, or are the values just random regardless.. as if the controller may as well not be connected?

frosty

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Xbox 360 controller: invalid axis values (linux)
« Reply #4 on: February 03, 2015, 09:28:35 pm »
I think the problem I mentioned is related to the linux switch to xcb. Do you still have the problem if you use an older version of sfml? (I think the 2.2 tag is pre-xcb). Also do the random values change as you move the controller axis as if it is reading the controller, but wrongly, or are the values just random regardless.. as if the controller may as well not be connected?

The values do change in response to moving the axis control. They do not change when the controller is still.

Another thing I noticed is that the axis values will also change very slightly when pressing some of the other buttons: LT, RT, and the center guide / xbox logo button.

I will try testing with an older version later.

frosty

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Xbox 360 controller: invalid axis values (linux)
« Reply #5 on: February 04, 2015, 09:39:37 am »
I think the problem I mentioned is related to the linux switch to xcb. Do you still have the problem if you use an older version of sfml? (I think the 2.2 tag is pre-xcb).

Okay, to test I rebuilt SFML from the 2.1 tag:

  • The error messages about not finding the USB device no longer appear.
  • The weird values I'm getting for the X/Y axis on the 360 controller are still there (including the bizarre crossover coming from moving other axis controls or pressing certain buttons)
« Last Edit: February 04, 2015, 09:46:36 am by frosty »

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 878
    • View Profile
Re: Xbox 360 controller: invalid axis values (linux)
« Reply #6 on: February 05, 2015, 08:59:40 pm »
Which values do you get when you move the stick around? Keep in mind that the axis values aren't supposed to return to exactly 0.

Instead you'll have to implement dead zones where you simply assume no or max movement. This is not a bug in SFML and there's no way to fix this without forcing dead zones that might be too big for some use cases.