M code kunundroms

More
11 May 2012 01:09 #19992 by JR1050
M code kunundroms was created by JR1050
Im hoping some one can shed some light on some user M codes.Ive have written some simple scripts for advancing and retracting a parts catcher using M124 and M125.Both work in MDI and should in auto..

Problem: I would also like to open and close the collet via m code in the part program,but I have the output pins tied to a pin in a hal comp that allows me to open and close the collet in maual mode with a push button,Is there any way to have it both ways?

Id imagine additional user mcode pins could be added to the source code,any one ever pull this off?Thanks as always.

Please Log in or Create an account to join the conversation.

More
11 May 2012 07:17 - 11 May 2012 07:31 #19997 by Rick G
Replied by Rick G on topic Re:M code kunundroms
You can use a custom M command to change the pin state with halui.
For example...

M104
#!/bin/bash
#change pin state to TRUE
halcmd setp and2.1.in1 TRUE
exit 0

Have you looked here...
www.linuxcnc.org/docview/html/gcode/m-co...tml#sec:M100-to-M199

Rick G
Last edit: 11 May 2012 07:31 by Rick G.

Please Log in or Create an account to join the conversation.

More
11 May 2012 10:08 #19999 by andypugh
Replied by andypugh on topic Re:M code kunundroms
JR1050 wrote:

Is there any way to have it both ways?

Yes, you can use logic functions "or2", "and2" "xor" etc in the HAL.

With a parport machine you might have:

loadrt or2 count=1
...
addf or2.0 servo-thread
...
net collet-pin or2.0.out => parport.0.pin-07-out
net pushbutton-collet parport.0.pin-01-in => or2.0.in0

So, in this situation a button connected to parport pin 1 would cause the state of output pin 7 to change. (Note that I have absolutely no idea if those two pins have the correct directions)

However, with this arrangement, a user M-code can also be used to set the output pin

#! /bin/bash
halcmd setp or2.0.in1 1

This sets the state of the other, unconnected, pin of the "or2" function, so will trigger the collet independently of the physical button,

You mentioned a HAL component, what does that do? Does it incorporate overrides to prevent collet release if the spindle is moving? If that is the case, then it might make sense to add an extra input pin to that, move the "OR" logic into the component, and use the M-code to setp the extra pin of the HAL component.

Id imagine additional user mcode pins could be added to the source code,any one ever pull this off?

I really don't understand this question. what do you mean by "user m code pin" ? The M100-M199 codes can run any executable file. It doesn't have to be a short bash script, it can be a 20,000 line python program.

Please Log in or Create an account to join the conversation.

More
11 May 2012 13:39 #20008 by JR1050
Replied by JR1050 on topic Re:M code kunundroms
Some clarity is in order....My set up uses a 5i20 and opto 22 pb24 racks.I have a comp written for all of my button functions called button logic and and they are connected to gpio pins like so

net sl_collet_open buttonlogic .0.sl-collet-open = hmi,gpio.056.out

or something like this,I dont have my hal file in front me right now....

My collet buttons only work in manual mode,they cannot be activated in Mdi or auto and my comps have error messages,not that they are fool proof,they are a work in progress.

I have shell scripts like so

#! /bin/bash

# M124 open the parts catcher

halcmd setp hmi gpio.055.out true

end ----or what ever, again Im not at the machine.
This works for advancing my parts catcher ,as the gpio pin isnt assigned a signal name.


If I try this

#! /bin/bash

halcmd sets sl_collet_open true
or
halcmd setp hmi,gpio.056.out true

I get no output,and this makes sense as according to the manual,an output pin cant have a signal attached to it.

So,I have considered trying to "or" them together in hal although I prefer logic in comp files and Im not sure it will work.It is next.thanks for the example.

As for creating a user pin in the source,There are a bunch of unused common M codes,M21-M40 that if there was some code that basically said "when I see M31 in a g code file,I will execute the code that M31 points to",it could be a comp or userspace thing.

I would like to see some sort of executeable Mcode file that can be attached to a thread that has free Mcodes available to be defined for whatever funtions,they would interact with hal just as a comp does.

maybe like this
component Mcodes

pin in m31
pin in m32
ectc

other comp pins

//m31
code here
{
}

//m32
code here
{
}

I noticed that user mcodes can be written in csh,what are the limitations of importing signals from hal,will it work more like comp?

I appreciate everyones help,I look at things different.....

Please Log in or Create an account to join the conversation.

More
11 May 2012 14:00 #20009 by BigJohnT
Replied by BigJohnT on topic Re:M code kunundroms
My collet closer has both physical buttons and M1xx to open and close the collet closer in G code.

M100
#!/bin/sh
# open the collet closer
eval halcmd setp or2.3.in1 1
sleep 0.25
eval halcmd setp or2.3.in1 0
sleep 0.5
exit 0

M101
#!/bin/sh
# close the collet closer
halcmd setp or2.4.in1 1
sleep 0.25
halcmd setp or2.4.in1 0
sleep 0.5
exit 0

hal snippet
# External Collet Open/Close Buttons
net collet-open-btn or2.3.in0 <= hm2_5i20.0.gpio.027.in_not
net collet-close-btn or2.4.in0 <= hm2_5i20.0.gpio.025.in_not
net collet-open hm2_5i20.0.gpio.043.out <= or2.3.out
net collet-close hm2_5i20.0.gpio.041.out <= or2.4.out

