Sending URScript to UR5 using Python socket

Hello,
I am trying to send a URScript code to UR5 via Python socket and I have tried this method:

I need force_mode to be activated during robot movement and I have tried sending one line at a time but then when the force_mode command is sent, it is activated and deactivated before sending another line. Also, I have tried sending the entire URScript at once (force_mode with moveL commands) but nothing happened. Robot did not move.

Does moveL work only when sending line by line? Is there a way to maintain force_mode when the robot is moving through desired points?

Something missing on that tutorial is that those commands are independent from each other, and it just executes them as 1-line programs. When you want to send a script that might affect the rest of the script or following commands, you have to send it as a function:

def myFun():
     # command_1 
     # command_2
     # ...
end

This way the robot will keep receiving all the commands until the last end is received, and executed them as a single program. Then the force_mode will remain active until the end.

Thank you so much, here is the example that works.

Script code:

def myFun():
while(True):
force_mode(tool_pose(), [1, 1, 0, 0, 0, 0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 2, [0.2, 0.2, 0.1, 0.35, 0.35, 0.35])
movej(get_inverse_kin(p[-0.06,-0.42,0.5,1.4,-0.6,0.3], qnear=[4.91,-1.42,-1.51,2.99,-1.15,0.57]),a=1.4,v=1.04)
movej(get_inverse_kin(p[-0.06,-0.5,0.5,1.4,-0.6,0.3], qnear=[4.8,-1.7,-1.16,2.98,-1.21,0.57]),a=1.4,v=1.04)
end
end

myFun()

Python code:

#!/usr/bin/env python3
import socket
import time
HOST=“192.168.22.14”
PORT=30002
print(“Starting program”)
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((HOST,PORT))
time.sleep(1)
f = open(“/home/lukrecia/catkin_ws/src/ft300s/src/funkcija.txt”, “rb”)
l = f.read(1024)
print(l)
s.sendall(l)
time.sleep(5)
print(“End program”)
data=s.recv(1024)
s.close()
print(“Receved”,repr(data))

1 Like