JOY2KEY - Using a USB Joystick/device

  • Askjerry
  • Askjerry's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
12 Nov 2015 18:37 - 13 Nov 2015 09:00 #65174 by Askjerry
JOY2KEY - Using a USB Joystick/device was created by Askjerry
I found a really nice joystick and thought it would be nice to have it to control LinuxCNC with. I heard that it was extremely difficult to configure a joystick so I never really thought i could do it. I heard about some programs... but you needed to compile (MAKE) them... there were missing library files...etc. I'm not too savvy with Linux... so I decided to try something else.

I went to the Synaptic Package Manager under the SYSTEM drop down... and typed in "joystick" into the search. It came up with JOY2KEY which I installed. I figured out that from the TERMINAL command prompt I could call it up and get some info by typing joy2key --help so I started tinkering with it.

It took about 8 to 10 hours for me to figure it out... so I'll pass this info along so you don't have the same learning curve. First... your system needs information about the joystick device... and there is a hidden file that has this description. I found a "shortcut" to setting this up... might be an easier way... but this worked.

Under CNC... click Pncconfig and pretend to set up a machine... get to the part about a USB JOYSTICK and tell it to add a rule.



It will tell you to plug and unplug the device a couple of times, then say it is complete. Quit Pncconfig without saving. That just did the boring/hard part for us. :P

Ok... now some explanation about joy2key... all it does is evaluate what you do on your joystick/controller and substitute keyboard strokes. So if you map "button 1" to the "space bar"... every time you hit the button... your computer will think you pressed the spacebar. LinuxCNC has a whole bunch of keyboard shortcuts: wiki.linuxcnc.org/cgi-bin/wiki.pl?Keyboard_Shortcuts

So... if we can make LinuxCNC (AXIS) think we pressed a key... we can run it with a joystick. ;)

The joystick/controller I have looks like this... after some experimentation I figured out the key (button) numbers.



If you go to TERMINAL and type joy2key -terminal -buttons 1 2 3 4 5 6 7 8 9 A B C D E F G then it will map out the buttons... so if you press a button and it is #3... you will see "3" in terminal. Just make a note of all the buttons. Pressing CTRL-C will end it.

The program will have you calibrate the joystick... since I have buttons... the lowest value was about -32K and the highest was about 32K. That made the thresholds about -16383 and 16383. Any number between those two values is treated as "zero". You can program in a threshold with -thresh so you don't need to do the calibration.

Most key names are easy... but some like "Page Down" which is used for the Z-Axis were a problem. If you do a Google search on keysymdef.h you will find these names.

So... equipped with this... and after talking to some Linux experts... I found that if you use: joy2key -config CNC it will look for a hidden file, pull the information from it... and execute. It will ask you to click on the screen you want to command.

I found out that if you go to GEDIT or whatever editor you use... you can write a file and save it as .joy2keyrc then it will use this data to run the software. (Configure as needed.)
All the configuration data is here: manpages.ubuntu.com/manpages/hardy/man1/joy2key.1.html

This is my file...
START cnc
# ----------------------------------------------
# --- Here is the command line               ---
# ----------------------------------------------
# joy2key -config cnc
# ----------------------------------------------
# Google keysymdef.h for the proper key names.
# ----------------------------------------------
#      -X points it at a screen
-X
#     Put in the calibration numbers for your joystick... or try mine.
-thresh -20000 20000 -20000 20000
#     I set the   -axis  (joystick)  to run the X-Axis and Y-Axis
-axis Left Right Up Down
#     Here is where I set up my buttons for the desired functions.
-buttons Page_Down comma F3 Page_Up period F5 bracketleft bracketright F9 F1 F7

The line START CNC is a header... so when we type joy2key -config CNC it knows what part of the file to pull the data from. And the cool part is... you can set up multiple configurations in this one file... then call what you want for whatever program you are using.

Bringing it all together...

1) Start AXIS (your CNC setup).
2) Open TERMINAL and type in joy2key -config CNC
3) When prompted, click on the AXIS screen.

That's it... down to a 3-step process.

I hope this helps... I know I'm going to enjoy using a joystick... it's going to be a real joy! :whistle:

Jerry
Attachments:
Last edit: 13 Nov 2015 09:00 by Askjerry.
The following user(s) said Thank You: ikkuh

Please Log in or Create an account to join the conversation.

More
14 Nov 2015 12:09 #65239 by BigJohnT

Please Log in or Create an account to join the conversation.

  • Askjerry
  • Askjerry's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
15 Nov 2015 02:03 #65266 by Askjerry
Replied by Askjerry on topic JOY2KEY - Using a USB Joystick/device
:huh:

Not sure I would say easier... in my method you identify the keys and type a 4 line text file... in yours you have to know how to edit HAL files, edit postgui files, etc. I think I'll do it my way... at least for now... any time I want to use the joystick, I just open terminal, type one command, and I'm done.

