User defined M-codes ***SOLVED***

More
30 Sep 2019 01:30 - 02 Oct 2019 22:28 #146662 by Scot
Hey there, folks,

I'm getting closer on my retrofit. And I'm at another point where my knowledge base isn't up to par with my desire.

What I'm trying to do is make my collet open and close using a user defined M-code since there is no such monkey in LinuxCNC, straight out of the box. I've read a bit on it but I'm not sure of specifics that I need to do.

My machine is set up with a relay that's wired and in place which operates the air solenoid that opens and closes my collet closer on my lathe. I'm using Pico-system's PWM board and everything is wired and in place. But the code and it's placement is missing.

That's what I'm under-educated with. Code is not my best suit, YET. I understand a tiny bit of it and I know I have to write a script that fits into one of the files in the my home/linuxcnc/configs file. But I don't quite understand exactly where to put it and how to marry it to the PWM board to operate it from an m-code command.

The bit of info which explains the idea is here:

linuxcnc.org/docs/2.7/html/gcode/m-code.html#mcode:m100-m199

This is a snippet from the user defined M-code section:

For example to open and close a collet closer that is controlled by a parallel port pin using a bash script file using M101 and M102. Create two files named M101 and M102. Set them as executable files (typically right click/properties/permissions) before running LinuxCNC. Make sure the parallel port pin is not connected to anything in a HAL file.

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

M102 Example File

#!/bin/bash
# file to turn off parport pin 14 to open the collet closer
halcmd setp parport.0.pin-14-out False
exit 0

From what I understand, this is the basic idea for what I want to do with my machine. The questions I have are where exactly do I place this kind of code and what pin do I marry it to, in order to make it work with the PWM board I have up and running? I don't understand how to make the file executable or where to put it so it works when I open LinuxCNC.

I see that likely the M101 would be to open the collet using these lines:

halcmd setp parport.0.pin-14-out True
exit 0

And I see that these lines would be to close the collet:

halcmd setp parport.0.pin-14-out False
exit 0

I'm just unsure what it means to make them executable or where to put them so they are executable. I'm waiting to hear back from Jon on which pins to associate with the script, but I figured I would put it out, here, too.

Any of you gurus out there able to share the things I'm missing?

Thanks in advance,

Scot
Last edit: 02 Oct 2019 22:28 by Scot. Reason: I solved the issue with the amazing help of the brilliant members of this list!

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

More
30 Sep 2019 02:21 #146667 by Todd Zuercher
Replied by Todd Zuercher on topic User defined M-codes
I answered your questions about where to save the file in your other thread,

To mark the file as executable, there are a few ways to do it. One way is to right click on the file in a file manager, select properties, security, then check the box for make executable. Or from a terminal, navigate to the files location then type "chmod +x yourfilename".
The following user(s) said Thank You: Scot

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

More
30 Sep 2019 06:36 - 30 Sep 2019 06:39 #146681 by pl7i92
Replied by pl7i92 on topic User defined M-codes
it is way better to not set the pin direct
use a SIGNAL

and set the signal
like sets insted of the setp
so you can track that signal in HAL
and use it to display the state
in order with a led in a panel

net collet parport.0.pin-14-out

M101 Example File

#!/bin/bash
# file to turn on parport pin 14 to open the collet closer
halcmd sets collet True
exit 0

M102 Example File

#!/bin/bash
# file to turn off parport pin 14 to open the collet closer
halcmd sets collet False
exit 0
Last edit: 30 Sep 2019 06:39 by pl7i92.
The following user(s) said Thank You: Scot

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

More
01 Oct 2019 23:42 #146839 by Scot
Replied by Scot on topic User defined M-codes
Well like I've said many times before, I'm really not versed in this stuff, but learning at a very rapid pace.

So if I set this up using a SIGNAL, where would I put this code?
"net collet parport.0.pin-14-out"

The current M100 and M101 files I have are placed in the ../linuxcnc/nc_files, file and appear like this:

This is the M100:

#!/bin/bash
halcmd setp ppmc.0.dout.04.out True
exit 0

This is the M101:

#!/bin/bash
halcmd setp ppmc.0.dout.04.out False.
exit 0

I can change the code in the M100 and M101 files without a hitch but I'm not sure where to put the code you recommended to use setting this up as a SIGNAL.

Scot

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

More
02 Oct 2019 02:03 #146845 by HueyHQ
Replied by HueyHQ on topic User defined M-codes

So if I set this up using a SIGNAL, where would I put this code?
"net collet parport.0.pin-14-out"

Put this in your HAL file - either in the main your_machine.hal or in a custom one.
I think in the main HAL file, there is a section for input and output signals, if you've used PNCConf, that is. But can go anywhere.

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

More
02 Oct 2019 08:46 #146866 by pl7i92
Replied by pl7i92 on topic User defined M-codes
to keep things togeter it is always best to get the pinouts to the MAIN Hal
as i asked you to only get a signal conected to the PIN ppmc.0.dout.04.out
in main
net collet ppmc.0.dout.04.out

This is the M100:

#!/bin/bash
halcmd sets collet True
exit 0

This is the M101:

#!/bin/bash
halcmd sets collet False.
exit 0

you can also use "sets collet 1" "sets collet 0"

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

Time to create page: 0.154 seconds
Powered by Kunena Forum