1. Home
  2. Knowledge Base
  3. Script Client-Server example

Universal-Robots Script Client-Server example.

 

Application Description:
This example focus on making a program on the UR robot that receives data from an external host e.g. a task server or a vision camera etc.

Function description:
For this purpose a TCP socket connection over Ethernet will be used. A Universal-Robots can be a TCP Client and from a program open a socket connection towards a TCP server. I this case the socket connection is setup to receive 3 real data (floats) from the host.

The illustrations below shows the starting position of the robot and the intended target position. Notice the object is rotated 45 degrees and therefore the data send to the robot will reflect that belo in the response from the host. Here the host will be a program running on a PC, but it could as well have been a Vision camera replying with the data cordinates for the object.

It is important to understand the X, Y, Z, Rx, Ry, Rz representation in relation to the robot and this article describes some of this:
Read more about X, Y, Z positions for the UR robot

A robot pose can be represented as 6 numbers because Universal-Robot are 6 axis robots and a pose can have the format of p[X, Y, Z, Rx, Ry, Rz]. The small “p” in front is to defined the list as a pose.

Also below is a illustration that shows the X, Y, Z direction in relation to the UR robot tool-head.

universal-robots-client-server-asking-3-data-point-from-host-tcp

 

Starting Pose – Notice where the Robotiq electrical gripper cable come out is the X direction and Y direction is towards the robot.

universal-robots-client-server-asking-3-data-point-from-host-pose-1

 

Intended target position for the robot – Notice the target object is rotated 45 degree.

universal-robots-client-server-asking-3-data-point-from-host-pose-2

 

This pose is 200mm offset to starting position in X direction and 50mm in Y direction and turned 45 degrees.

 

Program Description:

The UR robot is setup with the IP address of 192.168.0.9.

In the BeforeStart routine a variable var_1 is assigned an IP address and port to a corresponding Server. In this case there will be a PC with the IP address of 192.168.0.100 a Server program listening on Port 30000. Var_1 will be False if there is not Server listening or True if there is a Server listening.

And the robot is moving to is idle position which is Waypoint 1.

In the main program the program check if the was a ready Server to connect to. If not the Loop will just keep looping until there is a Server with an active port.

When the connection has been established the robot send a trigger string which can be freely defined, but must be what the Server expect – in this case in choosen to send a string “asking_for-data”.

Then the robot expect to receive a list 3 real data (floats) to put into variable var_2.

In this case the robot which is the client closes the socket connection, but it could also be left open if the server can handle that properly.

When the robot receives the list of data – the list actually contains 4 elements for example [3, 200, 50, 45]. The first element represents the number of data received – in this case 3 as expected and the there data are 200, 50, 45.

Therefore it is possible to check whether any data was received – so in this case it is checked that the first element of the list in variable 2 is different than 0 which means data has been received.

Each element is inserted into another list contained in var_3 which is a Pose with the format of [X, Y, Z, Rx, Ry, Rz] and in this mode the  robot uses meter as measurements and therefore X and Y data are divided by 1000 whereas the angles are in radians so therefore the Rz data is converted from degrees to radians.

In order to move from the current position to the intended position based on the data received the function “pose_trans” is used. Therefore the current position is established and inserted into var_5.

Thereafter the current position is trans posed with the received data into var_4 which now contains the intended target position (pose). Var_4 is a variable waypoint.

Then the robot move in a linear move to this computed var_4 waypoint and wait 1 second before moving back to idle position Waypoint 1.

Program code:

universal-robots-client-server-asking-3-data-point-from-host-urp

 

Program code:

Host program in Python code.

A Server must be active to reply data to the robot and in this case a small Python server program is used. This example below is a Server that listen for incomming requests. The server runs on a PC with the IP addreess 192.169.0.100 and uses port 30000.

When a connection is received the server will monitor the data received and if the data is “asking_for_data” the server will reply with 200, 50, 45 back to the Client. These data is the offset the target item is away from the idle position of the robot.

universal-robots-client-server-asking-3-data-point-from-host

 

# Echo client program
import socket
import time
HOST = "192.168.0.100" # The remote host
PORT = 30000 # The same port as used by the server
print "Starting Program"
count = 0
 
while (count < 1000):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 s.bind((HOST, PORT)) # Bind to the port 
 s.listen(5) # Now wait for client connection.
 c, addr = s.accept() # Establish connection with client.
try:
 msg = c.recv(1024)
 print msg
 time.sleep(1)
 if msg == "asking_for_data":
 count = count + 1
 print "The count is:", count
 time.sleep(0.5)
 print ""
 time.sleep(0.5)
 c.send("(200,50,45)");
 print "Send 200, 50, 45"
except socket.error as socketerror:
 print count
 
c.close()
s.close()
print "Program finish"

 

Note 1:

When this robot program is executed and the server is active and responding with data – these data can be observed in the Variables tab as shown on the illustration below. And the robot moves to the offset position 200mm X, 50mm Y and turn the head 45 degrees. These data could as well has been from a vision camera.

universal-robots-client-server-asking-3-data-point-from-host-urp-data

Note 2:

It is also possible to reference to a new plane created in the Features menu under installation. Below is the first argument in the pose_trans command the Plane_1 – which beforehand needs to be created in the Features screen. In this way a new plane coordinate system is the reference. This is use full for example in a vision system where the Plane_1 has been set to the same area as the camera field of view.

universal-robots-client-server-asking-3-data-point-from-host-urp-data-plane

 

Note 3:

It is also possible to send the position data over to the host via Client-Server connection.

The Polyscope program is modified to read the pose position and read the joint positions – and then send these variables over to the host.

Program code:

 

universal-robots-client-server-asking-3-data-point-from-host-urp_position_1
universal-robots-client-server-asking-3-data-point-from-host-urp_position_2

Program code:

Host program in Python code.

The python code on the host is also modified to read and print the data for the pose and joint positions.

# Echo client program
import socket
import time
HOST = "192.168.0.100" # The remote host
PORT = 30000 # The same port as used by the server
print "Starting Program"
count = 0
 
while (count < 1000):
 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 s.bind((HOST, PORT)) # Bind to the port 
 s.listen(5) # Now wait for client connection.
 c, addr = s.accept() # Establish connection with client.
 try:
   msg = c.recv(1024)
   print "Pose Position = ", msg
   msg = c.recv(1024)
   print "Joint Positions = ", msg
   msg = c.recv(1024)
   print "Request = ", msg
   time.sleep(1)
   if msg == "asking_for_data":
     count = count + 1
   print "The count is:", count
   time.sleep(0.5)
   print ""
   time.sleep(0.5)
   c.send("(200,50,45)");
   print "Send 200, 50, 45"
 except socket.error as socketerror:
   print count
 
c.close()
s.close()
print "Program finish"

Program run:

The robot is in this position – Notice the X, Y, Z, Rx, Ry, Rz values in the Move screen.

universal-robots-zacobria-modbus-read-position-1

Below is the printout on the screen with the X, Y, Z, Rx, Ry, Rz values when the Python program is executed. The values are collected from the Polyscope program variables “pose_position” and “joint_positions” and correspond with the actual values of the robot position. The X, Y, Z are in m and Rx, Ry, Rz are in radians.

>>>
Starting Program
Pose Position = p[2.39984e-06,0.299984,0.299999,-2.47874e-05,3.14002,-5.52232e-05]
Joint Positions = [-1.95426,-1.65715,1.71108,-1.62348,-1.55893,2.75828]
Request = asking_for_data
The count is: 1

Send 200, 50, 45

 

Notice that when the data has a very small value – then the exponent of 10 notation is used – for example in this case

