SDL joystick ranges have change (Ubuntu)

I have an SDL app that used to receive jostick values from values from
SDL_JoystickGetAxis in the range (-32768 to 32767) as specified here:
http://sdl.beuc.net/sdl.wiki/SDL_JoystickGetAxis here .

Since switching to Ubuntu, the same code with same joystick now produces
values in the range (0,255).
I’m using Ubuntu 8.04.

What gives? Is this a change with newer SDL libraries or an issue specific
to Ubuntu?–
View this message in context: http://www.nabble.com/SDL-joystick-ranges-have-change-(Ubuntu)-tp21631811p21631811.html
Sent from the SDL mailing list archive at Nabble.com.

Unfortunately SDL has had its fair share of custom code for certain
types of gaming controllers. Logically, the best place for handling
special circumstances is as clsoe to the device firmware as possible,
the kernel module/driver is usually the most convenient place for
this, but SDL has made some compromises for portability. I suppose the
best way to find out if there is special code in place is to grep for
it in the source code.

That said, it might be in SDL, or in your kernel driver. However, this
is all moot, because…

You really shouldn’t be hard coding these limits into your games.
Theoretically every gaming controller giving the same identifier
string should have the same numeric bounds, but even this is not
always true as subtle difference in the physical controller (usually
from abuse) change the range of motion of various components of gaming
controllers. The same can be said of the neutral position that a
joystick will revert to naturally, in fact this is usually the first
thing to wear down as the springs lose their springiness.

The best approach I’ve found is to keep a buffer of controller data
for each axis you have to deal with. Record the highest value and the
lowest value and use those values for interpreting joystick data.
Allow the player to adjust the neutral-state of his or her joystick. A
calibration process that can be initiated by the user can provide a
good opportunity to “teach” your application what it needs to know.On Fri, Jan 23, 2009 at 3:11 PM, stuartreynolds wrote:

I have an SDL app that used to receive jostick values from values from
SDL_JoystickGetAxis in the range (-32768 to 32767) as specified here:
http://sdl.beuc.net/sdl.wiki/SDL_JoystickGetAxis here .

Since switching to Ubuntu, the same code with same joystick now produces
values in the range (0,255).
I’m using Ubuntu 8.04.

What gives? Is this a change with newer SDL libraries or an issue specific
to Ubuntu?


http://codebad.com/

The best approach I’ve found is to keep a buffer of controller data
for each axis you have to deal with. Record the highest value and the
lowest value and use those values for interpreting joystick data.
Allow the player to adjust the neutral-state of his or her joystick. A
calibration process that can be initiated by the user can provide a
good opportunity to “teach” your application what it needs to know.

Now, I’m not too familiar with Ubuntu, but every time I plug in a new gamepad or joystick on Windows, the first thing I do is go into the Game Controllers control panel and calibrate the stick(s). Then Windows builds its neutral-state and range-of-motion data and does all the adjustments for you before it reaches the event queue. Are you saying that Linux doesn’t provide that for you?>----- Original Message ----

From: Donny Viszneki <donny.viszneki at gmail.com>
Subject: Re: [SDL] SDL joystick ranges have change (Ubuntu)

I don’t know. The few that I’ve used have just worked fine without any
special work (save the above technique.) No distribution of GNU/Linux
I’ve used has provided such a facility as you’ve described.On Fri, Jan 23, 2009 at 4:52 PM, Mason Wheeler wrote:

Now, I’m not too familiar with Ubuntu, but every time I plug in a new gamepad or joystick on Windows, the first thing I do is go into the Game Controllers control panel and calibrate the stick(s). Then Windows builds its neutral-state and range-of-motion data and does all the adjustments for you before it reaches the event queue. Are you saying that Linux doesn’t provide that for you?


http://codebad.com/

masonwheeler wrote:

Now, I’m not too familiar with Ubuntu, but every time I plug in a new
gamepad or joystick on Windows, the first thing I do is go into the Game
Controllers control panel and calibrate the stick(s). Then Windows builds
its neutral-state and range-of-motion data and does all the adjustments
for you before it reaches the event queue. Are you saying that Linux
doesn’t provide that for you?

I ran jscalibrator. The range is still 0,255, nothing like what
SDL_JoystickGetAxis reports.

I do auto calibration also within my app in order to deal with small
variations. There’s a couple of things wrong here though. I can understand
the need to recalibrate for a different joystick, or for wear on a joystick.
But this is not what has happened. I shouldn’t need different calibration if
my app runs with the same hardware. I need to recalibrate here, not because
of wear and tear or manufacturing variances, but because the software
somewhere between the kernel and SDL changed.

What’s really screwed up my app is that the calibration routine I broke
because SDL_JoystickGetAxis no longer produces what its docs says it
produces. The docs said it outputs -ve and +ve values, now it only outputs
+ve values. I’ve fixed my the calibration to workaround this new behavior.
However, now I get the effect that if I assume my initial best guess of what
centered was (x=0,y=0) (given valid values from the range (-32768 to 32767)
), then this translates into pushing hard along the diagonal if the actual
range is (0, 255). The result is wacky behavior before the user moves the
joystick.
I kinda feel like this is a driver level issue and that the app shouldn’t
have to deal with it. Providing an abstraction layer is, after all, kind of
the point of SDL, right?>>----- Original Message ----


View this message in context: http://www.nabble.com/SDL-joystick-ranges-have-change-(Ubuntu)-tp21631811p21633684.html
Sent from the SDL mailing list archive at Nabble.com.

I do auto calibration also within my app in order to deal with small
variations. There’s a couple of things wrong here though. I can understand
the need to recalibrate for a different joystick, or for wear on a joystick.
But this is not what has happened. I shouldn’t need different calibration if
my app runs with the same hardware. I need to recalibrate here, not because
of wear and tear or manufacturing variances, but because the software
somewhere between the kernel and SDL changed.

Have you asked Ubuntu people for help?

What’s really screwed up my app is that the calibration routine I broke
because SDL_JoystickGetAxis no longer produces what its docs says it
produces. The docs said it outputs -ve and +ve values, now it only outputs
+ve values. I’ve fixed my the calibration to workaround this new behavior.
However, now I get the effect that if I assume my initial best guess of what
centered was (x=0,y=0) (given valid values from the range (-32768 to 32767)
), then this translates into pushing hard along the diagonal if the actual
range is (0, 255). The result is wacky behavior before the user moves the
joystick.

Is there a commandline interface to dump the raw joystick data? This
might help determine where the problem was introduced.

I kinda feel like this is a driver level issue and that the app shouldn’t
have to deal with it. Providing an abstraction layer is, after all, kind of
the point of SDL, right?

If Ubuntu has a good reason to force some kind of weird change that
would cause the problems you’re describing, that’s a good reason for
SDL to compensate for it. But I doubt that’s the case.On Fri, Jan 23, 2009 at 5:19 PM, stuartreynolds wrote:


http://codebad.com/