Custom Python M-code. Interpreter state not idle
04 Aug 2023 10:41 #276878
by Faggan
Custom Python M-code. Interpreter state not idle was created by Faggan
Hi,
Im writing a custom python M-code. according to manuals and guides it is recommended to check the interpreter state (among other things) before sending commands.
(s.interp_state == linuxcnc.INTERP_IDLE)
s.interp_state returns an integer 0-3 that corresponds with the state. The Idle state is from what i can understand integer 0.
However. The state returned is 2 (paused?) I get the same result on my physical machine and in simulation.
In short. because its not idle i cant send mdi commands. Or at least i think thats why. Never the less, it should be idle...
I have copied the example in the python interface manual and it has the same issue.
Im writing a custom python M-code. according to manuals and guides it is recommended to check the interpreter state (among other things) before sending commands.
(s.interp_state == linuxcnc.INTERP_IDLE)
s.interp_state returns an integer 0-3 that corresponds with the state. The Idle state is from what i can understand integer 0.
However. The state returned is 2 (paused?) I get the same result on my physical machine and in simulation.
In short. because its not idle i cant send mdi commands. Or at least i think thats why. Never the less, it should be idle...
I have copied the example in the python interface manual and it has the same issue.
Please Log in or Create an account to join the conversation.
04 Aug 2023 13:51 #276887
by MaHa
Replied by MaHa on topic Custom Python M-code. Interpreter state not idle
Sometimes, for inspiration how to solve a certain problem, i have a look at other linuxcnc python code, eg. axis ui.
github.com/LinuxCNC/linuxcnc/blob/master...axis/scripts/axis.py
From line 963 to 993 could be related to what you are doing.
github.com/LinuxCNC/linuxcnc/blob/master...axis/scripts/axis.py
From line 963 to 993 could be related to what you are doing.
Please Log in or Create an account to join the conversation.
04 Aug 2023 14:01 #276888
by Faggan
Replied by Faggan on topic Custom Python M-code. Interpreter state not idle
Hi,
Thanks for your reply.
It looks a lot like what i've seen on other examples.
My main issue is that s.interp_state == linuxcnc.INTERP_IDLE is never true.
I have even tried omitting that check and running a simple mdi command like: "c.mdi("G0 X10 Y20")" but the command is not processed. Instead i get a "KeyboardInterrupt" and the program exits. Probably due to the fact that the Interpreter is indeed not idle.
Thanks for your reply.
It looks a lot like what i've seen on other examples.
My main issue is that s.interp_state == linuxcnc.INTERP_IDLE is never true.
I have even tried omitting that check and running a simple mdi command like: "c.mdi("G0 X10 Y20")" but the command is not processed. Instead i get a "KeyboardInterrupt" and the program exits. Probably due to the fact that the Interpreter is indeed not idle.
Please Log in or Create an account to join the conversation.
04 Aug 2023 16:38 - 04 Aug 2023 16:39 #276911
by cmorley
Replied by cmorley on topic Custom Python M-code. Interpreter state not idle
Hard to diagnosis accurately without sample code, but are you polling s right before the interpreter state check?
Last edit: 04 Aug 2023 16:39 by cmorley.
Please Log in or Create an account to join the conversation.
04 Aug 2023 16:51 #276913
by Faggan
Replied by Faggan on topic Custom Python M-code. Interpreter state not idle
This code wont work: (copied from python interface manual)
import linuxcnc
s = linuxcnc.stat()
c = linuxcnc.command()
def ok_for_mdi():
s.poll()
return not s.estop and s.enabled and s.homed and (s.interp_state == linuxcnc.INTERP_IDLE)
if ok_for_mdi():
c.mode(linuxcnc.MODE_MDI)
c.wait_complete() # wait until mode switch executed
c.mdi("G0 X10 Y20 Z30"
Thats not the specific code I want to run. But it has the same issue.
The issue specifically is: (s.interp_state == linuxcnc.INTERP_IDLE)
This is not true the interpreter is not idle.
s.interp_state returns a 2. From what i can tell from the manual, provided the statuses for interp_state is in order 2 should mean INTERP_PAUSED.
import linuxcnc
s = linuxcnc.stat()
c = linuxcnc.command()
def ok_for_mdi():
s.poll()
return not s.estop and s.enabled and s.homed and (s.interp_state == linuxcnc.INTERP_IDLE)
if ok_for_mdi():
c.mode(linuxcnc.MODE_MDI)
c.wait_complete() # wait until mode switch executed
c.mdi("G0 X10 Y20 Z30"
Thats not the specific code I want to run. But it has the same issue.
The issue specifically is: (s.interp_state == linuxcnc.INTERP_IDLE)
This is not true the interpreter is not idle.
s.interp_state returns a 2. From what i can tell from the manual, provided the statuses for interp_state is in order 2 should mean INTERP_PAUSED.
Please Log in or Create an account to join the conversation.
04 Aug 2023 17:57 #276922
by cmorley
Replied by cmorley on topic Custom Python M-code. Interpreter state not idle
Took a bit for the penny to drop
This is an mcode, so the interpreter is always running - 2 is interp reading.
This is an mcode, so the interpreter is always running - 2 is interp reading.
Please Log in or Create an account to join the conversation.
04 Aug 2023 18:07 #276923
by Faggan
Replied by Faggan on topic Custom Python M-code. Interpreter state not idle
Ok? But then how do i get access to it with a python script? Can i?
Please Log in or Create an account to join the conversation.
05 Aug 2023 05:18 #276971
by cmorley
Replied by cmorley on topic Custom Python M-code. Interpreter state not idle
you don't need to - you already know what state the interpreter is in: 2, reading.
I'm not an expert on mcodes, but i don't think running MDI commands is possible.
What are you actually trying to do with the M code?
I'm not an expert on mcodes, but i don't think running MDI commands is possible.
What are you actually trying to do with the M code?
Please Log in or Create an account to join the conversation.
09 Sep 2023 10:40 - 09 Sep 2023 10:40 #280326
by andypugh
Replied by andypugh on topic Custom Python M-code. Interpreter state not idle
Just got to this.
Inside a remap you can use canon commands, rather than MDI if you want axis movements etc.
If you look in the stdglue routines you will (probably) not see any use of MDI, but rather things like:
Inside a remap you can use canon commands, rather than MDI if you want axis movements etc.
If you look in the stdglue routines you will (probably) not see any use of MDI, but rather things like:
emccanon.enqueue_SET_SPINDLE_SPEED(self.speed[0])
Last edit: 09 Sep 2023 10:40 by andypugh.
Please Log in or Create an account to join the conversation.
10 Sep 2023 19:08 #280424
by cmorley
Replied by cmorley on topic Custom Python M-code. Interpreter state not idle
Can you post the example you are referencing? I can't tell if you are remapping an mcode or running an external program from an mcode.
Please Log in or Create an account to join the conversation.
Time to create page: 0.133 seconds