Remapping M100-M199 in Python

More
15 May 2017 22:06 #93243 by DaBit
DaBit created the topic: Remapping M100-M199 in Python
I was trying to implement a couple of FDM 3D-printer M-codes, such as M104 (set extruder temperature) using remapping to a Python function.

Now, this works for available G-codes and M-codes outside the 100-199 range. If I do this:

(ini file)
..
[RS274NGC]
..
REMAP = M104 modalgroup=10 py=testfunc
..

(./python/remap.py)
..
..
def testfunc(self, **words):
    print "Hello there!"
..
..

Then using M104 in a program results in 'undefined M code'.
If I remap M204 it works fine.

Now, it is not a total disaster since one must translate reprapwhatever flavor G-code to LinuxCNC G-code anyway (or adapt the slicer), but to be honest I expected some sort of hierarchy like 'if the M1xx code is remapped using python/ngc use that, else try to find the user script, else error'.

MachineKit seems to do just that: (click, around line 629) . Is it possible to obtain the same behaviour with LinuxCNC master?
More
17 May 2017 21:27 #93316 by andypugh
andypugh replied the topic: Remapping M100-M199 in Python
This is actually very easy, and doesn't need remap.
Just create an executable python file (start the file with #! /usr/bin/python ) which contains your python code. Then call it M104

The M-codes from 100 to 199 simply execute a file of that name, and python files count as executable.
More
18 May 2017 15:46 #93356 by DaBit
DaBit replied the topic: Remapping M100-M199 in Python
Yes, I know, but it is less flexible. Only P and Q parameters, less control over interpreter; cannot choose whether the code is a queuebuster or not for example, and I have to do the remapping of e.g. M84 in ngc or python anyway. And I hate the 15 different files with 10 lines of code each, but that's not the real reason, oh nooooo.. :)

Not sure how to do AIO/DIO (M66 & companions) in script. Something like import emccanon; emccanon.SET_AUX_OUTPUT_BIT(xx) I presume?

Remapping is a nice feature, I only don't like all the exceptions and special cases. Should be a generic thing imho.
More
19 May 2017 12:35 - 19 May 2017 12:51 #93380 by bevins
bevins replied the topic: Remapping M100-M199 in Python
This works for me.

Map your motion.digital-out-xx in hal
Map your motion.digital-in-XX in hal
import linuxcnc
from interpreter import *
from emccanon import MESSAGE, SET_MOTION_OUTPUT_BIT, CLEAR_MOTION_OUTPUT_BIT,SET_AUX_OUTPUT_BIT,CLEAR_AUX_OUTPUT_BIT

def M6_Remap(self, **words):
    #--------------------------------------------------
    # if in preview mode exit without doing anything and all ok
    #----------------------------------------------------------
    if self.task==0:
        return INTERP_OK

    try:

         self.execute("M65 P2") 
         self.execute("M66 P5 L3 Q5")
         self.execute("M65 P3") 


This works extremely well.
Last Edit: 19 May 2017 12:51 by bevins.
Time to create page: 0.096 seconds
Powered by Kunena Forum