Author Topic: Linux joystick problems  (Read 12203 times)

0 Members and 1 Guest are viewing this topic.

Linux joystick problems
Hey... I just remembered:
Fs2_open_linux can't use some "features" of my joystick:
Throttle-Axis (z-axis), rx-axis and the coolie-hats...

But I didn't ever gave some more info about my joystick! Maybe this would help you!

My joystick is a
Saitek Cyborg 3D Rumble Force (USB/HID-Device).
It's fully functional under linux (okay... Force Feedback still is not supported ;) ).
It has the following features:
6 axis (x, y, z, rx)
9 Buttons
1 Coolie-Hat

When I use jstest, I see that the axis are mapped "strange":
0 = x
1 = y
2 = Coolie-Hat left/right
3 = Coolie-Hat up/down
4 = z
5 = rx

Shouldn't z and rx come first?


And... Uh... jstest also reports 23 axis!! Why that?


And now a question to all FS2_open_linux-users:
How many of you do have / use a joystick and does this joystick have an z- and rx-axis?
« Last Edit: April 14, 2005, 12:35:14 pm by 2173 »

 
And another question:
I took a look into the code...
Well... I don't code C(++) but one thing looks suspicious to me...

Code: [Select]
               if (joy)
                {
                        nprintf (("JOYSTICK", "Joystick #%d: %s\n", j - JOYSTICKID1 + 1, SDL_JoystickName(j)));
                        if (j == Cur_joystick) {
                                for (int i = 0; i < SDL_JoystickNumAxes(joy); i++)
                                {
                                        joystick.axis_valid[i] = 1;
                                }
                        }
                        SDL_JoystickClose (joy);
                }


If a joystick gets detected and used, a message is drawn (written in log file), right?
But there's no such message in my fs2_open.log or somewhere else?

 
Okay... I've found something out!
FS2_Open can use ALL Axes of my Joystick!
The Problem is: It doesn't do it!
I mean... When I set my coolie-hats for steering (instead of my X-/Y-Axis) I can steer with them...
Same with my Throttle- / Rudder-Axis...
So FS2_Open just don't use the settings from the options-menu???
That's very strange!

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Quote
Originally posted by Mr_Maniac
If a joystick gets detected and used, a message is drawn (written in log file), right?
But there's no such message in my fs2_open.log or somewhere else?

The nprintf() is the key there.  Those are filtered so that only what you want goes in the log.  I think that only "General" and "Warning" go in by default so "JOYSTICK" won't show up unless you tell it to.  The easiest way is to "touch ~/.fs2_open/data/debug_filter.cfg", assuming that file doesn't exist yet.  Next time you run the game that file will start being populated with the various message types.  You can edit it later to turn off things that get logged.  So for something like table parsing, which I find pretty much useless, you would change this line "+Parse" to "-Parse" and it would silence the parse messages.  The various options are case insensitive as well so don't worry about what case it is.

And I do use a joystick, a Logitech Wingman Force, though it's not connected right now.  It's got a throttle control which does work as well as a HAT which also works.  The HAT is an issue since you have to tell SDL that it exists.  If you don't then you'll have weird axis problems.  This is done with an environment variable but I can't remember off the top of my head what that is.  A search on libsdl.org should find it if you aren't already using it.

 
Okay okay....
The real Problem IS, that my coolie-hats get handled first!
Axis-Mapping:
x>x
y>y
Coolie-hat left/right>z
Coolie-hat up/down>rx
Rudder>ry
Throttle>rz

I've found the environment variable you are talking about, but there's this problem again!
My Coolie-Hat gets mapped to throttle and rudder and my throttle and rudder will be used as the coolie hat!
I'm searching in the whole Internet but I can't find a solution!
And why doesn't fs2_open accept ry and rz as Throttle and Rudder?
It seems to accept only z and rx!
I'm confused!
Can I try some code-hacks? I've already tried to swap the numbers in code/controlsconfig/controlsconfig.h...
And I've tried many changes in the code!
And I'll try further things...
Maybe I'll be successful somewhen :)

EDIT:
fs2_open DOES only use x,y,z and rx...
I can map ry and rz to anything I want in the options-screen but it doesn't work...
« Last Edit: April 15, 2005, 03:56:52 pm by 2173 »

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Quote
Originally posted by Mr_Maniac
fs2_open DOES only use x,y,z and rx...
I can map ry and rz to anything I want in the options-screen but it doesn't work...

So you can map them in controlconfig?  If there are ok in controlconfig then it should work fine in game.  Looking at the code a bit closer it supports 6 axes but only gets a position on the first 4.  Your HAT should be seen as buttons rather than an axis (with the env variable) which is why this is screwed up.  This seems to be what you are saying when you try the env variable so that should be right.  The HAT should be buttons at that point.  If the HAT wasn't seen as a set of axes then it would work fine as you'd have x, y, z (should be throttle), rx (should be rudder).