X = 2.39984e-06,0.299984 (Which = 2.39 to the power of 10-6  – which is litteraly 0 (zero) because it is a very small value.

Y = 0.299984 (Which is in meter = 299.984mm (which is 300mm because the fractions is below 0.1mm which is the robots repeatability).)

Notice that the joint values are in Radians. In order to convert them to degress to compare them with the move screen these formulas can be used.

Formula for converting Radians to degrees on UR:

(Radian / Pi) x 180 = The Degree shown in the Move Screen.

Formula for converting degrees to Radians:

Pi x (The Degree shown in the Move Screen) / 180 = Radian

So when the J0 value is shown as -1.95426 radians the conversion to degrees is

(-1.95426 / pi) x 180 = -111.97 degrees as shown on the move screen.

 

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 Universal Robots support Centre and Forum.

Also check out the CB3 forum



Article Attachments

Was this article helpful?

46 comments

  1. I have seen examples for transferring numbers. I want to know the functions which we can use for transferring string like socket_sen_string(send). What is the function for receive string. If I can get a manual with all socket functions, that will be helpful.

    1. Balasubramani

      There are several commands to read from a socket – for example socket_read_string()

      The script manual should be available at yur nearest robot provieder.

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



      1. Hi Zacobria,

        I have tried the method what you suggested. But I’m Communicating UR5 with AGV which has Ip address as 192.1.1.3 and port number as 7171. After opening the port, it will ask for tth password as “Enter Password:” string. Then I have to send a password as “password$n” . In this password string “$n” is for new line or enter. Then it should connect. This method is working when I try to communicate AGV with PLC. But it is not working with UR5. I want to know how to send “$n” new line or enter in UR5 or phython program because I want to send all commands with new line or enter. I’m new to scripting. So, if you can forward some sample programs with TCP/IP, it will be helpful.

        Thanks in Advance

        Regards,
        Balasubramani

        1. Hi Balasubramani

          Thanks for the question.

          Maybe consider to use the “socket_send_byte()” if you need to send special characters.

          Also some notes in this thread.
          http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/universal-robots-ur-script/

          Author:
          By Zacobria Lars Skovsgaard
          Accredited Universal Robots support Centre and Forum.

          Also check out the CB3 forum



  2. Hello Zacorbia,

    I have connected the UR3 to LabView through a TCP/IP Connection over LAN.

    This is the program that I have used:

    lan_1:= False
    Loop lan_1?= False
    Wait: 0.5
    lan_1:=socket_open(“192.168.0.100”,30000)
    Wait: 0.1
    socket_send_string(test_no)
    socket_send_string(counter)
    Wait 0.5
    socket_close()

    I use this as a Sub program in a larger main program. The Robot starts working in about 1 second after it Transfer the data but the Problem I am facing is that, it takes about 5 seconds for the data to reflect on Labview.

    Is there any idea from you, regarding why there is a delay in the Transmission?

    Thanks
    Sharafath

    1. Hello Mohammed

      Thanks for the question. Normally the transmission is faster.

      Maybe consider to test the socket connection with the “sockettest” program in order to see how fast the communication is without Labview.

      More informations about testing the socket communication at this link.

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/testing-ur-client-server-and-script-commands/

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



      1. Hello Zacorbia,
        I tried connecting it using the python and the results are very good. But the there is a one second delay in both python and labview before the Robot starts moving. This is for the connection to open, send data and Close Connection. So i think the proble is with Labview. I Need to see how to reduce it.. thanks for your Support again.

        best regards
        Sharafath

  3. Hello zacobria

    I am trying to control a UR from the computer via port 30004, I am sending a position that is saved in the variable var_3, however if I want to send another position, I have to wait for the first position to reach its destination and then move to The other position. How can I make it so that I do not have to wait for the var_3 variable to reach its destination so I can send it another position?

    Is the same code of the example, only that instead of sending (X,Y,Z,RX,RY,RZ), I am sending (J1,J2,J3,J4,J5,J6).

    I hope to have your help.

    1. Hello ALEXANDER

      Thanks for the question.

      If the method used is to send raw script commands then the behavior you see is normal – a new command has to wait for the proveious to finish.

      If the method is to establish a “Client-Server” scenario – then the Polyscope program on the robot can be constructed so it can receive more variables and store them in seperate variables in the Polyscope program. So instead of only one time “asking for data” then instead ask more times one by one

      In principle:
      “Asking for var_1”
      “Asking for var_2”
      “Asking for var_3”
      “Asking for var_n”

      The programmer need to make the logic in the program so each variable is received and stored in a variable before asking for the next.

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



      1. Hi zacobria, i had success implementing the interruption of an a trajectory from point A to point B, following your instructions, now i have another issue:

        – By moment I am making the movement from point A to point B, the robot makes a little stop or better sayed, makes a sudden hit, and then it continues to the next move I gave: my question is:

        How can I avoid that sudden hit in order to prevent damages in the robot and making a better integration of all the motions?

        Thanx for ur help, ill be looking forward.

        1. Hi ALEXANDER

          Thanks for the question.

          It is important to control the acceleration and deceleration and also sometimes nessecary to insert blends in order to make smooth moves. And the values can be different in case by case – because the nature of the move can be with small turns or sharp turns and even 180 return – then the robot needs to stop in order to reverse. So depending on the nature of the move the acceleration and deceleration and blends might need to be tested case by case.

          Author:
          By Zacobria Lars Skovsgaard
          Accredited Universal Robots support Centre and Forum.

          Also check out the CB3 forum



  4. I try to open the port 30000, however I do not get the communication from the computer to the robot, the correct program, however it has not opened that port, you know that this problem is due? How can I solve that
    The code of the robot is.

    BeforeStart

    Var_1: = socket_open (“192.68.3.11”, 30000)

    Robot Program.

    Loop var_1 = False
    Var_1: = socket_open (“192.68.3.11”, 30000)
    Wait (0.5)
    Socket_send_string (“ask_for_data”)

    The ip 192.168.3.11 is of my computer.

    1. Hi alexander

      Thanks for the question.

      The ip addresses 192.68.3.11 and 192.168.3.11 are different – is that intended ?

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



      1. Hi zacobria.

        I made a mistake, the ip address is 192.168.3.11, this is the computer, in the robot program has the ip address of the computer 192.168.3.10.
        The problem is that the port is not opened in socketTest. I do not know what the problem might be, you could support me.
        Using socketTest with port 30002 if I can set_digital_out (1, True) and if it works, but when using it as a server with port 30000 there is no connection.

        1. I made a mistake, the ip address is 192.168.3.11, this is the computer, in the robot program has the ip address of the computer 192.168.3.11.
          The problem is that the port is not opened in socketTest. I do not know what the problem might be, you could support me.
          Using socketTest with port 30002 if I can set_digital_out (1, True) and if it works, but when using it as a server with port 30000 there is no connection.

          1. Hi ALEXANDER

            Is the sockettest set to be a server – listen on IP address 192.168.3.11 port 30000 ?

            See also this link
            http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/testing-ur-client-server-and-script-commands/

            Author:
            By Zacobria Lars Skovsgaard
            Accredited Universal Robots support Centre and Forum.

            Also check out the CB3 forum



          2. Hi zacobria.

            That is, the socketTest server escschaen the port 30000 and ip address 192.168.3.11.
            In fact I did what appears in the link that you gave me, but I can not connect, there is no communication from the client.

          3. Hi ALEXANDR

            I am no sure what “escschaen” means ?

            It has been seen before that the antivirus software on a PC can block incomming connections.

            Also if the port 30000 is in use already – another port can be tested for example port 12345.

            Author:
            By Zacobria Lars Skovsgaard
            Accredited Universal Robots support Centre and Forum.

            Also check out the CB3 forum



  5. Hi,

    I would like to ask how do set UR as server, is it same as python server socket opening?

    Thank you.

    1. Hi Troy

      To my knowledge there is no server function when using Polyscope, but port 502, 30001, 30002 and 30003 etc. are server ports.

      Also consider to see these links.

      https://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/universal-robots-script-programming/

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-from-host-to-robot-via-socket-connection/

      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



  6. Hello:
    I want to send the ideal position to UR5 from my PC.I finished basic control.
    If I send this message : s.send(“movej(p[0.2, 0.4, 0.3, 0.02, -0.05, 0.6], a=1.0, v=0.1)” + “\n”)
    the UR5 robot can move to the position.
    But,if I do this :
    x=0.2
    s.send(“movej(p[x, 0.4, 0.3, 0.02, -0.05, 0.6], a=1.0, v=0.1)” + “\n”)
    then UR5 can not move. I do not know why? UR5 can not identify variable of x?
    what should I do to solve the problem?

    1. Hello fcc

      Thanks for the question.

      It depends on how and from which environment (for example a Python program) you send the movej command.

      The “x” is not to be defined on the robot – the “x” need to be defined in the program on the sender side.

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



      1. Hi zacobria
        Thanks for you answer
        I use Python program to control UR5. As the follow
        x=0.2
        s.send(“movej(p[x, 0.4, 0.3, 0.02, -0.05, 0.6], a=1.0, v=0.1)” + “\n”)
        you see, I defined the variable x equal to 0.2 on the sender side.
        I guess if UR5 received data is x,not 0.2, right ? And no program on UR.
        could you give me some suggestions. Thanks !
        the program of PC as follow:

        # Echo client program
        import socket
        import time
        import xlrd
        HOST = “192.168.1.254” # The remote host
        PORT_30002 = 30002
        print “Starting Program”
        data = xlrd.open_workbook(‘pos_data.xls’)
        data.sheet_names()
        table = data.sheets()[0]
        nrows = table.nrows
        ncols = table.ncols
        i=0

        while(True):
        if i<=nrows-1:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(10)
        s.connect((HOST, PORT_30002))
        pos_x = table.cell(i,0).value
        pos_y = table.cell(i,1).value
        pos_z = table.cell(i,2).value
        pos_rx = table.cell(i,3).value
        pos_ry = table.cell(i,4).value
        pos_rz = table.cell(i,5).value
        i=i+1
        time.sleep(2.00)
        s.send("movej(p[pos_x, pos_y, pos_z, pos_rx, pos_ry, pos_rz], a=1.0, v=0.1)" + "\n")
        else:
        break
        s.close()
        print "Program finish"

        1. Hello fcc

          Its noticed that the data seems to come from a file – so in order be sure the values has been inserted correct into the variables – it be considered to view the variables so it is to see possible what is actually being send to the robot – maybe consider to insert a “Print” of the data before being send
          .
          .
          i=i+1
          Print pos_x
          Print pos_y
          Print pos_z
          Print pos_rx
          Print pos_ry
          Print pos_rz
          time.sleep(2.00)
          s.send(“movej(p[pos_x, pos_y, pos_z, pos_rx, pos_ry, pos_rz], a=1.0, v=0.1)” + “\n”)
          .
          .

          What is the result on the screen ?

          Author:
          By Zacobria Lars Skovsgaard
          Accredited Universal Robots support Centre and Forum.

          Also check out the CB3 forum



          1. Hello zacobria
            Thanks for your suggestion and answer.
            Following your suggestion,I print values of x, y ,z ,rx, ry,rz.The results as follow:
            x= -0.0258347653299
            y= 0.435661483693
            z= 0.535229942093
            rx= -1.78857219646
            ry= -0.263185369542
            rz= 0.165402253191

            x= -0.0258526753224
            y= 0.435689660794
            z= 0.535206669639
            rx= -1.78861045012
            ry= -0.263262829694
            rz= 0.165411509796
            …….
            ……..
            Actually,these data of position are correct and data of position come from UR5. When I pull the arm of
            UR5,Python program on PC is running and records information of position.
            I guess the s.send() function can not send variable of position in Python environment.Just do this:
            # Echo client program
            import socket
            import time
            HOST = “192.168.1.254” # The remote host
            PORT_30002 = 30002

            print “Starting Program”

            count = 0

            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.settimeout(10)
            s.connect((HOST, PORT_30002))
            time.sleep(2.00)
            s.send(“movej(p[0.04028, 0.37802, 0.35704, 3.3640, 0.3817, 0.0580], a=1.0, v=0.1)” + “\n”)
            s.close()
            print “Program finish”

            Everything is OK. If I do this:

            # Echo client program
            import socket
            import time
            HOST = “192.168.1.254” # The remote host
            PORT_30002 = 30002

            print “Starting Program”

            count = 0

            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.settimeout(10)
            s.connect((HOST, PORT_30002))
            x=0.04028
            y=0.37802
            z=0.35704

            time.sleep(2.00)
            s.send(“movej(p[x, y, z, 3.3640, 0.3817, 0.0580], a=1.0, v=0.1)” + “\n”)

            s.close()
            print “Program finish”
            The UR5 can not move to target position.
            In other words, If I have 10 points(data of target position),I can write 10 lines of code,as follow:

            time.sleep(2.00)
            s.send(“movej(p[0.04028, 0.37802, 0.35704, 1.3640, 0.3817, 0.024580], a=1.0, v=0.1)” + “\n”)
            time.sleep(2.00)
            s.send(“movej(p[0.02428, 0.31802, 0.35704, 2.3640, 0.2317, 0.003580], a=1.0, v=0.1)” + “\n”)
            time.sleep(2.00)
            s.send(“movej(p[0.02728, 0.33802, 0.35704, 3.0640, 0.3467, 0.023580], a=1.0, v=0.1)” + “\n”)
            time.sleep(2.00)
            s.send(“movej(p[0.05028, 0.27802, 0.35704, 3.3540, 0.25817, 0.0480], a=1.0, v=0.1)” + “\n”)
            …..ten lines of code.

            But If I have 10000 points(data of target position).I have to input 10000 points of information in Python environment. The workload is very large.
            is there another function which can send lots of data of target position to UR5 or other methods ?
            could you help me to solve the problem or give me some suggestions. Thank you sincerely!

          2. Hello fcc

            Maybe consider to use a syntax like shown below

            s.send (“movej(p[” + x + “,” + y + “,” + z + “,” + rx + “,” + ry + “,” + rz + “],” + “1.0” + “,0.1)” + “\n”)

            It is not clear if the variable name used is for example x or pos_x, but in the command it should be the variable name with the correct value.

            It can also be considered to use the “sockettest” program and send the command to the sockettest program – because then it can be seen what the server on port 30002 excately receive – which should be the same wether is is fixed numberes or by variables.

            Author:
            By Zacobria Lars Skovsgaard
            Accredited Universal Robots support Centre and Forum.

            Also check out the CB3 forum



          3. Hello zacobria
            Thanks for your help
            I find a function to solve my problem
            Just use function of str()
            as follow :
            x=0.2;
            y=0.3
            z=0.1
            rx=0.2
            ry=0
            rz=0
            s.send (“movej(p[” + str(x) + “,” +str(y) + “,” + str(z) + “,” + str(rx) + “,” + str(ry) + “,” + str(rz) + “],” + “1.0” + “,0.1)” + “\n”)
            Then ,UR5 can move to ideal position.
            Thank you very much sincerely

  7. Hi,

    In all your client-server programs, the server is always the robot. In my case I have created a program where the Ubuntu PC opens a raw socket with IP of the robot and port=30002.

    the basic function of the python code on the PC is to just send get/set functions to the robot and manipulate the digital/analog IOs.

    I already have the code. I am able to set the digital/analog output pins from the python code.
    eg: set_digital_out(4, ‘True’) – to turn on the 4th digital output pin.

    I am facing a problem in reading the reply of the get functions.
    for eg:
    socket.send(get_digital_out(4))
    state = socket.recv(1024)
    expected output: state = True/False.
    But I get the reply as a garbage string.

    Am I doing anything wrong in this case?

    Thanks.

    Do you’ve any ideas about how can I read a clean output in this case?

    1. Hi Schazool

      Thanks for the question.

      Actually in the ”Client-Server” examples the robot is the client.

      Whereas in the examples sending script commands to port 30002 – the robot is the server.

      When sending raw script commands the consider to read this article.

      https://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/universal-robots-script-programming/

      When sending the command “set_digital_out(4, ‘True’) ” to port 30002 – will not return a reply for this command. As mentioned in the article – it is possible to set outputs by writing to port 30002, but not to read back.

      Also notice the part about the timing.

      The data you see coming back is not garbage – consider to read this article

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/client-interfaces-cartesian-matlab-data/

      To read output it is for example possible to read the status via the MODBUS – consider to read this article

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/modbus-registers-input-and-output-handling-via-port-502/

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



  8. Hi, I am trying to send information of the robot to a computer. I followed the steps above and tried both Sockettest and Python script but the UR log shows that “not able to open socket 0 to host XXX.XXX.X.X at port 30000 connection timed out.” Do you have any advice on this problem? I’ve also tried another port number and none of them worked. I was able to send commands (e.g. set a digital output on or make the robot move) from the computer to the robot.

    Thank you so much.
    Best wishes,
    Taylor

    1. Hi

      Is the server responding when tested from another client ?

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



      1. The server responded to its self but I haven’t tested it with other client. What is the best way to do that?

        Thanks!

        1. Maybe it can be considered to use the SocketTest program to test the server.

          Author:
          By Zacobria Lars Skovsgaard
          Accredited Universal Robots support Centre and Forum.

          Also check out the CB3 forum


          !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?’http’:’https’;if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+’://platform.twitter.com/widgets.js’;fjs.parentNode.insertBefore(js,fjs);}}(document, ‘script’, ‘twitter-wjs’);


          !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?’http’:’https’;if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+’://platform.twitter.com/widgets.js’;fjs.parentNode.insertBefore(js,fjs);}}(document, ‘script’, ‘twitter-wjs’);

          1. Hi,

            Thank you for your help. I’ve solved the problem. It is because the firewall setting. I still have another question. In the Python script above, if I want to set a digital output to True with Python 3.5, is c.send(b”set_digital_out(2,True)\n” correct? (I replaced the line c.send(“(200,50,45)”) ) It does not seem to work but it works with the Python script here (http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-from-host-to-robot-via-socket-connection/) when I used s.send(b”set_digital_out(2,True)\n”

            Thank you so much again!

          2. Hi Taylor

            Good to hear that you got it working.

            I have not used Python 3.5 so I am not sure how that works.

            The command “set_digital_out(2,True)” is normally not used in a “Client-Server” scenarion – which is the topic on this page, but might be consider when sending script commands directly to port 30002 like shown in this example.

            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



        2. I have the same problem as you, could you support me with that? How did you solve the problem of port 30000? please.

  9. Hello,

    I am using a Cognex insight with my UR10. I am having data streaming out of my cognex in the format: (350.3,163.9) 2.8░ score = 71.8. This basically the patMax function in my cognex program where it is sending out the location of image/pattern i am trying to detect. As UR is 6DOF and the movej is taking x,y,z,rx,ry,rz. How can I transform the data I am getting into UR understandable format, or do i need to. Kindly let me know.

    1. Hello Arunava

      Thanks for the question.

      Does the data transmitted by the camera represent X, Y and the Angle of the object captured by the camera ?

      Ideal is if possible then ask the camera just to send X, Y, Rz (angle) in a comma separated format. If it is not possible to change the format the camera send out – then it might be considered to use the command “socket_read_byte_list” and then take out each byte that is of interest from the received list and thereby remove unwanted information – and then use the X, Y, Rz information like shown in the example at this current page.

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



  10. Hello,

    I wonder whether the client-server script can be used to aggregate execution data of the robot towards an iot cloud platform ? Let me explain: we want to remotely monitor the usage and status of several robots. We thus need some kind of way to have the robot push status info and data over TCP/IP to a generic cloud API or a method that reads with a certain interval the status of the robot and then sends this info to the cloud API.

    Is there any info available on this specific topic ?

    Hope you can help – Thanks !
    Marc

    1. Hi Marc

      Thanks for your question.

      I would think you can use this example as base and build on that – for example to create an Robot ID variable on each robot and then send the status data you wish to monitore to a server for collection over such TCP connection – and then let the server collect status from all the robots that connects to the server.

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum

  11. Hi,

    I’m trying to figure out what goes wrong for my setup: I have copied the code you provided, changed the IP, but now, when it reached var_2 = socket_read_ascii_float(3) and then continues to the wait it comes up with an error: “unsupported operand type(s) for ==: [ 0, nan,nan,nan,nan,nan] and 0”

    Any idea?

    1. Hi Eelke

      Thanks for your question.

      It might be because the data that is being send to the UR is not as expected.

      Are you also using Python on the Host side ?

      In this python example the data send is (200, 50, 45) which on the UR side becomes [3, 200, 50, 45] because 3 elements has been received.

      In your example it looks like nothing is received (0) – or it is wrong format.

      If using some other program language then maybe consider without the “(” and “)” or use “[” and “]” when sending from host – because the formatting of the data send over the TCP socket might be different in other languages.

      Does it work when you use the test program Socket test as this example shows ?

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/testing-ur-client-server-and-script-commands/

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      1. Lars,

        Thanks for your reply. It turned out that I didnt have proper indents in python and thus the data was not sent.
        Now the data is send, but still get a (similar) error:
        Type error: unsupported operand type(s) for ==: [3,200,50,90] and 0

        I get this error also when I use the socket test method (manually entering the data).

        Any thoughts?

        1. Hi Eelke

          Are you using Socket_read_ascii_read_float(3) ?

          Because I do not see any decimals in you error messages.

          Can you list your program from the UR txt file ?

          Regards
          Lars

          1. Yes I do. And looking at the variables tab, it shows correctly.

            But.. I figured it out: var_2[0] != 0 was mistyped as var_2 != 0
            Changing it did the trick.

            Thanks for the effort.

  12. 227 thoughts on “UR Script: Client-Server example”

    Yakov
    29 – December – 2015 at 21:46
    Hi,
    I have a script of movement for robot UR3. It works perfect, but before end, the robot stops movement some points before finish.

    The following error occures:
    – Protective Stop error (C204A3) Invalid setpoints: sudden change in target speed.

    This is the code:
    http://m.uploadedit.com/ba3n/1451395048886.txt

    Reply ↓

    Yakov
    29 – December – 2015 at 22:45
    The starting position is shown on http://imgur.com/5tqdLue. The “finish” position is shown at http://imgur.com/DqsWAIs. Thank in advance. Yakov.

    Reply ↓

    zacopressadmin Post author
    30 – December – 2015 at 13:47
    Hi Yakov

    Thanks for your question.

    When there are so many lines in a single script file it makes it very difficult to troubleshoot and therefore I do not favour this method of programming so much.

    I have tested your program on my UR3 and it does the same as you explain.

    The reason is the “t” value is too small in some of your lines towards the end of your program among the last 50 lines.

    The error messages appear because the “t” value is too small and therefore too little time given for the robot to physically move from the last move command to the next move command. Although the distance might be small, but since the “t” values are very small then it is still too little time.

    The way I troubleshoot on your program was to set the “t” value for the very first line in your program to the value 5 – because then I was more sure the robot had time enough to start moving even if the robot started from a position a little bit away from the first move command – and also more importantly that there is time enough to begin a new run one more time from the last move command to the first command.

    But the robot still stopped with an error.

    Then I removed the 50 last lines in your program and then the robot was able to run the commands without and error – and the robot could also start to rerun the second run.

    Then I step by step eliminated more of the last lines in your program and I fount that this line

    movej([0.139359552772267,-1.63168689101785,0.176167122494477,-1.52592076919271,0.0496141828741168,0.32920732553195], t=0.120199664894113,r=0.002)

    is the first line with error.

    I changed the “t” value to

    movej([0.139359552772267,-1.63168689101785,0.176167122494477,-1.52592076919271,0.0496141828741168,0.32920732553195], t=1.120199664894113,r=0.002)

    i.e. I give the robot one more second to move – and then the robot could move pass this command.

    But there are more lines with too little time among the last 50 lines.

    So you might consider singling out more lines in order to find out which line has error.

    It can help on the trouble shooting to set the last line to

    movej([0,-1.5707963267949,0,-1.5707963267949,0,0], t=1.1255332132815,r=0.002)

    then it is easier to troubleshoot the last lines because the robot now can reach the last position.

    Author:
    By Zacobria Lars Skovsgaard
    Accredited Universal Robots support Centre and Forum.

    Also check out the CB3 forum

    Reply ↓

    Yakov
    4 – January – 2016 at 19:40
    Thank you very much. I advanced in your direction – simply removed parameter ‘r’ at the last command. Ant it works now. By the way, now I have another problem. I have a robot sending all Joint Data on secondary port. Because this port is slow, the movement at the simulator is not smooth as in the real world (thread sleep and redraw take a time). Is it available to config/change that robot sent this data on the Real Time port? Thank in advance.

    Reply ↓

    zacopressadmin Post author
    4 – January – 2016 at 22:55
    Hi Yakov

    I am not aware of such command.

    Some of these data can also be read from the MODBUS server – for example register address 400-405 is the current robot pose.

    More informations at this link.

    http://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

    Reply ↓

    Ana
    11 – December – 2015 at 22:26
    Hello,

    How can I stop the robot motion without interrupting my program?

    Thanks

    Reply ↓

    zacopressadmin Post author
    12 – December – 2015 at 10:08
    Hi Ana

    Thanks for your question.

    You might consider to have an If condition for the robot movement – and then if the conditions is not present then execute a stopj() command. The If condition needs to have the “Check expression continuously” checked in order to react when the change occur.

    In below example the robot move when Input_0 is True – when Input_0 is switched to False the robot stops, but the program continues as can be seen with the I/O in the Thread still changing

    Program
    Robot Program
    Wait: 0.01
    If digital_in[0]≟ True (“Check expression continuously” = checked)
    MoveJ
    Waypoint_1
    Waypoint_2
    ElseIf digital_in[0]≟ False
    stopj(5.0)

    Thread_1
    Wait: 0.01
    Set DO[0]=On
    Wait: 1.0
    Set DO[0]=Off
    Wait: 1.0

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Support Forum.

    Reply ↓

    GANESH P
    9 – December – 2015 at 17:31
    Hi Lars,
    Thanks for your valuable suggestions i have one more doubt regarding script programming.
    (i) From my PC GUI i can able to run my script program with the help of dashboard server but if the code stopped because of some bug how can i monitor and get the status of UR10 to my PC GUI.
    (ii) How can i get the status of UR10 to my PC GUI.
    for e.g status such as weather the robot is in IDLE , ESTOP or the robot is moving etc…

    Regards
    GANESH P

    Reply ↓

    zacopressadmin Post author
    9 – December – 2015 at 18:22
    Hi Ganesh

    I am not sure if all your bugs can be detected, but you might consider to read the robotmode in the MODBUS register 258 – more information 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 ↓

    Jon
    20 – November – 2015 at 20:12
    Hi,

    My UR is failing to open a socket on my network with the command socket_open(IP,PORT). Is there a line of code I should be running before this to initiate my socket….

    Cheers

    Jon

    Reply ↓

    zacopressadmin Post author
    21 – November – 2015 at 16:39
    Hi Jon

    Thanks for your question.

    Have you prepared a server that can service the socket_open command from the robot ?

    The robot will be a client with the socket_open and needs a server to listen on the address and port.

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Support Forum.

    Reply ↓

    Markus
    2 – October – 2015 at 15:41
    Hello, is it possible to send a message to the UR Robot and it shows the message on the touchpanel?
    kind regards

    Reply ↓

    zacopressadmin Post author
    2 – October – 2015 at 18:32
    Hi Markus

    Have you tried what is described at this link ?

    http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-popup-messages/

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Support Forum.

    Reply ↓

    Luka
    8 – September – 2015 at 16:38
    Hi Las,
    Thanks for your reply. It’s my fault. Someone has amended the program. Thanks again for your time.
    B.R.
    Luka

    Reply ↓

    Luka
    8 – September – 2015 at 15:16
    Hi Lars,
    Today when i run the program that i wrote before ,it always pop up a SyntaxError dialog box in which says:”
    SyntaxError: line 1 def lk_20150327(): ^” (lk_20150327 is the file name).However,the program work well before. I really don’t know what went wrong. Waiting for your help.
    B.R.
    Luka

    Reply ↓

    zacopressadmin Post author
    8 – September – 2015 at 15:51
    Hi Luka

    Can you list the entire program.

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Reply ↓

    Luka
    25 – June – 2015 at 16:10
    Hi Lars,
    When i send a series poses continually by the pc, the robot don’t move smoothly. Instead there is a jerking when it moves. Would u help me to make it moves smoothly?
    B.R.
    Luka

    Reply ↓

    zacopressadmin Post author
    26 – June – 2015 at 08:12
    Hi Luka

    Thanks for your question.

    For a smooth move trajectory planning is very important and if it is possible to make the path in advance – just like driving in a car a curve can be taken much smoother when positioning – deceleration and exit path and acceleration can be planned ahead.

    If the path can not be planned then it is important to run with a slower speed and maybe only send updates when there is changes in acceleration – deceleration – direction and speed. In other words if the robot is already moving in a direction and there is no change – then don’t send new commands.

    Maybe also consider to implement SpeedJ, SpeedL, StopJ and StopL commands.

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Reply ↓

    Luka
    10 – June – 2015 at 16:58
    Hi Lars,
    The problem is the list element numbering, I used it from 1-6.
    Thanks for your help.
    B.R
    Luka

    Reply ↓

    Luka
    10 – June – 2015 at 14:01
    I use Assigment,and the x,y,z i just use to replace the actual coordinates, they are both numbers.

    Reply ↓

    zacopressadmin Post author
    10 – June – 2015 at 14:09
    Can you list the entire program as it is for example from the created text file on the UR so I dont have to keep guessing ?

    The variable a seems not to have been created by using Assigment because then there would be a :=

    For the movej command try enter as Script

    Reply ↓

    Luka
    10 – June – 2015 at 11:55
    The program as follow
    movej
    waypoint_1
    a=get_actual_tcp_pose();
    movej
    wayponit_2
    movej(p[x,y,z,a[4],a[5],a[6]])

    Reply ↓

    zacopressadmin Post author
    10 – June – 2015 at 11:16
    This program will not work because x, y and z is also not defined.
    And the list element numbering must be from 0-5.
    The variable a seems not define with correct syntax – did you use the Assigment or Script to write the line ?

    Reply ↓

    Luka
    10 – June – 2015 at 10:07
    Hi Lars,
    Thanks for your reply.
    It’s about the first problem, when I use the tcp pose like that,there will a nameerror,it tells me that the “a” is not defined,but it has already been defined.I don’t know where the problem is, waiting for your help.
    B.R
    Luka

    Reply ↓

    zacopressadmin Post author
    10 – June – 2015 at 10:42
    Hi Luka

    I need to see the entire program.

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Reply ↓

    Luka
    9 – June – 2015 at 16:20
    Hello Lars,
    I have two problems.
    1. I am trying to get the tcp pose(or joint positions) when the robot in a new position. I use the function “get_actual_tcp_pose” to get the tcp pose, then i want use the Rx Rz and Rz in the vector. Can I use them as follow?
    a=get_actual_tcp_pose();
    movej(p[X1,Y1,Z1,a[4],a[5],a[6]]);
    If can’t, can u give me some advice?
    2.I want to send the tcp pose to the PC ,can I send them only in string by the function socket_send_string()?

    Reply ↓

    zacopressadmin Post author
    9 – June – 2015 at 22:42
    Hi Luka

    Thanks for your question.

    1.
    Yes you can.

    2.
    Yes.

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Reply ↓

    lmur
    1 – June – 2015 at 17:34
    Hi Lars,
    We are developing a script that connects and send instructions to the robot indefinitily, the code should be something like that:

    While(True)
    send_move()
    sleep(0.08)

    The problem is that after one minute using the script, the robot works with some ‘lag’, it can read the command sent, but it needs a lot of time to do it.
    Do you have any suggestions?
    Thank you in advance,
    lmur

    Reply ↓

    zacopressadmin Post author
    2 – June – 2015 at 12:18
    Hi Imur

    My suggestion is to not to program in this way because it is not so elegant.

    Because there are several factors that influence the move – if you keep sending move commands then it might be different for how long time it takes for the robot to move from the previous position to the new position and that will obviously affect the communication because the robot need to reach before sending a new command.
    Maybe you consider to send just small bites of a path so each move command only take short time and is finished before a new command comes – but then you have acceleration and deceleration to take care of and the move is difficult to make smooth.

    I robot motion it is better if you can plan the path first and make a trajectory in your program with optimized waypoints in order to get a smooth move.

    This is normal in motion also like in a car – if giving new commands all the time the car will not drive smooth – but by planning ahead the move will be smooth.

    If you don’t know the next position in advance and therefore cannot plan the trajectory then maybe you can consider to use the SpeedJ and SpeedL and StopJ and StopL commands, but you still need to take care of acceleration and deceleration if you change direction or change speed.

    The best robot moves is when the trajectory is planned in advance and then let the robot move.

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Reply ↓

    lmur
    3 – June – 2015 at 05:22
    Hello Lars,

    Thanks for your help.
    I’m sorry I didn’t explain it before. I’m sending speedL and stopL to the robot every time that the loop executes due to the trajectory is not known. Even when I’m sending the SpeedL and StopL commands, after one minute (more or less) of execution the lag comes. Any further suggestions?
    Thank you in advance,
    Lmur.

    Reply ↓

    zacopressadmin Post author
    3 – June – 2015 at 10:00
    Hello Imur

    Need to see the code – what software version are you running ?

    Reply ↓

    Frank Hoch
    11 – May – 2015 at 18:10
    Dear Lars,

    i saw your video on facebook (https://www.facebook.com/zacobria.universalrobots/videos/777617525662949/) and i wanted to know, how you implemented that in your software. Did you make a feedback loop to increment a certain value from the SpaceNavigator offset to the current position via the servoj(….) command?

    Best Regards,

    Frank

    Reply ↓

    zacopressadmin Post author
    11 – May – 2015 at 23:24
    Hi Frank

    It belongs to the group of products we sell, it uses various script commands send from a PC.

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Reply ↓

    Frank Hoch
    26 – May – 2015 at 17:11
    Hi Lars,

    I tried to implement it myself and maybe you can give me a little guidance, tell me what i’m doing wrong or even tell me, that it’s not possible that way. So here is what i did:
    I’m parsing both ports 30003 and 30002 and found out, that the Secondary Client only sends a message every 100ms and the Realtime client every 8 ms.
    Every time i received a message from the Realtime Client (every 8 ms) i did send a “servoj(….)” command to the controller (port 30002) from my Application on a pc. In each Iteration i incremented the value for one joint a little bit. I tried modifying the values of the gain and the lookahead_time but i never got out a smooth movement.
    The Log on the teachpanel displayed “servoj started” “servoj stopped” again and again.
    As i stopped my Application and therefore also stopped sending commands the robot did still move for about 3 to 5 seconds. Because of that i’m guessing it queued the commands and was still working on emptying that list.

    My question now is, if it is possible to use the servoj command over ethernet and if, in which timesteps should i do this (in the documentation they say the command should be send every 8 ms). Is it okay that the command is executed and stopped everytime (visible in the logfile) or is it only possible to use that command on a scriptprogram on the robot were it is always running and receiving commands (poses) over ethernet (Client-Server)?

    I very much appreciate your help.

    Best Regards,

    Frank Hoch

    Reply ↓

    zacopressadmin Post author
    26 – May – 2015 at 18:35
    Hi Frank

    Thanks for your question.

    I have not used ”servoj” over Ethernet so I don’t know how it behaves.

    Can to reason that you see the robot still move after last command be because you do not send stopj or stopl commands ?

    Maybe the lack of smooth move is because you need to work on the acceleration and deceleration – or because you change direction very often – the less change of direction will give a more smooth move – also because there is less acceleration and decelerations.

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Reply ↓

    Frank Hoch
    27 – May – 2015 at 16:13
    Hi Lars,

    since the servoj command terminates itself over ethernet, there is no use to terminate it via command. And also there’s no command to stop this command.
    I only moved the robot in one direction and the servoj command doesn’t allow oneself to alter the acceleration or velocity.
    Since your not using it that way, i’ll try implementing a program on the controller and send poses to it.
    Thanks again for your help, i’ll write again when i fixed it and tell you how.

    Greetings,

    Frank

    Frank Hoch
    23 – June – 2015 at 17:14
    Hi Lars,
    i’m stuck again. I wrote following program for the controller, which does work.
    It sends a “request” to my server-pc which then sends 6 Jointvalues back to the controller, which are read and moved to.
    The Problem is the timeframe.

    def move_test():
    Connected = False
    Counter=0
    WorkPos = [0, 0, 0, 0, 0, 0]
    TempPoint=[0, 0, 0, 0, 0, 0, 0]
    while (Connected == False ):
    global Connected = socket_open(“192.168.1.20″, 30000,”socket0″)
    sleep(0.1)
    end
    while (True):
    socket_send_string(“request”,”socket0″)
    TempPoint = socket_read_ascii_float(6,”socket0″)
    if (TempPoint[0]!=0):
    global Counter = 0
    while Counter < TempPoint[0]: WorkPos[Counter] = TempPoint[Counter+1] global Counter = Counter+1 end servoj(WorkPos, a=0.5, v=0.2, t=0.008, lookahead_time=0.15, gain=100) end end end I checked the communication between the two with wireshark and the controller only sends a request every 16 ms and i dont know why and what to do now. Because of that the movement isn't really smove and the robot's kind of humming when moving. When i increase the parameter "t" in the servoj function it only adds that to the 16 ms i already have. I don't know what i did wrong. Do i need to implement it otherwise? Thanks in advance Frank Hoch zacopressadmin Post author 23 - June - 2015 at 18:33 Hi Frank The timing might be the socket_send and socket_read commands. Instead of frequent updates I would approach it so the robot movement (acceleration – deceleration – direction change and speed change) are only done if it is necessary. In other words if the robot is already moving in a direction and there is no change – then don’t ask or send new command. Maybe also consider to implement SpeedJ, SpeedL, StopJ and StopL commands. Author: By Zacobria Lars Skovsgaard Authorised Universal-Robots Distributor. Frank Hoch 23 - June - 2015 at 18:49 But in the script-documentation for the “servoj” command it states: “Prefered use is to call this function with a new setpoint (q) in each time step (thus the default t=0.008)” therefore i think it should be called every 8 ms. I just looked at the descriptions of the SpeedJ, SpeedL commands. What kind of parameter is “joint speeds”? The speed of every joint and therefore 6 speeds? Can i use the function to get different joints to different speeds but with the same acceleration? Sorry for all the questions but the documentation is really short on infos and there are no examples for that :(. Thanks again zacopressadmin Post author 23 - June - 2015 at 19:49 I have not used ServoJ – but maybe others in the forum have. For SpeedJ a common speed for the joints you have specified to move. Peter Tobin 6 - May - 2015 at 02:18 Hi when the safety circuit is triggered and pauses the process, is there an output that can be used to to wire to a lamp to indicate to an operator that the system has paused? This is on a CB2 controller Cheers Peter Reply ↓ zacopressadmin Post author 6 - May - 2015 at 08:38 Hi Peter Thanks for your question. On a CB2 if running a later version of the software – you can also set outputs at certain level when the program stops. Under Installation I/O setting – each output. Author: By Zacobria Lars Skovsgaard Authorised Universal-Robots Distributor. Reply ↓ liukun 24 - April - 2015 at 16:22 Hi, Lars, Now I have a problem when I send a series of poses to ur10, can I use a variable to record some poses on ur, then when I give a signal to ur,it can playback these recorded poses, just like as follows: … i=0; while(i<6) a[i]=get_actal_tcp_pose(); i=i+1; … i=0 while(i<6) movej(a[i]); i=i+1; … Maybe u can give me some advice to record these poses and then playback them.Waiting for your reply. B.R. Liukun Reply ↓ zacopressadmin Post author 24 - April - 2015 at 20:50 Hi Liukun Thanks for your question. Yes this is actually similar to what the example here on this page does. But instead of storing the data in one variable – I think for your case you can consider to store the data in variables for each pose. Author: By Zacobria Lars Skovsgaard Authorised Universal-Robots Distributor. Reply ↓ Jan Michael Due 24 - April - 2015 at 15:33 Is it not practically possible to use the robot as a TCP server? The examples show the robot as client!? Reply ↓ zacopressadmin Post author 24 - April - 2015 at 20:42 Hi Jan Michael Tak and thanks for your question. For socket communication made in the GUI then there is only the Client option. But the robot has some server running like port 30001, 30002, 30003 which can receive script commands as shown here on this page. And then there is port 502 which is the Modbus server – these port are all servers running on the robot, but they are fixed. To program a server on the robot is also an unfortunate approach – because the robot is a robot which is busy doing robot stuff i.e. move arround – so it is not ideal to program it to be a server to spend precious cpu time to server others – when it is a robot. Then a server can better be on another hardware then. Author: By Zacobria Lars Skovsgaard Authorised Universal-Robots Distributor. Reply ↓ Lei 24 - March - 2015 at 23:17 Hi, Lars, On my laptop, in visual studio, I use a command to display both foreign ip address and foreign port which gives me the client ip address and port. Every time I run the program in ur5, ip address of ur5 is correct but the port displayed is different. B.R. Lei Shi Reply ↓ zacopressadmin Post author 25 - March - 2015 at 08:38 Hi Lei Are you using the same program on the robot as shown in this example on the forum ? Can you consider to try another software as your server just to trouble shoot wether it is the server side or the robot side. Can you consider to use the socket test program to troubleshoot each side ? The port should be the same each time if you do not change it in the UR program. Author: By Zacobria Lars Skovsgaard Authorised Universal-Robots Distributor. Reply ↓ Lei 26 - March - 2015 at 18:29 Hi, Lars, I tested with SocketTest as in this post. It worked. So there must be something wrong in my server part. I will check it. Thanks for the help. B.R. Lei Reply ↓ Lei 21 - March - 2015 at 22:13 Hi, Lars I have problem in open the socket. I am using PC as server, in UR5, I ran a script that opened socket at port 30000, but it is not able to connect to server. On server side, I opened a server socket, bind IP address and listen. I am using c++, by the way. I can see the foreign ip address is correct(same as set in UR5), but port is a random high port, like 41234,etc. Do you have any idea how to fix this? Thank you very much! BR Lei Reply ↓ zacopressadmin Post author 23 - March - 2015 at 10:41 Hi Lei Thanks for your question. I think you should be able to set a fixed port on the server side e.g. port 30000 – and then use that port number in your Client UR program as shown in this example. The port number should not be random. Author: By Zacobria Lars Skovsgaard Authorised Universal-Robots Distributor. Reply ↓ Lei 24 - March - 2015 at 21:57 Hi, Lars, Thanks for the reply. I already set the port 30000 at servo side, and at ur5 side, I set the port to 30000 as well (by using socket_open). I can read that on server side the ip address and port is right. But when I read client port, it is random port, although I set the client to 30000 in ur5. Does it relate to firmware versions? Thanks a lot. B.R. Lei Shi Reply ↓ zacopressadmin Post author 24 - March - 2015 at 22:34 Hi Lei From where do you know the random port ? Regards Lars Reply ↓ Vlad 13 - March - 2015 at 15:39 Hi, I have a question related to the data acquisition part. I structured the script on my polyscope to send me the actual joint positions (a simple script based on three lines: connection, function, send_socket_string). Even If I have some conversion algorithms and I managed to get accurate float data, I want to assign some buttons in order to increment the values receive. Foe example if i want to move one joint , I simply store the other joint values and increment/decrement the desired joint value with a precision set by me. This will happen when I press a button from my interface. My concern is that the robot loops the polyscope script and keeps sending the joint positions, loop that will constantly block my move commands to it. So, if I want to send a new joint position, the channel is blocked by the incoming data from the robot.Though, I want a real time representation of the joint positions if i continuously press the interface button (just like on the teaching pendant.) Is there any solution to avoid this problem? My guess is that I should send and receive data on different ports or somehow implement some break routines on the polyscope. Is this achievable? PS: Is there any port list available for the UR10? Thank you in advance, Cheers Reply ↓ zacopressadmin Post author 13 - March - 2015 at 22:37 Hi Vlad Thanks for your question Yes you might consider to use a multiple ports by opening more sockets with different names. For your second question I have not seen such list – so try ports that are not normally used by common TCP/IP. Regards Zacobria Reply ↓ Jonathon 11 - March - 2015 at 18:36 I’m not entirely sure how to get the variable from polyscope to my machine, however if I run get_forward_kin() without assigning a variable, I get the following in buf: (note this is just the first part) where the number represents the number in the array and the number next to this is the byte followed by the letter/symbol that this represents [136] 19 '' char [137] 80 'P' char [138] 82 'R' char [139] 79 'O' char [140] 71 'G' char [141] 82 'R' char [142] 65 'A' char [143] 77 'M' char [144] 95 '_' char [145] 88 'X' char [146] 88 'X' char [147] 88 'X' char [148] 95 '_' char [149] 83 'S' char [150] 84 'T' char [151] 65 'A' char [152] 82 'R' char [153] 84 'T' char [154] 69 'E' char [155] 68 'D' char [156] 103 'g' char [157] 101 'e' char [158] 116 't' char [159] 95 '_' char [160] 102 'f' char [161] 111 'o' char [162] 114 'r' char [163] 119 'w' char [164] 97 'a' char [165] 114 'r' char [166] 100 'd' char [167] 95 '_' char [168] 107 'k' char [169] 105 'i' char [170] 110 'n' char [171] 0 '' char [172] 0 '' char [173] 0 '' char [174] 16 '' char [175] 25 '' char [176] 63 '?' char [177] 63 '?' char [178] 63 '?' char [179] 63 '?' char [180] 63 '?' char [181] 63 '?' char [182] 63 '?' char [183] 63 '?' char [184] 1 '' char [185] 0 '' char [186] 0 '' char [187] 0 '' char [188] 0 '' char [189] 0 '' char [190] 9 '\t' char [191] 5 '' char [192] 0 '' char [193] 0 '' char [194] 0 '' char [195] 0 '' char Reply ↓ Jonathon 11 - March - 2015 at 18:29 Hi! First of all, thank you for all of the tutorials on here. It has helped a lot. I’m having trouble with regards to reading data from the robot. I’ve connected and can send commands such as move, get forward kin and setting variables etc. I used the following Send(tcpSocket, "global kin = get_forward_kin()"); to set the variable kin which works fine. I’m constantly reading from the robot using String messageSection = Encoding.ASCII.GetString(state.buffer, 0, bytesRead); char[] buf = Encoding.ASCII.GetChars(state.buffer, 0, bytesRead); strm.Write(buf); However I’ve no idea how to get the value of the global variable kin which I set. It updates in polyscope which I can see in the UI, but I need a way of reading this into an array My knowledge of packets etc is limited and I have read the documentation regarding the structure of the packets, but I can’t seem to determine the x,y,z,ax,ay,az values I should get from the variable Any help would be much appreciated Regards Jonathon Reply ↓ zacopressadmin Post author 11 - March - 2015 at 18:04 Dear Jonathon Thanks for your question. The code you show – is that on the robot – or is it on your host (maybe PC) ? What for example does the value kin have in polyscope when you see it updating ? Author: By Zacobria Lars Skovsgaard Authorised Universal-Robots Distributor. Reply ↓ Jonathon 11 - March - 2015 at 18:45 Thank you for your quick reply. That is on my host PC, I’ve only declared variables on the robot as I plan on controlling everything remotely through my computer. The polyscope value is p[] and for example currently contains p[-0.4759,-0.3459,-0.2390,0.4446,1.7350,-1.5158] which is correct. Reply ↓ zacopressadmin Post author 11 - March - 2015 at 18:48 Hi Jonathon OK – then think you need to see your kin variable on your PC – can you print it to screen – what does it contain ? Reply ↓ zacopressadmin Post author 11 - March - 2015 at 18:34 Hi Jonathon OK – then you can look at this example – this send position data to the PC and get new position data from the PC . The small Python program is running on the PC and receives the position data from the robot – and send back new data to the robot. http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/

    You need a program running on the robot – so the robot program is the client and the PC is the server.

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Jonathon
    11 – March – 2015 at 18:40
    Thank you!

    I’m assuming the main part then would be

    socket_send_string(kin) in which my host PC would receive kin as a string, correct?

    finally, when trying to connect I get not able to open socket 0 to host: ip here at port 30001

    (which is the port I’m using). Is this UR related, or network related? If the latter, I’ll be able to sort this. Just wasn’t sure which

    zacopressadmin Post author
    11 – March – 2015 at 19:30
    Hi Jonathon

    Yes thats right something like that (depending on how the rest of your program is made – but it lookks good).

    Port 29999, 30001, 30002 and 30003 is already used by the robot for other purpose.

    Try using port 30000 or something else (there are other port used on the robot).

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Jonathon
    11 – March – 2015 at 19:19
    That’s great! Thought it would involve a whole lot of encoding!

    Tried switching to port 30000 however I still seem to get the same message

    Jonathon
    12 – March – 2015 at 15:02
    Just thought I’d add, in case anyone else has this problem or wants an alternative way that it is also possible to read the data from the robot using textmsg()

    Example pseudo code

    Socket s = new socket(ip,port)
    s.connect()
    send(s, “textmsg(varName,\ “endofrequest\”)”)
    string temp = s.receive();

    This means that there is no need for a program to be running on the robot and that data can be requested any time through the click of a button, in my case the winform

    zacopressadmin Post author
    12 – March – 2015 at 19:33
    Hi Jonathon

    Thank you very much for sharing.

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Matthieu Ebert
    2 – February – 2015 at 16:31
    Hi Lars,

    thanks for the answer. The base system works in Rotation Vectors Rx,Ry,Rz I assume not in RPY?

    Do you have an Idea why I do not get the same pose orientation if I programm a pose in the gui (base system) or send it via socket ? The x,y,z positions are the same but the orientation not. I am trying (x,y,z,0,3.14,0)

    Cheers.

    Matt

    Reply ↓

    zacopressadmin Post author
    12 – February – 2015 at 08:05
    Hi Matt

    In the Pose editior you can change the Vector – RPY and Angle display value.

    For the orientation:

    Did you make a new feature profile ?

    How do the two methods differ in the two scenarios ?

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Reply ↓

    zacopressadmin Post author
    12 – February – 2015 at 08:14
    Hi Matt

    I just tried with the same coordinates as you use and the robot does the same when I do it from GUI and when I do it from socket connection.

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Reply ↓

    M.Ebert
    30 – January – 2015 at 22:34
    Hi,

    in which system are the orientation coordinates of the pose you send via socket, rotation vector or RPY ?

    I do not get the same result regarding the orientation if I send a pose or type it in manually in the GUI

    Thanks.

    Matt

    Reply ↓

    zacopressadmin Post author
    31 – January – 2015 at 11:39
    Hi Matt

    Thanks for your question.

    It is in the base system.

    In the Move screen set the feature in Base view.

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Reply ↓

    Hagen
    22 – January – 2015 at 18:18
    Dear Lars,

    yes sorry I mean this message. I want to deactivate this….

    Best Regards
    Hagen

    Reply ↓

    Hagen
    21 – January – 2015 at 19:45
    Dear Lars,

    my program still waits for an input via tcp/ip. Every two seconds when the program doesn’t received any input, the robot writes an misstake in the protocol from the Robot. RTMaschine socket_read_ascii_float: timeout. I want to deactivate this.

    Best Regards
    Hagen

    Reply ↓

    zacopressadmin Post author
    21 – January – 2015 at 19:59
    Dear Hagen

    Thanks for your question.

    I dont think it is an mistake – just a messages.

    Regards
    Lars

    Reply ↓

    Hagen
    19 – January – 2015 at 21:09
    Dear Lars,

    I read from TCP Socket.

    Best regards
    Hagen

    Reply ↓

    zacopressadmin Post author
    20 – January – 2015 at 20:51
    Dear Hagen

    OK noted.

    What about the other questions ?

    Where does the robot write a mistake ?

    I am not sure what you wish to deactivate ?

    Regards
    Lars

    Reply ↓

    Hagen
    6 – January – 2015 at 19:08
    Dear Hagen,

    thank you very much for your help. My program now still works :-)
    But I have one last simple question:

    Is it possible to deaktivate that the roboter writes always an misstake in the memory when he can not read the input?

    Thank You!

    Best regards
    Hagen

    Reply ↓

    zacopressadmin Post author
    6 – January – 2015 at 19:09
    Hi Hagen

    Can you explain a little more?

    Where does the robot write a mistake ?

    By “input” – do you read from the TCP socket – or from a physical I/O input ?

    I am not sure what you wish to deactivate ?

    Regards
    Lars

    Reply ↓

    Hagen
    16 – December – 2014 at 16:13
    Dear Lars,

    I have revised my script, but I get the same error with the ClientTest Programm and the python scripts. I am very helpless.
    Best Regards Hagen

    here is my new script file:
    def ur_recive_data_froom_pc():
    modbus_add_signal(“192.168.0.40″, 255, 8000, 2, “DI8″)
    modbus_set_signal_update_frequency(“DI8″, 10)
    modbus_add_signal(“192.168.0.40″, 255, 8001, 3, “DO4″)
    modbus_set_signal_update_frequency(“DO4″, 10)
    modbus_add_signal(“192.168.0.40″, 255, 2006, 3, “Kommando”)
    modbus_set_signal_update_frequency(“Kommando”, 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([])
    modbus_set_runstate_dependent_choice(“DO4″,0)
    modbus_set_runstate_dependent_choice(“Kommando”,0)
    set_payload(0.0)
    set_gravity([0.0, 0.0, 9.82])
    hub=100
    varmsg(“hub”,hub)
    AsT=p[0, 0, 0, 0, 0, 0]
    varmsg(“AsT”,AsT)
    GST=[0,0,0,0,0,0]
    varmsg(“GST”,GST)
    pointer=0
    varmsg(“pointer”,pointer)
    Counter=0
    varmsg(“Counter”,Counter)
    Move_To_Pos=p[0,0,0,0,0,0]
    varmsg(“Move_To_Pos”,Move_To_Pos)
    Receive_Data=[1,0,0,0,0,0,0]
    varmsg(“Receive_Data”,Receive_Data)
    Socket_Closed= True
    varmsg(“Socket_Closed”,Socket_Closed)
    $ 2 “VorStart”
    $ 3 “FahreAchse”
    $ 4 “Wegpunkt1″
    movej([-1.7423237174973465, -1.0245752138879913, 0.8613564024448606, -1.8197865872030046, 1.7353615720384665, -1.0504540488194238], a=1.3962634015954636, v=1.0471975511965976)
    while (True):
    $ 5 “Roboterprogramm”
    $ 6 “Move_To_Pos≔Move_To_Pos”
    global Move_To_Pos = Move_To_Pos
    varmsg(“Move_To_Pos”,Move_To_Pos)
    $ 7 “Receive_Data≔Receive_Data”
    global Receive_Data = Receive_Data
    varmsg(“Receive_Data”,Receive_Data)
    $ 8 “Counter≔Counter”
    global Counter = Counter
    varmsg(“Counter”,Counter)
    $ 9 “If Socket_Closed≟ True ”
    global thread_flag_9 = 0
    thread Thread_if_9():
    $ 10 “socket_open(’192.168.0.100′, 30000)”
    socket_open(“192.168.0.100″, 30000)
    $ 11 “Socket_Closed≔ False ”
    global Socket_Closed = False
    varmsg(“Socket_Closed”,Socket_Closed)
    thread_flag_9 = 1
    end
    if (Socket_Closed == True ):
    global thread_handler_9 = run Thread_if_9()
    while (thread_flag_9 == 0):
    if (not(Socket_Closed == True )):
    kill thread_handler_9
    thread_flag_9 = 2
    else:
    sync()
    end
    end
    else:
    thread_flag_9 = 2
    end
    $ 12 “pose_position=get_forward_kin()”
    pose_position=get_forward_kin()
    $ 13 “joint_positions= get_joint_positions()”
    joint_positions= get_joint_positions()
    $ 14 “socket_send_string(pose_position)”
    socket_send_string(pose_position)
    $ 15 “Warten: 1.0″
    sleep(1.0)
    $ 16 “socket_send_string(joint_positions)”
    socket_send_string(joint_positions)
    $ 17 “Warten: 1.0″
    sleep(1.0)
    $ 18 “socket_send_string(‘Asking_Waypoint_1′)”
    socket_send_string(“Asking_Waypoint_1″)
    $ 19 “Warten: 3.0″
    sleep(3.0)
    $ 20 “Receive_Data= socket_read_ascii_float(6)”
    Receive_Data= socket_read_ascii_float(6)
    $ 21 “Während Counter < Receive_Data[0]" thread Thread_while_21(): while (True): $ 22 "Move_To_Pos[Counter] = Receive_Data[Counter+1]" Move_To_Pos[Counter] = Receive_Data[Counter+1] $ 23 "Counter≔+1" global Counter = +1 varmsg("Counter",Counter) end end if (Counter < Receive_Data[0]): global thread_handler_21=run Thread_while_21() while (Counter < Receive_Data[0]): sync() end kill thread_handler_21 end $ 24 "varmsg('Move_To_Pos', Move_To_Pos)" varmsg("Move_To_Pos", Move_To_Pos) $ 25 "movel(Move_To_Pos)" movel(Move_To_Pos) $ 26 "socket_send_string('Asking_Waypoint_2')" socket_send_string("Asking_Waypoint_2") $ 27 "Receive_Data= socket_read_ascii_float(6)" Receive_Data= socket_read_ascii_float(6) $ 28 "Counter≔0" global Counter = 0 varmsg("Counter",Counter) $ 29 "Während Counter< Receive_Data[0]" thread Thread_while_29(): while (True): $ 30 "Move_To_Pos[Counter]= Receive_Data[Counter+1]" Move_To_Pos[Counter]= Receive_Data[Counter+1] $ 31 "Counter≔+1" global Counter = +1 varmsg("Counter",Counter) end end if (Counter < Receive_Data[0]): global thread_handler_29=run Thread_while_29() while (Counter < Receive_Data[0]): sync() end kill thread_handler_29 end $ 32 "varmsg('Move_To_Pos', Move_To_Pos)" varmsg("Move_To_Pos", Move_To_Pos) $ 33 "movel(Move_To_Pos)" movel(Move_To_Pos) $ 34 "socket_send_string('Asking_Waypoint_3')" socket_send_string("Asking_Waypoint_3") $ 35 "Während Counter < Receive_Data[0]" thread Thread_while_35(): while (True): $ 36 "Move_To_Pos[Counter]= Receive_Data[Counter+1]" Move_To_Pos[Counter]= Receive_Data[Counter+1] $ 37 "Counter≔+1" global Counter = +1 varmsg("Counter",Counter) end end if (Counter < Receive_Data[0]): global thread_handler_35=run Thread_while_35() while (Counter < Receive_Data[0]): sync() end kill thread_handler_35 end $ 38 "varmsg('Move_To_Pos', Move_To_Pos)" varmsg("Move_To_Pos", Move_To_Pos) $ 39 "movel(Move_To_Pos)" movel(Move_To_Pos) end end Reply ↓ zacopressadmin Post author 16 - December - 2014 at 18:35 Hi Hagen Can you set you pointer to 0 in your program just after where you are receiving the first set of data like in my program ? Are you receiving the data you send on the robot ? – try and look in the Variables Tab while the program is running and follow the variables – do they change as expected ? Where and when does the program exactely stop ? Regards Lars Reply ↓ Hagen 15 - December - 2014 at 16:03 Hi, yes I received the message “Asking_Waypoint1″ on my pc. Best Regards hagen Reply ↓ Hagen 15 - December - 2014 at 15:21 Dear Lars, I exactly send the daas from your example: (0,0.4,0.3,0,3.14,0) The following is the code from the script file: def ur_recive_data_froom_pc(): modbus_add_signal(“192.168.0.40″, 255, 8000, 2, “DI8″) modbus_set_signal_update_frequency(“DI8″, 10) modbus_add_signal(“192.168.0.40″, 255, 8001, 3, “DO4″) modbus_set_signal_update_frequency(“DO4″, 10) modbus_add_signal(“192.168.0.40″, 255, 2006, 3, “Kommando”) modbus_set_signal_update_frequency(“Kommando”, 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([]) modbus_set_runstate_dependent_choice(“DO4″,0) modbus_set_runstate_dependent_choice(“Kommando”,0) set_payload(0.0) set_gravity([0.0, 0.0, 9.82]) hub=100 varmsg(“hub”,hub) GST=[0,0,0,0,0,0] varmsg(“GST”,GST) AsT=p[0, 0, 0, 0, 0, 0] varmsg(“AsT”,AsT) pointer=1 varmsg(“pointer”,pointer) Move_To_Pos=p[0,0.4,0.4,0,3.14,0] varmsg(“Move_To_Pos”,Move_To_Pos) Receive_Data=[0,0,0,0,0,0,0] varmsg(“Receive_Data”,Receive_Data) Schleife_1=0 varmsg(“Schleife_1″,Schleife_1) Schleife_2=0 varmsg(“Schleife_2″,Schleife_2) Schleife_3=0 varmsg(“Schleife_3″,Schleife_3) Socket_Closed= True varmsg(“Socket_Closed”,Socket_Closed) $ 2 “VorStart” $ 3 “FahreAchse” $ 4 “Wegpunkt1″ movej([-1.7423237174973465, -1.0245752138879913, 0.8613564024448606, -1.8197865872030046, 1.7353615720384665, -1.0504540488194238], a=1.3962634015954636, v=1.0471975511965976) while (True): $ 5 “Roboterprogramm” $ 6 “pointer≔0″ global pointer = 0 varmsg(“pointer”,pointer) $ 7 “Socket_Closed≔ True ” global Socket_Closed = True varmsg(“Socket_Closed”,Socket_Closed) $ 8 “Receive_Data≔[0,0,0,0,0,0,0]” global Receive_Data = [0,0,0,0,0,0,0] varmsg(“Receive_Data”,Receive_Data) $ 9 “Move_To_Pos≔Move_To_Pos” global Move_To_Pos = Move_To_Pos varmsg(“Move_To_Pos”,Move_To_Pos) $ 10 “If Socket_Closed≟ True ” if (Socket_Closed == True ): $ 11 “socket_open(’192.168.0.100′, 30000)” socket_open(“192.168.0.100″, 30000) $ 12 “Socket_Closed≔ False ” global Socket_Closed = False varmsg(“Socket_Closed”,Socket_Closed) end $ 13 “pose_position=get_forward_kin()” pose_position=get_forward_kin() $ 14 “joint_positions= get_joint_positions()” joint_positions= get_joint_positions() $ 15 “socket_send_string(pose_position)” socket_send_string(pose_position) $ 16 “Warten: 1.0″ sleep(1.0) $ 17 “socket_send_string(joint_positions)” socket_send_string(joint_positions) $ 18 “Warten: 1.0″ sleep(1.0) $ 19 “socket_send_string(‘Asking_Waypoint_1′)” socket_send_string(“Asking_Waypoint_1″) $ 20 “Warten: 3.0″ sleep(3.0) $ 21 “Receive_Data= socket_read_ascii_float(6)” Receive_Data= socket_read_ascii_float(6) $ 22 “pointer≔0″ global pointer = 0 varmsg(“pointer”,pointer) $ 23 “Während pointer < Receive_Data[0]" while (pointer < Receive_Data[0]): $ 24 "Move_To_Pos[pointer]= Receive_Data[pointer+1]" Move_To_Pos[pointer]= Receive_Data[pointer+1] $ 25 "pointer≔+1" global pointer = +1 varmsg("pointer",pointer) end $ 26 "varmsg('Move_To_Pos', Move_To_Pos)" varmsg("Move_To_Pos", Move_To_Pos) $ 27 "movel(Move_To_Pos)" movel(Move_To_Pos) $ 28 "socket_send_string('Asking_Waypoint_2')" socket_send_string("Asking_Waypoint_2") $ 29 "Warten: 3.0" sleep(3.0) $ 30 "Receive_Data= socket_read_ascii_float(6)" Receive_Data= socket_read_ascii_float(6) $ 31 "pointer≔0" global pointer = 0 varmsg("pointer",pointer) $ 32 "Während pointer < Receive_Data[0]" while (pointer < Receive_Data[0]): $ 33 "Move_To_Pos[pointer]= Receive_Data[pointer+1]" Move_To_Pos[pointer]= Receive_Data[pointer+1] $ 34 "pointer≔+1" global pointer = +1 varmsg("pointer",pointer) end $ 35 "varmsg('Move_To_Pos', Move_To_Pos)" varmsg("Move_To_Pos", Move_To_Pos) $ 36 "movel(Move_To_Pos)" movel(Move_To_Pos) $ 37 "socket_send_string('Asking_Waypoint_3')" socket_send_string("Asking_Waypoint_3") $ 38 "Warten: 3.0" sleep(3.0) $ 39 "Während pointer < Receive_Data[0]" while (pointer < Receive_Data[0]): $ 40 "Move_To_Pos[pointer]= Receive_Data[pointer+1]" Move_To_Pos[pointer]= Receive_Data[pointer+1] $ 41 "pointer≔+1" global pointer = +1 varmsg("pointer",pointer) end $ 42 "varmsg('Move_To_Pos', Move_To_Pos)" varmsg("Move_To_Pos", Move_To_Pos) $ 43 "movel(Move_To_Pos)" movel(Move_To_Pos) end end Thank you for your help! Best Regards Hagen Reply ↓ zacopressadmin Post author 15 - December - 2014 at 16:07 Hi Hagen Do you receive the “Asking_Waypoint_1″ on you PC ? For me it looks like you lines from $5 to $9 seems different. Regards Lars Reply ↓ Hagen 15 - December - 2014 at 15:50 Dear Lars, I have now try it with the test program (Socket_Test), but I get the same error. I have compared my code in the roboter with the picture and I have the same. I can receive datas from the robot, I get the message Robit is on position….. But when I try to send coordinates I get the timeout error in reason of endless loop. I am helpless. Best Regards Hagen Reply ↓ zacopressadmin Post author 15 - December - 2014 at 15:25 Hi Hagen Which data do you exactely send ? Try to copy the “program_name.script” file and list here Regards Lars Reply ↓ Hagen 15 - December - 2014 at 14:27 Hey Lars, thanks for your answer. I have worked with your example on this page 1:1. My connection works, I can receive datas from the ur to my laptop, but I get the error whenmy python script tries to send the coordinates to the UR. Thank you very much for your help! Best Regards Hagen Reply ↓ zacopressadmin Post author 15 - December - 2014 at 14:19 Hi Hagen You can also use the test program to send the coordinates to UR – then you can see if it is the Python or the UR program you have to look into. Regards Lars Zacobria Singapore Reply ↓ Hagen 12 - December - 2014 at 20:46 Dear Lars, thanks for your answer. I have write the program now in the GUI and test it. My Python Scripts connect to the UR and the UR send me the actually position. But he can’t received datas from my pc. When the UR sends ask for Waypoint 1 I get the message: Runtime Error, endless Loop in the programm and before this I get Ethernet-package lost from the pc to the ur….MASTER had not Dates to send. I hope you can help me! Best regards Hagen Reply ↓ zacopressadmin Post author 13 - December - 2014 at 19:27 Hi Hagen The endless loop messages sound like you are missing a Wait statement or other programming error. For the Ethernet-package loss – try to test the connection like this.
    http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-tcp-socket-test/

    Regards
    Lars
    Zacobria
    Singapore

    Reply ↓

    Hagen
    11 – December – 2014 at 22:56
    Dear Lars,

    thank you for this really good website. But now I have some questions,maybe I don’t understand your program…..

    which part of the program I have to load on the UR? And how can I make this? I have saved the first program as an script and load it in a new program on the ur, but everytime I get the message: Syntax Error first line….

    I hope you can Help me!

    Best Regards
    Hagen

    Reply ↓

    zacopressadmin Post author
    12 – December – 2014 at 09:35
    Dear Hagen

    Thanks for your question.

    For this example – the UR program you need to write the program in the UR GUI – like it is shown on the screen snippet.

    The script code is the output that the UR generates by itself after you have made a program in the GUI environment.
    I put the script code there just to help understand the GUI program because it has good comments and you can see the entire program line if you cannot read it in the GUI snippet.

    You cannot load the script program into UR like it is here – it would need a lot of modification and removal on many unnecessary lines.

    The Python program part running on the PC you should be able copy and paste into your Python environment on your PC, but make sure the quotation marks is transferred correct – I have seen editors that change the quotation mark and other character when copy n pasts – This one ̎ is the one I use.

    Author:
    By Zacobria Lars Skovsgaard
    Authorised Universal-Robots Distributor.

    Reply ↓

    Yusuf
    27 – November – 2014 at 06:38
    Hi Lars,
    Thank you for your effort in this forum.
    We recently purchased UR5 for academic purposes to use in haptic human robot interaction. However, I have a very fundamental problem. I searched through this forum, and tried couple of suggestions proposed. However, none of them solved my problem.
    Since I will use UR5 in haptic interaction with humans, from force sensor that we purchased we read force values continuously. What we do is to convert this force to a position command by admittance controller. Since force is changing fast during an action, corresponding position changes also. Nevertheless, I need to feed this position values to the robot. By TCP communication, I send position datas to robot, and client in the robot interpret these position values and moves accordingly. However, at each position command, robot first stops then starts to move. And this causes significant jerky motion which is not desirably in our field of study. I tried to solve it by using various commands, movep, movel, movej, speedj etc I also applied blend radius but, my problem still continues. Instead of position commands, I tried speed commands. I send speed values, and increase them or decrease them at each step just in one direction. Still, at each speed command, it stops and starts to move again. Also, although I feed the same speed over and over again, it still stops and starts to move again.
    Coming back to move commands, when I play with blend radius, it still moves jerky but after a certain r value, it does not give any motion, after lots of samples are kind of buffered, it moves suddenly more than what I want in one step, and then stops and wait for a while again.
    I really need to solve this problem, this application was the only reason why we purchased this robot, and if we can’t solve it, it will be a big problem for us. I am sure there should be a solution for this, but I don’t know where and how to get it.

    Thanks for your and anybody elses help in advance.

    Reply ↓

    zacopressadmin Post author
    27 – November – 2014 at 07:51
    Dear Yusuf

    Thanks for your question.

    I understand your challenge and I think there are ways to improve the motion which I will explain also, but first I need to explain some physics.

    I can imagine that you have some kind of device on the robot that can give you some information’s that you want to use for moving the robot.

    I have tried something similar using a joystick as input to move the robot. I know that a joystick is different compared to your device, but I don’t think that matters because the phenomena is the same.

    The main challenge you have is two things.

    1.
    You need to keep in mind all the time that in any motion there is 3 phases which’s – Acceleration – Cruise – Declaration. Even the fastest cars in the world have to obey this physics.

    Where it is most obvious is when you start moving forward and after a while need to reveres. In order to do this you need to

    Accelerate – Cruise – Decelerate – Stop – Accelerate – Cruise

    But not only when you need to reveres – this physics is also in play when you change direction, but then the Acceleration and Deceleration can be more smooth depending on the speed and how aggressive the change of direction is – but you still have this to think about this.

    2.
    The next important thing to think about is “Inertia”. An object has a mass (a weight) that has an influence on motion – especially when moving around at speed.
    And a robot typically has a bigger mass than a human arm for example – and if you have a tool or device on the robot this also has to be added into the mass. So Inertia has an impact on the above Acceleration – (not so much on the Cruise) – but again on the Deceleration.

    Then I also think it is important to think about that Industrial robots is typical used in Pick and Place – i.e. the robot move from place to place and stops to pickup or deliver items. Therefore this looks very nice because the stop is a natural part of the task.
    Also in Pick and Place the path is in most cases are very static (even in applications using a Vision camera) and the path can be programmed beforehand.

    In your case the task is a Process task and the motion and path becomes very important. And the path is not known beforehand.

    Then try and take a look at these videos.

    https://www.youtube.com/watch?v=_rjRett4S7k&list=UU6_OLDDfKqqVbSJHhiWLDqg

    https://www.youtube.com/watch?v=7dcB62vsTwg&list=UU6_OLDDfKqqVbSJHhiWLDqg

    https://www.youtube.com/watch?v=PLi10y6LIAc&list=UU6_OLDDfKqqVbSJHhiWLDqg

    Although I am using a joystick – the fact that the robot does not know where to go before the user grabs the joystick and commands the robot on the fly – which is the same for you – the robot does not know where to go before you start applying your data from the input device.

    In the beginning making this application I had exactly the same struggle as you and the robot jerked a lot, but now it is better as you can see.

    If you look closely at these videos you can actually also see how the jerk becomes less because my software becomes better.

    In this application I use mainly SpeedJ – StopJ and SpeedL – StopL.

    I use two main tricks to overcome the jerk. One is to allow the robot to slow down when there is a change of direction – and second I have a routine I call “Crossover” when the direction completely change 180 degree.

    The consequences for controlling the slow down (deceleration) are that the robot “overshoots” a tiny bit. And also the moves a fairly slow, but that’s ok for my application.

    I am sure you can improve the jerks, but all the time you need to think about your speed and acceleration and deceleration and you need to think about the Inertia.

    Even a human arm carrying something heavy will have problems to make a smooth move. This is why Welding is a skill like an artwork performed by someone who has been trained for a long time.

    It took also me some time to make my software so the acceleration and declaration is dynamic depending on the speed and nature of the direction change. If the change of direction is small you can have higher deceleration and acceleration, but is the change of direction is fairly big – you need to prepare the speed in advance – slow down – decelerate and the accelerate again.

    Regards
    Lars
    Zacobria Singapore

    Reply ↓

    Yusuf
    27 – November – 2014 at 18:17
    Hi Lars,
    Thank you for your quick answer. I tried several things as you stated and as I mentioned. What the problem with the commands is at each time robot wants to stop. Even in the speed change. If I use stop as you said, it directly reduces the speed to 0 which is already my problem. I know that acceleration cruise and deceleration is needed. However, when I command a new position or speed before the robot actually achieves to previous command, robot first stops and then executes the new command. Or it might be an illusion since it starts to accelerate and the inertia is the reason of jerky feeling since the acceleration transition is too high. What I meant is, when you look at the figure below, is it really accelerating to new configuration or does it stop first and accelerate again although the motion direction does not change?
    https://dl.dropboxusercontent.com/u/46685222/Ads%C4%B1z.png

    Can you provide me a very simple code segment just to use move, speed, stop etc to solve this issue during motion in just one axis where positions in that axis are changing from 1 to 1.4 and from 1.4 to 2.0? I searched this forum but I couldn’t find a basic code segment to solve this problem.

    Thank you again.

    Reply ↓

    zacopressadmin Post author
    27 – November – 2014 at 22:51
    Hi Yusuf

    I mainly send such commands

    s.send (“speedl([” + x + “,” + y + “,” + z + “,” + rx + “,” + ry + “,” + rz + “],” + “1.2″ + “,100.0)” + “\n”)

    s.send (“stopl(0.2)” + “\n”)
    s.send (“stopl(0.5)” + “\n”)
    s.send (“stopl(2.0)” + “\n”)

    And then send many such speedl repeatedly quickly after each other so the update happens all the time.

    As you can see the time is set to 100 which is a high value and if there is not updates following then the robot just continue in the direction it already are moving – but if the input device is stopped then a stop is issued.

    The speed analyses are dynamic – so the stop commands are depending on the speed already travelling and also depending on how aggressive the change of direction is.

    With the joystick it is also possible to make the robot move in a jerky fashion if the user forces the joystick fast back and fourth and often change direction – then the robot will also jerk in this situation – but then it is really because the user asks for it.

    Regards
    Lars Skovshaard
    Zacobria Universal-Robotgs distributor Singapore

    Reply ↓

    Yusuf AYDIN
    19 – January – 2015 at 20:57
    Dear Lars,
    To resolve the jerk issue, I am trying something different. For that, I thought to send script commands directly from port 30002, like speedl command and try to read the speed (to get feedback) from another port like 50000 which is opened to teaching pendant. In a simpler way, to get feedback, I thought to use program in teaching pendant, and to send speedl commmand, I thought to use direct port 30002 communication. However, whenever I open port 30002, program in teaching pendant loses the connection in port 50000 and it also fails to read the speed of the robot.
    According to the techinal support of universal robots, I should be able to do this, however, I couldn’t manage to do that. Do you have any comments or experience on this?

    Thanks in advance

    zacopressadmin Post author
    20 – January – 2015 at 20:04
    Hi Yusuf

    Thanks for your question.

    I am not sure how you have made your program – maybe use a different port as 30002.

    Because port 30002 is the build-in server to receive direct script commands – and I dont think it is good to use both direct script command combined with a program made in the GUI – then it is better to client program in the GUI and receive data on a different port than 30002.

    Regards
    Lars

    SJ Teo
    1 – September – 2014 at 17:43
    Dear Lars,

    I have an issue with the connection between the UR5 and my PC. I am not sure why I am unable to receive messages from the UR5
    This is the simple code I had created to test the connection.

    IP address for PC: 192.168.1.50
    IP address for UR5: 192.168.1.15

    socket_open(’192.168.1.50′, 30002)
    socket_send_string(“Waiting For Command″)
    Wait (1s)

    I was using Socket Test Master to check if there is any connection between my PC and the UR5 but there wasn’t any connection established. I tried to access the firewall settings to open the ports but it didn’t work either. I observed from the teach pendant that it seems that the socket isn’t opened. Have I made a mistake with the coding?

    However, I was able to ping the UR5 from my PC.

    Reply ↓

    zacopressadmin Post author
    23 – October – 2014 at 11:16
    Dear Teo Sheng Jie

    Thanks for your question.

    I can see that you are using port 30002 which is the build in UR server for direct script commands and therefore better not use port 30002 for a client server scenario.

    Regards
    Zacobria
    Authorized Universal-Robots distributor
    Singapore

    Reply ↓

    Arun Kumar Saini
    25 – July – 2014 at 08:59
    First of all I am highly thankful to you for publishing all the hints to program UR5 from the host computer. As far as client-server script is concerned, I have some queries:

    1. I have understood that we need to implement some proprietary protocol between PC (acting as client) and a own script running on UR5. After decoding the commands we can call URScript APIs e.g. movej(), force() and so on and return response back to host computer.

    2. In reference to first point, I am trying to send the standard commands as a string from the host computer, then receive these as string on UR5 and then trying the execute whatever has come from the host.
    Command sent from host:
    s.send (“movej([-0.02181775122354601, -1.6084183115691042, 2.4693336906149663, -3.1593435916391637, -0.05405930428631578, -0.10558026613138694], a=1.3962634015954636, v=1.0471975511965976))”

    Command received as string on UR5:
    string from server = socket read string()

    Is it possible to directly execute the command present in the string on UR5?

    Reply ↓

    zacopressadmin Post author
    25 – July – 2014 at 13:59
    Dear Arun

    Thanks for your question.

    1.
    You can send some raw command (e.g. your movej…) commands to robot server at port 30002 and the robot will execute the command right away. (No program is running on the robot).

    An example on this method can be found here

    http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-via-socket-connection/

    2.
    Or as you mention you can create a client program on the robot that asks a server (e.g. PC) for data – which is the example called client-server here.

    But to send data which is essential a robot command (script command) like movej… is not so elegant because it is a command that is used to make a program – so to use a command that is to make a program inside a program can be ambiguous.

    I think it is better to exchange the Data (not commands) and then wrap the data into a command on the robot program is better programming practice.

    Regards
    Zacobria

    Reply ↓

    Amir masoud
    27 – June – 2014 at 22:53
    Hi Lars,
    I have a problem with sending a sequence of points to UR5 and get a smooth trajectory. I read Adam’s post but it did not help me.
    I am trying to send a sequence of pose to robot, in TCP/IP connection. I need the robot visits all the poses smoothly.
    I used movej, movel but they move the robot to the current received pose and stop there.
    After that polyscope reads the next point and so on.

    Is there any way that I can give the robot a path by PC, and somehow set the time component of the corresponding trajectory, let say I have three points to be visited and I want to set a trapezoidal velocity profile during visiting the sequence of points. In this case the robot should have max velocity at the second point and zero veloc

Leave a Reply

Your email address will not be published. Required fields are marked *