Remap g-code: Wait for ngc commands to complete?
- chowderhead
- Offline
- Senior Member
-
Less
More
- Posts: 57
- Thank you received: 11
01 Feb 2023 21:35 #263467
by chowderhead
Remap g-code: Wait for ngc commands to complete? was created by chowderhead
It seems when remapping g-code, either in pure Python or using prolog/ngc/epilog, any ngc commands (either in ngc file or self.execute()) are queued and subsequent Python code is immediately executed. I need to await the conclusion of a G38 before executing subsequent code, how do I do that?
Thanks!
Thanks!
Please Log in or Create an account to join the conversation.
01 Feb 2023 22:05 #263470
by andypugh
Replied by andypugh on topic Remap g-code: Wait for ngc commands to complete?
I think that you might have almost guessed it in the title.
After a c.mdi() use a c.wait_complete()
linuxcnc.org/docs/stable/html/config/pyt...mand_code_attributes
After a c.mdi() use a c.wait_complete()
linuxcnc.org/docs/stable/html/config/pyt...mand_code_attributes
Please Log in or Create an account to join the conversation.
- chowderhead
- Offline
- Senior Member
-
Less
More
- Posts: 57
- Thank you received: 11
01 Feb 2023 22:20 #263473
by chowderhead
Replied by chowderhead on topic Remap g-code: Wait for ngc commands to complete?
Thank you for the quick reply!
That works for the linuxcnc python module, but I don't see wait_complete() in the interpreter module doing a print(dir(self)) from the python routine called by REMAP, so I don't think it'll work. I suppose I could import linuxcnc in remap.py and fire mdi commands, but it seems a bit kludgy...
That works for the linuxcnc python module, but I don't see wait_complete() in the interpreter module doing a print(dir(self)) from the python routine called by REMAP, so I don't think it'll work. I suppose I could import linuxcnc in remap.py and fire mdi commands, but it seems a bit kludgy...
Please Log in or Create an account to join the conversation.
01 Feb 2023 22:43 #263475
by andypugh
Replied by andypugh on topic Remap g-code: Wait for ngc commands to complete?
Can I see the code?
This might just be a consequence of how LinuxCNC works, with a realtime queue that is fed from userspace code.
Without actually setting up a remap I can't easily see what the interpreter library can do (it's not importable outside a remap, AFAIK).
Can you dir(interpreter) in your remap and look for a flush() command?
This might just be a consequence of how LinuxCNC works, with a realtime queue that is fed from userspace code.
Without actually setting up a remap I can't easily see what the interpreter library can do (it's not importable outside a remap, AFAIK).
Can you dir(interpreter) in your remap and look for a flush() command?
Please Log in or Create an account to join the conversation.
- chowderhead
- Offline
- Senior Member
-
Less
More
- Posts: 57
- Thank you received: 11
01 Feb 2023 23:05 - 01 Feb 2023 23:06 #263476
by chowderhead
Replied by chowderhead on topic Remap g-code: Wait for ngc commands to complete?
There is no flush in interpreter.
The following blows up with a cryptic error message:
The following blows up with a cryptic error message:
from interpreter import *
from emccanon import MESSAGE
import hal
from time import sleep, time
throw_exceptions = 1
def M33(self, **words):
if not hal.get_value('welder.wc_ready'):
self.set_errormsg('Weld controller is not ready')
return INTERP_ERROR
if hal.get_value('welder.touch_start'):
# Enable touch sense:
touch_sense = hal.get_value('welder.touch_sense')
if touch_sense:
# Shouldn't happen
self.set_errormsg('M33 called but touch sense already enabled')
return INTERP_ERROR
else:
hal.set_p('welder.touch_sense', '1') # Value must be a string
# Wait until touch sense has been enabled
enabled = hal.get_value('welder.touch_sense_enabled')
while not enabled:
sleep(0.1)
enabled = hal.get_value('welder.touch_sense_enabled')
self.execute('G90')
self.execute('G38.2 Z-10 F10')
self.execute('G91')
hal.set_p('welder.touch_sense', '0')
hal.set_p('welder.welder_on', '1')
return INTERP_OK
Last edit: 01 Feb 2023 23:06 by chowderhead.
Please Log in or Create an account to join the conversation.
01 Feb 2023 23:49 #263479
by andypugh
Replied by andypugh on topic Remap g-code: Wait for ngc commands to complete?
It's probably no help, but what is the cryptic error message?
Please Log in or Create an account to join the conversation.
02 Feb 2023 03:25 #263490
by cmorley
Replied by cmorley on topic Remap g-code: Wait for ngc commands to complete?
yield INTERP_EXECUTE_FINISH
A little bit on it near the end of this section.
linuxcnc.org/docs/2.9/html/remap/remap.h...ntions_ngc_to_python
A little bit on it near the end of this section.
linuxcnc.org/docs/2.9/html/remap/remap.h...ntions_ngc_to_python
The following user(s) said Thank You: chowderhead
Please Log in or Create an account to join the conversation.
- chowderhead
- Offline
- Senior Member
-
Less
More
- Posts: 57
- Thank you received: 11
02 Feb 2023 16:01 #263531
by chowderhead
Replied by chowderhead on topic Remap g-code: Wait for ngc commands to complete?
Thank you! There is a lot on that page to digest, and I didn't see this one. I'll give it a try when I'm back in the shop.
On a related note, I'm running 2.10 on my home machine and 2.9 at the shop. They seem to yield different results with similar remaps. I'll confirm today and post the results here.
On a related note, I'm running 2.10 on my home machine and 2.9 at the shop. They seem to yield different results with similar remaps. I'll confirm today and post the results here.
Please Log in or Create an account to join the conversation.
- chowderhead
- Offline
- Senior Member
-
Less
More
- Posts: 57
- Thank you received: 11
03 Feb 2023 16:42 - 03 Feb 2023 16:45 #263608
by chowderhead
Replied by chowderhead on topic Remap g-code: Wait for ngc commands to complete?
Thanks for the help, works a charm!
I can confirm a difference between 2.9 and 2.10. The following simple remap:
Initialized by:
Completes without issue in 2.9, but produces the following in 2.10:
I can confirm a difference between 2.9 and 2.10. The following simple remap:
def M34(self, **words):
self.execute('G91')
self.execute('G1 Z-0.1 F300')
self.execute('G90')
Initialized by:
REMAP= M34 modalgroup=10 python=M34
Completes without issue in 2.9, but produces the following in 2.10:
emc/task/emctask.cc 69: interp_error: remap_finished: got -13 - not in cblock.remappings!
remap_finished: got -13 - not in cblock.remappings!
Last edit: 03 Feb 2023 16:45 by chowderhead. Reason: Copied meta data
Please Log in or Create an account to join the conversation.
03 Feb 2023 18:08 #263614
by cmorley
Replied by cmorley on topic Remap g-code: Wait for ngc commands to complete?
Please Log in or Create an account to join the conversation.
Time to create page: 0.084 seconds