Lathe Collet Closer M Code

More
18 Nov 2015 19:05 #65454 by OT-CNC
Hi,

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
More
18 Nov 2015 21:35 #65464 by Todd Zuercher
You can use a custom M-code like you have there, or you could use a M62-65,

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.


.
More
19 Nov 2015 00:04 #65470 by OT-CNC
Replied by OT-CNC on topic Lathe Collet Closer M Code
Todd,

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.
More
19 Nov 2015 02:18 #65476 by Todd Zuercher
In your ini file under the section [RS274NGC]. Under that there should be a line USER_M_PATH =
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
More
19 Nov 2015 17:05 - 19 Nov 2015 17:09 #65520 by andypugh
Replied by andypugh on topic Lathe Collet Closer M Code

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
linuxcnc.org/docs/2.7/html/man/man9/near.9.html
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-codemanualspindleoutput
0000
0010
0100
0111
1000
1011
1100
1111

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
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
and M102 needs
halcmd setp collet-interlock.in-2 1
Last edit: 19 Nov 2015 17:09 by andypugh.
More
24 Nov 2015 15:31 #65735 by OT-CNC
Replied by OT-CNC on topic Lathe Collet Closer M Code
Andy and Todd,

Thanks for the info, I will continue more on this.
More
17 May 2018 02:01 #110802 by OT-CNC
Replied by OT-CNC on topic Lathe Collet Closer M Code
I'm re-visiting this. I was able to make the executable M100 and M101 files and link them with the USER_M_PATH. Initial testing worked. I have changed the code so I can use my foot petal momentary switch/ solenoid and the M100/M101 to run it. Something is wrong in my file as I can't read a state change in the or2.1.in1.

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??
More
17 May 2018 07:14 - 17 May 2018 07:15 #110808 by nkp
Replied by nkp on topic Lathe Collet Closer M Code
del
Last edit: 17 May 2018 07:15 by nkp.
More
17 May 2018 09:01 #110811 by andypugh
Replied by andypugh on topic Lathe Collet Closer M Code
Delete the HAL lines that attempt to link the or2.1.in1 pins.
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
so that the script is changing the value of the signal. (That is allowed, setp is set pin, sets is set signal)
More
17 May 2018 12:17 #110815 by Todd Zuercher
Or alternatively, you could change your custom M code to use "sets" to change the state of the hal signal, rather than "setp" to the hal pin. If that might be more convenient to you. This is a nice way to do it if your custom M-code needs to toggle more than one input pin.
Time to create page: 0.089 seconds
Powered by Kunena Forum