Custom M-Code (Python)

More
16 Jul 2019 21:43 #139610 by TheBigLebowski
Replied by TheBigLebowski on topic Custom M-Code (Python)
For Reference, the code below is pulled directly from the INI file. Note that I am currently testing in virtual box, not on the machine.
# REMAPPING
# for tool change commands
REMAP=M6 modalgroup=6 prolog=zbotatc_M6_prolog ngc=m400
REMAP=M7 modalgroup=8 argspec=p py=smart_cool_M7
REMAP=M8 modalgroup=8 argspec=p py=smart_cool_M8
REMAP=M9 modalgroup=8 py=smart_cool_M9 

#for get user input stuff

REMAP=M10 modalgroup=4 python=m10
REMAP=M11 modalgroup=4 python=m11
REMAP=M12 modalgroup=4 python=m12 

# for various GUI functions
REMAP=M600 modalgroup=10 argspec=PQ ngc=m600

REMAP=g30 modalgroup=1   argspec=xyza py=g300
REMAP=m998 modalgroup=5 argspec=xyza py=m998
REMAP=g50 modalgroup=1                py=g500
REMAP=g47 modalgroup=1 argspec=xyZpqRd py=g470
REMAP=g84 modalgroup=1 argspec=rpxyza prolog=cycle_prolog epilog=cycle_epilog py=g840

[PYTHON]

TOPLEVEL= python/toplevel.py
PATH_PREPEND= python
LOG_LEVEL=8

From toplevel
import hal, time
import serial
import sys
import commands
import redis
import emccanon
from interpreter import *
from constants import *  #goody bag of values from Tormach
import tormach_file_util
import datetime

import remap

From Remap File
#!/usr/bin/python
import sys
from interpreter import *
from Tkinter import *

list = []

def m10(self, **words):
	global list
	if not self.task: return INTERP_OK
	list.append(self.blocks[self.remap_level].comment)
	return INTERP_OK

def done(self, dialog, entries):
	for entry in entries:
		val = entry[1].get()
		if val.isdigit:
			self.params[entry[0]] = float(val)
	dialog.update()
	dialog.destroy()

# Show the entries
def m11(self, **words):
	if not self.task: return INTERP_OK
	dir(self)
	global list
	entries = []
	row = 1
	if not hasattr(sys, 'argv'):
		sys.argv  = ['']
	dialog = Tk()
	dialog.title(self.blocks[self.remap_level].comment)
	for item in list:
		ret = item.split(";")
		prompt = ret[0]
		if len(ret) == 1:
			param = "_" + prompt.replace(" ", "")
		else:
			param = "_" + ret[1].replace(" ", "")
		Label(dialog, text=prompt).grid(row=row)
		entry = Entry(dialog)
		entry.grid(column=1, row=row)
		try:
			entry.insert(0, self.params[param])
		except:
			pass
		entries.append((param, entry))
		row += 1
	Button(dialog, text='OK', command=lambda: done(self, dialog, entries)).grid(row=row, column=0, sticky=W, pady=4)
	mainloop()
	return INTERP_OK

def m12(self, **words):
	global list
	list = []
	return INTERP_OK

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

More
16 Jul 2019 21:53 - 16 Jul 2019 21:54 #139613 by TheBigLebowski
Replied by TheBigLebowski on topic Custom M-Code (Python)
It just occurred to me that Tormach uses m10 and m11 for the collet closer on their lathes, so maybe the remap is being overwritten when other M codes are loaded? Though I don't see why they would be loaded when the mill INI is the one that is activated. I will try and change the M codes later on.

If anybody sees something else, let me know
Last edit: 16 Jul 2019 21:54 by TheBigLebowski.

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

More
16 Jul 2019 22:18 #139619 by andypugh
Replied by andypugh on topic Custom M-Code (Python)
Try the M22 version that appears later in the thread.

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

More
17 Jul 2019 00:12 #139649 by TheBigLebowski
Replied by TheBigLebowski on topic Custom M-Code (Python)
Still getting the same Out of Range error.

I tried the new code and it did not change anything. I also re-modified the other files just to make sure.

Any suggestions?

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

More
17 Jul 2019 00:41 #139654 by andypugh
Replied by andypugh on topic Custom M-Code (Python)
It looks like something deep down in the code is not getting a parameter it expects,

Does the error occur when you try to run the remaps, or when you start the config?

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

More
17 Jul 2019 01:17 #139662 by TheBigLebowski
Replied by TheBigLebowski on topic Custom M-Code (Python)
The INI file runs fine and brings up pathpilot as it should.

The error comes up when I attempt to run the Gcode through the mdi in Pathpilot, so it is happening somewhere in the remaps.

The last called routine is shown as Remap > (pycall(m11) > TK GUI

So either the List from the previous gcode (pycall(m10)) is being lost, or it cant find the TK file. My guess would be on the former.

To verify I think i can try to bring up the TK GUI without carrying any data to it. If it works that would point towards the previous list info being lost / mishandled.
14:17:58 | pycall(m11):
Traceback (most recent call last):

  File "python/remap.py", line 395, in m11
    dialog = Tk()

  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1762, in __init__
    baseName = os.path.basename(sys.argv[0])

IndexError: list index out

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

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
17 Jul 2019 20:28 #139717 by Todd Zuercher
Replied by Todd Zuercher on topic Custom M-Code (Python)
I don't know much of anything about Pathpilot. But it looks like it comes with some G-code remapping already. So you have to modify Andy's install instructions by only adding your new M-codes to the list of remapped codes Tormach already has in the ini file and adding the appropriate lines to Tormach's already existing remap.py file. If you tried adding a 2nd remap.py file, I don't think that will work.

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

More
20 May 2020 23:12 #168419 by spacemanspiffee
Replied by spacemanspiffee on topic Custom M-Code (Python)
Did you ever get this working? I'm starting down this rabbit hole and am running into the same error you have here.

Any help would be much appreciated.

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

More
28 Jun 2020 18:36 #173017 by TheBigLebowski
Replied by TheBigLebowski on topic Custom M-Code (Python)
I never did get this working. I have since bought a new machine (fadal) and use its built in variables to do what i wanted

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

More
22 Mar 2022 10:15 #238003 by Thom
Replied by Thom on topic Custom M-Code (Python)

If your code is part of a remap then you _can_ import emccanon. I have never figured out what the magic is to do it outside of a remap.
So, rather than a custom M-code in the M100-M199 range, you can remap another code of your choice, and then it will (probably) be easier.

Hi are there any news?
Could not find anything about this topic..
Is the emccanon access possible from an other python script (like Python Hal Component)

Best regards,
Thomas

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

Time to create page: 0.076 seconds
Powered by Kunena Forum