I’m trying to define a URscript function in python using socket communication.
I have used s.send() command to pass the function, although the command is executed in python terminal it is not reflected on the robot(UR5e) means that the robot is not executing the function which we have passed.
So do we have to use s.send command to pass the function or is there some other way to do this and how we can write it to make the robot work according to the function.
Thanks in advance
Hi
Could you please tell us more in detail?
Is xmlrpc server running?
I will give you advice if you publish python code.
Here is my python code and I’m using socket communication
import socket
import time
HOST = "192.168.1.228" # The remote host
PORT = 30003 # The same port as used by the server
print "Starting Program"
count = 0
while (count<5):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
time.sleep(0.1)
def zero_ftsensor():
zero_ftsensor()
def force_mode(task_frame, selection_vector, wrench, type, limits):
task_frame= p[]
selection_vector= [0, 0, 1, 0, 0, 0]
wrench= [0.0, 0.0, 2.0, 0.0, 0.0, 0.0]
type= 2
limits= [0.1, 0.1, 0.01, 0.3490658503988659, 0.3490658503988659, 0.3490658503988659]
s.send("movej(get_inverse_kin(p[.327703289323, .476061350313, -.097627345841, -2.812739082151, 1.304660291291, -.023691609980], qnear=[1.2080140113830566, -2.283745904962057, -1.968592643737793, -0.42255671442065434, 1.551553726196289, 0.5063714981079102]), a=1.3962634015954636, v=1.0471975511965976" + "\n")
time.sleep(0.5)
s.send("movej(get_inverse_kin(p[.327714366290, .476029125399, -.118442542479, -2.812736183950, 1.304738140748, -.023707104201], qnear=[1.2080497741699219, -2.3317533932127894, -1.9631872177124023, -0.37998469293627934, 1.5515055656433105, 0.50634765625]), a=1.3962634015954636, v=1.0471975511965976" + "\n")
time.sleep(0.5)
def end_force_mode():
end_force_mode()
s.send("movej(get_inverse_kin(p[.327730194161, .476086610312, -.097604445909, -2.812638420151, 1.304676383799, -.023700524115], qnear=[1.2079901695251465, -2.283733984033102, -1.9685449600219727, -0.422532395725586, 1.551541805267334, 0.5063834190368652]), a=1.3962634015954636, v=1.0471975511965976"+ "\n")
time.sleep(0.5)
s.send("movej(get_inverse_kin(p[.303899571901, .476060424078, -.097640923256, -2.812774988664, 1.304630843166, -.023677841810], qnear=[1.2490949630737305, -2.268569131890768, -2.007960319519043, -0.39916451395068364, 1.5498871803283691, 0.547391414642334]), a=1.3962634015954636, v=1.0471975511965976)"+ "\n")
time.sleep(0.5)
def zero_ftsensor():
s.send("force_mode(tool_pose(), [0, 0, 1, 0, 0, 0], [0.0, 0.0, 2.0, 0.0, 0.0, 0.0], 2, [0.1, 0.1, 0.01, 0.3490658503988659, 0.3490658503988659, 0.3490658503988659])")
time.sleep(0.5)
s.send("movej(get_inverse_kin(p[.303899571901, .476060424078, -.097640923256, -2.812774988664, 1.304630843166, -.023677841810], qnear=[1.2490949630737305, -2.268569131890768, -2.007960319519043, -0.39916451395068364, 1.5498871803283691, 0.547391414642334]), a=1.3962634015954636, v=1.0471975511965976)" + "\n")
time.sleep(0.5)
s.send("movej(get_inverse_kin(p[.303932640600, .476072954596, -.123883177495, -2.812715881976, 1.304681068896, -.023687024763], qnear=[1.249143123626709, -2.3310352764525355, -2.000452995300293, -0.34417279184375005, 1.5498275756835938, 0.5473432540893555]), a=1.3962634015954636, v=1.0471975511965976)" + "\n")
def end_force_mode():
s.send("end_force_mode()")
time.sleep(5)
s.send(" movej(get_inverse_kin(p[.303899571901, .476060424078, -.097640923256, -2.812774988664, 1.304630843166, -.023677841810], qnear=[1.2490949630737305, -2.268569131890768, -2.007960319519043, -0.39916451395068364, 1.5498871803283691, 0.547391414642334]), a=1.3962634015954636, v=1.0471975511965976)" + "\n")
time.sleep(0.5)
s.send(" movej(get_inverse_kin(p[.303932640600, .476072954596, -.123883177495, -2.812715881976, 1.304681068896, -.023687024763], qnear=[1.249143123626709, -2.3310352764525355, -2.000452995300293, -0.34417279184375005, 1.5498275756835938, 0.5473432540893555]), a=1.3962634015954636, v=1.0471975511965976)" + "\n")
count = count + 1
print "The count is:", count
print "Program finish"
data = s.recv(1024)
s.close()
print ("Received", repr(data))
print "Status data received from robot"
How can I define a URscript function in like for example in URscript there is force_mode() function how can I deploy it in python.
Do I have to use s.send(force_mode()) to define it?
myfunction = “def myFunction():\n”+" while (1):"+"\n"+" sync()"+"\n"+" end"+"\n"+"\nend\n"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, SocketPORT))
s.sendall(myFunction.encode())
s.close()
This is a generic form, but you can easily modify to fit your application
Be careful with spaces using this method. just like python, the lines have to match
Thanks a lot for your response