# Python Script to Control movements of cobot

**URL:** <https://forum.universal-robots.com/t/python-script-to-control-movements-of-cobot/33473>\
**Category:** URScript\
**Created:** [March 28, 2024, 4:48pm UTC](https://forum.universal-robots.com/t/python-script-to-control-movements-of-cobot/33473 "2024-03-28T16:48:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![asishkumar.sharma](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@asishkumar.sharma](https://forum.universal-robots.com/u/asishkumar.sharma)\
**Post date:** [March 28, 2024, 4:48pm UTC](https://forum.universal-robots.com/t/python-script-to-control-movements-of-cobot/33473/1 "2024-03-28T16:48:24Z")

</div>

The below code works perfectly without any problem. The problem I find is the movement is not smooth. If I remove the time between commands the robot does not moves. The python code does not behaves like the pendant. Is there a way not to use the timer in between commands, and movements are smooth.

import socket  
import time  
tcp\_socket = socket.socket(socket.AF\_INET, socket.SOCK\_STREAM)  
tcp\_socket.connect((“10.232.49.5”, 30002))  
tcp\_command = ‘set\_digital\_out(2, True)\n’  
tcp\_socket.send(str.encode(tcp\_command))  
time.sleep(3)

#global Waypoint\_1\_q = [-0.07097226778139287, -2.0622245273985804, 2.2466591040240687, -1.7546187839903773, -1.562280003224508, -0.05255490938295537]

start\_point = “movel([-0.07097226778139287, -2.0622245273985804, 2.2466591040240687, -1.7546187839903773, -1.562280003224508, -0.05255490938295537], a=1.2, v=0.1)\n”  
tcp\_socket.send(str.encode(start\_point))  
time.sleep(3)

approach = “movel([0.04418822377920151, -1.6160809002318324, 2.214836899434225, -2.1689473591246546, -1.5629714171039026, 0.06623820215463638], a=1.2, v=0.1)\n”  
tcp\_socket.send(str.encode(approach))  
time.sleep(3)

Waypoint\_2 = “movel([0.02882671356201172, -1.4694293302348633, 2.212179485951559, -2.312949319879049, -1.5635736624347132, 0.05195114389061928], a=1.2, v=0.05)\n”  
tcp\_socket.send(str.encode(Waypoint\_2))  
time.sleep(3)

tcp\_command = ‘set\_digital\_out(2, False)\n’  
tcp\_socket.send(str.encode(tcp\_command))

tcp\_socket.close()

---

<div class="post-metadata">

**Author:** ![hpwgis](https://avatars.discourse-cdn.com/v4/letter/h/8edcca/32.png) [@hpwgis](https://forum.universal-robots.com/u/hpwgis)\
**Post date:** [March 29, 2024, 4:11pm UTC](https://forum.universal-robots.com/t/python-script-to-control-movements-of-cobot/33473/2 "2024-03-29T16:11:53Z")

</div>

i would recommend against sending encoded commands like that as RTDE control and receive interface handles such for you and you dont need random sleeps as such

---

<div class="post-metadata">

**Author:** ![benjamin.schmautz](https://avatars.discourse-cdn.com/v4/letter/b/c89c15/32.png) [@benjamin.schmautz](https://forum.universal-robots.com/u/benjamin.schmautz)\
**Post date:** [April 2, 2024, 1:45pm UTC](https://forum.universal-robots.com/t/python-script-to-control-movements-of-cobot/33473/3 "2024-04-02T13:45:01Z")

</div>

Check out my UR Robot Controller on GitHub.

> **[GitHub - schmautzpower/UR\_Robot\_Control: Control UR Robots with Python](https://github.com/schmautzpower/UR_Robot_Control)**
>
> Control UR Robots with Python. Contribute to schmautzpower/UR\_Robot\_Control development by creating an account on GitHub.

It contains a function called run\_program to send bulk lines of code in interpreter mode, so movements calculated in python can be run smoothly on UR. I takes the commands not encoded as list and send them.

This controller use all open ports of the Robot as RTDE, Control, Dashboard, Interpreter to grant best performance of all functions of the robot.

---

<div class="post-metadata">

**Author:** ![bba](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/bba/32/555_2.png) [@bba](https://forum.universal-robots.com/u/bba)\
**Post date:** [April 2, 2024, 3:07pm UTC](https://forum.universal-robots.com/t/python-script-to-control-movements-of-cobot/33473/4 "2024-04-02T15:07:49Z")

</div>

Hi,  
What you describe is not a good way to control our robots remotely. Once upon a time it was the method to use but it has problems and the better approach is to use RTDE natively OR, some 3rd party SDK that does this for you OR, interpreter mode as someone else has advised.

The best place to start understanding what the options are is here :  
[Developer Network](https://www.universal-robots.com/developer/)  
And, more specifically this article :  
[Five ways to program a cobot](https://www.universal-robots.com/developer/insights/five-ways-to-program-a-cobot/)  
And, on the subject of 3rd party client libraries :  
[Client libraries for external monitoring and control](https://www.universal-robots.com/developer/insights/client-libraries-for-external-monitoring-and-control/)

And finally, this article talks about all the various native interfaces and provides some examples :  
[Remote operation of robots](https://www.universal-robots.com/articles/ur/interface-communication/remote-operation-of-robots/)  
(see RemoteOperationGuideV1.1.pdf - read this thoroughly)