In code/io/joy_unix.cpp, joy_get_pos() change this (if not using the env variable!!):
Code: [Select]
if (z && joystick.axis_valid[2])
*z = joy_get_unscaled_reading(axis[2], 2);
if (rx && joystick.axis_valid[3])
*rx = joy_get_scaled_reading(axis[3], 3);

to:
Code: [Select]
if (z && joystick.axis_valid[5])
*z = joy_get_unscaled_reading(axis[5], 5);
if (rx && joystick.axis_valid[4])
*rx = joy_get_scaled_reading(axis[4], 4);

and see what you get.

If the HAT is configured as an axis then it will probably stop working but the throttle and rudder should work.  This is assuming that the order is right which by your list is this:
0 = x
1 = y
2 = HAT left/right
3 = HAT up/down
4 = rudder
5 = throttle

The inteded setup is:
0 = x
1 = y
2 = throttle
3 = rudder

Also report how many buttons that SDL sees with a printf() in joy_init().  Check the output of SDL_JoystickNumAxes(), SDL_JoystickNumButtons() and SDL_JoystickNumHats() to see if it's finding what we want it to see.

EDIT: Oh and I am going to add this so that it will print the config to the debug log in the future.
« Last Edit: April 16, 2005, 12:45:48 am by 1252 »

 
Well... Changing the numbers in joy_get_pos() doesn't work...
There are so MANY places in the sourcecode where I thought: "That could be it!"
But... Well... No!
For example:
In code/controlconfig/controlsconfig.h the axis-names get defined
Code: [Select]
#define JOY_X_AXIS      0
#define JOY_Y_AXIS      1
#define JOY_Z_AXIS      2
#define JOY_RX_AXIS     3
#define JOY_RY_AXIS     4
#define JOY_RZ_AXIS     5

And it looks like I could swap the numbers... But... No effect...

In code/controlconfig/controlsconfig.cpp
Code: [Select]
#ifdef GRAVIS_OEM
int Axis_map_to[] = { JOY_X_AXIS, JOY_Y_AXIS, JOY_RX_AXIS, JOY_Z_AXIS, -1 };
int Axis_map_to_defaults[] = { JOY_X_AXIS, JOY_Y_AXIS, JOY_RX_AXIS, JOY_Z_AXIS, -1 };
#else
int Axis_map_to[] = { JOY_X_AXIS, JOY_Y_AXIS, JOY_RX_AXIS, -1, -1 };
int Axis_map_to_defaults[] = { JOY_X_AXIS, JOY_Y_AXIS, JOY_RX_AXIS, -1, -1 };
#endif

Here I thought, that I could swap the axis-names... But no...

Seems like NOT A SINGLE Function does have any effect for my joystick... (and that's very strange)...
Well... Some functions HAVE an effect... But not that effect that the function should give me...Name: Saitek Cyborg 3D Rumble Force
Axes: 23
Trackballs: 0
Buttons: 9
Well... I'll do that print() now... I'll edit this message when it's done...

Thanks for the help :)

[size=15]EDIT[/size]:
This is how SDL sees my joystick:
Code: [Select]
Name: Saitek Cyborg 3D Rumble Force
Axes: 23
Trackballs: 0
Buttons: 9
« Last Edit: April 16, 2005, 09:16:40 am by 2173 »

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Quote
Originally posted by Mr_Maniac
This is how SDL sees my joystick:

Eww, that's freaky.  What does that printf() line look like?  Also, since I forgot to ask, what are you using in that enviroment variable (SDL_LINUX_JOYSTICK)?

...Later that day...

Hehehe, forgot to hit "Submit Reply" before I left.  Obviously I've been out drinking with WMCoolmon. ;)

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Split the thread out of the general discussion since it's easier to read this way.

I'm testing the new changes to the joystick code now.  It is *far* less demanding on the event processing side so keeps the game running faster.  Many orders of magnitude faster in fact.  I was losing about 30 FPS using a joystick with the old code but so far it hasn't even registered a single FPS drop with the new code.  I'm testing the last of the button changes and will get this in CVS during the next couple of hours.  The only real concern so far is if it's going to process the events fast enough.  So far it is but it needs to be tested by someone with less of a super computer than I have. :)

