.hal for cheap joypads (simple remote pendant)
- pippin88
- Offline
- Elite Member
Less
More
- Posts: 260
- Thank you received: 45
22 Mar 2013 12:53 - 22 Mar 2013 13:12 #31714
by pippin88
.hal for cheap joypads (simple remote pendant) was created by pippin88
I've got both a lathe and a router that I'm driving via LinuxCNC.
For the router I have a generic XBox controller- this was left over from when I was using Mach3 (as it's the easiest to get going).
For the lathe I'm using a PS2 / dual shock clone, similar to what is used in the remote pendant articles:
wiki.linuxcnc.org/cgi-bin/wiki.pl?Simple_Remote_Pendant
wiki.linuxcnc.org/cgi-bin/wiki.pl?Adding...imple_Remote_Pendant
I wrote a bit of an article a while ago on my site regarding the PS2 joypad + lathe: 7xcnc.com/software/linuxcnc/pendant/
I had some difficult getting the XBox controller working to satisfaction. I started with the code above, but my Y and Z axes were inverted. (Worked as predicted with keyboard, not with joypad).
I tried the solution included in the article which successfully inverted the movement, but lost the different speeds, and didn't work for incremental either.
So I fiddled and found a way to change it.
For continuous (paragraph of code before and after added for contex):
To invert the incremental moves is easier.
Hope that helps.
If the above is definitely a better way to handle this, maybe the wiki could be updated? (I'm fairly new to this, so there may be mistakes.
Full custom_postgui hal file is attached
For the router I have a generic XBox controller- this was left over from when I was using Mach3 (as it's the easiest to get going).
For the lathe I'm using a PS2 / dual shock clone, similar to what is used in the remote pendant articles:
wiki.linuxcnc.org/cgi-bin/wiki.pl?Simple_Remote_Pendant
wiki.linuxcnc.org/cgi-bin/wiki.pl?Adding...imple_Remote_Pendant
I wrote a bit of an article a while ago on my site regarding the PS2 joypad + lathe: 7xcnc.com/software/linuxcnc/pendant/
I had some difficult getting the XBox controller working to satisfaction. I started with the code above, but my Y and Z axes were inverted. (Worked as predicted with keyboard, not with joypad).
I tried the solution included in the article which successfully inverted the movement, but lost the different speeds, and didn't work for incremental either.
So I fiddled and found a way to change it.
For continuous (paragraph of code before and after added for contex):
## hook up the joysticks
net joy-x-sig mux2.0.in0 near.0.in2 near.3.in2 <= input.0.abs-x-position
net joy-y-sig mux2.1.in0 near.1.in2 near.4.in2 <= input.0.abs-y-position
net joy-z-sig mux2.2.in0 near.2.in2 near.5.in2 <= input.0.abs-hat0y-position
## reverse x, y & z using scale as needed
## renumber if you have scale elsewhere in .hal files (e.g. spindle stuff)
loadrt scale count=3
addf scale.0 servo-thread
addf scale.1 servo-thread
addf scale.2 servo-thread
## link scale to mux output for x axis then set the gain to -1
## x-axis is correct for me so gain = 1, doesn't invert
net reverse-x scale.0.in <= mux2.0.out
setp scale.0.gain 1
## link scale to mux output for y axis then set the gain to -1
net reverse-y scale.1.in <= mux2.1.out
setp scale.1.gain -1
## link scale to mux output for z axis then set the gain to -1
net reverse-z scale.2.in <= mux2.2.out
setp scale.2.gain -1
## send signal to analog jog if not in incremental jog mode
net joy-x-jog halui.jog.0.analog <= scale.0.out
net joy-y-jog halui.jog.1.analog <= scale.1.out
net joy-z-jog halui.jog.2.analog <= scale.2.out
To invert the incremental moves is easier.
## To change the direction of incremental move (e.g. if moves opposite to desired) just change the plus and minus portion of halui.jog.N.increment-(plus or minus)
## and2 outputs to halui incremental jog
net jogincx_final halui.jog.0.increment-plus <= and2.0.out
net jogincy_final halui.jog.1.increment-minus <= and2.1.out
net jogincz_final halui.jog.2.increment-minus <= and2.2.out
net jogincxn_final halui.jog.0.increment-minus <= and2.3.out
net jogincyn_final halui.jog.1.increment-plus <= and2.4.out
net joginczn_final halui.jog.2.increment-plus <= and2.5.out
Hope that helps.
If the above is definitely a better way to handle this, maybe the wiki could be updated? (I'm fairly new to this, so there may be mistakes.
Full custom_postgui hal file is attached
Last edit: 22 Mar 2013 13:12 by pippin88.
Please Log in or Create an account to join the conversation.
Time to create page: 0.045 seconds