Hello,
I use a URScript thread to make a light blink:
thread vert_clignotant_gauche_thread():
vert_clignotant_gauche_polarity=False
while True:
if vert_clignotant_gauche_polarity:
set_analog_out(0, 0.5)
vert_clignotant_gauche_polarity=False
else:
set_analog_out(0, 0)
vert_clignotant_gauche_polarity=True
end
sleep(0.5)
end
end
When the robot is not moving, it works fine.
However, when the robot is moving, the thread gets launched, it does one loop in the while and then stops without showing any warning in the logs.
Any idea what is happening?
Thanks
Syntax seems good. I usually include a sync() command inside most while(true) loops. I’m guessing the only reason you don’t see a runtime error is due to the sleep command, but it happening only when the robot is moving makes it sound like a possible scheduling error, which a sync() might correct.
Thanks for your reply. Would you place the sync() before or after the sleep command?
I usually put it as the last instruction before the loop restarts, so right after the sleep. I’d probably throw another sync() before the End of the actual thread as well, just for kicks.
Hello, I just tried what you mentionned, the behaviour did not change. Any idea?
Thanks
The script you sent shows the definition of the thread. When are you actually starting it?
I launch a thread in an installation URCAP what is constantly watching a push button.
If the button is pushed, then it launches light blink thread.
The button thread does not stop because I still can see global variables changing when I push the button
How are you monitoring it/launching it from a button push in the CAP? If you’re using sockets, you may be running it as primary when it should use the secondary socket. I usually just launch all my threads to start, and include a locking boolean that I control in the code. So like:
while(runThread == False):
sync()
end
//Do
//Thread
//Stuff
That way the thread is always running, and unlocks itself when the variable changes to true. Not sure if that could fix your problem or not
Your solution made it work. Thanks a lot.