- Posts: 617
- Thank you received: 0
Lathe Collet Closer M Code
What M code do you use in linuxcnc for a lathe collet closer?
www.linuxcnc.org/docs/html/gcode/m-code.html#_m_codes
Do I need to use user defined m codes?
M101 Example File
#!/bin/bash
# file to turn on parport pin 14 to open the collet closer
halcmd setp parport.0.pin-14-out True
exit 0
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
Please Log in to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
-
- Posts: 4739
- Thank you received: 2
Your M code file needs to be placed in the location specified in your ini file.
linuxcnc.org/docs/2.7/html/config/ini-co...ml#_rs274ngc_section
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.
.
Please Log in to join the conversation.
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.
Please Log in to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
-
- Posts: 4739
- Thank you received: 2
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
Please Log in to join the conversation.
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:
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.
| G-code | manual | spindle | output |
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
This truth-table can be encoded in a LUT 5 HAL component.
linuxcnc.org/docs/html/man/man9/lut5.9.html
There is a tool here to calculate LUT5 codes:
docs.google.com/spreadsheets/d/1_VlL39jU...TS6C6PHBDoE3JitvLzs/
You want 168 or 0xA8 (in hex) to have the required function
Then M101 needs to contain
Please Log in to join the conversation.
Thanks for the info, I will continue more on this.
Please Log in to join the conversation.
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
#!/bin/sh
# open the collet closer
eval halcmd setp or2.1.in1 1
sleep 0.5
exit 0
In the executable M101
#!/bin/sh
# close the collet closer
eval halcmd setp or2.1.in1 0
sleep 0.5
exit 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.
Any suggestions??
Please Log in to join the conversation.
Please Log in to join the conversation.
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
Please Log in to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
-
- Posts: 4739
- Thank you received: 2
Please Log in to join the conversation.
