# Using speedl() with a timed loop

**URL:** <https://forum.universal-robots.com/t/using-speedl-with-a-timed-loop/27959>\
**Category:** URScript\
**Created:** [April 15, 2023, 12:31pm UTC](https://forum.universal-robots.com/t/using-speedl-with-a-timed-loop/27959 "2023-04-15T12:31:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mvrooij](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/mvrooij/32/2151_2.png) [@mvrooij](https://forum.universal-robots.com/u/mvrooij)\
**Post date:** [April 15, 2023, 12:31pm UTC](https://forum.universal-robots.com/t/using-speedl-with-a-timed-loop/27959/1 "2023-04-15T12:31:53Z")

</div>

Dear,

I want to have the robot (a UR10, CB3) make a simple linear move. a movel() would do it, but I want to do some processing while the move is taking place. So I converted the arguments to movel to a difference vector and a time and use speedl() to do the move. If I use the difference vector and the time I computed, speedl works fine.

However, if I program something like:

steps = time/some\_unit\_of\_time  
speedl(xd,a) ← should start the robot off in the direction given by xd and return when the robot reaches the encoded velocity  
c = 0  
while 0 \< steps:  
steps = steps -1  
sleep(some\_unit\_of\_time)  
do\_stuff\_really\_quick()  
end  
stopl(a)

The robot stops immediately after the speedl(), then enters the timed loop… not what I wanted. If I use speedl(xd,a,time) the robot moves correctly, but I still have to wait, just as if I had used movel().

So how can I achieve this behavior? Threads don’t work (e.g. using a thread to issue a stopl()) since I get a “robot already controlled by another thread”-exception.

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [April 17, 2023, 12:15pm UTC](https://forum.universal-robots.com/t/using-speedl-with-a-timed-loop/27959/2 "2023-04-17T12:15:16Z")

</div>

Have you tried enter\_critical on your thread? I’m not sure if it would solve you problem or not:

![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/e/e7475873cc77f7ce960b8ec9a504ee17c2e76fea.png)
