Control Z-axis movement after receiving io signal?

More
4 years 9 months ago #233039 by chen1234
Hi everyone, I'm having a problem.
I use the self.execute("G0 Z %d"%b) instruction in the remap code, it executes once after receiving an io signal, this remap code instruction can be executed normally in a single line at MDI, but I am putting this The remapping code instruction is placed in the .ngc file. It is not single-stepped but executed together until there is no signal. I need self.execute("G0 Z %d"%b) to execute once a signal is received, How should I fix it?
Thank you in advance.
Below is the code:
Code:
def m203(self,**words):     yield INTERP_EXECUTE_FINISH     if self.task:         a = (words['s'])         b = a         while 1:             x = hal.get_value('lcec.0.5.RXPDO-4')               print('x_in4 =',x)             if x == 1:                 y = hal.get_value('lcec.0.5.RXPDO-5')                   print('y_in5 =',y)                 if y == 1:                     print("in5 = ",y)                     self.execute("G0 Z %d"%b)                     b += a                 elif y == 0:                     print("in5 = ",y)             elif x == 0 or hal.get_value('lcec.0.5.TXPDO-2') == 1:                 break 

Please Log in to join the conversation.

More
4 years 8 months ago #234412 by andypugh
I think that the problem is the "while 1", which will loop all the code indefinitely.

You need to edge-detect the hal pin.
Code:
old_pin = 0while 1 if hal_pin == 1 and old_pin == 0: Do this thing once old_pin = 1 else: old pin = 1

Please Log in to join the conversation.

Time to create page: 0.149 seconds
Powered by Kunena Forum