G1 Moves and Arbitrary Python within single custom G-code/M-code Help

More
22 Mar 2021 21:36 #203297 by jiso
Problem
I would like to be able to define a custom G-code or M-code able to execute arbitrary Python code between G1 moves, similar to the example below. The reason is because information about how to prepare the tool or the number of moves required is only available during execution of the ngc file.
""" remap.py """
def m200(self, **words):
    self.execute("G1 X100 Y0")
    prepare_tool_for_move()
    self.execute("G1 X100 Y100")
    prepare_tool_for_move()
    # and so on...

Things I've Tried
1. Everything Together
Placing everything in the same function results in the Python executing where it is placed, but the G-code executing after the function handler returns (i.e. in the order shown below). I think this is due to read-ahead (linuxcnc.org/docs/devel/html/remap/remap...euing_and_read_ahead).
""" remap.py """
def m200(self, **words):
    self.execute("G1 X100 Y0")     # 3
    prepare_tool_for_move()        # 1
    self.execute("G1 X100 Y100")   # 4
    prepare_tool_for_move()        # 2

2. Separating Python into its own M-code
I also tried separating the tool prep into its own M-code and then executing that from the main remap function, but was unable to get it to work. This linked topic suggests that custom remapped functions cannot be executed from remapped functions (www.forum.linuxcnc.org/10-advanced-confi...rom-a-remapped-cycle).
""" remap.py """
def m300(self, **words):
    prepare_tool_for_move()

def m200(self, **words):
    self.execute("G1 X100 Y0")
    self.execute("M300")
    self.execute("G1 X100 Y100")
    self.execute("M300")

3. Yield read-ahead
The last major thing I tried was to stop read-ahead with yield INTERP_EXECUTE_FINISH. As per testing and the documentation, it does not seem possible to execute commands with the interpreter following such a yield (linuxcnc.org/docs/devel/html/remap/remap...ntions_ngc_to_python).
""" remap.py """
def m200(self, **words):
    self.execute("G1 X100 Y0")
    yield INTERP_EXECUTE_FINISH
    prepare_tool_for_move()
    """ interpreter does not execute commands beyond here """
    self.execute("G1 X100 Y100")
    yield INTERP_EXECUTE_FINISH
    prepare_tool_for_move()

4. linuxcnc module
I've done some testing with linuxcnc.command.mdi in remaps, but I haven't gotten it to work yet, and it's not something I've examined closely.




Is there a way for this type of sequential operation to occur with a single G-code/M-code?

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

More
22 Mar 2021 22:47 #203313 by andypugh
In the Python interface there is a wait_complete() call.

linuxcnc.org/docs/2.8/html/config/python-interface.html

I don't know what that is equivalent to in the remap environment (which is different)
github.com/LinuxCNC/linuxcnc/blob/65f426...s/emcmodule.cc#L1375

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

Time to create page: 0.073 seconds
Powered by Kunena Forum