Thread execution leads to error

Hi all,

first I watn to apologize for possibly raising an old issue again but I didn’t find an adequate (for me) solution.
My task is rather simple: I want to stop a movej depending on the value of an digital input. I tried to do it as follows:

def test():
 
 thread moveThread():
    movej(p[-0.255, -0.624, 0.462, 1.209, -2.129, 0.759], a=1.0, v=0.05)
    movej(p[-0.52, -0.319, 0.36, 0.773, -3.071, -0.285], a=1.0, v=0.05)
    return False
 end
 
 thread stopThread():
 while(digital_in[0] < 1):
   sleep(0.02)
 end
 stopj(2)
 return False
 end
 
 moveThrd = run moveThread()
 stopThrd = run stopThread()
 join stopThrd
 kill moveThrd
 kill stopThrd
 
end

test()

The robot stops, as desired, but I got an error message “Another thread is already controlling the robot” (this lead me to kill both threads, but this didn’t help). Is there a better solution for this task?

Thansk in advance,

Roland

Hi all, thanks for reading, I solved the problem in the following way:

def test():
 
 thread moveThread():
    movej(p[-0.255, -0.624, 0.462, 1.209, -2.129, 0.759], a=1.0, v=0.05)
    movej(p[-0.52, -0.319, 0.36, 0.773, -3.071, -0.285], a=1.0, v=0.05)
	return False
 end
 
 thread allThread():
 moveThrd = run moveThread()
 while(digital_in[0] < 1):
   sleep(0.02)
 end
 kill moveThrd
 stopj(2)
 return False
 end
 
 allThrd = run allThread()
 join allThrd
end

test()

Cheers,

Roland