UR Script: Send Commands from host (PC) to robot via socket connection.
The example “UR Script: Script programming from the teaching pendant.”on CB2 forum used the “Script” function available in the teaching pendant to type Script code or import entire files with script code program into the robot and run from the teaching pendant.
UR Script: Script programming from the teaching pendant.
Note: Variable will not work when sending raw script commands because variables (and other programming technique like loop – If-Else etc) needs to be controlled either by the external host program (e.g. a Python program) – or within a Polyscope program. Such variable cannot be left in between a host program and a Polyscope program – there is no controller in between.
To send variables – make loops – use If-Else and to get informations back from the robot then the client-server method can be considered.
UR Script: Client-Server example.
Application Description:
This example focus on making a script that entirely control the robot remotely from a host computer by Script programming.
The format is the same as in previous chapter and as documented in the Script manual, but the teaching pendant is not used for programming in this example. On the robot a server on TCP port 30002 is running to receive script commands and thereby control the robot.
Python® is used as the scripting language for making these program for testing the script programming with the robot. The Script file can also still be edited in a Notepad.
With this method the data flow is sort of “one way” i.e. it is possible to send commands to the robot, but it is not meant to read data back i.e. inputs or other read data cannot be send back to the host with this method. To send back data see the “Client-Server” example.
Function description:
1. Script program for Socket connection to test the connection:
The first program example is just to test the connection and illustrate how to send a script file through via the Ethernet to the TCP port 30002 on the robot.
In this case the robot has already been configured to IP address 192.168.0.9 and the host must be in the same subnet e.g. in this example defined as 255.255.255.0
Programm description:
The first Program 1 just turns digital output number 2 ON and the robot does not move at all and the program looks like this.
# Echo client program import socket HOST = "192.168.0.9" # The remote host PORT = 30002 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT))
s.send ("set_digital_out(2,True)" + "\n")
data = s.recv(1024)
s.close()
print ("Received", repr(data))
When the program is run the robot sends back status data which is normal.
The program is run from the host computer and will only have one passage because there is no loop in the program.
The library “socket” in imported into the program so the Socket connection is available. The “Host” in this case is the Robot and “PORT” is the open port on the Robot that listens for Script code.
Then the Script code necessary to connect and send on the Socket. The “s.send” command send that actual script code for the robot to execute which in the case is (“set_digital_out(2,True)” Which is like previous chapter. The + “\n”) at the end of the line is a linefeed because the Robot need a linefeed after each command. The Socket connection needs to be closed again with the s.close() command. The print (“Received”, repr(data)) command prints the output from the robot on the Host or PC monitor – in this case status data.
The second Program 2 is similar and just turn digital out number 2 OFF again and the robot does not move at all.
# Echo client program import socket HOST = "192.168.0.9" # The remote host PORT = 30002 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT))
s.send ("set_digital_out(2,False)" + "\n")
data = s.recv(1024)
s.close()
print ("Received", repr(data))
When the program is run the robot sends back status data which is normal.
2. Script program for Socket connection that makes the robot move:
This program send in Script mode via socket port runs through 6 Waypoints.
The first 3 positions are defined by joint position data.
The next 3 positions are defined by a pose.
Notice the “p” in front of the data wich are represented as X, Y, Z, Rx, Ry, Rz.
# Echo client program import socket import time
HOST = "192.168.0.9" # The remote host PORT = 30002 # The same port as used by the server
print "Starting Program"
count = 0 while (count < 1): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) time.sleep(0.5)
print "Set output 1 and 2 high"
s.send ("set_digital_out(1,True)" + "\n") time.sleep(0.1) s.send ("set_digital_out(2,True)" + "\n") time.sleep(2)
print "Robot starts Moving to 3 positions based on joint positions"
s.send ("movej([-1.95, -1.58, 1.16, -1.15, -1.55, 1.18], a=1.0, v=0.1)" + "\n") time.sleep(10)
s.send ("movej([-1.95, -1.66, 1.71, -1.62, -1.56, 1.19], a=1.0, v=0.1)" + "\n") time.sleep(10)
s.send ("movej([-1.96, -1.53, 2.08, -2.12, -1.56, 1.19], a=1.0, v=0.1)" + "\n") time.sleep(10)
print "Robot starts Moving to 3 positions based on pose positions"
s.send ("movej(p[0.00, 0.3, 0.4, 2.22, -2.22, 0.00], a=1.0, v=0.1)" + "\n") time.sleep(10)
s.send ("movej(p[0.00, 0.3, 0.3, 2.22, -2.22, 0.00], a=1.0, v=0.1)" + "\n") time.sleep(10)
s.send ("movej(p[0.00, 0.3, 0.2, 2.22, -2.22, 0.00], a=1.0, v=0.1)" + "\n") time.sleep(10)
print "Set output 1 and 2 low"
s.send ("set_digital_out(1,False)" + "\n")
time.sleep(0.1) s.send ("set_digital_out(2,False)" + "\n") time.sleep(0.1)
count = count + 1 print "The count is:", count
print "Program finish"
time.sleep(1) data = s.recv(1024)
s.close() print ("Received", repr(data))
print "Status data received from robot"
Result feedback from robot when the program is executed
Disclaimer: While the Zacobria Pte. Ltd. believes that information and guidance provided is correct, parties must rely upon their skill and judgement when making use of them. Zacobria Pte. Ltd. assumes no liability for loss or damage caused by error or omission, whether such an error or omission is the result of negligence or any other cause. Where reference is made to legislation it is not to be considered as legal advice. Any and all such liability is disclaimed.
If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
Author:
By Zacobria Lars Skovsgaard
Accredited 2015-2018 Universal Robots support Centre and Forum.
Hi all,
I’m working with an UR5 arm and I’d like to control the force using a socket connection. In particular, after the robot arrives in a “home position” (defined by me), it should be able to apply 10N in Z-axis direction. I wrote this code, but it doesn’t work: the robot stops in home and doesn’t apply any force. Could you tell me if there is something wrong in the code? Do you have an example of correct code? Thank you.
string command = “movel(p[-0.416,0.268,0.232,2.9,1.16,0], a=0.5, v=0.5)\n”; //Home
send(client,command.c_str(),command.size(),0);
sleep(6.0);
command = “sync()\n”;
send(client,command.c_str(),command.size(),0);
command = “force_mode(get_actual_tcp_pose(), [0, 0, 1, 0, 0, 0], [0.0, 0.0, 10.0, 0.0, 0.0, 0.0], 2, [0.1, 0.1, 0.15, 0.17, 0.17, 0.17])\n”;
send(client,command.c_str(),command.size(),0);
sleep(10.0);
command=”end_force_mode()\n”;
send(client,command.c_str(),command.size(),0);
Hi Gianmarco
Thanks for the question.
One way to get hints for script programming is to make a program in Polyscope for example in this case using the force mode in Polyscope – and then save the program on a USB drive.
The robot will then also save a xx.script file – which can be open and studied for how such script program looks like.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hello Gianmarco,
I want to send position and handle DIDO to UR10(CB) through Ethernet (socket communication) .I am trying the sample code from below link but program remains in waiting state at line “TcpClient tcpClient = tcpListener.AcceptTcpClient();”
https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/ethernet-socket-communication-via-urscript-15678/
I have enabled the Ethernet communication and configured the IP of robot. Dose it requires any other configuration?
(communicating the robot through port “30002”.)
Hi Rutuja
Where in which menu was the Ethernet communication enabled ?
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hello,
Enabled the Ethernet from “/intiallization /EtherNet/Ip” and enabled Ethernet/IP Adapter
Set IP of UR from “Setup Robot / Network / IP address” as 192.168.127.1
Hello Rutuja
The Ethernet/IP setting is for the “Ethernet-IP” protocol adapter which is used on some PLC types e.g. A/B PLC. This is not the robots actual ethernet address.
The robots actual main Ethernet adapter address can be set from the main screen in:
Setup Robot
Network
A static IP address details of the robot can be set in this screen – which is the address that can be connected from an external device using a socket connection.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hello,
I’m connected via port 30002, and can issue movej commands to the UR5. I am however having difficulty figuring out how to retrieve “robot state data”. The information that comes back from the socket after I issue a command does not adhere to the robot state package protocol, where the first 4 bytes are the size of the data, and the 5th byte is the “robot package type”, a value of 16. I get random data back when I recieve from a socket after a move or set_digital_out command. Any help would be appreciated, thanks.
Hello Omar
Thanks for the question.
First consider to read this article – to see that it is not directly possible to get a direct reply to commands with this method – so instead other methods can be used.
https://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/universal-robots-script-programming/
Properly the data you see coming back is “matlab data” – mayby see this article.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/client-interfaces-cartesian-matlab-data/
Another way of getting status of the robot and to get data back is to use the MODBUS interface.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/modbus-internal-registers-read-and-write/
Another way to get data back is to establish Client-Server scenario – see this article.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-client-server/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Awesome, thank you for the help.
So in theory, it would be possible to use a modbus server side to set a general register bit to “true” and a script in the pendant to do this:
while (1) //always true
sleep(5) //sleep 5 seconds
var1 = read_port_address(128)
if var1 == True:
joint_positions = get_joint_positions()
socket_send_string(joint_positions)
write_port_register(128, 0)
Thanks again for the help.
Hello Omar
Yes – in principle.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hello,
We are currently working on a UR10 and using Python URX to drive it and also using the UR Modern Driver. We were initially using Polyscope 3.4 and everything ran normal, no connection interruption and no socket issues.
However when we updated to Polyscope 3.5 we started having intermittent timeout issues in which a “Did not receive a valid data packet from the robot in 0.5” accompanied with “timeout: timed out”.
We suspect it might be an issue with the modern driver and particulary with the ursecmon.py file and the update to 3.5 but we also suspect a socket connection problem.
Is there any way to work around this issue?
Hello Ahmad
Thanks for the question.
I have not experienced any abnormalities in using version 3.5 or 3.6 for other purposes, but I am also not familiar URX or UR Modern Driver. But I would start looking on the external components.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
I’m received 1,060 bytes through the socket and moving.
I would like to move it after referring to the current position. I want to set the current position to the origin and move relative to the origin. How do you apply it with the actual cartesian coordinates value?
Current Positions (X = -418, Y-516, Z = 82, RX = -0.71, RY = -1.76, RZ = 1.75) to Origin Coordinate
Hello James
Thanks for the question.
When using the socket connection at for example port 30002 – then the reference origin of the robot is the base of the robot.
Therefore to use a new origin reference from the current position – has to be calculated in the external application using the current position coordinates.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Thank you for your reply.
I am not sure how to calculate by applying the current position value to the origin.
I’m sorry, but I’d appreciate it if you could link up with the method of calculation or reference.
For the coordinates below, you write down multiple coordinates when the current position value is the origin.
I’m sorry I think it’s too basic.
1. current position(X=-418.36,Y=-516.81,Z=82.63,RX=-0.7143,RY=-1.7621,RZ=1.7595)
->Set Origin (X=-0.74, Y= -0.04, Z = -0.02,RX=-0.3798,RY=6.2705,RZ=0.0342)
2. current position(X=-419.99,Y=-515.80,Z=-117.74,RX=0.8731,RY=-1.7471,RZ=1.8610)
->Origin (X=-0.72, Y= 200.33, Z = -0.02,RX=-0.0083,RY=0.0439,RZ=-6.1263)
3. current position(X=-374.71,Y=-470.09,Z=-117.91,RX=-0.8731,RY=-1.7472,RZ=1.8610)
->Origin (X=-0.72, Y= 200.34, Z = -64.36,RX=-0.0085,RY=0.0436,RZ=-6.1263)
4. current position(X=-470.15,Y=-375.51,Z=-116.65,RX=-0.8731,RY=-1.7472,RZ=1.8610)
->Origin (X=133.63, Y= 200.36,Z= -64.40, RX=-0.0057,RY=0.0460, RZ=-6.1263)
Hello James
Maybe it can be considered to program on the robot because Polyscope has such functions already – below are some links with examples.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/planes-and-position-variables-1/
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/planes-and-position-variables-2/
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/speedl-trans-pose-example/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi,I have some questions on python editor.
If I have two sets of coordinates of the point, and I want to do robot cycle.
How can I edit the program?
Such as this two sets:
A=”’J1=str(-111.73*3.1415926/180)
J2=str(-90.53*3.1415926/180)
J3=str(66.46*3.1415926/180)
J4=str(-65.89*3.1415926/180)
J5=str(-88.81*3.1415926/180)
J6=str(67.61*3.1415926/180)
s.send ((“movej([” + J1 + “,” + J2 + “,” + J3 + “,” + J4 + “,” + J5 + “,” + J6 + “], a=2.0, v=0.1)” + “\\n”).encode(‘utf8′))
time.sleep(10)”’
B=”’ \nJ1=str(-111.73*3.1415926/180)
J2=str(-90.53*3.1415926/180)
J3=str(66.46*3.1415926/180)
J4=str(-65.89*3.1415926/180)
J5=str(-88.81*3.1415926/180)
J6=str(67.61*3.1415926/180)
s.send ((“movej([” + J1 + “,” + J2 + “,” + J3 + “,” + J4 + “,” + J5 + “,” + J6 + “], a=2.0, v=0.1)” + “\\n”).encode(‘utf8′))
time.sleep(10)”’
thanks in advance
Hi Huiting
Thanks for the question.
This forum is not made for Python programming advise, but made for advise on Universal Robots.
Maybe consider this article for some hints where it can be seen how joints values can be send.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-from-host-to-robot-via-socket-connection/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi I have set up a socket between the UR5 and a C# desktop application on port 30002.
Whilst I can send digital IO commands such as the example set_digital_out(2,True) or the up to date set_standard_digital_out(2,True) as soon as I try to send an analog command a running script (if there is one) halts and the socket is closed.
I just cannot seem to be able to send the following analog commands:
set_analog_out(0, 1.0)
set_standard_analog_out(0, 1.0)
I have ensured that the output domain has been set via both the pendant gui and also use of set_analog_outputdomain(0, 1)
Any ideas; is this a bug?
Thanks, SJB
Hi Steven
Thanks for the question.
No it is not a bug.
I just tried on my robot and it works fine.
Maybe consider to try and use the Sockettest program to test the commands.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/testing-tcp-connection-host-to-ur/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi Lars, thanks for your reply; I managed to resolve the issue… outdated firmware and manual…!
3.5.2 details:
Example Parameters:
– n is standard analog output port 1
– f = 4 volts (or mA depending on domain setting)
By updating the firmware to 3.6 and changing over to the method as described 3.6.0 all is ok
Example Parameters:
– n is standard analog output port 1
– f = 1.0, that corresponds to 10V (or 20mA depending ondomain setting) on the output port
Cheers, SJB
Hi!
I have some problem with io control.
example: s.send (“set_digital_out(2,true)” + “\n”) & s.send (“set_digital_out(2,False)” + “\n”)
This function is open and close digital_ouput.
I need control configurable_output my code is ”s.send (“set_configurable_out(2,true)” + “\n”)”
But it doesn’t work.I want to know my code is wrong or not? How can I handle this problem?
Hi 林冠良
Thanks for the question.
I just tested on a robot with software version 3.5.3.10825 robot with the command “set_configurable_digital_out(1, True)” and it sets the configurable output high.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi. Thanks you for this post. I have one question. I have no programming experience. How do you send this written code? when the robot is connected to the computer with a Ethernet, I don’t know how to send program in .txt.
Hi Pavel
Thanks for the question.
I am not aware of any methods for how to send the code in .txt format – because the program sending needs to take care of the timing of the commands.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
if all of your code example is about ‘set_digital_out’ or ‘movej’, then how about getting the result from ‘get_target_joint_positions()’? thank you
Hi jan sebastian
Thanks for the question.
As described in the introduction at this link it is not possibleto read with this method. Maybe consider the other possibilities as mentioned in the article.
https://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/universal-robots-script-programming/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi,
I have the following error when try to run the first program.
—————————————————-
Traceback (most recent call last):
File “Host.py”, line 13, in
s.connect((HOST, PORT))
File “/usr/lib/python2.7/socket.py”, line 228, in meth
return getattr(self._sock,name)(*args)
TypeError: an integer is required
————————————————————–
I connect the PC with the robot through a Ethernet IP cable. I set 169.254.165.30 as the UR5’s IP address. When I ping the 169.254.165.30, I don’t have packets lots.
So, I don’t know whats wrong.
Please, Could you help me?
Hi Jhon
Thanks for the question.
The python error messages indicate that there is a error in your python script.
The IP address does not look to be a valid IP address. What works good is to use a router that makes a small ethernet so the robot is connected to the router with its own IP address and the PC is connected to the same router with its own IP address.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi Zacobria,
Thanks for your help. Now I can move the robot and also implemented a Client- Server communication between the PC and the UR5 robot.
I have another question. How can I use the UR functions get_actual_joint_positions() or get_actual_tcp_positions() without use a Client – Server?
Hi Jhon
Thanks for the question.
Maybe consider the articles about reading from MODBUS registers where some of the information might be found
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/modbus-registers-read-position/
https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/modbus-server-16377/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi
I want to know
“”s.send(“movej([ – 1.95,-1.58,1.16,-1.15,-1.55,1.18],a = 1.0,v = 0.1)”+“\ n”)””
In this code -1.95 is the J1 joint angle?!
Because I try this code but J1 angle is not -1.95 on robot.
So I want to know why J1 use -1.95.
Thanks!!
Hi Lin
Thanks for the question.
I think the first element is called j0 – and the data might be in Radians – wheres as the robot Move screen might express the data in Degrees.
More informations at this link
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/x-y-and-z-position/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi
I am new to this kind of programming.
I have to use java to send commands to our UR3.
How to send xml rpc request to ur3
Is it possible to show some kind of example code?
Thanks In advance
Hi Rajan
Thanks for the question.
I am not familiar with Java, but maybe some hints can be found at this link.
https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/real-time-data-exchange-rtde-guide-22229/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Thank you for your quick reply
Hi Rajan,
I am trying to use Python to set up the XML-RPC communication between the robot and my PC(windows 10)
But after I set up everything (i.e. connected the ethernet cable to my PC and used the official script found on the website), the robot returns an error saying “couldn’t connect to host”
The reason I want to use XML-RPC is that the robot can call any Python function on my PC directly.
Thanks!
Hi Ruiwen
Which script and website do you refer to for the “official script” ?
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi,
Thanks for your fast response. Here you are
https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/xml-rpc-communication-16326/
I am trying to move a ur5 arm. I understand that it is relatively easy to give joint angle commands to the the joints of the arm. Is it possible to move the ur5 end effector to a certain point by running a python script? If so, how do i go about doing it?
Vivek
Maybe consider informations in the article at this link.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/functions-1/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
I figured that movej(p[]) does the job for me. But i have a different question.
Q: I am not able to connect to UR5 via socket on python. Here is the code and the error.
————-BEGIN—————
#!/usr/bin/env python
# Echo client program
import socket
import time
HOST = ‘192.168.1.7’ # IP entered on ur5 using the pendent
PORT = 30002 # The same port as used by the server
print ‘Starting Program’
count = 0
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
time.sleep(0.05)
s.send (“set_digital_out(2,True)” + “\n”)
time.sleep(0.1)
print “0.2 seconds are up already”
s.send (“set_digital_out(7,True)” + “\n”)
time.sleep(2)
s.send (“movej(p[99.38, -305.81, -528.99, 0.0390, -3.1944, -0.0257], a=1.0, v=0.1)” + “\n”)
time.sleep(2)
s.send (“set_digital_out(2,False)” + “\n”)
time.sleep(0.05)
print “0.2 seconds are up already”
s.send (“set_digital_out(7,False)” + “\n”)
time.sleep(1)
data = s.recv(1024)
s.close()
print (“Received”, repr(data))
print “Program finish”
—————END——————-
Error:
line 11 in module
s.connect((HOST,PORT))
socket.error: [Errno 111] Connection refused
Please let me know what can be done to be able to connect to UR5 properly.
Thank you
Vivek
Thanks for the question.
1.
Can you ping the robot from your external device ?
2.
Which Python version are you using ?
3.
The example shown are made with Python 2.7.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
1. I was able to ping. No packets lost.
2. Same. Python 2.7
Vivek
1.
What is the IP address of your external device ?
2.
Are you able to connect using the test method as described at this link
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/testing-tcp-connection-host-to-ur/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
1. 10.122.138.189
2. I am using a linux device so i didn’t do it that way. But was i supposed to enter the computer’s ip address somewhere in the ur5 network info
Vivek
1.
That is a different subnet than the robot so then there will proberly not be any connection to a 192.168.x.x network.
Did you ping 192.168.1.7 from 10.122.138.189 ?
2.
I am not sure what you mean by “supposed to enter the computer’s ip address somewhere in the ur5 ” ?
3.
The robot need to have its own IP address in the same subnet range as on the external device you are trying to communicate from – which is normal rules for network communication.
4.
Maybe consider to perform the test as mentioned earlier.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Ok. I think i figured it out. I was supposed to use a different ip for the pc than ur5. I tried i92.168.1.12 for ur5 and 192.168.1.10 for the pc and did the exact code. The connection went thru but ur5 said the inverse is not found as i was using the movej(p[]). I tried just movej([]) and it worked.
1. Can you tell me why movej(p[]) is not working and if there are any other ways to command ur5 to go to points?
Thanks
Vivek
The example at this link also show Movep
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-from-host-to-robot-via-socket-connection/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Got it. I was plugging values in mm instead of m. Glad the arm didn’t move and hit things in its way.
Hello everyone,
I am new to UR3 programming through socket. I tried to run the first code sample but got an error stating the “connection refused”. Ping works fine but telnet cmd fails to connect to robot. Any help is greatly appreciated.
Hello hemanth
Thanks for the question.
I am not aware of that Telnet is available on the robot – I am not sure how you tested the example, but the example does not involve Telnet ?
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi
What configuration must to be on polyscop for this program?
Kind Regards
Diego
Hi Diego
Thanks for the question.
The network settings of the robot need to be configured e.g. IP address etc.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hello,
Why am I getting the following message when I enter:
>>> s.send(“set_digital_out(2,True)”+”\n”)
Traceback (most recent call last):
File “”, line 1, in
TypeError: a bytes-like object is required, not ‘str’ ?
Thank You in advance and Best Regards,
Daniel Byberg
Hello Daniel
The command looks like a part of a Phyton program and some thing missing – has the socket been open ?
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi Lars,
Thank you for your reply. I have imported the socket and managed to solve the problem at last – I had to add “.encode(‘utf8’)” at the end of each string sent to the robot, like in these lines:
s.send ((“set_digital_out(4,False)”+”\n”).encode(‘utf8’))
s.send ((“movej([1, -1.5707, -1.5707, 0, 1.5707, -1.5707], a=0.25, v=0.25)”+”\n”).encode(‘utf8’))
Do you know the possible reason for Python requiring this specification? Anddo you know if it is possible to make the encoding implicit, so I don’t have to repeat it for every command?
Best Regards,
Daniel Byberg
Hi Daniel
Sounds good that you found a solution.
Maybe it could be the Python version if the program is exactly as in the example.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi
I’m using UR3 in a project. I’m writing a code to command the robot through socket connection. I have to send commands only from the PC. I should not run any program on the robot (.urp file)
My problem is i want to create a variable and then tell the robot to move to it. I was able to create the variable but i coudn’t move the robot to it.
The code is in c++ but it won’t matter
Here is how the code looks like:
WSADATA WSAData;
WSAStartup(MAKEWORD(1, 0), &WSAData);
SOCKET sock;
SOCKADDR_IN sin;
sin.sin_addr.s_addr = inet_addr(“192.168.1.68”);
sin.sin_family = AF_INET;
sin.sin_port = htons(30002);
sock = socket(AF_INET, SOCK_STREAM, 0);
bind(sock, (SOCKADDR *)&sin, sizeof(sin));
connect(sock, (SOCKADDR *)&sin, sizeof(sin));
send(sock, “movej([1.5708,-3.1415,1.5708,-1.5708,0.0000,3.1415],a=1.5,v=1.4)\r\n”, 200, 0);
//send(sock, “newpos=get_actual_tcp_pose() \r\n”, 200, 0);
Sleep(5000);
WSAStartup(MAKEWORD(1, 0), &WSAData);
sock = socket(AF_INET, SOCK_STREAM, 0);
bind(sock, (SOCKADDR *)&sin, sizeof(sin));
connect(sock, (SOCKADDR *)&sin, sizeof(sin));
send(sock, “Start_pos=get_actual_tcp_pose() \r\n”, 200, 0);
Sleep(3000);
WSAStartup(MAKEWORD(1, 0), &WSAData);
sock = socket(AF_INET, SOCK_STREAM, 0);
bind(sock, (SOCKADDR *)&sin, sizeof(sin));
connect(sock, (SOCKADDR *)&sin, sizeof(sin));
send(sock, “movej([-3.1415,-1.5708,0.0000,-3.1415,-1.5708,3.1415],a=1.5,v=1.4)\r\n”, 200, 0);
Sleep(3000);
//WSACleanup();
WSAStartup(MAKEWORD(1, 0), &WSAData);
sock = socket(AF_INET, SOCK_STREAM, 0);
bind(sock, (SOCKADDR *)&sin, sizeof(sin));
connect(sock, (SOCKADDR *)&sin, sizeof(sin));
send(sock, “movej(Start_pos,a=1.5,v=1.4)\r\n”, 200, 0);
//Sleep(3000);
WSACleanup();
Hi Rami
Thanks for the question.
What is the value of “Start_pos” after this line “send(sock, “Start_pos=get_actual_tcp_pose() \r\n”, 200, 0);” ?
Normally when reading on port 30002 then Matlab data is returned by the robot which is not related to “get_actual_tcp_pose()”.
More informations about UR Matlab data at this link
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/client-interfaces-cartesian-matlab-data/
To send a position variable to the robot the data that flow has to be like when sending fixed data.
For example in Python a command like this
s.send (“movep(p[0.1,0.3,0.3,3.14,0,0], a=0.1 , v=1)” + “\n”)
Will move the robot to the position in the list.
To do that with a variable it can look like this
start_pos = “0.1,0.3,0.3,3.14,0,0”
s.send (“movep(p[” + start_pos + “], a=0.1 , v=1)” + “\n”)
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi Zacobria,
Thank you for your reply,
Actually what i wanna do is basically using the variables that i created inside the robot directly through the socket commands. Is it possible?
I have another question please, Is there any way to get the values of the tcp pose remotely and without launching any urscript program?
Many thanks
Hi Rami
I am not aware of a method to read internal Polyscope variables from an external device directly.
The TCP pose can be read from a MODBUS register – more informations at this link.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/modbus-registers-read-position/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi Lars,
I need to update traget poses of a movel command during a movement. I found no way to do this without stopping the robot.
It is not essential to use the movel command, the only essential thing is that the robot makes a fluent motion. Is the speedl function with a motion planning a solution? Or is there an other way to do this or something simmilar like this?
I allready tried it with raw script commands via socket connection, with a client-server approach and with polyscope programming. But I couldn’t find a good solution.
Thanks,
Oliver
Hi Oliver
Thanks for the question.
Maybe “speedl” will work better, but to update a target on the move can be interesting because if the update to go 180 degree backwards then it will need a full stop and start move in the other direction.A change of target even if it is a small turn will proberly involve decleration and acceleration and therefore to create a smooth move can be a challenge.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi Lars,
I need to update traget poses of a movel command during a movement. I found no way to do this without stopping the robot.
It is not essential to use the movel command, the only essential thing is that the robot makes a fluent motion. Something like with the movep commands expect that Is the speedl function a solution?
Is there a way to do this or something simmilar like this?
I allready tried it with raw script commands via socket connection, with a client-server approach and with
Forum,
I need some preferably python logic to convert the received status returned by the UR in to its current location Joint Position co-ordinates that is easily readable or a method of getting these co-ordinates without having to build a Client-Server relationship with the use of a installed UR:Script on the UR bot.
Any suggestions or advice would be beneficial
thanks
Biv
Hi Biviano
Thanks for the question.
Maybe consider using the Matlab data – more informations at this link.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/client-interfaces-cartesian-matlab-data/
Or maybe consider the MODBUS interface – more informations at this link.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/modbus-registers-read-position/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Lars,
Your a star, the article did the trick and everything is working. Thanks very much.
I hope you can help with a related issue though. In our python code we know(thanks to you) how to load an installation. But it does take some time. We were hoping we could check the installation first to see what was loaded and only load if the one we want was different. Is there a method of checking what installation is loaded from the python code(e.g. Dashboard payloads)
thanks
Anthony
Anthony
I have not seen such function.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Great forum guys,
But I have a question and would like to see some code if possible. From this forum we have figured out the basics of calling the script commands from a linked Linux machine using python. However, what would be the code/commands to call a actual entire script program on a UR5 robot. Eg. If we teach our UR5 activity independently, how can we externally command the UR5 robot to perform the taught script/program?
thanks in advance
Anthony
Hi Anthony
Thanks for the question.
One possibility that can be considered is to use the Dashboard server on port 29999 that can load and play programs. More informations at this link
https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/dashboard-server-port-29999-15690/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Thanks Lars,
Your solution appears to have the right things being called(load, play, etc) but continually have an issue, even when manually(not through code) trying to play scripts as the following error is displayed and have not found a satisfactory solution to as yet.(Even this forums FAQ page) The error is: “Protective Stop C207A0: Fieldbus input disconnected.”
Any help you could be to stop this error from occurring would be gratefully accepted
Thanks again in advance
Anthony
Hi Anthony
Have you read the information at this forum about this messages at this link below ?
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/protective-stop-c207a0-fieldbus-input-disconnected/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Lars,
Yes I have read and tried this, it does not fix the issue, in-fact it is not even a proper work around. For the UR5 to be connected to a console sending the python commands the Ethernet must be connected so you should not be disabling it. But if you do follow the hint, nothing will happen as there is no longer a connection. The reason for the hint is that so many people are asking about it but this response is in way satisfactory for their problem
thanks in advance
Anthony
Anthony
The article mentioned does not disable Ethernet.
It disables the Ethernet IP/Adapter protocol for Fieldbus – not the Ethernet. This is not related to sending commands from a python program, but it might be related to the error messages “Protective Stop C207A0: Fieldbus input disconnected.” you mentioned.
Commands from a python program can still be send to the robot when the Ethernet IP/Adapter is disabled.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi,
I an using the robot scripts as well as external python script together to achieve a specific job.
In my scenario, I am setting a specific digital output gpio to high to notify the robot that the python code is done executing.
Python side –
# notify robot that you’re done executing
s.send (“set_digital_out(7,True)” + “\n”)
time.sleep(0.1)
on the robot side –
#Waiting for Digital out 7 to go high
Loop digital_out[7] = False
Wait 0.01
#Once Digital output 7 is set to True over the socket, do something on robot side.
….. ….
The problem here is, the execution of my script on the robot stops when the Digital output 7 is set True
over the socket.
At the same time, if I manually try to set the Digital out 7 as True by going to the I/O tab on the GUI, the program on the robot executes perfectly.
Can you please help me understand why the execution on the robot side stops when the digital output is set to True over the raw socket connection? What should be done to avoid this?
Thanks a lot.
Hi Schazool
Thanks for the question.
Yes this is normal behavior of the robot – Maybe consider to read this article.
https://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/universal-robots-script-programming/
It can also be considered to use the MODBUS registers to exchange informations such as changing a bit in a MODBUS register by the external program and then read this register from the Polyscope program to take decisions – and then for example set the output from the Polyscope program.
Some examples of using the MODBUS register can be found at this link.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/modbus-internal-registers-read-and-write/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Thank you so much for the insight. I will consider the MODBUS register option.
Before that, I wanted to ask you something on the similar lines.
Instead of using registers, I set up some MODBUS IOs on the robot. I took help from your webpage –
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/modbus-io-nodes/
I created a Digital IO on the MODBUS client on the robot UI.
P.S – I do not have a physical MODBUS connected to the robot, but I could get the green light on my MODBUS Digital IO when I used the same IP address as the robot.
My questions –
1) Does the UR robot have an inbuilt MODBUS inside it? I ask this because most of the documentation on the Internet says we’ve to plug an external MODBUS with it’s own IP address. So I am confused how I got a green light in my MODBUS client tab.
2) How can I turn on/off these MODBUS IOs from the ethernet socket, by an external program like python? Instead of the registers, I can use the MODBUS IO status in my robot program in my if clause.
3) Can this approach be a good alternative instead of using the registers in my scenario?
I really appreciate your help.
1.
Yes the robot has a MODBUS server running. There are some more informations about the internal MODBUS server at this link.
https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/modbus-server-16377/
2.
The example at this link below shows both – how the MODBUS registers can be read and set by the Polyscope program and also how the MODBUS registers can be read and set by an external program e.g Python.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/modbus-internal-registers-read-and-write/
3.
It is the same. The internal MODBUS server can access both registers and the physical I/O.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi,
i’m new to this kind of programming.
I have to use c# to send commands to our UR 10.
How does this kind of socket connection look like in c#?
Is it possible to show some kind of example code?
Thanks
Hi Woffer
Thanks for the question.
At the moment I do not have a C# example, but in Python. Maybe others on the forum have.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi,
I have to use c# as well to send commands to a UR 10. I figured out, how to send coordinates, so that the ur moves to the point. As connction I use a Tcp-Interface via port 30002. As far as I know, the UR10 should give a feedback after reaching the desired position . So I tried to receive the feedback, but got just this sequence of characters:
8????????? URControl ?Oct 12 2016, 14:02:40 ????????? ? . ???? ?? ?? ?? ????Z0 =??B@?A??MA??q???!?Q?`??!?TD- ?XB@>wA??B
Bn??h?Z0 ? ??H?B@|?A???B?????!?Q?`??!?TD- ?J B@\BQ?B”v???86@ ??hB@??B?XB?????D- ???_?6?)?y?????g?~????4?6R??>?{(??c?>?z??D?? ??[]????@4J^?a+??;=?+?D@r?8??4???k|??,???5y????!GCGS?q6$D??X?}???+S7????6j?? `1?_M 5 ?? ??????? ???? %??/? ???? C??? ;D??BD ? ??W?(,/c@W?(,/c?W?(,/c@W?(,/c?W?(,/c@W?(,/c?W?(,/c@W?(,/c?W?(,/c@W?(,/c?W?(,/c@W?(,/c@Z????@D @Z????@D @
??????@D @
??????@D @
??????@D @
??????@D ???R8-se??WJ?D??? ??333333?? ????$?/??PH?? ??K]?c?A ????????????%?????kP??|??!?TREP ??!?TREP??!?TREP = :?G?t??? | . ??Q? ?? ?? ?? ??h?Z0 =? B@?yA??MA?????!???`??!?TD- ? B@?A??B
G
?? (?Z0 ? ???]B@??A???B~????!???`??!?TD- ?SPB@ BQ?B”z????` ?? B@?yB?XB???? (?Z0 \ ????? ???? %??G?` ????@ C??? ;D??BD ? = :n?d?u | . ??? ?? ?? ?? ????Z0 =??B@?yA??MA??????!???`??!?TD- ??B@>wA??B
G,???D- ? ??’B@l?A???B?????!???`??!?TD- ?J B@?BQ?B”z!???? ??hB@?B?XB????h?Z0 ?? ???
?????WT????? ? 5 ??V.???? ?v??e??{6?V???????T????|?f???L?[b? J ??? ??? ?pbM? ?pbM? A? B@??>??d???? ???? %??p? ???? C??? ;D??BD ? = :?LGKM?? | . ??_ ?? ?? ?? ?????` =??B@??A??MA??????!???`??!?TD- ? B@>wA??B
KR???D- ? ?S?B@?JA???B????”??`??!?TD- ?@?B@/BQ?B”z4??86@ ??hB@??B?XB????h?Z0 <z4??{%p ???B???B??B ??? e?h????????d[?????????&???,?F[H???d?L?+?????d???? ???? %???b? ???? C??? ;D??BD ? = :9??tqML | . ???@ ?? ?? ?? ?????` =?@B@?yA??MA??????!???`??!?TD- ? B@/A??B
J????D- ? ? ??B@]/A???B?????!???`??!?TD- ?@?B@?BQ?B”r???!:?? ???B@??B?XB???? (?Z0 7U???? ???? %??p? ???b? C??? ;D??BD ? = :s???B?? | . ??l@ ?? ?? ?? ?????` =?`BA 7A??MA?????!???`??!?TD- ?PB@M?A??B
F=??h?Z0 ? ? ??
I tried to convert this sequence in different Encodings (the example above is encoded to ASCII), but none worked. I’m not sure, what I’m doing wrong, respectively what kind of Encoding this is. Do you have any recommandation, what I could try to get a proper message as return.
Furthermore I tried the script command –> string position = “set_configurable_digital_out(0, True)” + “\n”; to activate a gripper, but it doesn’t react at all. Did I use the command right?
Thank you very much in advance!
Regards Maximilian
Hi Maximilian
Thanks for the questions.
1.
The data streamed out from port 30002 and 30003 are sometimes refered to as Matlab data. Maybe consider to check out this article.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/client-interfaces-cartesian-matlab-data/
2.
When working with the “set_configurable_digital_out(0, True)” + “\n” command maybe consider to test it out using the Sockettest – more information on how to test commands at this link.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/testing-tcp-connection-host-to-ur/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Tweet
Follow @zacobria
Hi, Maximilian
Maybe you can try BitConverter.ToString().
Hi there,
Is there any way to send a script file and generate a urp file from that without using the teaching pendant to manually import the script?
Hi Natasha
Thanks for the question.
I have not seen such function to convert script files.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Hi,
I have a question about the Inizialize Robot Screen and remote programming via socket.
If this is not the appropriate forum area please forgive me.
I’m using DashBoard socket 29999 to manage controller set-up, program loading, start, stop etc.
The only problem I have is to press the OK button on the dashboard when initializing the robot.
Is there any way to send remotely the OK button press event like “close popup” for popups?
Thank you.
Hi Thor
Thanks for the question.
There is an Auto Initialize function. Some more informations at this link.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/auto-load-program/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Hi, regarding my previous post I may have been misunderstood.
I don’t use physically the Dashboard.
I load the program remotely thanks to Dashboard socket 29999. The same I do for managing the program (start, stop, pause).
My problem is ONLY to press the OK button in the Initialization Screen.
It seems there is no way to do it remotely without interacting physically with the dashboard.
Thanks for help.
Hi thor
On port 29999 Dashboard server – There are the commands
close popup
and
brake release
The command “close popup” removed the messages about the “initialization” and the command “brake release” released the brakes when sending these commands to port 29999.
Some more informations at this link
https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/dashboard-server-port-29999-15690/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Follow @zacobria
Hi Lars,
I saw your old reply to the following post
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I am new to UR5 and I wonder if the universal robot can be controlled through visual servoing, such as grabbing the targrt in motion with stereoscopic vision tracker. I would be grateful if you could give me some directions or reference.
Best Regards
chen
Reply ↓
zacopressadmin Post author
30 – December – 2014 at 11:21
Hi Chen
Thanks for your question.
There are different ways to track items.
1.
UR has a Conveyor tracking function when using an encoder signal.
2.
You can use a vision camera and make an application to move the robot based on the feedback from the camera.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I want to know how to send the streaming control values to the joints
and also i use c++ for all my applications
Hi ravi prakash
Thanks for your question.
I have no information´s on this.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
how to do visual servo with UR5 using external pc and sending streaming joint control
I have no information´s on this.
Hi Lars,
As an example above, how can I analyse the result of the data through port 30002 ? Another Question , If I can send messages to UR robot through port 30003, or how can i do ?
thanks, i expect to you reply.
Hi Gavin
Thanks for your question.
I have not used the data flow from port 30002 and therefore I have not analyzed them, but I have seen that the data is called “MATLAB” data. At this link below there is a file to download called “Client_Interface.xlsx – which provides some more information.
http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/remote-control-via-tcpip-16496/
At this link is some information for Matlab.
https://www.mathworks.com/matlabcentral/fileexchange/50655-ur5-control-using-matlab
An example for how to send data to port 30002 is at this link below – and this can also be done to port 30003.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-from-host-to-robot-via-socket-connection/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Hi Lars,
thanks for your quickly reply. In my experiment , I have analysed the data of port 30003 successfully,
but it’s not the same with port 30002 and 30001 , so I can’t analysed the data from Client_Interface.xlsx.
In this case , I can use port 30003 to recv data , thanks very much.
Hi Gavin,
I’m trying to read data from port 30003 by means of Matlab software from a UR10 robot.
I have not implemented any Polyscope code on the robot but I’m only sending strings from Matlab through a TCP interface.
I’ve read in your post that you have analysed the data of port 30003 successfully, could you please send me more detailed informations about how did you do it?
I would like to read the robot mode in order to know when the robot has finished his tasks.
Thank you very much in advance.
Lorenzo
Hi Lars.
Thanks very much for your help. Programm runs now via modbus commands over python. I´ve setted variables by the raw_input commands to the UR. It works really good. Great help.
But now i have another problem. When i do an input via RFID Sensor or keyboard to set an digital output as example DO3, the python program runs but the signal comes first after the second input.
For example.
I make a input to set DO3 = Nothing happens
after the loop in python program i make an input again and the DO3 ist True
Between 1-15 Second then i can repeat it with no problems.
But when i wait longer the same problem begins and i have to input twice to run the signal.
Is there a shutdown with the connectivity between host and server?
Here’s the programs that i took for testing.
# RFID Mobile-Robot-Szenario
import socket
import time
HOST= “10.136.90.155” #The remote host
PORT = 30002 # The same port as used by the server
while True:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
time.sleep(0.01)
RFID = raw_input(“M druecken”)
if RFID == “m”:
s.send (“set_digital_out(3,True)” + “\n”)
time.sleep(5)
s.send (“set_digital_out(3,False)” + “\n”)
time.sleep(5)
elif RFID == “E004015006D988FE”:
s.send (“set_digital_out(2,True)” + “\n”)
time.sleep(5)
s.send (“set_digital_out(2,False)” + “\n”)
time.sleep(5)
Hi Udo
Thanks for your question.
I dont think there is a shutdown.
Have you checked that the If RFID == “m” is true when there is no response ?
Maybe consider to insert a print “If is true” inside the If statement and see on the screen that the program entered there.
Maybe consider to check with a test software like “sockettest” setup as client to see the data is being sent as espected.
Also considet to move the
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
before the While loop becasue the socket is being opened during each program run and there is no close of socket.
Maybe a small
time.sleep(0.5)
as first line inside the loop before sending the data
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Hi Zacobria-Team.
I´ve worked with your tutorial, to learn how to script and control the UR over an external computer.
Thanks for this help. The programm above works with no problems.
Now i started to try, to head for a signal in digital IN.
My task is, to push a button on my keybord and with a python programm to make a command with if/else to set_digital_in (n,b)
The programs run but on the teach pendant in Register I/O doesn´t blink the headed lamp.
Here´s the script
# RFID Mobile-Robot-Szenario
import socket
import time
HOST= “10.136.90.155” #The remote host
PORT = 30002 # The same port as used by the server
while True:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
time.sleep(0.5)
RFID = raw_input(“RFID-CODE?”)
if RFID == “1”:
s.send (“set_digital_in(3,True)” + “\n”)
time.sleep(3)
s.send (“set_digital_in(3,False)” + “\n”)
elif RFID == “2”:
s.send (“set_digital_in(5,True)” + “\n”)
time.sleep(3)
s.send (“set_digital_in(5,False)” + “\n”)
Note: The Program is running. There is no syntax error or somthing else. My only problem is that the lamps in I/O will not adressed.
Can you help me in my problem.
Hi Udo
Thanks for your question.
I see two issues in this method.
1.
When sending commands to port 30002 from an external host for example a PC to port 30002 on the robot – is a kind of one way communication. It is only possible to send to the robot in this manner – so it is possible to send move commands and the robot will move and it is possible to send outputs on the robot.
But it is not possible to get a feed back in this method – so it is not possible to read an input and get the result on the PC python program.
To read an input from a PC external host it can be done via the MODBUS server on port 502.
More informations here.
http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/modbus-server-16377/
and here
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/modbus-registers-and-nodes/
Address 0 is the input bits.
Or instead use a Client-Server method where a Polyscope GUI program on the robot is reading the input and send it back to the server (external Python PC host) over a TCP connection.
2.
I see this command in your program
s.send (“set_digital_in(5,True)” + “\n”)
But normally an input is set by a device connected to the input forexample a sensor and not from the program.
Instead it is possible to set outputs
s.send (“set_digital_out(5,True)” + “\n”)
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Thanks for the fast answer.
I tried it with the outputs too but wenn i run a Robot programm on the teach pendant it stops when i ask the output-signals via if/else command.
My considerations about the digital in were, that i control an RFID sensor with a programm who sets the headed lamps.
Ok so it doesn´t work.
But with the output signals i have the problems with the program-stop an that should not be. 😉
How can i clear off the program-stop in teach pendant, when he ask the output signals with if/else?
Hi Udo
I just tried on a robot to check on an output with If/Else and it works OK and the program does not stop (unless there is nothing to do because of the state of the outputs checked).
Maybe consider to put the status of the output into a variable and then check on the variable for the If/Else.
Regards
Zacobria
I don´t know what i make wrong.
Made a little Programm, which should drive over two WP if digital_out[3]= True
Here´s a pic about my program in german.
I start it and it stops, when i set the digital_out[3] via python program true
http://i993.photobucket.com/albums/af57/Mshrak/Mobile%20Uploads/11E1733E-E0CC-4A79-956A-987C0DCA91C6_zpsdl73wmzy.jpg
Hi Udo
Ok now I understand what you are trying to do.
This will not work because the Polyscope program might be terminated when an external command is send to port 30002 from the python program. Then two controller processes are trying to control the robot which might be ambigius.
Instead You might consider to either set the output in the Polyscope program or make a Client-Server solution where the Polyscope is running and communicate with the python program – or set a MODBUS registers on port 502 by the python program and then read that register value in the Polyscope program.
An example of the Client-Server data exchange is at this link.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-client-server/
An example of using MODBUS register is at this link.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/modbus-registers-and-nodes/
You need to look at the part that uses port 502 from the python program and then the Polyscope program read the register and uses that information in the Polyscope program.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Hey,
I was trying to make robot swing around it second joint. I tried to put the joint angles but then robot did not behave the same way as it was programmed by the teach pendant, unless i right exactly same numbers, but it is not practical to write 10 decimals. Then i tried to move arm and capture its pose XYZRxRyRz but that was even more crazy, unless it is one waypoint, otherwise the movement is not what was expected. I try to do this via socket connection by Python. I attach the code i tried to use. Last question: if there has to be a combination of two: joint angles and pose, in what sequence they have to be written, like one joint angle and the pose, then another joint angle and pose, or it is in a different way? Thanks in advance
# Echo client program
import socket
import time
HOST = “169.254.178.76” # The remote host
PORT = 30002 # The same port as used by the server
print “Starting program”
count = 0
with open(‘movement.txt’, ‘r’) as commands_to_send:
commands = commands_to_send.read()
print commands
count = 0
while (count < 1):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
time.sleep(2)
s.send ("set_digital_out(1,True)" + "\n")
time.sleep(0.1)
s.send ("set_digital_out(2,True)" + "\n")
time.sleep(2)
print "Robot moves by pose"
s.send("movej(p[-0.266, -0.24, 0.065, 2.01, -1.5, 0.27], a=1, v=0.1)" + "\n")
time.sleep(10)
s.send("movej(p[-0.24555, 0.195, -0.041, 0.79, -3.0, 0.08], a=1, v=0.1)" + "\n")
time.sleep(10)
s.send("movej(p[0.2665, 0.2355, 0.072, 1.76, 2.65, 1.08], a=1, v=0.1)" + "\n")
time.sleep(10)
s.send ("set_digital_out(1,False)" + "\n")
time.sleep(0.1)
s.send ("set_digital_out(2,False)" + "\n")
time.sleep(2)
count = count + 1
print "count is: ", count
data = s.recv(1024)
s.close()
print ("Received", repr(data))
Hey Edvardas
It is not necessary to use all 10 digits after the dot.
The reason the robot does not move as with the teach pendant might be because the command “time.sleep(10)” does not provied enough time to make the entire move from one position to the next position.
I tried your program and first I removed these lines from the execution because I dont know why you have inserted that ?
#with open(‘movement.txt’, ‘r’) as commands_to_send:
#commands = commands_to_send.read()
#print commands
Then I changed the time command after each move command to
time.sleep(30)
This will give 30 seconds to move instead of 10 seconds and as the positions in your example are far from each other and the robot moves slowly then 10 seconds is not enough to reach the position before it is overwritten with a new position. With 30 seconds there is enough time to reach the position in the command.
To the last question:
It is not necessary to have both joint move and pose move. It is possible to only one or the other, but it is also possible to combine them and then it does not matter which order they come because each command stands on it own.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Hey again,
I used the text file before where commands would be written by another program and this Python code would read it and send it, but because of problems I had i just tried to make it reach one waypoint. Thanks for the help, increased the time and a speed by 5 times and robot behaves as it should. Another question: is it possible to send any other commands via socket like movement, for example Wait command? Thanks in advance.
Hi Edvardas
Yes a wait in python is for example time.sleep(1) is a wait of 1 second.
To set outputs
set_digital_out(5,True)
sets out 5 high.
Regards
Zacobria
Last question,
Does time.sleep(1) when writing after s.send movement waypoint work for two purposes: movement time given and time of waiting afterwards or it waits the remaining time of time.sleep(1) given? Thanks in advance.
Hi Edvardas
No it is just a flat wait independent on the move.
Regards
Zacobria
Hello,
I tried moving my robot by pose or just to change orientation. The problem i had was that if i dont write joint angles in 10 numbers after dot (those numbers i took from program waypoint), then it will always do random rotation until it breaks. Do I need to combine XYZRxRyRz with joint angles? So for example if i want to do 4 waypoint movement i need to write first movement by joint following movement by pose? Because in this example pose doesnt change, as I understand.
Hello Edwardas
It is not necessary to combine XYZRxRyRz with joint angles – it is possible to use only one method or the other – and it is also possible to combine, but not necessary. This example just shows the two methods together, but it is possible to use only angle representation or only pose representation or combine then.
For example a command like this
s.send (“movej([-1.95, -1.58, 1.16, -1.15, -1.55, 1.18], a=1.0, v=0.1)” + “\n”)
will move by joint angles values.
And a command like this
s.send (“movej(p[0.00, 0.3, 0.4, 2.22, -2.22, 0.00], a=1.0, v=0.1)” + “\n”)
will move by pose values.
Notice the difference is the “p”.
I am not sure what you mean by “in this example pose doesnt change” – it does change.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Hi Lars
I am trying to read RFID information into a UR10 using an Arduino and an RFID and ethernet shield. I want the UR10 to then execute certain tasks based on the information contained on the RFID tags that have been read. I have read some of the posts describing the socket connections, but I am still new to this type of programming.
I am thinking of setting up a UDP server on the Arduino using the ethernet shield and then sending the RFID information through UDP packets. I am not 100% sure if I am on the right track.
I would appreciate any help in this regard.
I am using Visual studio with a bunch of plug-ins, because the UR10 forms part of a bigger system of connected devices ( “intelligent” conveyor system etc.) and this makes coding everything easier.
Kind regards
Carl
Hi Carl
Thanks for your question.
If you can setup the Arduino as a Socket Server – then it should be possible to exchange data with the UR client. That has been done with Raspberry.
The example here on this page shows how an example of a Client-Server socket communication and it can look very similar on a Raspberry.
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-client-server/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Hi Lars
Thank you for your input on my previous question.
I have followed the examples and have connected all my external devices. For some reason, my program won’t act on the input that it is given. The script code for the program is below, I am pasting it as I downloaded it from the robot.
def carl():
modbus_add_signal(“172.22.222.12”, 255, 0, 2, “MODBUS_1”)
modbus_set_signal_update_frequency(“MODBUS_1″, 10)
set_analog_inputrange(0, 0)
set_analog_inputrange(1, 0)
set_analog_inputrange(2, 0)
set_analog_inputrange(3, 0)
set_analog_outputdomain(0, 0)
set_analog_outputdomain(1, 0)
set_tool_voltage
(0)
set_runstate_outputs([])
set_payload(0.0)
set_gravity([0.0, 0.0, 9.82])
var_1=””
varmsg(“var_1”,var_1)
$ 2 “Robot Program”
$ 3 “socket_open(‘172.22.222.100′,12345,’varsocket’)”
socket_open(“172.22.222.100″,12345,”varsocket”)
$ 4 “While var_1 ≟ ””
while (var_1 == “”):
$ 5 “var_1≔socket_read_string(‘varsocket’)”
global var_1 = socket_read_string(“varsocket”)
varmsg(“var_1”,var_1)
end
$ 7 “Wait: 5.0”
sleep(5.0)
$ 8 “If var_1 ≠ ””
if (var_1 != “”):
$ 9 “If var_1 ≠ ‘blue'”
if (var_1 != “blue”):
$ 10 “If var_1≠’pink'”
if (var_1 !=”pink”):
$ 11 “If var_1≠’silver'”
if (var_1 !=”silver”):
$ 12 “var_1≔””
global var_1 = “”
varmsg(“var_1”,var_1)
else:
$ 13 “Else”
$ 14 “MoveJ”
$ 15 “silver”
movej([-1.5512461144242795, -2.2733734671613957, -0.701043582957093, -3.6288670450464475, -1.5175348837669784, 0.004072912366868142],
a=1.3962634015954636, v=1.0471975511965976)
$ 16 “var_1≔””
global var_1 = “”
varmsg(“var_1”,var_1)
end
else:
$ 17 “Else”
$ 18 “MoveJ”
$ 19 “pink”
movej([-2.3742061144242563, -2.2733734671613957, -0.701043582957093, -3.6288670450464475, -1.5175348837669784, 0.004072912366868142],
a=1.3962634015954636, v=1.0471975511965976)
$ 20 “var_1≔””
global var_1 = “”
varmsg(“var_1”,var_1)
end
else:
$ 21 “Else”
$ 22 “MoveJ”
$ 23 “blue”
movej([-3.412367433287107, -1.9277860297288356, -1.3079322093221013, -3.360050625637806, -1.7799582600146593, -0.09935586851942535],
a=1.3962634015954636, v=1.0471975511965976)
$ 24 “var_1≔””
global var_1 = “”
varmsg(“var_1”,var_1)
end
end
end
I am not sure why the robot won’t act on the change of variable_1. It does not seem to enter the If statements.
I am using the sockettest program as in the example you provided to host a server and send in the strings for variable_1.
Kind regards
Carl
Hi Carl
Thanks for your question.
If you look in the “Variables” tab during program run – does the Var_1 become blue – pink and silver at the correct time ?
Does the Var_1 become back to “” before checking with the If statement ?
Maybe consider to test with numbers instead of strings.
Can you list the .txt file of code also ?
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
HIi Lars
Yes, the variable changes to pink and blue etc. It then skips the If statements completely.
It only changes back to “” after skipping the If statements.
I have tried with numbers, using the read_ascii_float(1) function, replacing blue and pink with numbers, but I had no luck either.
I initially tried the opposite, using basic If statements, but this did not work, and hence I attempted the != signs, in the hope that the problem was with the ?= sign.
Below is my attached .txt file
Program
Init Variables
Robot Program
socket_open(“172.22.222.100″,12345,”varsocket”)
While var_1 ≟ “”
var_1≔socket_read_string(“varsocket”)
‘socket_close(“varsocket”)’
Wait: 5.0
If var_1 ≠ “”
If var_1 ≠ “blue”
If var_1≠”pink”
If var_1≠”silver”
var_1≔””
Else
MoveJ
silver
var_1≔””
Else
MoveJ
pink
var_1≔””
Else
MoveJ
blue
var_1≔””
‘Else’
Kind regards
Carl
Hi Carl
There might be some hidden character in the string send and therefore the expression is not true.
Below is an example using “socket_read_byte_list” and then check on the byte ascii values for blue – pink and silver.
Program
BeforeStart
var_1≔False
Robot Program
var_1≔socket_open(“192.168.0.100”,12345)
Wait: 3.0
Loop var_1≟False
var_1≔socket_open(“192.168.0.100”,12345)
socket_send_string(“Test”)
Wait: 5.0
var_2≔socket_read_byte_list(10)
If var_2[1]≟98 and var_2[2]≟108 and var_2[3]≟117 and var_2[4]≟101
Popup (blue)
If var_2[1]≟112 and var_2[2]≟105 and var_2[3]≟110 and var_2[4]≟107
Popup (pink)
If var_2[1]≟115 and var_2[2]≟105 and var_2[3]≟108 and var_2[4]≟118 and var_2[5]≟101 and var_2[6]≟114
Popup (silver)
socket_close()
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Hi Lars
Thank you for your help. With some tweaking your program worked. So here is what I think went wrong.
When using the sockettest program, it sends the “enter” along with the string to the client, and hence a “hidden” character. The robot then obviously reads the enter along with the string and my statements were never true.
I think this error will not happen if the server, an arduino ethernet server in my case, were to reply or send a string as the entering or sending of the “enter” will be omitted.
Kind regards
Carl
Hi!
I was wondering how the robot is handeling the incoming data trough Ethernet/TCP, as we’re having trouble with stopping the robot when we want. As I mentioned in another post, we’re controlling the robot with LabVIEW. The problem is:
LabVIEW has a loop which runs several times sending coordinates. As we stop the loop, for example with a stop button, the robot continues to move as many times as the loop has been running before it stops. How can we control this? Is there any way to flush the robot’s buffer, or do we have to solve this in LabVIEW? Maby we have to change the robot program?
Now, the only program in the robot is a program that is listening on a TCP port waiting for incoming data, nothing else.
Hi Eyvind
Thanks for your question.
Maybe considder to send a StopL() command to the robot.
Or make some form of handshake – so there is some form of sync between the external host and the robot.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Hi!
Is there any possibilities for using the offline UR5 simulator with TCP network? We are creating a LabVIEW program which should control the robot, but we need to test the program when we’re not with the actual robot.
The tought scenario is that we could set the network settings in the simulator, make LabVIEW listen and send coordinates to the robot trough port 30001, the robot simulator reads the coordinates and move.
A problem is that I’m not able to set any network settings in the offline simulator. When I press “apply”, it apllies the settings (or not), but when I press “update” to check if the setting sare set, it’s just set to “Disable network”.
Do you have any ideas about how we could solve this issue?
Hi Eyvind
Thanks for your question.
Have you tried from inside the Unix eviorment in the Virtual box to open a terminal and go to /etc/network and configure the IP address in the “interfaces” file ?
Also set the Network inside the Ubuntu “settings” enviorment to “Bridged adapter” with the active interface on the PC computer where Virtual box is running.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Hi everybody,
I’m completely new to UR 10 and I would like to programm the robot via socket using Matlab.
How could I make the robot move through several way-points with costant velocity?
I would be grateful if you could give me some detailed informations.
Thank you very much in advance,
Lorenzo
Hi Lorenzo
Thanks for your question.
To my knowledge the data send out on port 30001 and 30002 are matlab data to be “read”. I have not seen examples to “write” i.e. control the robot in this method.
There are some information at this link – where a file Client_Interfaces with further informations can be downloaded.
http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/remote-control-via-tcpip-16496/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Hi,
I am completely newby with UR. I have an UR10 and I’d like to program it via tcp connection in Windows OS. Can you please list me all the possible way to communicate with the robot in windows? Besides, I’l like also to know if there is an easy way to dowload programs(.script,.txt) from a remote pc and run them automatically.
Thank you for your time
Hi Gradeka
Thanks for your question.
The main different ways to program is in Polyscope GUI and with UR Script and they can be combined.
To see different examples these links provide some.
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-programming-from-the-teaching-pendant/
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-via-socket-connection/
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-client-server/
http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/basic-ur-teach-waypoints/
Programming is virtual endless so it is not possible to list all possible ways.
I am not aware of a method to download programs and make them run automatically.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Thank you for your quick reply. I’d like to ask you one more question. If I want to simply make a digital output blink via URScript, with a while loop, how can I do it? Probably the question is not so intelligent but searching in the documentation does not help me. I tried somenthing like:
def myProg():
i=0
val=True
while i<10:
set_digital_out(0,val)
val=not val
i=i+1
end
end
but it says that i is not initialized. please give me some hint or tell me where to find some guidelines for programming.
Thank you
Hi Gradeka
Thanks for your question.
I do not use this way of programming very much because my experience is that it becomes difficult for others to service – and I do not have much information’s about it.
Also because this task of making an output blink is very easy to make in the Polyscope GUI.
There is not much information about this method but at this link there are some few notes.
http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/secondary-program-17257/
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Sorry for the late answer.
In any case I found which was the problem (stupid for the most maybe). It was just the indentation of the inner functions. Now it works great
I have just a small other question: is there a way to interpret a string as a command (as in python there is exec())? For example:
var=”popup(“Hello”,”Windows”,False,False)”
??exec(var)???
Thank you in advance
Hi Gradeka
Great that you solved it.
I have not seen a command like exec() in UR script.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
137 thoughts on “UR Script: Commands via Socket connection”
Aqib Khan
8 – January – 2016 at 01:59
Hi Lars,
I have two UR10 arms and I am really a novice in using them and also python. I am trying to make them move at same time by sending commands through the PC via opening up sockets at the same time. I used the program quoted on this forum for opening up a socket. The thing I am doing is to call the functions to execute the arms at the same time if the user wants.
Now the problem is… the functions execute when we want to run a single arm. You’ll get the idea once you see the program. but If I give the option to invoke both the arms at the same time then, functions execute one after the other, in a sequence, even though they are called at the same time. First one arm executes one full motion and when that ends the other arm executes its motion. But not simultaneously.
Now I have done another thing, and that is define a bash file ‘Both.sh’ and I call two separate files in that bash file where each file contains the code for the arm motion.The same code which is defined in the function arm() below. Only this way both the Arms execute simultaneously. My problem is that I dont want to call multiple files in a bash file. I want to execute simultaneous motion through function calls. is it possible….? please help
Below is my code.
def main():
return(eval(raw_input(‘Please enter your choice\n\t’)))
def arm1():
print (‘Now Arm 1 motion is being launched now’)
print
print (‘Be Advised to watch the operation carfeully and be prepared to encounter any mishap and react instantly’)
print
print (‘Thank you\n’)
# Echo client program
import socket
import time
#Postures for movej
posture1=”[0,-1.57,1.57,-1.57,1.57,0]”
posture2=”[-1.57,-1.57,1.57,-1.57,1.57,0]”
posture3=”[-1.56164,-1.40275,1.99724,-1.63731,-0.119222,-1.46024]”
posture4=”[-1.56165,-1.40488,1.06426,-1.63919,0.523,-1.46022]”
posture5=”[6,-1.57,1.57,-1.57,-1.57,0]”
#Postures for movel
#posture1=”[0,-1.57,1.57,-1.57,1.57,0]”
#posture2=”[0.165,0.687,0.433,0,0,0]”
HOST =’192.168.0.9′ # The remote host
PORT = 30002 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
#s.send (“set_digital_out(2,True)” + “\n”)
#s.send(“movej([0,-1.57,1.57,-1.57,1.57,0], a=0.3, v=0.04,t=5,r=0)”+ “\n”)
#string_to_send=”movej(“+posture+”, a=0.3, v=0.04,t=5,r=0)”+ “\n”
#s.send(string_to_send)
#movej
s.send(“movej(“+posture1+”, a=0.3, v=0.05,t=10,r=0)”+ “\n”)
time.sleep(10)
s.send(“movej(“+posture3+”, a=0.3, v=0.05,t=5,r=0)”+ “\n”)
time.sleep(10)
s.send(“movej(“+posture4+”, a=0.3, v=0.04,t=5,r=0)”+ “\n”)
time.sleep(10)
s.send(“movej(“+posture1+”, a=0.3, v=0.05,t=5,r=0)”+ “\n”)
time.sleep(10)
s.send(“movej(“+posture5+”, a=0.2, v=0.02,t=20,r=0)”+ “\n”)
time.sleep(25)
s.send(“movej(“+posture1+”, a=0.2, v=0.02,t=20,r=0)”+ “\n”)
time.sleep(20)
data = s.recv(1024)
s.close()
print (“Received”, repr(data))
def arm2():
print (‘Now Arm 2 motion is being launched now’)
print
print (‘Be Advised to watch the operation carfeully and be prepared to encounter any mishap and react instantly’)
print
print (‘Thank you’)
# Echo client program
import socket
import time
#Postures for movej
posture1=”[0,-1.57,1.57,-1.57,1.57,0]”
posture2=”[-1.57,-1.57,1.57,-1.57,1.57,0]”
posture3=”[-1.56164,-1.40275,1.99724,-1.63731,-0.119222,-1.46024]”
posture4=”[-1.56165,-1.40488,1.06426,-1.63919,0.523,-1.46022]”
posture5=”[6,-1.57,1.57,-1.57,-1.57,0]”
#Postures for movel
#posture1=”[0,-1.57,1.57,-1.57,1.57,0]”
#posture2=”[0.165,0.687,0.433,0,0,0]”
HOST =’192.168.0.10′ # The remote host
PORT = 30002 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
#s.send (“set_digital_out(2,True)” + “\n”)
#s.send(“movej([0,-1.57,1.57,-1.57,1.57,0], a=0.3, v=0.04,t=5,r=0)”+ “\n”)
#string_to_send=”movej(“+posture+”, a=0.3, v=0.04,t=5,r=0)”+ “\n”
#s.send(string_to_send)
#movej
s.send(“movej(“+posture1+”, a=0.3, v=0.05,t=10,r=0)”+ “\n”)
time.sleep(10)
s.send(“movej(“+posture3+”, a=0.3, v=0.05,t=5,r=0)”+ “\n”)
time.sleep(10)
s.send(“movej(“+posture4+”, a=0.3, v=0.04,t=5,r=0)”+ “\n”)
time.sleep(10)
s.send(“movej(“+posture1+”, a=0.3, v=0.05,t=5,r=0)”+ “\n”)
time.sleep(10)
s.send(“movej(“+posture5+”, a=0.2, v=0.02,t=20,r=0)”+ “\n”)
time.sleep(25)
s.send(“movej(“+posture1+”, a=0.2, v=0.02,t=20,r=0)”+ “\n”)
time.sleep(20)
data = s.recv(1024)
s.close()
print (“Received”, repr(data))
#Start of the Program
input=eval(raw_input (‘\nThis is a program to run a real time simulation for the Universal Arms ……Please Enter “yes” if you wish to continue or Enter “no” if you wish to exit….Enter in quotes\n\t’))
if input==’yes’:
print(‘\n\n’)
print(‘\tPlease read and follow the instructions very carefuly…. for a smooth execution\n’)
print(‘\n’)
choice=main()
if choice==1 or choice==’single’:
choice2=eval(raw_input(‘Would you like to execute the Right Arm or the left. Please enter right or left in quotes\n\t’))
if choice2==’right’:
print
print(‘Now the right arm is being executed in motion….get ready\n’)
print
print (‘Starting……………’)
print
time.sleep(3)
print (‘Go…………………………..\n\n\n’)
arm1() #function call
elif choice2==’left’:
print
print(‘Now the left arm is being executed in motion’)
print
print (‘Starting……………’)
print
time.sleep(3)
print (‘Go…………………………..\n\n\n’)
arm2() #function call
if choice==2 or choice==’both’:
print
print(‘Now both the arms are being executed in motion…..get ready…..’)
print
print (‘Starting……………’)
print
time.sleep(3)
print (‘Go…………………………..\n\n\n’)
arm1() #Here is the Problem……..
arm2()
elif input==’no’:
print
print (‘Thankyou very much for doing a test run of the program\n’)
print
print (‘The program is exiting now’)
Reply ↓
zacopressadmin Post author
8 – January – 2016 at 08:59
Hi Khan
Thanks for your question and nice program.
I think the reason for the separate move you see is because after each move command there is a “wait” statement time.sleep(xx)” which is fair to give the robot time to move. And when counting there are a total 85 seconds. So when the first routine for arm 1 is activated then it goes like this – move wait move wait move wait move wait….. and so on – and that’s one first arm only – then when the first arm is finish moving then the second routine only starts at this moment and therefore they run separately.
There are properly several ways to change this – you might consider to have a routine called “both” and then also have two sockets – one call s1 and one called s2 for each robot and then in the “both” routine you open both sockets and send each move command to both robot just after each other something like this.
…………………
HOST1 =’192.168.0.9′ # The remote host
PORT1 = 30002 # The same port as used by the server
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1.connect((HOST1, PORT1))
HOST2 =’192.168.0.10′ # The remote host
PORT2 = 30002 # The same port as used by the server
s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s2.connect((HOST2, PORT2))
s1.send(“movej(“+posture1+”, a=0.3, v=0.05,t=10,r=0)”+ “\n”)
s2.send(“movej(“+posture1+”, a=0.3, v=0.05,t=10,r=0)”+ “\n”)
time.sleep(10)
s1.send(“movej(“+posture3+”, a=0.3, v=0.05,t=5,r=0)”+ “\n”)
s2.send(“movej(“+posture3+”, a=0.3, v=0.05,t=5,r=0)”+ “\n”)
time.sleep(10)
s1.send(“movej(“+posture4+”, a=0.3, v=0.04,t=5,r=0)”+ “\n”)
s2.send(“movej(“+posture4+”, a=0.3, v=0.04,t=5,r=0)”+ “\n”)
time.sleep(10)
……………….
If you wish to make the two robots more differently then you might need to have posture variables unique for each robot.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Reply ↓
Aqib Khan
9 – January – 2016 at 00:50
Dear Lars,
Thank you for the reply and thank you for the compliment. Yes the solution yo sent just worked perfectly. I defined another function both( ) and its executed.
I have another question, even though my problem is solved, but do you think we could have achieved the same solution by using multi process method for example
from multiprocessing import Process
def func1():
print ‘func1: starting’
def func2():
print ‘func2: starting’
if __name__ == ‘__main__’:
p1 = Process(target=func1)
p1.start()
p2 = Process(target=func2)
p2.start()
p1.join()
p2.join()
Reply ↓
zacopressadmin Post author
9 – January – 2016 at 14:10
Hi Khan
Thank you.
For the multi processing question – it’s hard to say because that on the external device and not on the robot. Maybe one way to find out is to try.
Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.
Also check out the CB3 forum
Reply ↓
BEN
10 – December – 2015 at 17:54
HI
I want to know how we can control two arms simultaneously because i want to use two arms UR10 for grasping a box .my question is how i can control both of them with UR Script program by Socket connection.(use different IP ).
Thanks and Regards
BEN
Reply ↓
zacopressadmin Post author
10 – December – 2015 at 17:16
Hi Ben
Thanks for your question.
There are different ways to do it. The two robots are to be seen as two individual robots with each their own program – and then if nessecary send status to each other.
I have not tried programming two arms that works together, but at these links is examples of controlling UR via script – and you can do that for two arms as well by sending script commands to two different IP adresses.
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-programming-from-the-teaching-pendant/
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Reply ↓
BEN
10 – December – 2015 at 18:47
Hello
thanks for you quick reply
so the idea that i control each arm different the other but i don’t know if that should work simultaneously because i want to use both of them for grasping a box and move it , so i think if i have a delay between the two arms i will have a problem for grasping.
Thanks and Regards
BEN
Reply ↓
zacopressadmin Post author
10 – December – 2015 at 18:47
Hi Ben
I think an electronic delay will be negligible compared to physics and maybe you can consider to use the force mode then it will be based on when a certain force is achieved which will be regardless of a delay.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Reply ↓
Allan
9 – December – 2015 at 23:32
Hi Lars
I have a question regarding controlling the UR-5 from a PC with a tcp/ip socket.
The way I’m controlling the robot today, is like the way you described in the this article, but I would like, if it’s possible, to use the Force_mode(..) feature, but can’t find much about this, can you give me a small examlpe or some hints.
The application I want to create is basically just moving an item from waypoint A to waypoint B and when the robot encounters a given force on it’s way to waypoint B, it stops. After a given time it moves back to waypoint A.
Hope you can help me.
Thanks in advance
Allan
Reply ↓
zacopressadmin Post author
10 – December – 2015 at 17:22
Hi Allan
Thanks for your question.
My experience is that when there is “iterations” and also when information’s from the robot is needed like an input – then it is better have the program on the robot – i.e. make a master program on the robot like the client/server example where it is possible to ask and to command by sending variable over such TCP socket connection.
We have to remember that the robot and its controller is closely related especially when it is operations that need relative fast updates and commands which force mode does – so to have a control loop over a TCP connection is more challenging to establish – rather than to let the internal controller and GUI environment do the control where fast updates are necessary – and then exchange user data over the TCP connection.
I think you can better achieve what you are looking for by having a master program on the robot GUI and then exchange user data over the TCP connection.
Below is an example of using the force_mode script command from within GUI.
movej([-0.1, -1.4, 1.64, -2.00, -1.57, 1.52], a=1.4, v=1.0)
sync()
force_mode(p[0.0,0.0,0.0,0.0,0.0,0.0], [0, 0, 1, 0, 0, 0], [0.0, 0.0, 30.0, 0.0, 0.0, 0.0], 1, [0.1, 0.1, 0.15, 0.35, 0.35, 0.35])
sleep(3.0)
end_force_mode()
stopl(3.0)
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Reply ↓
Allan
16 – December – 2015 at 21:49
Hey Lars
Thanks for your reply.
Maybe I don’t understand the force_mode feature correct and what’s possible to control by a socket connetion to the robot, but is the following example not possible?
Pseudo code:
//move to first position
socket.send(“movel(p[X1,Y1,Z1,RX1,RY1,RZ1],a=A1, v=V1)\n”);
//sync
socket.send(“sync()”);
//enable force mode. Force = 30N and is “measured” on the Z-axis.
socket.send(“force_mode(p[0.0,0.0,0.0,0.0,0.0,0.0], [0, 0, 1, 0, 0, 0], [0.0, 0.0, 30.0, 0.0, 0.0, 0.0], 1, [0.1, 0.1, 0.15, 0.35, 0.35, 0.35])\n”);
//move to 2nd position, where force mode is activ. When the force of 30N is reached, the robot //stops at that point.
socket.send(“movel(p[X2,Y2,Z2,RX2,RY2,RZ2],a=A2, v=V2)\n”);
//waits for the robot to stop at the point where it reaches 30N of force in the Z -axis.
Sleep(10);
//disable force mode
socket.send(“end_force_mode()”);
//move back to the first position
socket.send(“movel(p[X1,Y1,Z1,RX1,RY1,RZ1],a=A1, v=V1)\n”);
Reply ↓
zacopressadmin Post author
17 – December – 2015 at 10:27
Hi Allan
An example:
s.send (“def myProg():”+ “\n”+”force_mode(p[0.0,0.0,0.0,0.0,0.0,0.0], [0, 0, 1, 0, 0, 0], [0.0, 0.0, 30.0, 0.0, 0.0, 0.0], 1, [0.1, 0.1, 0.15, 0.35, 0.35, 0.35])” +”\n” +”sleep(10)”+”\n” + “end”+”\n”)
s.send (“end_force_mode()” + “\n”)
I pseudo form the code is
def myProg():
force_mode(xxx)
sleep(10)
end_force_mode()
end
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Reply ↓
Allan
17 – December – 2015 at 21:06
Hi again
Thanks for the hint, it works now.
There is only one issue when I use the force mode, the Robot moves very unstable along the Z-axis, even if I program it in the GUI or command it by the socket connection. The documentation describes that, when the robot is in force mode, the position of TCP is not accurate.
But can it be true that while the robot moves along the z-axis, it moves uptil +- 1 cm along the x and y-axis as well?
If I narrows the limits, in the force_mode function, the robot just stops, the a warning is displayed on the GUI, saying that the position is to big.
/Allan
zacopressadmin Post author
18 – December – 2015 at 09:52
Hi Allan
A few things.
1. My experience is that the force function works best when the robot has the force to work with i.e. that the robot meets the “obstruction” that creates the force. For example in polishing there is a surface that the robot approach and thereby a force is build up and thereby the robot can “find” the force. If the robot is standing out in thin air it will start moving in the direction according to your program, but if there is no force then the robot will search for the force.
2. You might need to work a little on the parameters you give. Each robot is slightly different in mechanics and therefore the force measured can be a little different from robot to robot.
3. When programming in script the programmer needs to control the communication flow and has to be more specific in the timing because now the controller is the programmer. Therefore the timing of commands becomes important – so small pauses in between commands might be necessary. This is why I think programming in the GUI is easier because then the controller is the robot itself.
4. I just tried this on my UR 3 and it looks quite good. (There is a delay for the robot to perform the force command).
s.send (“def myProg():”+ “\n”+”force_mode(p[0.0,0.0,0.0,0.0,0.0,0.0],[0, 0, 1, 0, 0, 0], [0.0, 0.0, 30.0, 0.0, 0.0, 0.0], 1, [0.1, 0.1, 0.15, 0.35, 0.35, 0.35])” +”\n” +”sleep(100)”+”\n” + “end”+”\n”)
time.sleep(5)
s.send (“end_force_mode()” + “\n”)
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Allan
21 – December – 2015 at 20:30
It doesn’t seems to work, the robot is still moving quite uneven.
Is it possible to implement this functionality by using an if statement and the force() function like this:
//moving to position 1
socket.send(“movel(p[X1,Y1,Z1,RX1,RY1,RZ1],a=A1, v=V1)\n”);
//if the robot measures a force above 30 N, it stops the movement //towards position 1
socket.send (“def myProg():\n if force() > 30: stopl(1)\n end\n”);
Sleep(10);
If it’s possible what is the right syntax?
zacopressadmin Post author
21 – December – 2015 at 21:39
Hi Allan
1.
Have you consider trying other values than 30 Newton e.g. 40 or 50 ?
2.
My experience is to use “If” in the GUI with force measurements – an example at this link.
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/force-feedback-function/
3.
When making iterations and conditional branch and reading inputs etc. a master program in GUI seems better and if data is necessary to send an external host then the client/server concept is a possibility.
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Gopi
26 – November – 2015 at 21:59
Hi,
I would like control the UR10 robot from PC using UR Script program by Socket connection, I have successfully opened the client connection from PC. and I could able to send “move” command to move the robot arm by specifying joint angles.. But I want to read the current joint positions and TCP positions and DIO status etc…
When I enabled the receive part of the client I am receiving some junk continuously .. I dont know what the junk means.. and How do we disable this … and How do we read the joint positions and TCP positions in this method..
I am using port 30002.
Also I have tested with port 30003 and getting the same issue..
Kindly help me to solve this issue..
Basically I want to run the UR10 from my PC with out the help of teach pendent..
I have read about your sample programs and all shows how to send the command from PC, I would like to see it for receiving responses also.
Thanks and Regards
Gopi
Reply ↓
zacopressadmin Post author
27 – November – 2015 at 08:37
Hi Gopi
Thanks for your question.
The data you see flowing from port 30002 and 30003 are not junk, but status information like Matlab data. This dataflow is normal – a little more information’s can be found at this link
http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/remote-control-via-tcpip-16496/
To receive a response from the robot you can consider either:
1. Have a local program on the robot that reads and sends back automatically or by request to a server program you have on a host e.g. PC. This is how the client-server program on this forum works at this link
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/
2. Or you can connect to the MODBUS registers on the robot via port 502 and read from a PC with MODBUS protocol and commands. More information’s about the MODBUS registers in the UR robot can be found here.
http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/modbus-server-16377/
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Reply ↓
Gopi
1 – December – 2015 at 20:03
Hi Thanks for your suggestion..
I have one more question, When I am trying to move the robot using TCP , X,Y,Z positions, Most of the times I ma facing singularity issue, Could you please suggest me, why this issue is occurring and how do we get it solved.
Thanks and Regards
Gopi
Reply ↓
zacopressadmin Post author
1 – December – 2015 at 21:24
Hi Gopi
Can you explain how you try to move the robot ?
Is it from within the GUI or script commands ?
What is the robot type ?
What are the coordinates of the from and to positions ?
Are you using MoveJ or MoveL etc. ?
Regards
Lars
Reply ↓
Gopi
9 – December – 2015 at 00:30
Hi Lars,
These are the answers with respect to your following question you have asked.
Ques:Can you explain how you try to move the robot ?Is it from within the GUI or script commands ?
Ans: We tried with both the methods and both the method gives us the same singularity issue.
Ques:What is the robot type ?
Ans: UR10 CB3.
Ques:What are the coordinates of the from and to positions ?
Ans: we are trying to move both joint angles as well as TCP Positions from random positions.
Ques:Are you using MoveJ or MoveL etc. ?
Ans: We are using both the above script commands.
Thanks & Regards
Gopi
zacopressadmin Post author
9 – December – 2015 at 10:46
Hi Gopi
If it is from random positions to random positions then there can be singularity – you might consider having waypoints (positions) in between. As a programmer it might be necessary to consider and manage avoiding the singularities by having more positions.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Shangke
2 – December – 2015 at 17:24
Hi
I would like to get the system clock in the script program when using the UR 10. How can I achieve it? I have checked the manual and did not find the function to return the system clock.
Thank you for your time.
Regards
Shangke
Reply ↓
zacopressadmin Post author
3 – December – 2015 at 10:44
Hi Shangke
Thanks for your question.
I can there are some time information in the Modbus registers 2048-2053 – maybe you can considder to read these registers. More information on this page
http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/modbus-server-16377/
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Reply ↓
GANESH P
26 – November – 2015 at 21:21
Hi
I am working on socket communication in UR10 robot, i made my UR10 as server and my PC as client after both gets connected, from my PC i tried to get status such as get (actual joint positions()) and digital IO but it is giving me some junk values, so help me to go froward from here…
Reply ↓
zacopressadmin Post author
27 – November – 2015 at 08:09
Hi Ganesh
Thanks for your question.
To get a feedback from the robot you can consider either:
1. Have a local program on the robot that reads and sends back automatically or by request to a server program you have on a host e.g. PC. This is how the client-server program on this forum works at this link
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/
2. Or you can connect to the MODBUS registers on the robot via port 502 and read from a PC with MODBUS protocol and commands. More informations about the MODBUS registers in the UR robot can be found here.
http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/modbus-server-16377/
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Reply ↓
Christian Hahna
30 – October – 2015 at 22:31
Hello Lars,
in our company we have the following problem(s):
We have the UR5 / CB3.
We try to operate the robot with the following code from a Laptop:
import socket
HOST = “192.168.1.56″
PORT = 30002
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send (“movel([-94.67,-36.74,196.62,3.2735,0.0192,-4.0174])” + “\n”)
data = s.recv(1024)
s.close()
print (“Received”, repr(data))
The code as such works and the robot arm moves but we always get
Protective Stop Error Messages such as “C153A0 – Position deviates from path : Base”.
We also had other Protective Stop Error Messages (e.g. 154, ….) depending how the
arm was positioned before. But it never looked like that the starting position would
be any weird. The arm always moves a few centimeters and then it stops because of
one of the Protective Stops.
Do you have any suggestion what we can do or how we approach this problem the
best way!?
Thanks and best regards
Christian
Reply ↓
zacopressadmin Post author
30 – October – 2015 at 23:06
Hi Chrisitan
Thanks for your question.
Can you check that it is a valid position you are asking the robot to go to ? The data seems unusual high because joint data in a script command can be in radians.
You can make a waypoint for the position you intend to move the robot to in a normal GUI program – then you can see the joint data in the x.script file for that program and use the same data for testing the position you ask the robot to go to.
Another reason can be if the position is very far away from where the robot is starting from and then it experiences a singularity – which means you might need to have more positions on route to the final position.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Reply ↓
Christian Hahna
2 – November – 2015 at 23:23
Hello Lars,
thanks for your quick reply to my last question. We could figure it and now it works.
But now we are confronted with another problem:
We want to receive the ‘actual TCP position’ of the robot arm and have it sent
to a PC. See to following code which runs on the PC:
import socket
import time
HOST = “192.168.1.11″
PORT = 30002
print “Starting Program”
s = socket.socket()
s.bind((HOST, PORT))
s.listen(5)
c, addr = s.accept()
print c.recv(1024)
c.close()
print “Program finish”
This is the code which runs on the robot. There we also have a pop-up-window to tell us
the current TCP position:
def sendDataToClient_FromRobot():
set_standard_analog_input_domain(0, 1)
set_standard_analog_input_domain(1, 1)
set_tool_analog_input_domain(0, 1)
set_tool_analog_input_domain(1, 1)
set_analog_outputdomain(0, 0)
set_analog_outputdomain(1, 0)
set_tool_voltage(0)
set_tcp(p[0.0,0.0,0.0,0.0,0.0,0.0])
set_payload(0.0)
set_gravity([0.0, 0.0, 9.82])
$ 1 “Robot Program”
$ 2 “MoveJ”
$ 3 “Waypoint_1″
movej([-0.9780608981942036, -0.7214399377484852, -1.8638256010495597, -0.589019797479601, -1.935071987309266, 0.7081922499350776], a=1.3962634015954636, v=1.0471975511965976)
$ 4 “MoveJ”
$ 5 “Waypoint_2″
movej([-0.9780527317397407, -0.7214353191283882, -1.8638286835667701, -0.5890214248041321, -1.9350801460022922, 0.7081919935392023], a=1.3962634015954636, v=1.0471975511965976)
$ 6 “socket_open(’192.168.1.11′, 30002)”
socket_open(“192.168.1.11″, 30002)
$ 7 “popup(get_actual_tcp_pose())”
popup(get_actual_tcp_pose())
$ 8 “socket_send_string(get_actual_tcp_pose())”
socket_send_string(get_actual_tcp_pose())
$ 9 “socket_close()”
socket_close()
end
The result we get sent to the PC and on the pop-up window on the GUI are of
course the same
(p[-0.09985, 0.00477246, 0.675595, -1.54106, 0.391288, 0.749075])
but when we check the TCP coordiantes of Waypoint_2 on the
GUI (last position of the robot arm -> the data supposed to be sent) the coordiantes
data here is different. Check it out:
X = -99.88 mm
Y = 4.81
Z = 275.61
RX = 3.9683
RY = -1.0074
RZ = -1.9288
X and Y are quite ok when you move the comma 3 places to the right but
then with Z, it seems to be completely wrong. RX, RY and RZ also don’t seem
to be right (except for RX when you move to comma 1 place to the right …. but
i am not sure because this should be the pose position of RY!?).
I hope you can help us again.
Thanks in advance!
Christian
Reply ↓
zacopressadmin Post author
3 – November – 2015 at 09:49
Hi Christian
Thanks for your question.
I looks like the 400mm difference in the Z value might be because the Move screen is set to show “View” instead of “Base”. The coordinate use in script is referenced to the Base. You might consider to try and set the drop down in the move screen to “Base” and check the value.
The difference in the rotation vectors might be because – since the joints can rotate 720 degree (+/- 360 degree) then there are more results to the same pose because a joint can be rotated 360 degree which will still be the same pose.
With the pose editor it is possible to set the robot in a desired pose base on the coordinate given in the pose editor and thereby verify the pose position with the data provided in the result.
The rotation data given in script are in radians.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Reply ↓
Christian Hahna
3 – November – 2015 at 20:40
Hello Lars,
thanks for you quick reply again!
We set it to ‘Base’, so the X, Y and Z coordinates are now ok.
Problem is still the RX, RY and RZ coordinates.
In the ‘Edit Pose’ screen the coordinates are as follows:
Feature: Base
Tool Position
X: -204.81 mm
Y: -164.14 mm
Z: 746.11 mm
Rotation Vector [rad] (–> we checked out all 4 possibilities in the drop down menue)
RX: 0.1245
RY: 2.3289
RZ: -2.3119
And this is what the function ‘get_actual_tcp_pose()’ returns to us:
p[-0.204787, -0.164126, 0.746095, -0.113889, -2.12709, 2.11159]
Why does the result of the function still differ from what we see on
the GUI!? Any ideas how we can fix this!?
Thanks,
Christian
zacopressadmin Post author
3 – November – 2015 at 20:54
Hi Chrisitan
Did you try to insert the data in the pose editor with the data the get_actual_tcp_pose() provied – and then see where this position is ?
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Christian Hahna
5 – November – 2015 at 15:59
Hi Lars,
thanks for you help.
Yes, the get_actual_tcp_pose() data and the data on the GUI
are actually the “same” …. as so far as the position of the arm
is the same.
Christian Hahna
5 – November – 2015 at 22:47
Hello Lars,
now we know that the END-Position of the robot arm is the same.
For example:
p[0.10976, -0.15826, 1.00264, -0.58548, 1.87436, -1.87662]
is the same END-Position like
p[0.10976, -0.15826, 1.00264, 0.7688, -2.4612, 2.4643]
(note how only RX, RY and RZ differ!) but the way the robot arm takes to get there is different.
And this is our problem.
Sometimes the pose given to us from get_actual_tcp_pose() is the same like on the GUI, sometimes it is different (but the END-Position is in both cases the same!). Same when we send commands via socket like
–> s.send(“movej([X, Y, Z, RX, RY, RZ]” + “\n”).
Sometimes the robot arm moves into the desired position without problems, sometimes the “Shoulder” wants to make a 360 degree turn first (which is not possilbe because there is the floor in the way).
Do you have any suggesten how we can approach this problem!?
When we can expect A (RX,RY, RZ) from get_actual_tcp_pose() and
when B (RX, EY, RZ)?
Or when do we have to send [a(RX,RY, RZ)] and when [b(RX, EY, RZ)],
so that the robot arm doesn’t try to make a whole turn around himself
first? (a, b: same end position, differnt ways / different data)
Thanks very much!
Christian
zacopressadmin Post author
5 – November – 2015 at 23:40
Hello Chrisitan
This is because of different rotation status of the joint at the time of get_actual_tcp_pose() because some joints can turn 720 deg (+/- 360 deg). I do not have the algorithm for the calculation. You might consider having more waypoints in between start and end positions to control the desired path – especially if you are using script and if there is a big distance between start and end positions.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Christian Hahna
10 – November – 2015 at 17:30
Thanks a lot, it works!
Christian Hahna
6 – November – 2015 at 21:04
Thanks for your reply Lars.
I’d have one last question about this problem.
This is what we send via socket connection:
s.send(“movej([-0.4437614627869806, -2.066329861363151, 1.867615889800172, -1.355958638052253, -1.52020726598505, -0.2980780494440687], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
This is the data we get from get_actual_tcp_pose() and we see on the Waypoint on the GUI. In this case, with this waypoint, it is both the same ….. but there are other waypoints where GUI and get_actual_tcp_pose() differ, but the end position is the same (as you explained, +/- 360 degrees. etc. ).
p[-0.298375, 0.0164997, 0.45658, 2.35501, 2.02907, -0.0562185]
Why for Example X, Y, Z is different from movej(p) and get_actual_tcp()/GUI?
In Edite Pose, i can’t find this data which made the robot move in his position.
Thank you,
Christian
Reply ↓
zacopressadmin Post author
8 – November – 2015 at 15:00
Hi Christian
It is because a joint can rotate 720 degrees (+/- 360 deg) and therefore the same pose can have different results because turning a joint 360 degrees will give the same position but the angle data and rotation vector is different for the same position and therefore different value for the same pose.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Reply ↓
Christian Hahna
9 – November – 2015 at 23:19
Dear Lars,
thanks again …. ok, we try a different approach now, but again we need you help.
We gonna have a couple of waypoints on a file on the robot/GUI, run this file and
want to have the waypoints accessed from a PC. We do not want to send the coordiantes, we
just want to send the commands like this: s.send(“Waypoint_1″).
So on the robot/GUI, the program knows, “Waypoint_1″ => movej([X, Y, Z, ax, ay, az]).
You know, like we send from the PC an integer and this integer is read and checked on
the robot/GUI. For example we send 1 for Waypoint_1 and if this assignment on the
robot is true, movej[Waypoint_1] is activated. After completion, the program waits for the
next integer we (might) send.
We tried to programme this according to this example
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/
and it works, but this is not exactly what we need.
We need some programme/code on the robot/GUI that waits constantly for input from the outside (a PC)
and only reacts when it receives input.
Can you give us some easy code example for this!? GUI and PC script.
Thanks,
Christian
PS: We can not find the ‘while’ on the ‘Program Structure Editor’ …. we see
in ‘Advanced’ the ‘Loop’, but no ‘While’ …. the meaning is for my understanding
the same but still i am not sure if this is correct in this UR5 context.
Reply ↓
zacopressadmin Post author
9 – November – 2015 at 23:06
Hi Christian
Thanks for your question.
Maybe you can consider something like this on the robot.
var_1≔socket_open(“192.168.0.102″,12345)
Loop var_1≟ False
var_1≔socket_open(“192.168.0.102″,12345)
var_2≔socket_read_ascii_float(3)
If the data type is different than this example the socket_read_………. needs to be adjusted to the data type to be received e.g. string or byte
The While is because the example is from some time ago where the Loop was called While – it was changed some time ago.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Thomas M
20 – October – 2015 at 20:46
Dear Zacrobria Team,
we have successfully installed a UR5 and have been able to send python commands via socket connection to move the robot. This is working.
Unfortunately we are not able to receive or display meaningful data received from the UR5. Please find below a simple example where we want to read the current tcp pose (could any other command).
Many thanks in advance,
Thomas
# Echo client program
import socket
import time
HOST = “192.168.1.56″ # The remote host
PORT = 30002 # The same port as used by the server
TEST = 0
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send(“get_actual_tcp_pose()” +”\n”)
data = s.recv(1024)
s.close()
print (“Received”, repr(data))
Output:
\\x00\\x00\\x004\\x14\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\x03\\tURControl\\x03\\x01\\x00\\x00B\\x14Feb 06 2015, 15:17:07′
Reply ↓
zacopressadmin Post author
20 – October – 2015 at 23:34
Hi Thomas
Thanks for your email.
The data received from port 30002 is not related to your command, but is data that is automatically is streamed out and I think it is Matlab data.
When you send data to port 30002 it is one way communication so you can make the robot move and also set output ports, but not read data in this way – more is described on this page.
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-via-socket-connection/
To receive data about the position of the robot it is possible to create a client server scenario where a program is running on the robot using the get_actual-tcp_pose and then send the result data back to the server (maybe a PC) over the TCP socket connection. An example is shown at this link.
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Reply ↓
Andi S
27 – August – 2015 at 20:55
Hallo,
thank you for your response!
I am still having my problems with the commands via socket connection…
I have two different codes in Python. If I loaded a program on the robot and run the following, it works:
import socket
import time
HOST = “192.168.1.10″ # The remote host
PORT = 29999 # The same port as used by the server
print “Creating Socket Connection…”
sckt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sckt.connect((HOST, PORT))
time.sleep(2)
print “… created Socket Connection!”
print “”
sckt.send (“play” + “\n”)
time.sleep(5)
sckt.send(“stop” + “\n”)
data = sckt.recv(1024)
sckt.close()
print (“Received”, repr(data))
print “”
print “Program finished”
—————————
The output in the console is the following:
Creating Socket Connection…
… created Socket Connection!
(‘Received’, “‘Connected: Universal Robots Dashboard Server\\nStarting program\\n’”)
Program finished
——————————
If I run the following Python-Code, there is no reaction: (I tried it both in ‘Run Progam’ and ‘Program Robot’)
import socket
import time
HOST = “192.168.1.10″ # The remote host
PORT = 29999 # The same port as used by the server
print “Creating Socket Connection…”
sckt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sckt.connect((HOST, PORT))
time.sleep(2)
print “… created Socket Connection!”
print “”
print “Initializing Stuff…”
sckt.send (“set_tool_voltage(0)” + “\n”)
time.sleep(0.25)
sckt.send (“set_tcp(p[0.0,0.0,0.0,0.0,0.0,0.0])” + “\n”)
time.sleep(0.25)
sckt.send (“set_payload(0.0)” + “\n”)
time.sleep(0.25)
sckt.send (“set_gravity([0.0, 0.0, 9.82])” + “\n”)
time.sleep(0.25)
sckt.send (“global Var_posInit=p[-0.250,0.750,0.4,3.14,0,0]” + “\n”)
time.sleep(0.25)
sckt.send (“global Var_posCur=get_actual_tcp_pose()” + “\n”)
time.sleep(0.25)
sckt.send (“global Var_posCorrZ=p[Var_posCur[0],Var_posCur[1],Var_posInit[2],Var_posCur[3],Var_posCur[4],Var_posCur[5]]” + “\n”)
time.sleep(0.25)
print “… initialized Stuff!”
print “”
print “Correct z Position…”
sckt.send (“movej(Var_posCorrZ, a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(3)
print “… corrected z Position!”
print “”
print “Moving to Initial Position…”
sckt.send (“movej(Var_posInit, a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(5)
print “… moved to Initial Position!”
print “”
sckt.send (“halt” + “\n”)
time.sleep(0.5)
data = sckt.recv(1024)
sckt.close()
print (“Received”, repr(data))
print “”
print “Program finished”
————————————-
The output is the following:
Creating Socket Connection…
… created Socket Connection!
Initializing Stuff…
… initialized Stuff!
Correct z Position…
… corrected z Position!
Moving to Initial Position…
… moved to Initial Position!
(‘Received’, ‘”Connected: Universal Robots Dashboard Server\\ncould not understand: \’set_tool_voltage(0)\’\\ncould not understand: \’set_tcp(p[0.0,0.0,0.0,0.0,0.0,0.0])\’\\ncould not understand: \’set_payload(0.0)\’\\ncould not understand: \’set_gravity([0.0, 0.0, 9.82])\’\\ncould not understand: \’global Var_posInit=p[-0.250,0.750,0.4,3.14,0,0]\’\\ncould not understand: \’global Var_posCur=get_actual_tcp_pose()\’\\ncould not understand: \’global Var_posCorrZ=p[Var_posCur[0],Var_posCur[1],Var_posInit[2],Var_posCur[3],Var_posCur[4],Var_posCur[5]]\’\\ncould not understand: \’movej(Var_posCorrZ, a=1.3962634015954636, v=1.0471975511965976)\’\\ncould not understand: \’movej(Var_posInit, a=1.3962634015954636, v=1.0471975511965976)\’\\ncould not understand: \’halt\’\\n”‘)
Program finished
—————————–
Why are those commands not working and the robot is responding with “could not understand”?
Thank you for your help and best regards,
Andi S
Reply ↓
zacopressadmin Post author
27 – August – 2015 at 21:29
Hi Andi
Thanks for your question.
I think it is because you are mixing the port purpose and commands.
Port 29999 is the dash board server where you can “start” and “stop” a program that is already loaded.
Port 30002 is a server port whereto you can send script commands.
So in the second part you might consider to send to port 30002. Maybe send one command at a time so you know which one is received by the robot.
But as mention in the forum page this is a sort of one way communication and for simple commands – for example it is not for reading back or variables etc..
It is better and more user friendly to program in the polyscope GUI or establish a client server communication.
Regards
Lars
Reply ↓
Andi S
31 – August – 2015 at 20:47
Hi Lars,
thanks a lot, the hint with the wrong port was very helpful. Finally I am able to control the robot by sending the commands via socket connection.
Initializing a variable works by sending the following:
sckt.send (“global Var_posInit=p[-0.250,0.750,0.4,3.14,0,0]” + “\n”)
But if I want to initialize a second one:
sckt.send (“global Var_posInit=p[-0.250,0.750,0.4,3.14,0,0]” + “\n”)
sckt.send (“global Var_posCur=get_actual_tcp_pose()” + “\n”)
The first variable is overwritten, so I only have my Var_posCur…
This problem only occurs if I use the Socket Connection. Initializing multiple variables with the polyscope GUI works fine. How can I prevent this overwriting?
Best regards,
Andi S
Reply ↓
zacopressadmin Post author
31 – August – 2015 at 20:54
Hi Andi
Thanks for your question.
I am not sure if it is intended to assign variable in this way over the socket.
In the GUI it works because it is within a program shell. You might consider to make a client/server scenario by having a small program on the robot that is written in GUI in a way so the robot program can receive data over the socket from a server – and then these data received on the robot are assigned to variables within the GUI program.
Regards
Lars
Reply ↓
Andi S
24 – August – 2015 at 23:11
Hello,
currently I am working on a task whose target is to pick up an item which could be located at any position p(x,y,z,rx,ry,rz). I want to transfer this position from the host PC. So far three questions/problems arised:
1. Preferably I would simply send commands via Socket Connection like shown above:
“s.send (“movej([-0.7203210737806529, -1.82796919039503, -1.8248107684866093, -1.3401161163439792, 3.214294414832996, -0.2722986670990757], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(2)”
If I do this, the robot doesn’t move but sends a response “Could not understand” or something similar.
2. I am interested in programming the robot in the URScript Programming Language on a PC as programming on the teaching pendant is rather time-consuming. Is there something like a programming environment to compile URScript-Code into a .urp-file?
3. I programmed a test-code on the teaching pendant and wanted to “load” and “play” it by commands sent via a socket connection. (by s.send (“load” + “\n”) and s.send (“play” + “\n”) )
If the program was already loaded, it was possible to play it with the command. But loading it via the command was not possible as the robot was searching in a “\root\” directory where the test.urp-file could not be found. Neither the path was correct. What is the correct directory of the programs stored on the robot?
Í hope I could explain my concerns understandable. Thank you in advance!
Best regards,
Andi S
Reply ↓
zacopressadmin Post author
25 – August – 2015 at 08:31
Hello Andi
Thanks for your questions.
1.
Just to be sure – are you sending from a Python program ?
If yes – Your command seems almost correct – only I can notice that you have “ at the front at end – and then the wait belongs to the Python.
s.send (“movej([-0.7203210737806529, -1.82796919039503, -1.8248107684866093, -1.3401161163439792, 3.214294414832996, -0.2722986670990757], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(2) #this wait is execute in Python – not on the robot. If you want it execute on the robot then you need to send it over and change it to sleep(2) i.e s.send(“sleep(2)” + “\n”)
2.
A the moment I am not aware of such compiler, but there is a Simulator so you can make GUI programs off line which creates .urp files. You robot provider might be able to help you with the simulator.
My experience is that if the script file becomes big then it is difficult to troubleshoot – the GUI is better then.
3.
By default programs are stored in /programs
And then you can organize directories below that.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
Reply ↓
Rick Norcross
11 – August – 2015 at 00:49
CanI, or how can I , execute a script file that is already resident on the robot’s controller?
i.e., is there a way to load and execute a script file across the socket interface?
Reply ↓
zacopressadmin Post author
11 – August – 2015 at 09:13
Hi Rick
Thanks for your question.
One way is to use the standard facility in the Polyscope GUI by making a polyscope program where the script file is imported and then configure in installation so this file is loaded upon start-up. Then you can start and stop the program through a socket interface.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
Reply ↓
Hayder
10 – August – 2015 at 22:04
I am connecting my laptop to both internet and robot via the gateway of the university
The problem is: when I setup the robot default gateway to the university gateway and press apply then update, it reverts back to 0.0.0.0. As a result the only way I could communicate with the robot is by setting the laptop’s gateway as the robot IP Address but then I cannot access internet.
I appreciate any help,
Hayder
Reply ↓
zacopressadmin Post author
10 – August – 2015 at 23:42
Hi Hayder
Thanks for your question.
Have you tried to use the DHCP option ? and see what ip adress the robot gets ? -and then use that to communicate.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
Reply ↓
Mohamed
26 – May – 2015 at 19:30
Hi Lars,
Excuse me! I have another question about how to use the Port 502 in order to communicate the server Modbus TCP, I want to establish a HMI with the robot and I don’t know how the format of information packet. Any ideas please? thank you.
regards
Reply ↓
zacopressadmin Post author
26 – May – 2015 at 20:59
Hi Mohamed
Yes it uses normal Modbus TCP protocol according to the Modbus TCP standard.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
Reply ↓
Mohamed
26 – May – 2015 at 18:20
Hi Lars,
First of all, thank you very much for this effort, it is really so helpful.
I have a question about the function used on script which allows us to free the drive and move the robot. So, I don’t find a kind of function like “tech_mode()” or “freedrive_mode()”, even when I use one of these I upload a script and I compile I get an error with “is not defined”. knowing that my robot is UR5 version 1.8.
So how do I do to resolve this problem?
Thank you in advance
Best regards
Reply ↓
zacopressadmin Post author
26 – May – 2015 at 18:15
Hi Mohamed
Thanks for your question.
I think the script command for free drive (or teach mode) was implemented after CB3 (Controller Box 3) – so you need a CB3 robot which is different as CB2 version 1.8
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
Reply ↓
Mohamed
26 – May – 2015 at 19:56
I see, thank you for the answer.
Regards.
Reply ↓
Allan
19 – May – 2015 at 17:23
Hi Lars Skovsgaard
I have a question regarding controlling the UR-5 from a PC with a tcp/ip socket.
The way I’m controlling the robot today, is like the way you described in the this article, but I would like, if it’s possible, to call waypoints or small waypoints sequences, programmed in the PolyScope software from my PC.
What I mean is, using the Polyscope to program small waypoint sequences and waypoints, by the touch screen teaching pendant, and then call these sequences by the PC tcp/ip socket connection.
By this way I don’t have to change/recompile my program, that runs on the PC, if I need to adjust the waypoint sequences or waypoints.
Is this possible, and if so can you give me some hints on how to do this?
Best Regards
Allan
Reply ↓
zacopressadmin Post author
19 – May – 2015 at 17:03
Hi Allan
Thanks for your question.
Yes that is possible and a good programming method.
Maybe you can consider to send simple data variables from your PC like 1 or 2 or 3 – or A or B or C
And then you Polyscope program has the waypoint sequence under an IF condition – so if you send 1 or A then perform sequence under that and so on.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
Reply ↓
Zoran
18 – May – 2015 at 19:02
Hi Lars,
I was wondering if you could help me. For our project we are implementing UR5 control by sending a script file to the robot from an external PC over a network. We are running Polyscope version 1.8. Sending the script file and implementing basic commands works fine. We are also able to enable the freedrive mode over Port 30002 with the command “set robotmode freedrive”, however, we are unable to enable the freedrive mode from within the script that we send to the UR5. Is this a limitation with Polyscope version 1.8?
The aim is to look at a digital input and enable the freedrive mode when this input is high. Based on your previous post, i cannot see how to link a digital input to trigger the freedrive mode. I am happy to try to update the firmware to v3.1, however, i am not sure if everything will continue to work. Is it possible to back-date the firmware if v3.1 doesn’t work with our current code?
Thanks,
Zok
Reply ↓
zacopressadmin Post author
18 – May – 2015 at 20:50
Hi Zoran
Thanks for your question.
To set the robot in freedrive mode with a script command is supported in software version 3.1 – which only runs on a UR CB3 robot.
If you are running software version 1.8 – it indicates that you have a CB2 UR robot and therefore you cannot upgrade to version 3.1.
CB2 and CB3 are very different robots and controller box and they cannot be compared.
If you have a CB3 robot then there was another person here on the forum who found that it is possible to set a CB3 in freedrive mode with a script command by setting an output and then hardwire that output to an input which is configured to set the robot in freedrive mode.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
Reply ↓
markus
2 – October – 2015 at 18:56
http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/assigning-special-functions-to-inputs-and-outputs-15418/
Reply ↓
Frank Hoch
4 – May – 2015 at 21:59
Hello Lars,
thanks in advance for every piece of information on this site and every answered question,
it helped me a lot.
One question i wasn’t able to get an answer for is the following:
Is it possible to send only one command over the tcp_ip socket on port 30002 which puts the robot (UR5 CB3 3.1) in freedrive mode for as long as i don’t terminate that statement? I already tried it using
1. “set robotmode freedrive”
2. “teach_mode()”
3. “freedrive_mode()”
but none of that worked.
I wrote a small skript on the robot which worked, therefore i know it’s possible to do that.
freedrive_mode()
sleep(10)
end_freedrive_mode()
But i could’t achieve to do that over the Socketconnection and using a defined timeframe isn’t dynamical or practical for my application.
What i got so far is a c++ GUI on a mac with which i’m trying to clone the teachpanel. Therfore i want to get the freedrive button on my gui, which should keep the robot as long in freedrive mode as im pushing it or until i send another signal to the controller which terminates it.
Can you please help me?
Thank you.
Best regards
Frank
Reply ↓
zacopressadmin Post author
5 – May – 2015 at 23:20
Hi Frank
Thanks for your question.
Can you consider to use a digital input ?
Each digital input can be configured in the Installation I/O menu so it has “Freedrive” function when activated.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
Reply ↓
Frank Hoch
6 – May – 2015 at 20:05
Hi Lars,
thanks for the reply.
Since i don’t have any digitalOutputs on the other Pc yet i’m not able to do that, but i’ll consider it.
I just wanted to make sure there’s absolutely no way to do that over the socket with just one command.
Could i wire a digital output from the controller directly to a digital input? Because i can set the outputs via only one command and therefore that would make it possible.
Thank you.
Best regards
Frank
Reply ↓
zacopressadmin Post author
6 – May – 2015 at 20:22
Hi Frank
You can wire output to input – but I think a program needs to be running before it reacts to a input change and set the robot in Freedrive. If you try then let me know the result.
Regards
Zacobria.
Reply ↓
Frank Hoch
6 – May – 2015 at 23:37
Hey Lars,
it worked!!!!
Thanks again very much, this has been bothering me for weeks.
Even the Universal Robots Support and my own reseller couldn’t help me with this.
Frank
zacopressadmin Post author
7 – May – 2015 at 20:25
Hi Frank
Thanks for the feedback and good to hear it worked.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
markus
1 – October – 2015 at 23:37
Hello,
“set robotmod freedrive” and “set robotmode run” worked for our CB2 robots when sent via Port 30002 but doesn’t work with a CB3. Does anybody know if that functionality can be activated on CB3 as well ?
br
Reply ↓
zacopressadmin Post author
1 – October – 2015 at 23:48
Hi Markus
According to the latest Script manual the command is
freedrive mode()
There is also an option to set this via an input on CB3. In the Input menu an action can be associated to each input.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Support Forum.
Reply ↓
Leandro Guilherme
29 – April – 2015 at 23:06
Hello Lars,
I made a C/C++ program to do this communication, and it work well to send information, so commands like movej and movel is working.
But when I send “get_actual_tcp_pose()\n” from my client program didn’t receive any data. My code look like:
char buffer[1024];
int n = write(sockfd, msg.c_str(), strlen(msg.c_str()));
bzero(buffer,1024);
int r = read(sockfd, buffer, sizeof(buffer));
Can you help my?
Thank!
Best regrads
Reply ↓
zacopressadmin Post author
30 – April – 2015 at 19:25
Hi Leandro
Thanks for your question.
If you are using server ports 30001, 30002 or 30003 then you will not get any thing back for this command.
You may consider using the command in a GUI program and then sending the data over to your host in a similar way as this example.
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
Reply ↓
lmur
3 – April – 2015 at 01:11
Hello Lars,
I’m trying to connect the robot (UR10) with my computer through and ethernet cable. I can ping it and execute scripts without ROS, but when I’m trying to execute some ROS scripts the UR10 log says “Not able to open Socket Socket 0 to host: “IP” at port: 50001: Connection timeout.
Could you give us some advice?
I am looking forward to hearing from you soon.
Kind regards,
Lmur.
Reply ↓
zacopressadmin Post author
3 – April – 2015 at 13:34
Hi Lmur
I have not been working with ROS and without the code it is hard to say what it can be.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
Reply ↓
chen
30 – December – 2014 at 15:17
Hi Lars,
Thank you for the fast reply!
Currently, we use the camera to guide the movement of UR5 accoring to a optical marker which could be recognized by the camera. If the marker moved, the robot will move correspondingly. For example the Marker is located in position A. Next step, the marker will move to position B very fast, and the robot should move to position B fast. But We have encounter the following problem:
If the robot is on its way to position B, but the Marker has been moved to position C from B. It seems it is difficult for us to stop the MoveJ (B Position) command, which led to the result as follow: The robot move to the Postion B from A, and then moved to position C from B. However, we hope the robot will not move to position B, but directly to position C from the current position, because of the moving of Marker.
Could you give us some advice?
This problem has bothered our team for a long time.
I would like to express my deep appreciation for your support!
I am looking forward to hearing from you soon.
Best regards,
chen
Reply ↓
zacopressadmin Post author
30 – December – 2014 at 16:02
Hi Chen
Depending on how you have constructed the program, but maybe you can use an “IF” statement – and then Tick “Check expression continuously”.
The if you have a different condition for Pos B and Pos C – then the program should be able to branch to the active condition right away.
Regards
Lars
Reply ↓
chen
30 – December – 2014 at 11:53
Hi Lars,
I am new to UR5 and I wonder if the universal robot can be controlled through visual servoing, such as grabbing the targrt in motion with stereoscopic vision tracker. I would be grateful if you could give me some directions or reference.
Best Regards
chen
Reply ↓
zacopressadmin Post author
30 – December – 2014 at 11:21
Hi Chen
Thanks for your question.
There are different ways to track items.
1.
UR has a Conveyor tracking function when using an encoder signal.
2.
You can use a vision camera and make an application to move the robot based on the feedback from the camera.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
Reply ↓
Julia
11 – December – 2014 at 20:46
Hi Lars,
thank you for the fast answer!
I use Python 3.4, but I think the connection should be work. My problem is that the ur5 doesn’t allowed the connection.
Thank’s for your help!
Julia
Reply ↓
zacopressadmin Post author
12 – December – 2014 at 08:33
Hi Julia
I just tested the program using Python 2.7 and it works.
I don’t know if using Python 3.4 it needs some changes – I know Python 3.4 is different from Python 2.7 and code cannot just be copied.
I have seen that when copying and pasting then the quotation marks can change to one of these ‘ ’ “ ” ‘ ‘ ” ”
This one ̎ is the one I use.
The robot just receives the data and there is no need for enabling on the robot – port 30002 is listening. You need to set the IP address of the robot in the Python program.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
Reply ↓
Julia
11 – December – 2014 at 20:21
Hi Lars,
thank’s for your answer. I can now ping the ur5, but when I tried your example I can’t connect to the robot with the error: “Target PC denied the connection.
I hope you can help me also this time!
Best Regards
Julia
Reply ↓
zacopressadmin Post author
11 – December – 2014 at 20:11
Hi Julia
Are you using Python 2.7 ?
(The examples are made with Python 2.7)
Regards
Lars
Reply ↓
Julia
9 – December – 2014 at 22:41
Hi Lars,
I have tried out your example to connect from my laptop to the robot with the small python script. But all the times I get an timeOut Error…..I have connect my laptop directly with the robot. I also can not ping the robot. I have’nt any idea why it didnt works and hope you can help me!
Best Regards
Julia
Reply ↓
zacopressadmin Post author
10 – December – 2014 at 10:12
Hi Julia
Thanks for your email.
You need to be able to ping the robot from your PC.
What is the IP address of the PC Ethernet port that you are using – and what is the IP address of the robot ?
Make sure they are in the same network.
A direct connection between the PC and robot can work, but make sure the PC and robot are not set for DHCP – and instead give them a fixed IP address.
You can also try to connect through a hub if you are using a DHCP server on your network.
If you are using a direct connection – and If you are using a RJ-45 ethernet port on your PC and at the same time have a Wireless connection on your PC – then make sure the PC is using the RJ-45 for the connection to the robot – maybe disable the Wi-Fi on the PC when you are testing this so the Wi-Fi is not confusing you for the IP address used for the test.
If you are using Wi-Fi on your PC – then connect the robot to a hub or access point that is in the same subnet as the PC.
Get the ping to work first.
Author:
By Zacobria Lars Skovsgaard
Authorised Universal-Robots Distributor.
Reply ↓
M.Ebert
4 – December – 2014 at 05:22
Hi Lars,
could you maybe show an example where the UR is the client and the PC the server. I am thinking of some kind of “position server” which is