This python code doesn't work
08 Jan 2016 17:58 #68071
by tome
This python code doesn't work was created by tome
I am trying to change some of my gladevcp buttons to execute python code (rather than straight mdi commands). I have one button that touches off X,Y at the current location and then reloads the file. It works fine. Using that same code snippet, but removing the reload and changing the MDI command, I added another button that should go to machine zer0. But it doesn't work - kinda. That is, it causes all axes of the machine to move a tiny bit (varies on the amount but 0.050" +/-) but not all the way to home (G53 G0 X0Y0Z0) as it should. I can push the buttons many many times and it will eventually move the gantry back to home and stop. Also, the code that is working queries the initial mode, changes mode to mdi to issue the command and then sets the mode back. Again, that code is working. The same code here never completes that - it changes to mdi mode (I can see the tab switch in Axis) but it doesn't switch back.
Oh, and this is running Wheezy and 2.7.3.
Here is the code:
Oh, and this is running Wheezy and 2.7.3.
Here is the code:
def on_gomachinezero_btn_pressed(self,obj,data=None):
#t = Tkinter.Tk(); t.wm_withdraw()
c = linuxcnc.command()
s = linuxcnc.stat()
s.poll()
start_mode = s.motion_mode
c.mode(linuxcnc.MODE_MDI)
c.wait_complete()
#c.mdi("G53 G0 Z0")
#time.sleep(3)
c.mdi("G53 G0 X0Y0Z0")
#time.sleep(2)
c.mode(start_mode)
Please Log in or Create an account to join the conversation.
09 Jan 2016 00:37 #68084
by andypugh
Replied by andypugh on topic This python code doesn't work
My first guess would be that because the time.sleep is commented out, it doesn't have time to move before the mode is changed.
However, time.sleep is a terrible way to wait for home to happen.
Why not poll s.inpos until it is true then exit the routine?
linuxcnc.org/docs/2.7/html/config/python-interface.html
However, time.sleep is a terrible way to wait for home to happen.
Why not poll s.inpos until it is true then exit the routine?
linuxcnc.org/docs/2.7/html/config/python-interface.html
Please Log in or Create an account to join the conversation.
09 Jan 2016 01:19 #68089
by cmorley
Replied by cmorley on topic This python code doesn't work
try adding c.wait_complete() between the last mdi command and the mode switch
Chris M
Chris M
Please Log in or Create an account to join the conversation.
09 Jan 2016 02:10 - 09 Jan 2016 02:18 #68091
by tome
Replied by tome on topic This python code doesn't work
Chris, you were right, I ended up putting this:
while c.wait_complete() == -1:
pass
after the mdi command and before the mode switch. Apparently something was interrupting the mdi command before completion.
Now a couple more questions. First is there a difference (in the ultimate outcome) of
while c.wait_complete() == -1:
pass
vs just having:
c.wait_complete()
?
Thanks.
-Tom
PS: Andy, the time.sleeps were in there when I was thrashing around thinking there was a timing issue, I wasn't really using them and they didn't actually help oddly enough.
while c.wait_complete() == -1:
pass
after the mdi command and before the mode switch. Apparently something was interrupting the mdi command before completion.
Now a couple more questions. First is there a difference (in the ultimate outcome) of
while c.wait_complete() == -1:
pass
vs just having:
c.wait_complete()
?
Thanks.
-Tom
PS: Andy, the time.sleeps were in there when I was thrashing around thinking there was a timing issue, I wasn't really using them and they didn't actually help oddly enough.
Last edit: 09 Jan 2016 02:18 by tome.
Please Log in or Create an account to join the conversation.
09 Jan 2016 05:09 #68102
by cmorley
Replied by cmorley on topic This python code doesn't work
I just use c.wait_complete(), never tried your way.
BTW, I believe wait_complete has a maximum wait time and I think it is configurable.
BTW, I believe wait_complete has a maximum wait time and I think it is configurable.
Please Log in or Create an account to join the conversation.
09 Jan 2016 05:12 #68103
by cmorley
Replied by cmorley on topic This python code doesn't work
c.wait_complete(time in seconds) default is 1 second apparently
Chris M
Chris M
Please Log in or Create an account to join the conversation.
09 Jan 2016 05:52 #68106
by tome
I think I found that in the code for axis-remote or Axis.... I found it somewhere in the code anyway. Not sure which is better practice?
-Tom
Replied by tome on topic This python code doesn't work
I just use c.wait_complete(), never tried your way.
I think I found that in the code for axis-remote or Axis.... I found it somewhere in the code anyway. Not sure which is better practice?
-Tom
Please Log in or Create an account to join the conversation.
Time to create page: 0.130 seconds