Remap M6 in python

More
1 year 6 months ago #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 to join the conversation.

More
1 year 6 months ago #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?

Please Log in to join the conversation.

More
1 year 6 months ago #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.

Please Log in to join the conversation.

More
1 year 6 months ago #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:
Code:
if self.task == 0: # ignore the preview interpreter     yield INTERP_EXECUTE_FINISH     return INTERP_OK

Also note this restriction for the 'yield' feature:
 

Attachment not found


linuxcnc.org/docs/html/remap/remap.html

which means that code like this is not allowed:
Code:
            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:
Code:
            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:

Code:
o<m6wrapper>sub M66 L0 E0                                                   ;force sync, stop read ahead     (call your python remap here) M66 L0 E0 o<m6wrapper>endsub m2

Please Log in to join the conversation.

More
1 year 6 months ago #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:
Code:
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:
Code:
self.execute('(msg,your debug message here)')

Please Log in to join the conversation.

More
1 year 6 months ago #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 to join the conversation.

More
1 year 6 months ago #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 to join the conversation.

Time to create page: 0.091 seconds
Powered by Kunena Forum