I'll look into your method a bit more... but for the neophyte... I think this way may be easier.

Perhaps a tie... dunno. :blush:

Jerry

Please Log in or Create an account to join the conversation.

More
15 Nov 2015 06:04 #65268 by cmorley
Replied by cmorley on topic JOY2KEY - Using a USB Joystick/device
hey congrats for figuring out pnccnof did this. I added it many years ago and always thought it was a easy way to get the device rule added.
I also applaud your continued documentation of your discoveries.
Surely you are helping people!

Chris M
The following user(s) said Thank You: ikkuh

Please Log in or Create an account to join the conversation.

More
15 Nov 2015 23:12 #65303 by BigJohnT
Replied by BigJohnT on topic JOY2KEY - Using a USB Joystick/device

I'll look into your method a bit more... but for the neophyte... I think this way may be easier.


I'm sure you have passed the neophyte stage some time ago, it is evident by your posts. I meant easier that you just start LinuxCNC and the joystick works.

JT

Please Log in or Create an account to join the conversation.

  • Askjerry
  • Askjerry's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
15 Nov 2015 23:22 #65304 by Askjerry
Replied by Askjerry on topic JOY2KEY - Using a USB Joystick/device
cmorley - Thanks. I was hoping to learn, and share so others could benefit from my errors and discoveries.

BigJohnT - In that respect, very true. Likely I won't use the joystick all the time... so it's easy to call it when i do need it. Also... I may end up using an Arduino in emulation mode... so my set-up may change as well. Don't really know yet.

Please Log in or Create an account to join the conversation.

More
17 Nov 2015 13:58 #65369 by andypugh
Replied by andypugh on topic JOY2KEY - Using a USB Joystick/device
An advantage of hal_input compared to keyboard emulation is that you get analogue jog from the analogue stick.

Also, keyboard emulation tends to be a bit unreliable with some UIs, it all depends on which UI elements (or other applications) are currently at the front and receiving key events. Halui and hal_input means that the joystick events go to LinuxCNC instead of Pet Rescue Saga (or whatever)

Please Log in or Create an account to join the conversation.

  • Askjerry
  • Askjerry's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
17 Nov 2015 17:07 #65383 by Askjerry
Replied by Askjerry on topic JOY2KEY - Using a USB Joystick/device
I agree... my thing was that several people told me, "Man it's really hard to get a joystick input to work with LinuxCNC... I wouldn't even bother with it... too much trouble."

So I managed to find a repeatable method to quickly get it up and operational if anyone wants to try it out.

That was a success as I see it. B)

I understand what you are saying... and it's like my pyVCP panels... more work up front... and better results with more options on the back-end. Once I finish getting my mill updated with the new features, calibrated, etc... (Which may be this evening.) Then I will take a look at analog inputs, HAL modifications for joystick, etc. (This "joystick" is just a Logitech controller... buttons where a joystick would go... no analog contingent at all. -32000, 0, and 32000 outputs only... so I wasn't going to do too much at this point. )

Once I do... then of course... I'll update this and add the code to save others from pulling their hair out. :)

Please Log in or Create an account to join the conversation.

  • Askjerry
  • Askjerry's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
30 Nov 2015 03:55 - 30 Nov 2015 03:56 #66086 by Askjerry
Replied by Askjerry on topic JOY2KEY - Using a USB Joystick/device
Now that I have my results for the updated MONSTER MILL on the forum...
forum.linuxcnc.org/forum/22-pyvcp/28572-...vcp-machine?start=50

I was wondering if anyone knows how to make a simple launcher that I could click on to run the JOY2KEY command so that if I want to use the joystick... all I have to do is click the launcher then the CNC screen.

Basically... right now I do the following...
1) Open Terminal
2) Type: joy2key -config cnc
3) Press Enter.
4) Click on the AXIS screen.

What I would like to do...
1) Click the launcher.
2) Click on the AXIS screen.

I know... not a big deal... but for someone else... they would not have to remember the command. B)

Is it possible? (Sorry... still not a Linux Guru.)

Thanks!
Jerry
Last edit: 30 Nov 2015 03:56 by Askjerry.

Please Log in or Create an account to join the conversation.

More
30 Nov 2015 10:07 #66094 by andypugh
Replied by andypugh on topic JOY2KEY - Using a USB Joystick/device

I was wondering if anyone knows how to make a simple launcher


I think that there is a way to do this with right-clicks or the GUI, just "create new launcher" or similar.
However, without having a Linux box to play with here, this is another way
Make a copy of the LinuxCNC launcher, then right-click it and look at the properties. You can see that it has a command-line as one of the properties. Just change that.

You can _probably_ make the same command-line launch both LinuxCNC and the joy2key
askubuntu.com/questions/60379/how-to-com...mmands-as-a-launcher

Please Log in or Create an account to join the conversation.

Time to create page: 0.149 seconds
Powered by Kunena Forum