Lathe Collet Closer M Code
What M code do you use in linuxcnc for a lathe collet closer?
Do I need to use user defined m codes?
M101 Example File
# file to turn on parport pin 14 to open the collet closer
halcmd setp parport.0.pin-14-out True
If so, can someone elaborate where the M101 file gets placed?
Here is what I want to implement. I have a collet closer hooked up to a pneumatic solenoid that is nc, output pin on mesa goes high, opens the closer. M101/M102 open/close. Somehow there has to be a safety implemented that the closer can not open when the spindle is turning. So this needs to be linked to a motion component in hal? A button to add to the axis gui like open/close and error message when open M code is sent while spindle is turning would be nice. Where do I start?
Thanks for your help
Your M code file needs to be placed in the location specified in your ini file.
Also you need to be sure to make sure your M1xx file is executable.
To add a button on screen you'll need to make a pyvcp or gladevcp panel with the button.
At first I thought I'd just use a simple And2 hal logic to lock out the release function when motion.spindle-on is true. But on second thought maybe not, because if it was commanded to open while running, it might open immediately at the next spindle stop, which might not be cool. Some ladder logic might be called for to do this right.
Thanks for the response. The M1XX does that go into the custom halfile?
If I use the M62-65, how do I link those M codes to hal pins? I don't see any options when I expand the hal configuration tree. I'm looking under iocontrol where the coolant flood and coolant mist are listed.
That line is used to specify the path(s) that contain your custom M code files.
Alternatively they can be saved in your default G code directory.
For your above file you would name the file "M101" saving it to your linuxcnc/nc_files/ directory should work.
M62-65 are connected to the halpins motion.digital-in-00 and motion.digital-out-00.
All of this is in the manuals.
Sounds, like you have a lot of reading to do. Good luck
OT-CNC wrote: Here is what I want to implement. I have a collet closer hooked up to a pneumatic solenoid that is nc, output pin on mesa goes high, opens the closer. M101/M102 open/close. Somehow there has to be a safety implemented that the closer can not open when the spindle is turning. So this needs to be linked to a motion component in hal? A button to add to the axis gui like open/close and error message when open M code is sent while spindle is turning would be nice. Where do I start?
Start with a HAL pin that goes high when the spindle is safe
I assume you have a spindle encoder and that the encoder velocity is already part of the spindle-speed-fb net.
Add this to your hal file:
loadrt near count=1 addf near.0 servo-thread setp near.0.difference 0.5 setp near.0.in1 0 net spindle-speed-fb near.0.in2
Now the pin near.0.out will go true when the spindle is doing less than 0.5 rps. You may want to decrease that further.
Now we need a truth table. bit0 is the spindle-speed pin, bit 1 is the manual release, bit 2 is the G-code input.
This truth-table can be encoded in a LUT 5 HAL component.
There is a tool here to calculate LUT5 codes:
You want 168 or 0xA8 (in hex) to have the required function
loadrt lut5 names=collet-interlock addf collet-interlock servo-thread setp collet-interlock.parameter 0xA8 net spindle-stopped near.0.out collet-interlock.in-0 net collet-manual collet-interlock.in-1 # in the postgui halfile you then need net collet-manual pyvcp.collet-button net collet-release collet-interlock.out hm2_5i25.0.gpio.10.out
Then M101 needs to contain
halcmd setp collet-interlock.in-2 1
halcmd setp collet-interlock.in-2 1
Here is what I have in the HAL:
# --- Collet Closer Foot Pedal Switch ---
########### ######## #########
#net collet-closer-pedal hm2_5i25.0.7i84.0.0.input-14 => hm2_5i25.0.7i84.0.0.output-09
loadrt or2 count=2
addf or2.1 servo-thread
net collet-closer-pedal hm2_5i25.0.7i84.0.0.input-14 => or2.1.in0
net user_m100m101code => or2.1.in1
# --- COLLET-OPEN/CLOSE ---
net collet-open-close or2.1.out => hm2_5i25.0.7i84.0.0.output-09
In the executable M100
# open the collet closer
eval halcmd setp or2.1.in1 1
In the executable M101
# close the collet closer
eval halcmd setp or2.1.in1 0
I have tried a few different flavors of the above, without the eval, no sleep, and 0/1 replaced with True/False
Can't see a status change using the halmeter. The closer pedal works, just don't see a state change of the or2.1.in1 when issuing a M100, M101 in MDI.
If those pins are linked to a signal then the M-code won't be able to change the value (it is probably quietly failing somewhere where you can't see the error message).
You should not need the eval.
Alternatively, and if you prefer, the M-code script could contain
halcmd sets user_m100m101code 1