# How to vary speed of robot based on an input signal

**URL:** <https://forum.universal-robots.com/t/how-to-vary-speed-of-robot-based-on-an-input-signal/35053>\
**Category:** URScript\
**Created:** [July 3, 2024, 8:03am UTC](https://forum.universal-robots.com/t/how-to-vary-speed-of-robot-based-on-an-input-signal/35053 "2024-07-03T08:03:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fs-mc.praktikant](https://avatars.discourse-cdn.com/v4/letter/f/f1d935/32.png) [@fs-mc.praktikant](https://forum.universal-robots.com/u/fs-mc.praktikant)\
**Post date:** [July 3, 2024, 8:03am UTC](https://forum.universal-robots.com/t/how-to-vary-speed-of-robot-based-on-an-input-signal/35053/1 "2024-07-03T08:03:15Z")

</div>

I would like to set the speed of each move type to a variable that changes according to an analog input 0-10 V.  
For example MoveP which is normally  
MoveP(p[x,y,z,rx,ry,rz],a,v,r)  
and a specific example from a script would be  
movep(p[-.476374192653, -.110109454364, .411062508372, 1.778737983435, -.728764202005, -1.755000199148], a=1.2, v=0.25, r=0.0)  
How could i change the v=0.25 to a variable that is calculated from the analog input value like  
var\_1 := analog\_in[0]  
var\_2 := var\_1 \* 2  
v := var\_2  
The v set as var\_2 does not correlate with the v in the movep(), it is simply a different object called v.  
Ideally the speed would be calculated every tick (8 ms) and the value will be continually updated during the run of the program.

General info I am using a UR5/CB3 with URSoftware 3.12.1.90940  
Any help would be appreciated

---

<div class="post-metadata">

**Author:** ![robin\_gdwl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/robin_gdwl/32/2676_2.png) [@robin\_gdwl](https://forum.universal-robots.com/u/robin_gdwl)\
**Post date:** [July 3, 2024, 1:46pm UTC](https://forum.universal-robots.com/t/how-to-vary-speed-of-robot-based-on-an-input-signal/35053/2 "2024-07-03T13:46:22Z")

</div>

Hey,  
I believe you are thinking about variable assignment in the wrong way.  
What you would need to do is assign `v=var_2` inside of the movep command.

So simply do this:

```python
var_1 := analog_in[0]
var_2 := var_1 * 2
movep(p[-.4763, -.1101, .41106, 1.7787, -.72876, -1.755000], a=1.2, v = var_2, r=0.0)

```

Are you trying to change the robot speed while the robot is still moving to the pose specified in the movep command?  
Usually you set the speed once per command and then only change it after the target pose was reached.  
If you want to change speeds while the robot is moving you cant do that via the v-parameter in the movep command. You would need to change the override speed via a socket connection to the secondary interface as explained here:

[https://www.universal-robots.com/articles/ur/programming/setting-the-speed-slider-inside-program/](https://www.universal-robots.com/articles/ur/programming/setting-the-speed-slider-inside-program/)

---

<div class="post-metadata">

**Author:** ![fs-mc.praktikant](https://avatars.discourse-cdn.com/v4/letter/f/f1d935/32.png) [@fs-mc.praktikant](https://forum.universal-robots.com/u/fs-mc.praktikant)\
**Post date:** [July 17, 2024, 12:10pm UTC](https://forum.universal-robots.com/t/how-to-vary-speed-of-robot-based-on-an-input-signal/35053/3 "2024-07-17T12:10:26Z")

</div>

Hi robin\_gdwl.

> Blockquote

Are you trying to change the robot speed while the robot is still moving to the pose specified in the movep command?

Yes this was what I wanted. The set slider speed program is what I used with these changes:

1. a separate thread that calculates the speed as calculateSpeed(analog\_in[0])
2. adding the sync() command to the main thread
3. replacing the digital\_in[0] in the link with analog\_in[0]
4. setting the speed\_high to the calculatedSpeed(analog\_in[0])

thank you for the help!