Watch for the changes to hit CVS, Mr_Maniac, and see if it's working any better for you.  It will also spit out the appropriate debug info for buttons, hats, axes and what not.  When you report how well it's works (or doesn't work) please include the debug output for the joystick too.

The new code could also be expanded to handle multiple joysticks simultaneously which I know has been asked for previously.  That may be a Linux (or rather SDL) only thing though but I'll figure that out when I get back to modifying controlconfig for the update joystick/mouse handling.

 
Quote
Originally posted by taylor

Eww, that's freaky.  What does that printf() line look like?  Also, since I forgot to ask, what are you using in that enviroment variable (SDL_LINUX_JOYSTICK)?


Err... Well... I tried to include that printf() line in some places... Everytime I get a "undefined reference:..."...
So I looked around at libsdl.org and made a little stand-alone program (copy&paste)...

And my SDL_LINUX_JOYSTICK looked like that:
Code: [Select]
SDL_LINUX_JOYSTICK="'Saitek Cyborg 3D Rumble Force' 4 1 0"
Well... And with this line my coolie-hat is still traded as two axes and my Rudder- and Throttle-axes are traded as a coolie-hat...

I'm searching help in different forums for that problem (maybe there's a way to swap the axes and to tell the driver that I DON'T have 23 axes...)

Oh... And for the testing:
I've an 1.333 MHz Athlon Thunderbird
with 512 MB RAM (non-DDR, 133 MHz, CL-2)
and an GeForce 3.

Is that "old" enough? ;)

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Quote
Originally posted by Mr_Maniac
Well... And with this line my coolie-hat is still traded as two axes and my Rudder- and Throttle-axes are traded as a coolie-hat...

Hmm, maybe there is some issue with the drivers for it perhaps?  I know that my Wingman Force works better with newer kernels.

Quote
Is that "old" enough?

Well I've got an AMD64 3400+, 1gig DDR400, with a 6800GT.  Anything slower than that is what needs to be looked at for the speed difference.  So, you qualify. ;)

Quote
(okay... Force Feedback still is not supported)

Well, actually... it sorta is.  I wrote up some Linux FF support for the icculus.org version almost 2 years ago.  Never had it working 100% as the effects kept sticking and would loop, but it did work.  I may dig up that old code soon and work on it some more.  It required a newer interface version but what got in the kernel didn't have an updated version specifier at the time.  Made it difficult to deal with for all of the different kernel versions.  Not as much of an issue now though and the driver a come a long way since then.  Of course your paticular joystick may not be supported by the iforce driver but one thing at the time. :D

 
Wow! Great! My Rudder and Throttle-Axes are now working!
And they're working great!

To the speed:
Well... Is there a fps-limiter in fs2_open for linux?
Because I never get (and I never got) over 120.0 FPS...
That's the exact line... 120.0 FPS and not more ;)
But that's not a problem!
And it seems, that it's really faster now!
Before this CVS-Commit I had lower fps in-mission... Well... At the beginning of a mission, when I looked into empty space, I had 120 FPS... Then, when I was flying around and had some action, my FPS went down... And even when the action was over and everything's clear again, the FPS won't go up to 120 FPS again...
Now, it seems that I always get 120 FPS when I look into empty space... Even after some action... Of course the FPS are going down in action, but it's already faster!

Quote
Hmm, maybe there is some issue with the drivers for it perhaps? I know that my Wingman Force works better with newer kernels.


Well... AFAIK my joystick was always mapped like this...
I had to write me a xml-config-file for flightgear...
And I always have the newest stable kernels (2.6.11 atm), so I think, that my Joystick is only a "strange" device...
And it seems that the joystick-driver doesn't get improved anymore?!?
But now that I can play fs2_open with my joystick, I'm fully satisfied! :)

And about Force Feedback:
What I meant was, that MY Joystick is not supported now...
But I hope that it'll get supported somewhen...
Well... It also could be, that it will "die" somewhen and that I have to buy a new one then... (I'm thinking of buying an Saitek X52 Flight System with "real" Force-Feedback and an external Throttle-Control... ;) )

THX! And great work!

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Quote
Originally posted by Mr_Maniac
Wow! Great! My Rudder and Throttle-Axes are now working!
And they're working great!

What was ultimately the fix, the updated code or something else you tried?

Quote
To the speed:
Well... Is there a fps-limiter in fs2_open for linux?
Because I never get (and I never got) over 120.0 FPS...
That's the exact line... 120.0 FPS and not more ;)[/B]

Yep, it's 120.  There is a cmdline options to turn it off but I've had problems in the past when it gets going too fast.

Quote
Before this CVS-Commit I had lower fps in-mission... Well... At the beginning of a mission, when I looked into empty space, I had 120 FPS... Then, when I was flying around and had some action, my FPS went down... And even when the action was over and everything's clear again, the FPS won't go up to 120 FPS again...
Now, it seems that I always get 120 FPS when I look into empty space... Even after some action... Of course the FPS are going down in action, but it's already faster![/B]

That's what I was noticing as well.  I stopped using a joystick a while ago and attached it to a different computer.  Wasn't until I moved it back that I started having the speed problems.  This is something I need to fix in the icculus.org version as well since it's using the same code.  If you start having issues where it isn't detecting your buttons presses fast enough let me know.

I think I'm going to add support for 8-way hats as well since those extra hat positions would be rather useful.

 
Quote
What was ultimately the fix, the updated code or something else you tried?


It was the updated code...
I've synced the CVS-Tree, compiled and it worked :)
I'm happy now!