LinuxCNC Joystick Pendant Control

I finally got my joystick controller setup for LinuxCNC and my mill.  I put the setup into a Microsoft Word Doc and it can be downloaded here or viewed below…  I copied this from John Thornton and others, but I used my notes and example so I could figure it out in 6 months or a year when I need to do it again:-)

Here are my HAL and INI config files: Zipped LinuxCNC Config Files

joystick values



The following text is copied from the WORD document linked above.

  1. I used the following pages as reference to setup game controller for Jogging
  2. When setting up, the game controller, I tried to use the hal_joystick component on this page:
    However, it says it has been depreciated from EMC 2.4. I tried to run it per the instructions, but it didn’t work, which makes
    sense w/ the depreciation. So, I skipped it.
  3. Then, I identified my joystick using this command from a terminal: less /proc/bus/input/devices
    a. I think Q or Esc quit out of the less program.
    b. This was my joystick from ANKO Corp and it was the last device listed.  Note the usb references.
  4. Once I did that, I then added a file to the folder: /etc/udev/rules.da. I wasn’t sure if I should do that or not, the instructions were you ‘might’ need to do that, so I went ahead and did it anyway. I made a file titled “joystick.rules” with the
    following text:

    SYSFS{idProduct}==”0003″, SYSFS{idVendor}==”05ef”, MODE=”0660″, GROUP=”plugdev”

    b. To add a file to the rules.d folder, you need to be sudo, so I created the file with gedit
    using: sudo gedit joystick.rules

    c. I got the above file info from the “less” command as documented above.

  5. The next step was to see what linuxcnc pins/parameters correlated to the buttons and analog joysticks on the joypad. To do that, we want to use the hal_input component of linuxCNC and then use the Hal Configuration window of Axis to look up the pins. Following one of the examples, I made a new file titled joystick.hal and put the following text in it:loadusr -W hal_input -KRAL ANKO

    a. The joystick.hal file goes in the directory with the other hal files and the .ini file. The .ini file needs to have the following line added:

    HALFILE = joystick.hal

    i. Also, in the *.ini files you need to have:

    HALUI = halui
    I had used the pncconf configurator and that line was already in the *.ini file.

    b. You could just put the line loadusr -W hal_input -KRAL ANKO in your hal file, rather than making the joystick.hal file and referencing it with HALFILE = joystick.hal.  Either
    way will work.

    c. Now, start Axis with LinuxCNC and goto the HAL CONFIGURATION:
    I like John Thornton’s rather simple description: ” Open up the Machine (AXIS), Show Hal Configuration, Pins.
    input and see what the pin names are and which one does what.”AXIS select hal
    AXIS hal configuration
    d. Navigate to PINS and input. I was able to see the pins that went to the joystick and to update them, I would press a button or joystick on the game controller (with one hand) and then use the mouse and click ‘input’ in the HAL configuration window to update the pin value. And, then scroll through the pins to see what I had pressed. I first started by looking at the TRUE,  FALSE, TRUE, FALSE listing of the buttons and when a button was pressed, I saw a FALSE, TRUE, TRUE, FALSE listing and knew I could find the button.  The button listing is as follows for my ANKO joypad:
    joystick values

  6. Setup the Jog Speed. I copied John Thornton’s method to setup jogging speeds and require pressing a button before jogging. In my custom_postgui.hal file I put the following  text:#SETUP JOYSTICK BELOW. Watch out for JOY vs. JOG.
    # Original try mixed them up and it didn’t work!
    #commands for the joystick here
    loadrt or2 count=2
    loadrt mux4 count=1addf or2.0 servo-thread
    addf or2.1 servo-thread
    addf mux4.0 servo-thread

    #set the jog speed for the joypad again use numbers that make sense for your machine
    #   this one must be 0 to prevent motion unless a button is pressed
    setp mux4.0.in0 0
    setp mux4.0.in1 4
    setp mux4.0.in2 20
    setp mux4.0.in3 40
    #setp mux4.0.in1 25   (I replaced John’s commands with mine above)
    #setp mux4.0.in2 100
    #setp mux4.0.in3 200

    # the following does the magic of setting the jog speeds
    net remote-speed-slow or2.0.in0 input.0.btn-a
    net remote-speed-medium or2.1.in0 input.0.btn-b
    net remote-speed-fast or2.0.in1 or2.1.in1 input.0.btn-c
    net joy-speed-1 mux4.0.sel0 <= or2.0.out
    net joy-speed-2 mux4.0.sel1 <= or2.1.out
    net jog-speed <= mux4.0.out
    #net joy-speed-final halui.jog-speed <= mux4.0.out
    #net joy-speed-final jog-speed <= mux4.0.out

    # Step 6 Set up the Axis Add the following to your postgui.hal file

    net jog-x-analog <= input.0.abs-x-position
    net jog-y-analog <= input.0.abs-y-position
    net jog-z-analog <= input.0.abs-z-position

    # 7. Reverse any Axis that go in the wrong direction

    setp input.0.abs-x-scale -63.5
    setp input.0.abs-z-scale -63.5

  7. Adding the above custom_postgui.hal required matching the previous hal notation from the main hal file. Needed to make sure some of the ‘net’ names matched.  Don’t copy anything here, just look to make sure it all matches up!net jog-speed halui.jog-speed
    net jog-z-analog halui.jog.2.analog

    I had mis-labeled jog-x-analog as joY-x-analog and it didn’t work at all! Watch out for that.Last note, I needed to add scaling at the bottom for the X and Z axis to ensure jogging in the correct direction.

  8. Done…


1 comment to LinuxCNC Joystick Pendant Control

  • admin

    ijohnsen ADMIN here… There is one issue w/ the joystick and that is that it gets ‘kicked’ off after using for a few minutes and then will not work. To get it to work again, I need to restart Linuxcnc. I think the issue is a NAMING issue of the joystick or/and it’s location. Note to look into, fix, and post update and issues found. Mark

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code lang=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" extra="">