Custom M code

More
01 Dec 2016 23:27 #83547 by an92626
Custom M code was created by an92626
Instead of ending my programs with an M30, I want to define a custom M code which does exactly like M30, but also moves the table to a end program position. I can do this including several G28 commands in my files, but would rather have a single custom end program code.

I tried creating a file called M130 in my cnc file folder, defined the folder in the ini file using both program_prefix and USER_M_PATH, but I get undefined M code. The file exists, it uses a capital M and no extension, and I have restart linuxcnc to allow the gui to find the file, but no luck. Have no idea what is causing the problem. Any suggestion what to look for. My M100 file only contains G code commands so maybe a user defined command is not the correct approach?

The wiki talks about custom gcode and mcodes using the CUSTOM section in the ini file, but it is not all that clear. It would be nice if I could define a M30.1 which would then run a sequence of 5-6 G codes.

Any Advice?

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

More
02 Dec 2016 08:36 #83559 by Rick G
Replied by Rick G on topic Custom M code

My M100 file only contains G code commands so maybe a user defined command is not the correct approach?

Might want to look at calling a separate .ngc file...

linuxcnc.org/docs/html/gcode/o-code.html#ocode:calling-files

Rick G

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

More
02 Dec 2016 13:28 #83572 by Todd Zuercher
Replied by Todd Zuercher on topic Custom M code
I' am not sure you can really run g-code as a custom M-code. You could simply set up an o-sub that does what you want and call that. Or for a little bit more of a challenge you should be able to do do it with remapping. linuxcnc.org/docs/html/remap/remap.html

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

More
04 Dec 2016 19:54 #83676 by an92626
Replied by an92626 on topic Custom M code
With the provided help I got this working.
I took the approach of creating a remapped m code. I decided to define a m code of m300 to take the place of the standard m30 code. Initially I was going to simply remap m30, but linuxcnc does not support remapping m code in group 4.

To start with I created a ngc subroutine named m300.ngc and placed this in the linuxcnc/nc_files folder. You can place it in other folders as long as you specify the folder's path in your ini file.
My m300.ngc file consisted of the following:
o<m300> sub
G91 G28 Z0.0
G91 G28 Y0.0
G91 G28 X0.0
G91 G28
m30
o<m300> endsub
Initially I missed the fact that that the first and last lines needed the "<m300>" with the brackets. I thought the brackets in the examples were there for highlighting the words. Also if you want your axis to return to home in a different order, you simply need to change around the g code commands in the m300.ngc file.

Once the subroutine was created and defined, I had to reference it in the ini file. The input in the ini file was as follows:
[RS274NGC]
PARAMETER_FILE = linuxcnc.var
USER_M_PATH = /home/shop/linuxcnc/nc_files
SUBROUTINE_PATH = /home/shop/linuxcnc/nc_files
REMAP=M300 modalgroup=10 ngc=m300

The subroutine_path statement defines the folder where my subroutines will be stored, and the remap statement tells linuxcnc that when a m300 command is found, go run the m300.ngc file. Depending upon what m or g code you are remapping, every m and g code is organized in one of 10 modal groups. If you are using undefined m codes, like my m300, it is a modal group = 10. If I wanted to simply remap the m30 code itself, it would have been a modal group 4, but unfortunately linuxcnc does not support remapping of modal group 4.

With these items complete and linuscnc restarted, issuing a m300 command in mdi would move the z axis to home, the y axis to home, the x axis to home, and then the a axis to home, and then if the machine was running a program, stop and rewind the program just like a m30 code would do.

I did take this remapping one step further by defining a gladevcp button on my gui which would execute this entire return to home process. To do this I followed the "adding custom mdi buttons" tutorial in the linuxcnc knowledge base.

In my hal file I included the following lines

#Define action for retract and home all buttons
net software-retract halui.mdi-command-00 gladevcp.retract
net software-homeall halui.mdi-command-01 gladevcp.home_all

These statement associate pressing the "retract" and "home_all" buttons in my gladevcp with mdi commands of 00 and 01 defined in the halui section of my ini file.

In my ini file I included the lines of
[HALUI]
MDI_COMMAND = G91 G28 Z0.0
MDI_COMMAND = M300

The first mdi_command line define a mdi command that will retract the z axis, and the second mdi_command defines a mdi command to run my newly remapped m300 command. The statements in my hal file refer to halui.mdi.command-00 and halui.mdi.command-01 which refer to the first and second mdi commands listed in the ini file. You do not actually number the mdi commands in your ini file so one need to be able to count.

That concludes how I was able to define a single m300 g code command which will return all my axis to their home position and how I can use that command in the mdi interface, in a regular ngc program, and also how I referenced that command using a gladevcp button on my gui.

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

More
07 Dec 2016 12:50 #83739 by andypugh
Replied by andypugh on topic Custom M code
It might be more robust to use G53 G0 Z0 to retract the Z, in case the G28 position were to get lost.

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

More
07 Dec 2016 23:57 #83759 by an92626
Replied by an92626 on topic Custom M code
Using the G53 G0 codes is a good idea. While I did not have trouble with the z axis, I had a issue with linuxcnc loosing the y parameter. I have been trying to figure out how to place something in the ini file to initial the parameter file values on statup, but using G53 instead fixes the problem.

Thanks.

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

Time to create page: 0.163 seconds
Powered by Kunena Forum