If statement continues to run even after condition is no longer met


#1

I have tried using blocky and teach programming methods and I’m stuck on the same issue

I am sending 24V to input 1 for 1 second and it turns off. I only want the dobot to run the motion 1 time and then wait until input 1 goes high again which may be 30 seconds, 5 minutes, whatever. The script begins correctly, the MG400 waits until my input trigger happens, but the script then keeps running again and again even though the input has gone low and the if statement no longer matches correctly.

When input 1 = 0, it should go to its waiting position at P3. Instead it runs about dozen times from P1 to P2 even though the if statement does not match true. It does eventually stop on its own some 35-40 seconds later. I can verify looking at the I/O panel that input 1 goes high and goes back low as intended. Not sure whats going on here! Heres a screenshot of my code.

Thanks in advance


#2

You need to add “Stop at this point” after Jump to P2 and MovJ to P3


#3

Thanks Hans, That did it! although I don’t fully understand why my code doesn’t work and why the stop command is necessary.

Is ‘Stop at this point’ basically an ‘exit’ or ‘break’ statement? I figured by me forcing the ‘repeat forever’ on the loop that it should ignore the first statement when the condition is no longer met. Trying to get a better understanding of how it processes the code and when I can rely on state changes and conditional statements.

Thanks


#4

I am having the same issue, but the “Stop at this point” or “Sync()” did not work for me. :frowning:


#5

Can you take a screenshot or post your code?


#6

I managed to get it to work using break and Sync() functions. Not very intuitive though.

while 1 do
if (DI(9))==1 then
DO(2,0)
print((DI(9)))
Sync()
break
else
DO(2,1)
Wait(500)
DO(2,0)
Wait(1000)
Sync()
end
end