Enjoy
John
The following user(s) said Thank You: chrimabelini

Please Log in or Create an account to join the conversation.

More
11 May 2012 14:04 #20011 by BigJohnT

Please Log in or Create an account to join the conversation.

More
11 May 2012 14:06 #20012 by andypugh
Replied by andypugh on topic Re:M code kunundroms
JR1050 wrote:

I get no output,and this makes sense as according to the manual,an output pin cant have a signal attached to it.

So,I have considered trying to "or" them together in hal although I prefer logic in comp files and Im not sure it will work.


In that case, simply create an extra input pin in buttonlogic, and then use logic in there to set the buttonlogic .0.sl-collet-open output pin if either is true.
(possibly also checking that another pin, linked to a spindle speed detector, is false)

As for creating a user pin in the source,There are a bunch of unused common M codes,M21-M40 that if there was some code that basically said "when I see M31 in a g code file,I will execute the code that M31 points to",it could be a comp or userspace thing.


This is already possible in the development branch.
www.linuxcnc.org/docs/devel/html/remap/structure.html
There is an awful lot of power there, though, and it isn't trivial. That might be what you want, but there my also be simpler ways.

I would like to see some sort of executeable Mcode file that can be attached to a thread that has free Mcodes available to be defined for whatever funtions,they would interact with hal just as a comp does.


You seem to be mixing a number of separate concepts there. If you are saying you want code to execute when a HAL pin changes, then you can do that with the MDI_COMMAND INI file option. (and MDI_COMMAND can call an O-word sub, or a custom M-code)
www.linuxcnc.org/docview/html/config/ini..._sub_halui_section_a

pin in m31
pin in m32


If you want to control HAL pins direct from G-code, then look at M66 and friends.

Alternatively, if you want to alter the value of HAL pins with custom M-codes, then you have already seen how to do that (for the M100-M199 codes)

I noticed that user mcodes can be written in csh,what are the limitations of importing signals from hal,will it work more like comp?

Again, I am not clear on quite what you are asking, but M100-M199 will run any executable file. If the file is a shell script then it can access HAL state through the halcmd interface. It can also use axis-remote to manipulate Axis, or linuxcncrsh to control a second, remote, linuxcnc installation over the network (linuxcnc.org/docs/html/man/man1/linuxcncrsh.1.html)
This probably still works too, though the file might have changed name: www.mailinglistarchive.com/html/emc-user...009-12/msg00461.html
If the executable file is Python or C then it needs to import various libraries, and it can interact in any way you fancy with the rest of LinuxCNC just like nay other module of the software can.

With LinuxCNC there are more ways to skin cats than they have lives. I am not sure this is a good thing, metaphorically or literally.

Please Log in or Create an account to join the conversation.

More
12 May 2012 10:47 #20029 by Rick G
Replied by Rick G on topic Re:M code kunundroms
Kinda brings us back to where we started.
You can use a button and a M1xx to effect the pin change.

Using hal you could use an OR

If button is pressed it changes the input 1 of the OR

or

M1xx changes the other OR input

either case the change is effected and the OR output pin changes.


The output to the Or connects to the collect changer pin.

Rick G

Please Log in or Create an account to join the conversation.

More
25 May 2012 02:09 - 25 May 2012 02:27 #20361 by JR1050
Replied by JR1050 on topic Re:M code kunundroms
Time finally allowed me to get back to the lathe in the shop.It turned out the best way to do this was to create a signal and import it into a comp and manipulate the i/o from there.Thanks to Andy for the suggestion.For those interested,i did it like so

This is my comp code,I have to add a section so the collet cant be opened while the spindle is running

//collet open button///

if((pb_open_col)==1&&(ls_collet_closed)==1&&(manual_mode)==1)
{
sl_col_close=0;
sl_col_open=1;
}
else
if((pb_close_col)==1&&(ls_collet_closed)==0&&(manual_mode)==1)
{
sl_col_open=0;
sl_col_close=1;
}

//collet mcodes//

if((mc_colopen)==1&&(ls_collet_closed)==1&&((auto_mode)==1||(mdi_mode)==1))
{
sl_col_close=0;
sl_col_open=1;
}
else
if((mc_colclose)==1&&(ls_collet_closed)==0&&((auto_mode)==1||(mdi_mode)==1))
{
sl_col_open=0;
sl_col_close=1;
}
Script that gets called from MDI or Auto mode

#!/bin/sh

# M121 open collet
halcmd sets mc_colclose false
halcmd sets mc_colopen true
halcmd sets mc_colopen false
exit 0


Signals created in hal

#net mc_colopen buttonlogic.0.mc-colopen #collet open mcode
#net mc_colclose buttonlogic.0.mc-colclose #collet close mcode

Close the collet

#!/bin/sh

# M122 close collet
halcmd sets mc_colopen false
halcmd sets mc_colclose true
halcmd sets mc_colclose false
exit 0


Ive also been playing with the Axis interface,Im still learning the TK/TCL part along with the python.I wanted to have all tabs similar to the way a Fanuc has soft keys,a work in
progress...




Attachments:
Last edit: 25 May 2012 02:27 by JR1050. Reason: bad pic

Please Log in or Create an account to join the conversation.

Time to create page: 0.171 seconds
Powered by Kunena Forum