In Polyscope we have “check expression continuously”. If we place a movel in a loop and select “check expression continuously” the robot can exit the loop and thus the movel before the robot reaches the next way point. By way of example, if we have a loop expression that exits at 1 minute and inside the loop we have a movel to a waypoint that take 3 minutes, with check_expression_continuously, the robot will jump out of the movel (use stopj(.25) for smoothing).
How can I achieve this Polyscope function but using entirely URScript? I’ve tried different versions of loops and incorporated threads, but none of these actually work. The robot always continues to the programmed waypoint before exiting the loop.
Hi,
if you save a Polyscope program having a moveL with a “check expression continuously”, then you can retrieve the .script file generated automatically.
For example if you save the program test.urp, in the same folder you will find test.script. You can open this file in a script node on Polyscope or directly connecting to the controller.
In this way you can see exactly how UR implements it using URscript.
Move should be executed on a separate thread.
Here is an example of script code:
thread move_robot():
movej(pt2_q)
move_done = True
end
# execute move on another thread
global move_done = False
move_th = run move_robot()
interrupt_move = True
cycle_counter = 0
# Wait until robots gets to the final position, or gets interrupted
while(not move_done):
sync()
cycle_counter = cycle_counter + 1
# below line is an example where move is interrupted after 0.4s
if interrupt_move and cycle_counter > 0.4 / 0.002:
kill move_th
stopj(0.25)
break
end
end
textmsg("Interrupt: " + to_str(interrupt_move) + ", Z = " + to_str(get_actual_tcp_pose()[2]))
Where pt2 is target waypoint. Depending on interrupt_move value move will be either executed until the end, or interrupted after 0.4s.
That would be correct in this simple example, but sync/if approach is more universal where sleep can be replaced with waiting for I/O, position, fieldbus etc