Remap M6 in python
- wrhammer
- Offline
- New Member
-
Less
More
- Posts: 13
- Thank you received: 0
11 Apr 2025 20:54 #326112
by wrhammer
Remap M6 in python was created by wrhammer
Pretty much got everything up and ready on my Biesse conversion but stuck on running the M6 tool change from auto mode in g-code. The M6 works great from the MDI and is really responsive using the self.execute command to execute the M64 and M65 motion output pins, G43 tool offsets etc. but nothing activates when I try and run an M6 in g-code. I've tried adding delays and waits on the interpreter, have messages printing to the log and the code runs but no outputs actually happen. I did see that the entire g-code is read first and it will immediately try the tool change but it doesn't actually happen. I get a successful tool change in my logs but the DRO and tool info don't update and none of the outputs actually fire to raise and lower solenoids for that bit. It seems like this is something really simple but struggling to find it! Any suggestions?
Please Log in or Create an account to join the conversation.
- andypugh
-
- Away
- Moderator
-
Less
More
- Posts: 23301
- Thank you received: 4938
15 Apr 2025 12:05 #326352
by andypugh
Replied by andypugh on topic Remap M6 in python
It looks like your remap "magic" in in the "remap_m6.py" file.
Can you attach that too?
Can you attach that too?
Please Log in or Create an account to join the conversation.
- wrhammer
- Offline
- New Member
-
Less
More
- Posts: 13
- Thank you received: 0
16 Apr 2025 02:06 - 16 Apr 2025 02:20 #326420
by wrhammer
Replied by wrhammer on topic Remap M6 in python
That's the main file and forgot to attach it! Here it is Andy.
-edit: Attached the latest test remap that I haven't tried yet. Original attached.
-edit: Attached the latest test remap that I haven't tried yet. Original attached.
Last edit: 16 Apr 2025 02:20 by wrhammer.
Please Log in or Create an account to join the conversation.
- Aciera
-
- Offline
- Administrator
-
Less
More
- Posts: 4306
- Thank you received: 1908
16 Apr 2025 05:36 - 16 Apr 2025 06:49 #326429
by Aciera
Replied by Aciera on topic Remap M6 in python
Python remaps are tricky to get right. I'm no expert but I have done a lot of trial and error during my work on Tilted Work Plane codes which uses a fairly complex python remap (although no M64, M65 usage).
github.com/LinuxCNC/linuxcnc/blob/master...ting/python/remap.py
On this background I would like to point out a few general things:
You might want to put something like this at the beginning of your remap so it does not execute on load:
Also note this restriction for the 'yield' feature:
linuxcnc.org/docs/html/remap/remap.html
which means that code like this is not allowed:
instead you could use:
Premature execution of the python remap by the read ahead may also be a problem. While 'yield INTERP_EXECUTE_FINISH' at the beginning would prevent that it would also bar the use of 'self.execute()' after it (as pointed out above). My usual workaround is to call the python remap through an ngc wrapper like this:
github.com/LinuxCNC/linuxcnc/blob/master...ting/python/remap.py
On this background I would like to point out a few general things:
You might want to put something like this at the beginning of your remap so it does not execute on load:
if self.task == 0: # ignore the preview interpreter
yield INTERP_EXECUTE_FINISH
return INTERP_OK
Also note this restriction for the 'yield' feature:
linuxcnc.org/docs/html/remap/remap.html
which means that code like this is not allowed:
if router_down:
print("Raising Router (P14)")
self.execute("M64 P14")
yield INTERP_EXECUTE_FINISH
time.sleep(2)
self.execute("M65 P14")
yield INTERP_EXECUTE_FINISH
instead you could use:
if router_down:
print("Raising Router (P14)")
self.execute("M64 P14")
self.execute("G04 P2")
self.execute("M65 P14")
Premature execution of the python remap by the read ahead may also be a problem. While 'yield INTERP_EXECUTE_FINISH' at the beginning would prevent that it would also bar the use of 'self.execute()' after it (as pointed out above). My usual workaround is to call the python remap through an ngc wrapper like this:
o<m6wrapper>sub
M66 L0 E0 ;force sync, stop read ahead
(call your python remap here)
M66 L0 E0
o<m6wrapper>endsub
m2
Attachments:
Last edit: 16 Apr 2025 06:49 by Aciera.
The following user(s) said Thank You: Mr. Mass
Please Log in or Create an account to join the conversation.
- Aciera
-
- Offline
- Administrator
-
Less
More
- Posts: 4306
- Thank you received: 1908
16 Apr 2025 06:16 - 16 Apr 2025 06:30 #326431
by Aciera
Replied by Aciera on topic Remap M6 in python
The task check to avoid execution on load can also be put into the ngc remap like this:
Also, as you have already found out, the 'print()' statements are actually executed during read ahead. If you want messages from the command queue you could use something like this:
o<g123remapwrapper>sub
o100 if [#<_task> EQ 1]
M66 L0 E0 ;force sync, stop read ahead
(call your python remap here)
M66 L0 E0
o100 endif
o<g123remapwrapper>endsub
m2
Also, as you have already found out, the 'print()' statements are actually executed during read ahead. If you want messages from the command queue you could use something like this:
self.execute('(msg,your debug message here)')
Last edit: 16 Apr 2025 06:30 by Aciera.
The following user(s) said Thank You: tommylight
Please Log in or Create an account to join the conversation.
- wrhammer
- Offline
- New Member
-
Less
More
- Posts: 13
- Thank you received: 0
17 Apr 2025 02:21 #326500
by wrhammer
Replied by wrhammer on topic Remap M6 in python
Thanks Aciera! Super helpful, I've pretty much just been trying anything including the yields. Makes sense to include the if self.task == 0 bit of code to keep it from executing on load and thanks for the input on read ahead. I think that is my core issue. I will give this a shot asap!
Please Log in or Create an account to join the conversation.
- wrhammer
- Offline
- New Member
-
Less
More
- Posts: 13
- Thank you received: 0
20 Apr 2025 03:24 #326744
by wrhammer
Replied by wrhammer on topic Remap M6 in python
That was it, adding the self.task == 0 at the beginning solved the read ahead issue and removing the yeilds in the middle of the g-c-code operation took care of it! Behaves like expected, M-codes execute and the tool change executes with the offset. Got quite a few commits trying to troubleshoot this one. Thanks for the help!
Please Log in or Create an account to join the conversation.
Time to create page: 0.086 seconds