UR Script: Client-Server example

Also checkout the new CB3 forum

UR Script programming – Client-Server example. UR Receiving coordinates from Host.

The example show the UR robot with a running program and the UR robot initiate a socket connection to a Host – in this case a PC.

The IP address of the PC is  192.168.0.100 and port 30000 is used in this examples.

The IP address of the UR is  192.168.0.9 and port 30000 is used in this examples.

Client program running on UR Robot.

universal-robots-zacobria-script-client-server-program-test

def P040413_sockettest_receive_3_coordinates():
  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(24)
  set_runstate_outputs([])
  set_payload(0.0)
  set_gravity([0.0, 0.0, 9.82])
  Move_To_Pos=p[0, 0.4, 0.4, 0, 3.14, 0]
  Pointer=0
  Receive_Data=[0, 0, 0, 0, 0, 0, 0]
  Socket_Closed=True
  $ 2 “BeforeStart”
  $ 3 “MoveJ”
  $ 4 “Waypoint_1″
  movej([-4.436072065494562, -1.3509294688607585, -1.5898662740424647, -1.7720278195761425, 1.5692639625048612, -2.8652732472940476], a=1.3962634015954636, v=1.0471975511965976)
  while (True):
    $ 5 “Robot Program”
    $ 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 “Pointer:=Pointer”
    global Pointer = Pointer
    varmsg(“Pointer”,Pointer)
    $ 9 “If Socket_Closed= True “
    if (Socket_Closed ==  True  ):
      $ 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)
    end
    $ 12 “socket_send_string(‘Asking_Waypoint_1′)”
    socket_send_string(“Asking_Waypoint_1″)
    $ 13 “Wait: 3.0″
    sleep(3.0)
    $ 14 “Receive_Data = socket_read_ascii_float(6)”
    Receive_Data = socket_read_ascii_float(6)
    $ 15 “Pointer:=0″
    global Pointer = 0
    varmsg(“Pointer”,Pointer)
    $ 16 “While Pointer < Receive_Data[0]“
    while (Pointer < Receive_Data[0]):
      $ 17 “Move_To_Pos[Pointer] = Receive_Data[Pointer+1]“
      Move_To_Pos[Pointer] = Receive_Data[Pointer+1]
      $ 18 “Pointer:=Pointer+1″
      global Pointer = Pointer+1
      varmsg(“Pointer”,Pointer)
    end
    $ 19 “varmsg(‘Move_To_Pos’, Move_To_Pos)”
    varmsg(“Move_To_Pos”, Move_To_Pos)
    $ 20 “movel(Move_To_Pos)”
    movel(Move_To_Pos)
    $ 21 “socket_send_string(‘Asking_Waypoint_2′)”
    socket_send_string(“Asking_Waypoint_2″)
    $ 22 “Wait: 3.0″
    sleep(3.0)
    $ 23 “Receive_Data = socket_read_ascii_float(6)”
    Receive_Data = socket_read_ascii_float(6)
    $ 24 “Pointer:=0″
    global Pointer = 0
    varmsg(“Pointer”,Pointer)
    $ 25 “While Pointer < Receive_Data[0]“
    while (Pointer < Receive_Data[0]):
      $ 26 “Move_To_Pos[Pointer] = Receive_Data[Pointer+1]“
      Move_To_Pos[Pointer] = Receive_Data[Pointer+1]
      $ 27 “Pointer:=Pointer+1″
      global Pointer = Pointer+1
      varmsg(“Pointer”,Pointer)
    end
    $ 28 “varmsg(‘Move_To_Pos’, Move_To_Pos)”
    varmsg(“Move_To_Pos”, Move_To_Pos)
    $ 29 “movel(Move_To_Pos)”
    movel(Move_To_Pos)
    $ 30 “socket_send_string(‘Asking_Waypoint_3′)”
    socket_send_string(“Asking_Waypoint_3″)
    $ 31 “Wait: 3.0″
    sleep(3.0)
    $ 32 “Receive_Data = socket_read_ascii_float(6)”
    Receive_Data = socket_read_ascii_float(6)
    $ 33 “Pointer:=0″
    global Pointer = 0
    varmsg(“Pointer”,Pointer)
    $ 34 “While Pointer < Receive_Data[0]“
    while (Pointer < Receive_Data[0]):
      $ 35 “Move_To_Pos[Pointer] = Receive_Data[Pointer+1]“
      Move_To_Pos[Pointer] = Receive_Data[Pointer+1]
      $ 36 “Pointer:=Pointer+1″
      global Pointer = Pointer+1
      varmsg(“Pointer”,Pointer)
    end
    $ 37 “varmsg(‘Move_To_Pos’, Move_To_Pos)”
    varmsg(“Move_To_Pos”, Move_To_Pos)
    $ 38 “movel(Move_To_Pos)”
    movel(Move_To_Pos)
  end
end

 

On the PC Side (i.e. Host or Server) is in this case running Socket test program just for testing the Socket purpose, but later a C program that can serve the UR robot is shown.

From the PC this telegram is send over the Socket connection

(0,0.4,0.3,0,3.14,0) 

ur-script-client-server-receive-3-coordinates

ur-script-client-server-receive-3-coordinates

universal-robots-zacobria-script-client-server

UR program that ask for the position coordinates from PC host.

Continuing the previous example – this example is extended to send the Pose and Joint positions to a PC server host – and also asks for the position to go to from the PC host.

Program to run on the UR as a Client program.

universal-robots-zacobria-script-client-server-program

def receive_3_coordinates_from_host():
  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(24)
  set_runstate_outputs([])
  set_payload(0.0)
  set_gravity([0.0, 0.0, 9.82])
  Move_To_Pos=p[0, 0.4, 0.4, 0, 3.14, 0]
  Pointer=0
  Receive_Data=[0, 0, 0, 0, 0, 0, 0]
  Socket_Closed=True
  $ 2 “BeforeStart”
  $ 3 “MoveJ”
  $ 4 “Waypoint_1″
  movej([-4.436072065494562, -1.3509294688607585, -1.5898662740424647, -1.7720278195761425, 1.5692639625048612, -2.8652732472940476], a=1.3962634015954636, v=1.0471975511965976)
  while (True):
    $ 5 “Robot Program”
    $ 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 “Pointer:=Pointer”
    global Pointer = Pointer
    varmsg(“Pointer”,Pointer)
    $ 9 “If Socket_Closed= True “
    if (Socket_Closed ==  True  ):
      $ 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)
    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 “Wait: 1.0″
    sleep(1.0)
    $ 16 “socket_send_string(joint_positions)”
    socket_send_string(joint_positions)
    $ 17 “Wait: 1.0″
    sleep(1.0)
    $ 18 “socket_send_string(‘Asking_Waypoint_1′)”
    socket_send_string(“Asking_Waypoint_1″)
    $ 19 “Wait: 3.0″
    sleep(3.0)
    $ 20 “Receive_Data = socket_read_ascii_float(6)”
    Receive_Data = socket_read_ascii_float(6)
    $ 21 “Pointer:=0″
    global Pointer = 0
    varmsg(“Pointer”,Pointer)
    $ 22 “While Pointer < Receive_Data[0]“
    while (Pointer < Receive_Data[0]):
      $ 23 “Move_To_Pos[Pointer] = Receive_Data[Pointer+1]“
      Move_To_Pos[Pointer] = Receive_Data[Pointer+1]
      $ 24 “Pointer:=Pointer+1″
      global Pointer = Pointer+1
      varmsg(“Pointer”,Pointer)
    end
    $ 25 “varmsg(‘Move_To_Pos’, Move_To_Pos)”
    varmsg(“Move_To_Pos”, Move_To_Pos)
    $ 26 “movel(Move_To_Pos)”
    movel(Move_To_Pos)
    $ 27 “socket_send_string(‘Asking_Waypoint_2′)”
    socket_send_string(“Asking_Waypoint_2″)
    $ 28 “Wait: 3.0″
    sleep(3.0)
    $ 29 “Receive_Data = socket_read_ascii_float(6)”
    Receive_Data = socket_read_ascii_float(6)
    $ 30 “Pointer:=0″
    global Pointer = 0
    varmsg(“Pointer”,Pointer)
    $ 31 “While Pointer < Receive_Data[0]“
    while (Pointer < Receive_Data[0]):
      $ 32 “Move_To_Pos[Pointer] = Receive_Data[Pointer+1]“
      Move_To_Pos[Pointer] = Receive_Data[Pointer+1]
      $ 33 “Pointer:=Pointer+1″
      global Pointer = Pointer+1
      varmsg(“Pointer”,Pointer)
    end
    $ 34 “varmsg(‘Move_To_Pos’, Move_To_Pos)”
    varmsg(“Move_To_Pos”, Move_To_Pos)
    $ 35 “movel(Move_To_Pos)”
    movel(Move_To_Pos)
    $ 36 “socket_send_string(‘Asking_Waypoint_3′)”
    socket_send_string(“Asking_Waypoint_3″)
    $ 37 “Wait: 3.0″
    sleep(3.0)
    $ 38 “Receive_Data = socket_read_ascii_float(6)”
    Receive_Data = socket_read_ascii_float(6)
    $ 39 “Pointer:=0″
    global Pointer = 0
    varmsg(“Pointer”,Pointer)
    $ 40 “While Pointer < Receive_Data[0]“
    while (Pointer < Receive_Data[0]):
      $ 41 “Move_To_Pos[Pointer] = Receive_Data[Pointer+1]“
      Move_To_Pos[Pointer] = Receive_Data[Pointer+1]
      $ 42 “Pointer:=Pointer+1″
      global Pointer = Pointer+1
      varmsg(“Pointer”,Pointer)
    end
    $ 43 “varmsg(‘Move_To_Pos’, Move_To_Pos)”
    varmsg(“Move_To_Pos”, Move_To_Pos)
    $ 44 “movel(Move_To_Pos)”
    movel(Move_To_Pos)
  end
end

 

See below for the corresponding PC server host to serve this above program.

29.2.2.2 Phyton program to serve the UR robot asking for coordinates (send_3_points_to_ur.py).

# 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”
s = socket.socket()         # Create a socket object
count = 0
count_2 = 0
data = 0
s.bind((HOST, PORT))        # Bind to the port
s.listen(5)                 # Now wait for client connection.
c, addr = s.accept()        # Establish connection with client.
   
while (count < 1):

    count = count + 1
    print “The count is:”, count
    time.sleep(0.5)
    print “”
    msg = c.recv(1024)
    print “The robot position is(XYZ vector)”
    print msg
    print “”
    time.sleep(0.5)
    msg = c.recv(1024)
    print “The robot position is(Joint angle)”
    print msg

    while (count_2 < 3):
        count_2 = count_2 + 1
        print “”
        msg = c.recv(1024)
        print msg
        time.sleep(1)
        if msg == “Asking_Waypoint_1″:
            c.send(“(0.1,0.4,0.4,0.01,3.14,0.01)”);
        if msg == “Asking_Waypoint_2″:
            c.send(“(0.1,0.4,0.3,0.01,3.14,0.01)”);
        if msg == “Asking_Waypoint_3″:
            c.send(“(0.1,0.4,0.2,0.01,3.14,0.01)”);
    print “”
    msg = c.recv(1024)
    print “The robot position is(XYZ vector)”
    print msg
    print “”
    msg = c.recv(1024)
    print “The robot position is(Joint angle)”
    print msg

c.close()

print “Program finish”

 

See below for the result on the PC screen.

Result on PC server host for the above programs.

>>>
Starting Program
The count is: 1

The robot position is(XYZ vector)
p[2.57614e-06, 0.399991, 0.500199, 3.38842e-06, 3.14, -6.99365e-08]

The robot position is(Joint angle)
[-4.43607,-1.35093,-1.58987,-1.77203,1.56926,-2.86527]

Asking_Waypoint_1

Asking_Waypoint_2

Asking_Waypoint_3

The robot position is(XYZ vector)
p[0.1, 0.4, 0.2, 0.01, 3.14, 0.01]

The robot position is(Joint angle)
[-4.68947,-1.54264,-2.23345,-0.929973,1.56907,-3.11231]
Program finish
>>>

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



267 thoughts on “UR Script: Client-Server example

  1. Christian Piechnick

    Hey,

    we are currently using a client-server connection to get a solution for the built-in inverse kinematics (with the get_inverse_kin function) and further work with this solution on the server side. However, when the function “get_inv_kin” does not find a solution, an error message pops up “getinverse:FUNCTION DIDNOT FIND A SOLUTION”. After that, our program is terminated and we have to restart it. Is their any possibility to handle this error in a way, no error message pops up?

    Best regards
    Christian

    Reply
    1. zacopressadmin Post author

      Hey Christian

      Thanks for the question.

      I am not aware of any method to catch the error so it does not show up.

      It might be possible to close the popup message via the Dashboard server on port 29000 – see this link

      https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/dashboard-server-port-29999-15690/

      But then the error message has allready occured and I guess you wish it does not occur at all.

      So therefore instead it can be considered to make sure there is no reason for the error in the first place. The robot properly throw the error message for a good reason e.g risk for singularity or risk for safety stop or maybe because of the pose the robot is in at the current position and the pose at target position etc.

      Therefore maybe first investigate and analyse “what is the reason for the error happen” ?

      And then make sure if these conditions is present (maybe the X or Y or Z or Rx or Ry or Rz has certain values when it happens) – then do not give the “get_inv_kin” command at all when such condition are present and bypass the command in the program.

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


      Reply
      1. Christian Piechnick

        Hello Lars,

        thanks for your quick reply. I totally understand that error messages for things like singularities etc. are necessary. However, the function “get_inverse_kin” does not move the robot, it just calculates the joint positions for a given cartesian position. Therefore, in my opinion there should not be an error message when this function cannot retrieve a solution, because its just a calculation and not a move command.

        Since we are controlling the robot live in a telepresence scenario, we cannot make sure that certain goal positions are reachable by default.

        The problem is not the error message itself, the problem is that our program gets stopped. Do you have any suggestions?

        Best regards
        Christian

        Reply
        1. zacopressadmin Post author

          Hello Christian

          Since it is only a calculation – then maybe consider what you are using the “get_inverse_kin” for ? and then see if there is another way to get to the same result without using the command “get_inverse_kin”. Maybe the result can be calculated in another way – maybe on the server.

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


          Reply
  2. Dani

    Hello again,
    is it possible to have two Connections at the same time.
    So i have a TCP Socket Connection to a PC: socket_open(“ippc”, 30000)
    and i want to do another one with socket_open(“127.0.0.1″,30002) where to Change the Speed ?!

    Thanks,
    Dani

    Reply
    1. zacopressadmin Post author

      Hi Dani

      Thanks for your question.

      Yes it is possible to have more than one socket connection by naming the socket and make reference to the socket name when using it like these examples.

      socket_open(“192.168.0.100″,30000, “socket_1″)
      socket_open(“192.168.0.100″,40000, “socket_2″)

      socket_send_string(“asking_for_data”, “socket_1″)
      socket_send_string(“asking_for_data”, “socket_2″)

      var_1 = socket_read_ascii_float(3, “socket_1″)
      var_2 = socket_read_ascii_float(3, “socket_2″)

      socket_close(“socket_1″)
      socket_close(“socket_2″)

      To change the speed slider there is an example at this link
      http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/setting-the-speed-slider-from-a-program-15293/

      And then instead use the references to the sockets.

      s1:=socket_open(“127.0.0.1″,30002, “socket_1″)
      s2:=socket_open(“192.168.0.100″,40000, “socket_2″)
      socket_send_string(“asking_for_data”, “socket_2″)
      data:=socket_read_ascii_float(3, “socket_2″)
      socket_close(“socket_2″)

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

      Also check out the CB3 forum

      Reply
  3. Dennis

    Hello Lars,

    we have a problem with the communication between the UR3 and a SensoPart VISOR V10 camera.
    We want to use the camera to locate an object and then the object will be picked up by the UR3. We want to trigger the camera with the UR3 and the camera should send back the coordinates and the rotation of the object back to the robot. Unlike other cameras in different tutorials this camera receives the data on port 2006 and send them on port 2005. We tried to open both ports at the same time with socket0 and socket1 then the UR3 triggers the camera over port 2006. Then the script tries to read the data from port 2005 like in your tutorial, but doesn’t receive anything. Do you have an idea, how to solve the problem?

    Regards
    Dennis

    Reply
    1. zacopressadmin Post author

      Hi Dennis

      Thanks for your question.

      Does the camera actually trigger when the trigger command is send to port 2006 ?

      Maybe next step to consider is to find out if data is actually send out from the camera on port 2005 – maybe that can be troubleshooted with the “Sockettest” program as described 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

      Reply
      1. Dennis

        Hi Lars,

        thanks for your help.
        We already had a socket connection to our PC for testing and when we send a trigger from PC to the camera, we get the correct data on port 2005 back to the pc. We figured out that the camera can receive the trigger command from two clients at the same time connected to port 2006, but can only send data to one client on port 2005. So we disconnected the pc client and had to change the format of the telegram. Then the robot gets the data and picked the object correctly.
        Thanks for your help and time.

        Best regards
        Dennis

        Reply
  4. Gavin

    Hi Lars:

    I want to get some status of Robot , such as Robot Mode, Safety Mode, Joint Modes …

    I worked to get this status by port 30003, but not success.

    so , I want to try get this by port 29999, but where Can I find the data structure of the 29999 to analyse?

    Reply
  5. Sanketh R

    Hello Lars,

    I have an application where the robot slows down automatically as it approaches the target. The values of the target is received from a camera PC.

    I have two sockets for this:
    1) Robot(Client)-CameraPC(Server)
    2) Robot(Server)-Internal host(127.0.0.1, Port 30002) for speed slider control.

    I am listening to the CameraPC on a thread to check if there are any messages, if there, I relay the message onto the Internal host for speed reduction. I have used sync() after every speed slider change or even if there are no messages from the camera PC.

    Everything works okay for the first few cycles, robot gets the co-ordinates, moves to the target and slows down as it approaches.
    After a few cycles. the speed slider hangs even though the program is still running as expected. Even though I physically notice the change in speed, the slider does not reflect this change. After a few more cycles, the program stops behaving as expected.

    Is it a buffer overflow problem? When I run the same program on the UR5 simulator everything works as expected. I see that the socket_read_float has a 30 byte limitation, could I flush the buffer in someway after every read operation?

    Thanks for your time

    Reply
    1. Sanketh R

      Ah yeah, I see now that the secondary client on 30002 is limited to 10 Hz. Now I see the problem… I think RTDE is a better fit in this case… Could you point me to a few examples of RTDE implementation?

      Thanks again, cheers and have a nice weekend.

      Reply
    2. zacopressadmin Post author

      Hi Sanketh R

      Are each Open of the TCP socket also Closed again ? – if not it maybe create a overflow.

      When you say “Internal host” – is that the main GUI program you mean ?

      Maybe check if the program you have in the Thread part are using unnecessary time due to communicating to the external camera – or make sure the socket is closed if there is no communication needed to flush.

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

      Also check out the CB3 forum

      Reply
  6. LYU Shangke

    Hi Lars,

    Can I specify the joint velocity and joint position independently at the same time for UR 10? For example, can I use the command “servoj(q,t )” and at the same also use the command “speedJ(qd,t)” to control the UR 10? (q and qd are given independently) We want to know whether the UR robot control system integrates/ differentiates the velocity/position commands internally when we use servoj or speedj.

    Thank you.

    Best wishes,
    Shangke

    Reply
  7. Steve

    Thank you for the great tutorial…Can I ask a few further questions regarding the control of UR robots?

    1. I am hoping to control UR robot using a host PC. I want my host PC to recieve robot’s status (position, velocity, torque, etc) and send commands (position or velocity) based on the robot’s status at 125 Hz, which is the maximum communication period for UR. It seems to me that to do so, I need to write client program on UR robot using URscript to send the robot’s status to the host and receive the commands from the host. Also, I need a host program, which can be in any language, to receive the robot status and send commands. Can you please confirm if my understanding is correct?

    2. URscript provides many useful functions…can I directly use them in host PC by any chance (like movej or get_actual_joint_positions())?

    3. For the host PC, would it be worth to configure it as a realtime system (Linux running real-time kernel)?

    Any help would be really appreciated

    regards,

    Steve

    Reply
    1. zacopressadmin Post author

      Hi Steve

      Thanks for your question.

      1.
      Yes – as Yes that´s one way to do it.

      You can also get some robot status from the UR robots internal MODBUS registers. In these registers are many status information´s about the robot. At this link you can see what these register contain. For example register 400-405 is the X, Y, Z, Rx, Ry, Rz position of the robot.

      http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/modbus-server-16377/

      An example of using MODBUS registers are shown here.

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/modbus-registers-and-nodes/

      2.
      No (not really – only some commands which I will explain below) – Script commands is best used in Polyscope locally on the UR robot. The result of these commands can then be put into a variable in Polyscope and then send the contents of the variable(s) over a TCP socket communiction – like in a Client-Server situation where the robot is the Client and the host (PC) is the server. An example here.

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

      You can send some direct raw script commands from within a host (PC) program like “set_digital_out(7, True)” through port 30001 or 30002 or 30003 – which will set the output 7 on the robot high – and you can also send direct raw “move………” commands which will make the robot move, but it will terminate the local Polyscope program on the robot. So it is like a one way communication i.e. no read back of data or input status. Instead the Client-Server method is more elegant.

      However some example of the one way method can be found at this link

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

      3.
      I have no experience with real time kernel on a host PC.

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

      Also check out the CB3 forum

      Reply
  8. Michael

    Good day, I have a question. I have made some simple program on UR (on Polyscope), where I want to start it through PC. It has to be done with variable or set_digital_in(7, True). When I send ,,set_digital_in(7, True)” from PC program ,,Socket Test”, robot stops. Condition in program is controlled continuously. My program seems like this:

    wait(0,01)
    if digital_in[7] = True
    MoveL
    Waipoint1
    Waipoint2

    OR another way

    wait(0,01)
    if wait for var_1=1
    MoveL
    Waipoint1
    Waipoint2
    .

    By both of programs is robot waiting and in that time I send from PC a command ,,var_1=1″ or ,,set_digital_in(7, True)”, but robot stops. Why? I know that robot can’t be controlled by PC and Robot controller together, but how to send variable or another command to robot while program is running?

    Reply
    1. zacopressadmin Post author

      Hi Michael

      Thanks for your question.

      It is possible to achieve what you are trying to do, but in a different way.

      First some information´s.

      The UR can be controlled in many different ways – either by Polyscope locally on the UR – or by raw TCP script commands through a TCP port – or by a mix of this as a local Polyscope program on the UR which are receiving data from a host (PC) (Client-Server situation).

      1.
      The reason for the robot stop when you send the command “set_digital_in(7, True)” from a PC through a TCP socket port and to port 30001 or 30002 or 30003 is because there can only be one controller – either Polyscope local on the UR – or raw commands through these TCP ports. So as soon you send this raw command then the Polyscope program stops because the TCP command took over.

      Too understand the raw script command method then maybe see this article.

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

      So this example makes the robot move, but the commands are entirely comming from the PC.

      2.
      The way you have made the program is OK for the method where you wish to react on a hardware signal – in this case the signal is meant to be a hardware signal on the physical input on the UR (in this case input 7). It is not so elegant to send a command like “set_digital_in(7, True)” – because it is trying to manipulate an input (not an output) – and if there is already a hard wired signal connected to that input that maybe pull the input low – then there is a conflict.

      And it will not help to use an output instead and sending a command like “set_digital_out(7, True)” the robot will still stop because there can only be one controller.

      3.
      One way to achieve what you are looking for is using Client-Server situation.

      Then it is possible to send data from a host (PC) which is the server – over to the robot which is the Client. And then put this data into a variable and use that as the trigger in your Polyscope program on the robot.

      An example is here

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

      4.
      Another way is to send data from the host (PC) into the robot MODBUS register on the UR – and then read this register back from within the Polyscope program on the UR and use the data information to take action in the Polyscope program.

      An example of using the MODBUS registeres are at the link below. It can be with or without the external nodes shown in the example – in your case you don´t need the external nodes if you can write directly to the registers on the robot side from the PC through port 502.

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/modbus-registers-and-nodes/

      5.
      Another way to start and stop the program on the UR is to use the Dashboard server on port 29999. The word “play” send to port 29999 will start the Polyscope program – the word “stop” send to port 29999 will stop the Polyscope program and there are more commands.

      An example is at this link.

      http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/dashboard-server-port-29999-15690/

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

      Also check out the CB3 forum

      Reply
  9. Gavin

    Hi Lars:
    I have one question to ask , when I analyse the Client_Interface.xlsx file through port 30003 receiving , I want to get the robot Mode and the joint Mode , the file contents like this:
    Robot Mode double 1 8 95 Robot mode
    Joint Modes double 6 48 96-101 Joint control modes
    Safety Mode double 1 8 102 Safety mode

    I don’t understand why use ‘double’ type to express the Modes type that I think it should use ‘uchar ‘ or ‘unsigned int’ or ‘int’ and so on.

    so , I analyse the result not correct, and there is an sentence : (only from software version 1.8 and on), I don’t understand so clearly.

    expect to your reply, thanks.

    Reply
    1. zacopressadmin Post author

      Hi Gavin

      Thanks for your question.

      1.
      I have no information for why a certain type is applicable for these data.

      2.
      Version 1.8 refers to the software version running on the robot and version 1.8 indicates that it is for the older CB2 model. Since there has been a new robot model CB3 and many new software releases and the latest are 3.3.0.145 as for today.

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

      Also check out the CB3 forum

      Reply
  10. Raj Samant

    Sir,
    I have 2 questions to ask.
    1 – Can i put UR in gravity compensation and record all joint positions in a file? like i hold the arm and move it around and simultaneously record joint pos. (kinesthetic teaching)

    2- Can i give the robot joint position and robot will reach that position in single sampling interval? (joint positions will be very close to its initial position)

    Reply
    1. zacopressadmin Post author

      Hi Raj

      Thanks for your question.

      1.
      It is possible to put the robot in Free drive mode with the command

      freedrive_mode()
      Wait: 10.0
      end_freedrive_mode()

      And then at the same time read the TCP pose or the joint positions into a variable.

      Thread_1
      Wait: 0.01
      var_1≔get_actual_tcp_pose()
      var_2≔get_actual_joint_positions()

      To record these data into a file you might consider to send the data to a host over a Client-Server connection and record the data in a file on the host.

      An example of a Client-Server communication is shown at this link.

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

      2.
      It is possible to use the ”movej” command and provide joint position in the movej command like this

      movej([-1.95, -1.58, 1.16, -1.15, -1.55, 1.18], a=1.0, v=0.1)

      An example of sending joint positions from an external host is shown at this link.

      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

      Reply
  11. Sanketh R

    Hello Lars,
    I am trying the Server-Client example using SocketTest 3.0 for Server side and the UR5 Robot PC as the Client. I have directly connected the PC to the UR5 Ethernet port and the following static IPs are set:
    UR5 IP: 192.168.178.100
    PC IP: 192.168.178.101
    I am able to ping the robot PC without any issues.
    The following is the code I am testing on UR5
    Program
    BeforeStart
    status_socket≔socket_open(“192.168.178.101″,30000)
    Loop status_socket≟ False
    status_socket≔socket_open(“192.168.178.101″,30000)
    Robot Program
    pose_position≔get_actual_tcp_pose()
    joint_position≔get_actual_joint_positions()
    var_1≔r2d(joint_position[1])
    Wait digital_out[7]≟ True
    socket_send_string(pose_position)
    Wait: 1.0
    socket_send_string(joint_position)
    Wait digital_out[7]≟ True
    pose_position≔pose_trans(get_actual_tcp_pose(),p[0.1,0,0,0,0,0])
    MoveJ
    pose_position
    Wait: 5.0

    I start the SocketTest TCP server to listen on 192.168.178.101:30000 and then run the program on the UR5. (Verified on the PC side that the socket is open)
    But the socket is not opened on the UR5 side (status_socket remains false), I also checked on the Linux terminal with “netstat -vatn” to query all the opened TCP connections.
    What could be the Problem here?

    Reply
    1. zacopressadmin Post author

      Hi Sanketh

      Thanks for your question.

      I just typed in your program and run it on my real robot and it works OK. The robot open the socket and the variable status_socket becomes true and the data of pose_position and joint_position are transferred to the “Socket test program” on the PC side.

      When I created the variables pose_position and joint_positions I used the “Assignment” in the GUI. I only used a “Script” entry method for the two lines of socket_send_string(pose_position) and socket_send_string(joint_position)

      Maybe verify the Ethernet addresses for server and client and maybe consider to use a hub in between the PC and robot which I find a more proper Ethernet environment.

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

      Also check out the CB3 forum

      Reply
  12. Wirat

    Dear Lars
    I would like to 2-3 questions ,
    1. In case that I would like to command Waypoint to Universal Robot to move to Waypoint which I need. Can I do or not? Do you have Sample for sending command from PLC to Universal Robot?
    2. In case that I use the first waypoint to reference Position, and I will use reference waypoint to move robot to other waypoint, can I do it or not?
    3. Now my robot use CB3 version 3.1 , when I upgrade Version to 3.2 , this is effect on my program such as script or other Program or not. Can it compatible with version 3.1
    Thanks you for your reply
    Sincerely Yours

    Reply
    1. zacopressadmin Post author

      Hi Wirat

      Thanks for your question.

      I do not have a PLC program example and I do not program PLC, but it should be possible to do what you describe – either by using a TCP socket connection – which requires the PLC can communicate via ethernet and then you can use the example here as help because it is similar data that can be send over the ethernet connection.

      There is also a general purpose register on the UR which is a MODBUS server which can be accessed on port 502. Then you can exchange bytes that can be used in the UR polyscope program.

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

      Also check out the CB3 forum

      Reply
  13. Wirat

    I have one question , In case of we use PLC to order Position of RB , Can we order Waypoint to RB?. Do you have Program Sample?

    Reply
    1. zacopressadmin Post author

      Hi Wirat

      Thanks for your question.

      I am not sure what RB means (Robotiq) ?

      By “order” – do you mean send waypoints data to the robot – or do youmena reveive waypoint position data from the robot ?

      If the PLC has TCP socket communication then you might be able to use the format shown on this page.

      If you mean read – then the robot has a MODBUS server on port 502 and register 400-405 contains the data for current possition. More about MODBUS at this page.

      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
      1. Wirat

        Hello Lars,
        Execute me for my question not clear, RB mean Robot Universal Robot UR10

        My Question is objective that I use PLC to order Robot to move in waypoint, Robot will wait to receive Waypoint Position from PLC, Could you have sample of Program for me , Please
        Sincerely Yours

        Reply
  14. Sascha

    Hi Lars,

    I’m trying to get the Waypoints I teached in the panel in to my computer over socket connection. Can you think of a way, to access the saved waypoints on the teachpanel? I already tried to just save the actual poses that I get while running the program over the :30003 Thread, but thats to much data, since I want to just simulate and visualize the movement in VREP (another RobotSimulationPlatform) by reading out a *.csv file with the waypointdata in it.
    Right now I give a Signal (config.DO.3 High) for 0.01seconds and when reading that Signal on the RTPort, saving the waypoint with bytes 252-293 (actual joint position). But I’m looking for a more elegant way, that doesn’t need any extra programming on the teach panel.
    Is there any function to get those waypoints?

    Best Regards

    Sascha

    Reply
    1. zacopressadmin Post author

      Hi Sascha

      Thanks for your question.

      There are different ways to get position data out. As you mention the registers can be used as storage and extracted as you do.

      Also the register 400-405 has actual position and if fetched at the right moment they will contain the current position. More information’s about registers at this link.

      http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/modbus-server-16377/

      The positions can also be send via TCP over the socket connection like this example does where both joint angles and pose are send over the socket. This can also be achieved with get_actual_pose and store in a variable and send over the TCP socket – but it requires programming to do so.

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/

      If there is stored waypoints must mean there is a program on the UR – so along with the program file stored for the program (either on the robot flash card or on an external USB drive) there is also stored a x.txt and x.script file – and the x.script file will also contain data about the waypoint position.

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

      Also check out the CB3 forum

      Reply
  15. Alexander Petkov

    Hi Lars!

    Quick question – can I manually move the robot while a program is running WITHOUT this interrupting the program? I’ve only used the simulator for now and even if I call freedrive_mode() and move the robot (in the Move tab), the program execution stops. How can I avoid that?

    Thank you,
    Alexander

    Reply
    1. zacopressadmin Post author

      Hi Alexander

      Thanks for your question.

      Also check out the CB3 forum

      The ”Move screen” is mainly to be used for programming and move the robot when it is not running a program and therefore the program execution will stop when the ”Move screen” is used for moving the robot during program run.

      Although it is possible to program so the freedrive_mode is active and then have waypoints before ending the freedrive it is a contradicting operation because the robot is on the way to a waypoint and will try and reach there so moving the robot by hand is not ideal when the robot is on the move.

      Instead the freedrive_mode is better to be activated when the robot is at a waypoint and waiting – for example this example

      Program
      Robot Program
      MoveJ
      Waypoint_1
      freedrive_mode()
      Wait: 3.0
      end_freedrive_mode()
      Waypoint_2
      Waypoint_3

      Above some time is given to move the robot by hand when it is standing still and the program execution is not stopped.

      Freedrive is related to “handdrive” and therefore if the goal is to be able to move the robot with controls (not hand) during program execution then it is possible to make control for example using inputs.

      Program
      Robot Program
      MoveJ
      Waypoint_1
      If digital_in[0]≟ False
      speedl([0,0,0.1,0,0,0], 1.2,0.5)
      stopj(1.0)
      Wait: 3.0
      Waypoint_2
      Waypoint_3

      Here the input 0 can be use to move the robot straight up (Z direction) – if Input 0 is false the robot will move up for 0.5 seconds. But again it is during the time the robot is waiting at a waypoint because it is contradicting to have another kind of move when the robot is on the move to another waypoint – two different tasks trying to move the robot should be avoided.

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

      Reply
      1. Alexander Petkov

        Hi Lars!

        Thank you for the immediate answer and sorry for not being specific enough about my question.

        What I’m trying to do is first to establish a socket connection with a remote server. While running the program (meaning while the socket is connected), I want to manually (by hand) set different positions to the robot and each time tell the server “remember this position”.

        I’ve got it all working except for the part that each time I try to move the robot, the program is automatically stopped.

        Getting back on your answer, I’m sure that there will not be any other robot moves except for the manual ones, e.g. there won’t be two different tasks trying to move the robot. The server only keeps the socket connection and listens for positions. All the movement is done by hand.

        I tried using Wait as you suggested:


        freedrive_mode()
        Wait: 3.0
        end_freedrive_mode()

        but moving the robot with the arrows in the Move Tab while the robot is waiting still stopped the program.

        Is this a behavior of the Move tab only? E.g. if I actually had a real robot and moved it by hand, would the program still stop? (again while robot is in freedrive mode and waiting)

        Hope I explained it well enough, sorry if I haven’t. Thanks!

        Regards,
        Alex

        Reply
        1. zacopressadmin Post author

          Hi Alexandre

          OK noted about the socket connection.

          There is a difference in “freedrive” and “movetab arrow keys” and thats actually two different methods or ways capable of moving the robot. The freedrive is for litterly using our hand on the robot to move the robot – so using the arrow key is not freedrive and therefore when you press an arrow key in the Move screen the program will stop because thats another control taking over the movement.

          It might be good now to try on a real robot because on the simulator obvoiusly cannot move the robot by hand.

          I tried both the programs I showed earlier on a real robot and as soon the robot is in freedrive mode I can move the robot with my hand and the program continues (not stopped) and as soon the wait is finish and the freedrive mode is ended – then the robot moves to the next waypoint in the program.

          Regards
          Lars

          Reply
    1. zacopressadmin Post author

      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
      1. Yakov

        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
    1. zacopressadmin Post author

      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
  16. GANESH P

    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
  17. Jon

    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
    1. zacopressadmin Post author

      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
  18. Luka

    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
  19. Luka

    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
    1. zacopressadmin Post author

      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
    1. zacopressadmin Post author

      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
  20. Luka

    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
    1. zacopressadmin Post author

      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
  21. Luka

    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
  22. Luka

    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
    1. zacopressadmin Post author

      Hi Luka

      Thanks for your question.

      1.
      Yes you can.

      2.
      Yes.

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

      Reply
  23. lmur

    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
    1. zacopressadmin Post author

      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
      1. lmur

        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
    1. zacopressadmin Post author

      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
      1. Frank Hoch

        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
        1. zacopressadmin Post author

          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
          1. Frank Hoch

            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

          2. Frank Hoch

            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

          3. zacopressadmin Post author

            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.

          4. Frank Hoch

            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

          5. zacopressadmin Post author

            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.

  24. Peter Tobin

    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
    1. zacopressadmin Post author

      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
  25. liukun

    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
    1. zacopressadmin Post author

      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
  26. Jan Michael Due

    Is it not practically possible to use the robot as a TCP server?
    The examples show the robot as client!?

    Reply
    1. zacopressadmin Post author

      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
  27. Lei

    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
    1. zacopressadmin Post author

      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
      1. Lei

        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
  28. Lei

    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
    1. zacopressadmin Post author

      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
      1. Lei

        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
  29. Vlad

    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
    1. zacopressadmin Post author

      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
  30. Jonathon

    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
  31. Jonathon

    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
    1. zacopressadmin Post author

      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
      1. Jonathon

        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
        1. zacopressadmin Post author

          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
          1. zacopressadmin Post author

            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.

          2. Jonathon

            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

          3. zacopressadmin Post author

            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.

          4. Jonathon

            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

          5. Jonathon

            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

  32. Matthieu Ebert

    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
    1. zacopressadmin Post author

      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
  33. M.Ebert

    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
  34. Hagen

    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
    1. zacopressadmin Post author

      Dear Hagen

      Thanks for your question.

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

      Regards
      Lars

      Reply
    1. zacopressadmin Post author

      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
  35. Hagen

    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
    1. zacopressadmin Post author

      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
  36. Hagen

    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
    1. zacopressadmin Post author

      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
  37. Hagen

    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
    1. zacopressadmin Post author

      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
  38. Hagen

    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
    1. zacopressadmin Post author

      Hi Hagen

      Which data do you exactely send ?

      Try to copy the “program_name.script” file and list here

      Regards
      Lars

      Reply
  39. Hagen

    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
    1. zacopressadmin Post author

      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
  40. Hagen

    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
  41. Hagen

    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
    1. zacopressadmin Post author

      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
  42. Yusuf

    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
    1. zacopressadmin Post author

      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
      1. Yusuf

        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
        1. zacopressadmin Post author

          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
          1. Yusuf AYDIN

            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

          2. zacopressadmin Post author

            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

  43. SJ Teo

    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
    1. zacopressadmin Post author

      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
  44. Arun Kumar Saini

    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
    1. zacopressadmin Post author

      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
  45. Amir masoud

    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 velocity at initial and terminal points.
    So my questions are:
    1- Can I store more than one point in a variable on poly scope of UR5 (perhaps in a thread) and read them during move command (in the main script)?
    2- What makes robot stop at each execution of move command? It is move command itself or the time that poly scope needs to read the next point over TCP/IP connection?
    3- What is the possible solution to send a path to robot (send a single point at a time or the entire path) and then robot follows the path smoothly?

    My script on poly scope:
    If socket_closed ==True
    socket_open(“192.168.0.10″,30000)
    socket_closed = False
    Pointer = 0
    received_data = [0,0,0,0,0,0,0]
    while received_data[0]<1
    received_data = socket_read_ascii_float(6)
    while Pointer < received_data[0]
    move_p[Pointer] = received_data[Pointer]
    Pointer = Pointer + 1
    movej(move_p,a=0.5,v=1.5,r=0.001)
    pose = get_forward_kin()
    socket_send_string(pose)

    Thank you in advance!
    Amir

    Reply
    1. zacopressadmin Post author

      Hi Amir

      Thanks for your question.

      A little theory and then I also need to ask some question to you.

      In every motion there is an “acceleration” – “cruise” and “declaration” which the moving object has to obey (that’s physics) – and in some case this automatically has the consequences of moves that does not look smooth.

      I think I understand your example as a three point move – the question is – how do you need the robot to move through the middle point and how can the robot move through the middle point.

      Some move scenarios that show the extreme:

      If the three point is on a on a strait line and the middle point is on this strait line – then it is easy to get a smooth and fast move through the middle point because the robot does not need to decelerate and accelerate at the middle point – which results in a very smooth move.

      If the three points is still on a line but the start and end point is at the same position and therefore the robot has to reverse 180 degree at the middle point – then it is obvious that the robot has to decelerate (all the way to zero speed) and accelerate up again – which results in a very not smooth move.

      I guess your example is something in between so the middle point is part of a triangle so the robot start at one point and the robot move both x and y up to a transition point and then maybe continue move x and y downwards. Then there is a few questions – do you need the robot to exactly stop at that middle point (zero speed – even if is just a split second) if yes you will obviously have an un-smooth move like above but less dramatic. (Note – Just passing through the exact point and then change direction – needs a stop at the particular point).
      So – if you say you do not need to stop, but you need to change direction – then the question becomes – what path pattern can you accept at the particular middle waypoint – can you accept a slight curved path in the transition – which can be a blend.

      If you can allow the robot to have a “blend” around the middle point then the robot will not exactly go through the middle point, but the moves can be very smooth. You can still get the robot to go through the middle point if your waypoint is away for you desired passage point with the radius of the blend – but then you need to manage that in your waypoint positioning and your move through the middle waypoint will be curved.

      You can also consider the circle moves (MoveP) – which is actually three points i.e. a start point and via point and end point – but the move is circular then – you can have true circle moves and you can have elliptical moves as well.

      You can also consider using StopJ or StopL commands which help to smoothen the declaration.

      With MoveJ or MoveL the robot will try to reach the position required, but in the Move command you can set the acceleration – velocity and blend which can be a help to smoothen the moves.

      MoveJ and MoveL are commands with “absolute” positions in space (either based on X, Y, Z, Rx, Ry, Rz Cartesian coordinates or 6 angle coordinates) – you can also consider to try SpeedJ and SpeedL commands.

      SpeedJ and SpeedL commands does not have absolute positions, but move the robot “in a direction” from the current position – and the move direction can be based on one axis’s (e.g. only move in X axis) or it can be based on all 6 axis at the same time – this can be usefull for very smooth moves.

      The answers to your questions.

      1.
      Well you can store many point in a single variable – and then nest them out into several Move x, y, z, Rx, Ry, Rz (which is waypoints) and the move the robot through these waypoints, but you will still have to consider all I mention above.

      2.
      The Move command it self.

      3.
      Oh – there are many solutions, but I guess you need smooth moves.

      I would use a mix of SpeedJ and MoveJ (or L) and StopJ and StopL and the work with blends.

      It all has to do with your path layout and the accuracy of the absolute path. You need to think about the “change of direction” at the particular waypoint which causes inertia – if the following waypoint is in the same direction as the robot is already moving then you can have higher speed at the waypoint because the inertia will just carry through.

      But if your change of direction is substantial and if you need to be exactly at the waypoint – and if the path out from the waypoint also needs to be specific – yeah then it is obvious that you will experience inertia and have to be more gentle on the declaration and acceleration.

      It is the inertia you need to manage – which is done by controlling speed and also very much the path to and from the waypoint – can it be curved or does it have to be straight?

      Regards
      Lars

      Reply
      1. Amir

        Hi Lars,

        Thanks for your complete answer. Actually, I have read the comments of other users in this forum regarding the movej command. In some of them you have mentioned that using SpeedJ or SpeedL could be very useful. I would be grateful if you could give me a brief example of using this command.
        For example, I want to send a set of points using TCP-IP to the UR5 and want to have a smooth curved path. I am using movej command but can you give me an example with speedj or speedL?

        Kind Regards

        Reply
        1. zacopressadmin Post author

          Hi Amir

          For a smooth curved path I think MoveP and circle move command is a good choice.

          There are some examples of using SpeedJ and L below in the comments.

          Regards
          Lars

          Reply
          1. Amir

            Hi Lars,

            Thanks for your answer. Actually, I have a trajectory with different points which I dont know its curvature. I cannot realize how I can use the combination of movej and speedj commands in my program. I have read the commands but still I cannot use it correctly. I would be grateful if you could describe more about it.

            Kind Regards

          2. zacopressadmin Post author

            Hi Amir

            Some examples I have is the one shown here on the forum and in the comments below.

            Regards
            Lars

  46. Farshid

    Hi Lars,

    I really appreciate for your complete answers. Yes, I have set the IP and Port and as I said I can open the socket and receive data from UR5 but cannot send data. Also, I have checked the joint angles and they have been defined from a specific positions using the robot software.
    I will do your suggestion but do you know which kind of formats are acceptable to be send to UR5?

    Kind Regards

    Reply
  47. Farshid Alambeigi

    Hi Lars,

    I am trying to two-way communication between the UR5 and my computer. On the Computer side, I used MATLAB software to send the data to the UR5. Here are my codes on the computer side and the robot side:

    Robot side :

    def tcpcopy4():
    modbus_add_signal(“192.168.1.11″, 255, 0, 3, “Register0_Activ”)
    modbus_set_signal_update_frequency(“Register0_Activ”, 10)
    modbus_add_signal(“192.168.1.11″, 255, 1, 3, “Register1_Posit”)
    modbus_set_signal_update_frequency(“Register1_Posit”, 10)
    modbus_add_signal(“192.168.1.11″, 255, 2, 3, “Register2_Speed”)
    modbus_set_signal_update_frequency(“Register2_Speed”, 10)
    modbus_add_signal(“192.168.1.11″, 255, 0, 2, “IN_Register0″)
    modbus_set_signal_update_frequency(“IN_Register0″, 10)
    modbus_add_signal(“192.168.1.11″, 255, 0, 2, “Modbus_1″)
    modbus_set_signal_update_frequency(“Modbus_1″, 10)
    set_analog_inputrange(0, 0)
    set_analog_inputrange(1, 2)
    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(“Register0_Activ”,0)
    modbus_set_runstate_dependent_choice(“Register1_Posit”,0)
    modbus_set_runstate_dependent_choice(“Register2_Speed”,0)
    set_payload(0.0)
    set_gravity([-4.8834236075059865, 4.883423607505988, -6.981170943280678])
    Pointer=0
    varmsg(“Pointer”,Pointer)
    move_to_pos=[0.3351,-2.3051,-1.7752,-3.7989,4.8433,2.1007]
    varmsg(“move_to_pos”,move_to_pos)
    received_data=[0,0,0,0,0,0,0]
    varmsg(“received_data”,received_data)
    socket_closed= True
    varmsg(“socket_closed”,socket_closed)
    x=p[-0.06290023646746996,-0.410538998140751,0.17933884868673777,0.10145224411008547,-3.0121549663289353,-0.003893153984806453]
    varmsg(“x”,x)
    $ 2 “BeforeStart”
    $ 3 “movej(move_to_pos)”
    movej(move_to_pos)
    while (True):
    $ 4 “Robot Program”
    $ 5 “move_to_pos≔move_to_pos”
    global move_to_pos = move_to_pos
    varmsg(“move_to_pos”,move_to_pos)
    $ 6 “received_data_1≔received_data_var”
    global received_data_1 = received_data
    varmsg(“received_data_1″,received_data_1)
    $ 7 “Pointer_var≔Pointer_var”
    global Pointer = Pointer
    varmsg(“Pointer”,Pointer)
    $ 8 “If socket_closed_var==True”
    if (socket_closed==True):
    ******************************************************
    $ 9 “socket_open(’192.168.0.100′,30002)”
    socket_open(“192.168.0.100″,30002)
    **********************************************************
    $ 10 “socket_closed_var≔ False ”
    global socket_closed = False
    varmsg(“socket_closed”,socket_closed)
    end
    $ 11 “end_eff≔4″
    global end_eff = 4
    varmsg(“end_eff”,end_eff)
    $ 12 “joint_angles=get_joint_positions()”
    joint_angles=get_joint_positions()
    $ 13 “Wait: 0.1″
    sleep(0.1)
    $ 14 “socket_send_string(‘asking’)”
    socket_send_string(“asking”)
    $ 15 “Wait: 3.0″
    sleep(3.0)
    $ 16 “received_data_1≔socket_read_ascii_float(6)”
    global received_data_1 = socket_read_ascii_float(6)
    varmsg(“received_data_1″,received_data_1)
    end
    end

    Computer side:
    t = tcpip(’192.168.0.9′,30002)

    fopen(t)

    Unfortunately I got the following error:
    RTMachine Not able to open socket socket_0 to host 192.168.0.10 at port: 30002 : connection timed out

    RTMachine socket_read_ascii_float : timeout

    I tried different ports in each side of communication but I got the same error. Also, I could control the robot using matlab and sending the command using one way communication. I really appreciate if you can help me on resolving my problem. Thanks!

    Reply
    1. zacopressadmin Post author

      Hi Farshid Alambeigi

      Tanks for your question.

      Great that you try MATLAB – I have not tired that myself, but here are my comments to your question.

      Port 30002 is a little special on the UR because on that port the robot already runs as a Server and is ready to receive raw script commands – which I guess is what you have used when you say you can control the robot using one way communication.

      So for this I think you need to use another port e.g. Port 30000.

      Then your PC needs to be a Server and the Robot is a Client (opposite as above).

      Therefore I think you need to create a server on the PC typically something with “Bind” and then the IP you refer to on the PC is the IP address of your PC (the server) and the port can be 30000.

      Looking at your robot code – it looks like your PC server is at IP address 192.168.0.100, but you need to look that up on the PC and verify that this is correct.

      When you have created a Server on the PC waiting for incoming data on the port 30000 – Then on the PC you need to create some logic that handle this data and send data back to the robot.

      So to use the port 30002 where the robot is a Server and the PC is a Client to send data in the direction from the PC to the Robot – compared to exchange two way data between the PC and the robot where the PC is a Server and the Robot a Client – is very different programming.

      I have not looked into your robot code, I think it will be good to the Server side running first.

      Regards
      Lars

      Reply
      1. Farshid

        Hi Lars,

        Thanks for your response. Actually, I have set the IP address of my PC and I want to consider it as the server. The problem is that if I consider 30000 as the port of my PC(server), I cannot connect to the robot. However, if I choose 30002 as the PC port I can connect to the robot but I cannot receive the data from it. But I receive some weird characters and also receive the mentioned error.
        Do you have any idea why I cannot connect with port 30000? and if I realized correctly, you are telling me that I should use port 30000 as the port of PC and UR5. is it correct?

        Reply
        1. zacopressadmin Post author

          Hi Farshid

          Yes I use port 30000 both on my PC and the Robot – see this example where the Server is made in Python

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

          I am not sure about MATLAB and how to program or set it up, but it looks like to me that some code is missing on the PC side in order to be a Server.

          They way I use it in above example is that the Server (PC) is listening – and it is the Robot that initiate the communication – and then the server respond to that.

          Regards
          Lars

          Reply
          1. Farshid

            Hi Lars,

            Thanks for your comments. I could figure out how to connect to the UR5 with the PC using port 30000. It is a bit different in Matlab in comparison with Python.
            I could send the data from UR5 to Matlab however I cannot send data from matlab to UR5. I receive this error in my log during sending data to robott:
            RTMachine socket_read_ascii_float: timeout

            First I thought that this error is related to connection problem and especially port 30000. but now I know that I have been connected to the robot because I do not see the open_socket error.
            Would you please let me know whether you have any idea about the mentioned error? Is it related to the format of data that I send?
            I use this command in Matlab to send the joint angles to robot:
            fprintf(t,’(0.5702 , -1.8912, -1.9855, -3.4750, 4.8196, 2.1002)’)

            Kind Regards

          2. zacopressadmin Post author

            Hi Farshid

            Very good that there is progress.

            It looks like it is the MATLAB that is not responding to the robot – or responding with something the robot does not understand.

            I am not sure for the syntax in MATLAB but the only data that should flow on the line and to be received on the robot side is

            (0.5702 , -1.8912, -1.9855, -3.4750, 4.8196, 2.1002)

            For example in my example the data is

            (0.1,0.4,0.4,0.01,3.14,0.01)

            And in Python it looks like this

            c.send(“(0.1,0.4,0.4,0.01,3.14,0.01)”);

            So if fprintf in MATLB means to send on a TCP port that has already been defined with IP address and a port then it looks similar as my c.send

            I assume you have defined t as the server IP address and port 30000 and open the server port beforehand.

            Your data looks OK although the three last elements (rotation vector data) looks a little high, but I think it is OK as they should be able to go to 6.28 radians.

            It will be good if you can see the data that is send out on the TCP line – maybe create an application on another computer that just receive and display the data or use a test software that can display the data received on a port – then you will know what reach the robot and help you in troubleshooting.

            Regards
            Lars

  48. Teguh Santoso Lembono

    Hi, I have several question:
    1. In URScript manual, it is mentioned that we can control UR10 at C-API level. Is there any documentation on this API? How to start using this API? Is the API library already available inside the controller?
    2. There are some researcher that install ROS inside UR10 controller. Is this safe, and does it nullify the warranty? It involves some ssh programming, the link is here: http://wiki.ros.org/ur_c_api_bringup
    3. Is it possible to use UDP socket with UR10 controller?

    Thank you very much!

    Reply
    1. zacopressadmin Post author

      Hi Teguh Santoso Lembono

      Thanks for your question.

      I have no experience with C-API, ROS or UDP and this might change the condition of the robot depending on how you use it.

      UR-GUI or Script programming is safer.

      Regards
      Zacobria.

      Reply
    2. Shuai

      Hi! Do you know how to use C-API to programming? I am working on this too. Can we get a further communication?

      Reply
      1. zacopressadmin Post author

        Hi Shuai

        Thanks for your question.

        Unfortunately I have not been working with C-API programming.

        Regards
        Zacobria

        Reply
  49. jacobnielsen

    Thank you so much for having this site – it makes my effort into script-programming of the UR so much easier. I’m wondering if you are willing to share the script used in the joystick application mentioned above, to which you also provided a youtube link? I’ve been using the speedl command to control the robots speed using sensor-feedback from at tool-mounted force sensor, but would really like to see some other examples on how to use it.

    Right now, I am providing the robot with scripts (whole programs, not just a line at at time) in order to make the movement as fluid as possible with the speedl command. I’m programming in objective c and using the 30002 socket to send the programs to the controller. However, occasionally i get log-errors saying “C19A0: Master had no data to send to joints” and “C29A1: Ethernet package loss detected from PC to robot” – these always com in pairs in the same order as written here? They seem to come at random times, but as I’m a bit uncertain of their meaning, I also do not know what may cause it?

    Best wishes,
    Jacob

    Reply
    1. zacopressadmin Post author

      Hi Jacob

      Thanks for your question.

      The joystick uses a method originating from this example.

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

      Getting the input from the joystick and converting the data into speedl as well.

      I think your method is the same just that the signal provider is to different type of devices.

      I have not experienced the error messages you mention, but it could be a timing issue e.g. if you send new commands before the previous was finished or sending too rapid commands or maybe even empty commands.

      Sometimes it is necessary to incorporate a small time delay e.g. time.sleep(0.001) to make sure the host software is not running faster than the receiver can handle.

      Regards
      Zacobria
      Universal Robots distributor Singapore.

      Reply
  50. Victor

    The float I’m sending from the PC is 88.11

    The “receive data” part of the robot program looks like:
    While camData=”"
    camData:=socket_read_ascii_float(29,socketname)
    ———————————————————————————-
    So I’m sending a float, and with the ‘socket_read_ascii_float’ command, I expect it to read the float sent from the PC.
    If I use ‘socket_read_ascii_float(29,socketname)’ I get ‘TypeError 3: expected lvalue type String but found List’
    If I use ‘socket_read_ascii_float(socketname)’I get ‘TypeError: Not an Int’

    Reply
    1. zacopressadmin Post author

      Hi Victor

      How many elements of floats do you send ?

      29 ?

      In this example I send exactly 6 floats and I prepare to receive exactly 6 floats.

      Receiving command on robot

      Receive_Data = socket_read_ascii_float(6)

      Sending command on external device

      c.send(“(0.1,0.4,0.4,0.01,3.14,0.01)”);

      It is only

      (0.1,0.4,0.4,0.01,3.14,0.01)

      That is transmitted on the line.

      Note that the variable Receive_Data then will contain 7 elements – where the first element will be 6 because 6 elements was received.

      Regards
      Zacobria

      Reply
      1. Victor

        Thank you for your response, I think that I’ve fixed the problem on the robot-side, now my problem is within the computer-side.
        Using Python, I think i’m sending a ‘list of lists’ while I want to send a ‘list of strings’..
        Though I don’t know what I’m doing wrong. If you have any ideas on how to do it in python, that would be great, otherwise, thank you for your help.

        Reply
        1. zacopressadmin Post author

          Hi Victor

          Can you show me an example of a contents of “list of strings” you wish to send ?

          Regards
          Zacobria

          Reply
          1. Victor

            The X coordinate i’m sending is 75.87 . And is a float.
            Python wont let me send it as float or string
            If i convert it into bytes it sends b’75.87′ and the robot can’t read it.
            I’ve tried both socket_read_byte_list, and socket_read_ascii_float

          2. zacopressadmin Post author

            Dear Victor

            I have tried this command from my PC and send to the robot

            sock.send(“(” + str(printx) + “, ” + str(printy) + “, ” + str(rightx) + “, ” + str(righty) + “)”);

            Where for example

            printx

            Is the X variable becoming a string before sending

            On the robot I use this command

            receive_data = socket_read_ascii_float(4)

            Notice that the list in

            receive_data

            will contain 5 elements where the first element is 4 because 4 data was received.

            On the robot the data are already converted to floats.

            Also note that on the robot data needs to be in meter – so if 75.87 means 75.87 milimeter – then you need to divide by 1000 so the robot can understand it.

            Regards
            Zacobria
            Universal-Distributor Singapore

  51. Victor

    Im sending a string from my PC to the robot, the robot reads it using ‘socket_read_ascii_float’ . But getting the following error code: ‘TypeError 3: expected lvalue type String but found List’

    Any thoughts on how to fix the problem?

    Reply
    1. zacopressadmin Post author

      Hi Victor

      Try use

      socket_read_string

      But can you consider sending floats or bytes to the robot ?

      Because you cannot use the strings and convert them to coordinates on the robot – that has to be done before sending.

      Regards
      Zacobria

      Reply
      1. Victor

        Alright, so Im sending a float value to the robot, and reading it with socket_read_ascii_float..
        Still getting the same error as written in my last post.
        I’ve tried sending it as bytes aswell

        Reply
        1. Victor

          Edit: While sending the x-coordinate float data that looks like ’88.11′ ,
          Im getting the error message: ‘TypeError: Not an Int’

          Reply
  52. kayvaan

    Hi,
    actually I’m using UR5 remotely, using 30002 port. Is there a way to determine if the pose I’ve sent to the robot is legal or not, *before* the robot tries to perform it.
    I’d like to prevent Robot/Security blocking issues, and to block wrong poses before.

    Thanks in advance.

    Reply
    1. zacopressadmin Post author

      Hi Kayvaan

      Thanks for your question.

      I would create an equation for a range of the 6 joint angles or coordinates if you prefer pose based on the typical working area for the particular task.

      If the data is outside any of these angles or coordinates – I would make the program so they are not sent to the robot.

      Regards
      Zacobria
      Universal-Robots Distributor Singapore.

      Reply
      1. kayvaan

        Thank you very much, and what about “unreachable pose” and “SECURITY CHECK: joint limit violation” warnings? Do I need to compute inverse kinetics before send my command? Is there a command to do that or I need to do it by myself?

        Thanks in advance

        Reply
        1. zacopressadmin Post author

          Hi Kayvaan

          Yes you will need to calculate that your self – also because there can be a tool that the robot do not know the physics about.

          Maybe follow same principle as the previous idea and then stop shortly before.

          Regards
          Zacobria.

          Reply
      1. Victor

        Thank you for your quick response, I have another question.

        Im sending a string of coordinates to the robot like this: “DET4 1 X:29.43 Y:105.04 VINKEL:314.64 LUTANDE:0″ from a camera. I want to put the X:29.43 and the Y:105.04 in two different variables, and need some help to figure out how to do it.

        Thank you!

        Reply
        1. zacopressadmin Post author

          Hi Victor

          You can send the coordinates as floats without the text and then use then in the robot for positions.

          If you send then as string to the robot you cannot use then for position because on the robot you cannot convert strings to floats – this has to be done before sending to the robot.

          Regards
          Zacobria

          Reply
          1. zacopressadmin Post author

            Hi Victor

            Not that I am aware of on the robot side.

            Regards
            Zacobria

  53. David

    What do i write to save the data in a variable, read by the script “socket_read_string” ?

    Im sending data in form of a string with coordinates to the robot from a PC, and i want to save that string to a variable.
    This is how far i’ve gotten right now:

    socket_open(ip adress,3000)
    socket_read_string(3000)

    Reply
  54. Adam

    Hi Lars,
    is there any way to write entire scripts in PC and somehow upload them to the robot? Can I just copy the text of your examples, make it a script file and execute it on a robot? Or am I forced to create basic structure in GUI and just add some small pieces of script code in “Script Code” structures?

    Thanks!
    Adam

    Reply
    1. zacopressadmin Post author

      Hi Adam

      It depends on how much you need the robot to do.

      You can send an entire script command file to the robot like this example

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

      without having any program on the robot itself. This is limited to a one-way communication and you cannot read input, make conditional branches or loops in this way.

      Otherwise you are right that you need a small program on the robot to call your script file.

      It depends on which script code you want to copy and paste.

      Some examples here show the script code that was created by the UR when the program was created in the GUI – and this code cannot directly be copied and pasted into a script file that is embedded to an exciting program (because it is already part of a complete program).

      But you can copy and paste those examples that is an external script file – and then embed this into the main GUI program. This example show this

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-programming-from-the-teaching-pendant/

      Regards
      Lars

      Reply
      1. Adam

        Thanks – that is what I was aiming at. The complete script cannot be executed. It is the best way to create a framework program via the teaching pendant and then use script structures to call small script chunks – which can be created and edited on the external PC by a user-friendly tool, such as Notepad++.

        Rgds,
        Adam

        Reply
      2. Adam

        Hi. Another challenge – is it possible to re-read script file during execution of the program? I am sending the robot a command via TCP/IP to execute sub-script from the file present on robot controller. After robot is finished I edit this script file and want robot to execute the edited file. But robot only reads the file when you start the program.

        Do you know a solution for this?

        Regards,
        Adam

        Reply
        1. zacopressadmin Post author

          Hi Adam

          Thanks for your question.

          Can you consider sending the changes over a TCP socket connection so you do not need to stop and restart the program ?

          Regards
          Zacobria
          Universal-Robots Distributor.

          Reply
          1. Adam

            Hi.
            There is one huge problem. When you are making movements with approach radius you don’t know when to execute another “movel” command.
            So I was doing something like this (on the robot controller):

            while(1)
            {
            waitForCoordinatesAndRadiusTCP()
            movel(coordinates, radius)
            }

            When radius=0, then robot controller waits until movel is completed and then waits for another set of coords, but when r0, it starts moving and immidiately proceeds to get another set of coords. Then instead of smooth movement I get small jerking movements, because previous destination and movel function is overwritten.
            The most brilliant solution in my imagination was to upload a script file with generated movel commands and just execute it by the robot controller, but then I need to restart the program to re-read the script file.
            How do you solve the problem of smooth movements when you send coordinates one after another?

            Best regards,
            Adam

          2. zacopressadmin Post author

            Hi Adam

            Thanks for your email.

            Try to avoid that it is possible to have a radius of 0 – that might be the reason for the jump.

            A good way to make smooth transitions is to perform a stopl() command e.g. stopl(1.0) in between moves to control the declaration.

            Speedl() is also a great command to make smooth moves.

            speedl([X, Y, Z Rx, Ry, Rz], accl, time)

            Move the tool head straight up (Z axis) at 25 m/s with acceleration 1.2 for 1 second.

            speedl([0.0,0.0,0.025,0.0,0.0,0.0], 1.2, 1.0)

            You might need other values on your robot depending on your seed settings.

            You can insert values for the other vectors and move the axis simultaneously.

            This function is used for the Joystick application seen here

            http://www.youtube.com/watch?v=7dcB62vsTwg

            Regards
            Zacobria
            Universal-Robots Distributor
            Singapore

          3. Adam

            Hi. I found a way to stick to my concept. I upload the file and then use DashBoard server at port 29999 to send “play” command. Then I am monitoring the execution state with “running” query. Works nice!

            Best regards,
            Adam

  55. Francis

    Hi Lars and others forum’s users,

    First of all, thank you for your work. I’m starting now with the UR and your help is well appreciated.
    If it is possible, what is the best way to read from a PC the instant variables’s values, of a program that is running on the robot?.
    Can you shown to me with a little example?

    Thank you very much in advance for your support.

    Reply
    1. zacopressadmin Post author

      Hi Francis

      Thanks for your question and acknowledgement.

      I was a little in doubt for “read from a PC” – do you mean read a variable that is on the PC program to be used over at the robot ? – or do you mean read a variable on the UR to be used in the PC program ?

      I assume it is the last case ie. “read a variable on the UR from a PC”

      It depends a little what kind of variable you need to read.

      1.
      If it is simple information like a short status of the robot – the easiest and fastest is to assign an output and set that in the UR program for certain status and read the UR output from the PC.

      This can be combined using more output e.g. 3 output can tell 8 different status information’s.

      2.
      If it is a more sophisticated variable like a byte or integer then I think you need to consider a Socket port communication and use script commands for example.

      socket_set_var(name,value,socket_name)

      This still have to be an Integer variable.

      3.
      There are also Modbus script commands available if your PC or external device can understand that, but they are kind of bit and byte oriented.

      4.
      To give an example – I would go for making a situation like the Client-Server example and maybe modify a little and create my own protocol and data exchange.

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

      The example here on the Forum can send string variables to the PC. Scroll down where it start to exchange the variable with the Python program below the line

      “UR program that ask for the position coordinates from PC host.”

      Depending on how often you need the data exchange you could use an UR output to tell the PC that there is a new variable to be exchanged or just have the socket port open all the time and constantly send the variables to the PC.

      But I would design my programs so there is only exchanged data when there is a change in the variable and when it is really necessary to exchange the variable – in order to keep the resources consumption lower.

      Regards
      Lars

      Reply
  56. Peter L.

    Hello Lars,
    I can only send Data like ..(0,0.5,0.5,0,3.14,0) . There are two dots in before the first bracket. It seems that the UR10 controll cannot read that Information. Can that be. Need the command socket_read_ascii_float the first Information in brackets? Or is that irrelevant?
    Thank you!

    Reply
    1. Peter L.

      Hello Lars,
      after a Long while I figured it out. It seems that There is no way. If I use your Code from the tutorial above I have to make sure that the command Begins with a ( . In my case I had to delete some functions in my external device. SO that it was possible to send
      (xxx
      instead of
      ..(xxx
      Thank you for your Support!

      Reply
      1. zacopressadmin Post author

        Hi Peter

        Thank you very much and thanks for sharing your experience.

        Good that you have found out.

        I would think that it should be possible to design the program on the UR side so this program can accept a . (dot) before the ( (parentheses) and even maybe so the UR program expect this, but then you need to have some small code before that receives the . (dot)

        Regards
        Lars

        Reply
  57. Peter L.

    Thank you Lars!
    how does the Robot control differ one number from the other. I mean how do you know, that there are 8 elements in my Array — in the paranthesis there are six numbers. but what about the comma and the paranthesis itself. The two hexadezimal Bytes my external device put on the beginning are not ASCII coded. The Robot will probably read a other sign. Is that a Problem even if i want the Robot to ignore the first elements?
    I think i do to lnow how the command socket_read_ascii_float() works and how he Counts the number of the Array. I think that would help me a lot.
    Does the UR10 initiates the Connection?
    I cannot Change the number from (6) to (8)… That accures an error like “resizing list is not supported”
    Thank you for your Support!

    Reply
    1. zacopressadmin Post author

      Hi Peter

      In my example my command on the external device is

      c.send(“(0.1,0.4,0.4,0.01,3.14,0.01)”);

      and it is only

      (0.1,0.4,0.4,0.01,3.14,0.01)

      That is send over the TCP connection.

      On the UR it is the command

      Receive_Data = socket_read_ascii_float(6)

      That expect to receive 6 elements – so maybe you need to change that to

      Receive_Data = socket_read_ascii_float(8)

      in your case – or maybe 9 if you keep the number 6 in your array.

      The variable

      Receive_Data

      contains the received array – and a little special thing is that it is actually an array with 7 element because the first element tell how many element will follow – so

      Receive_Data

      Is actually

      (6, 0.1,0.4,0.4,0.01,3.14,0.01)

      So my program uses element 0 which is 6 as the amount of loops to nest out the data with

      Pointer=pointer+1

      Reading the elements one by one until pointer is 6 and therefore have read all elements.

      In the loop the elements are put into anther variable

      Move_To_Pos

      by

      Move_To_Pos[Pointer] = Receive_Data[Pointer+1]

      When all 6 elements has been loaded into

      Move_To_Pos

      Then this variable is used to move the robot

      movel(Move_To_Pos)

      Regards
      Lars

      Reply
  58. Peter L.

    Hello Lars,
    Thank you very much for your answer. I try to send aascii code from my external device to the ur10. The code consists of 20 hexadezimalvalues. When I translate it with other Tool I can see that i am sending Values in Brackets like (1, 0.4, 3.14, 0, 0, 0). BUT as you can see the 1 consists only of one two-digit hexadecimal value, but the 3.14 consits of four. Could that be a reason why the Robot dont react on the command? I didnt put the” on the beginning and at the end, because in the example i didn’t see them. Are the ” necessary?
    The second Thing is that my external device automatically put two Bytes in the code. These two Bytes tells the length. What I now tried to do is, that i changed your code from above and said “while pointer < Receive_Data[3]"
    Because on [0] the UR10 puts number automatically and on [1] and [2] my external device. So I put the "6" by myself. Now my external device sends a code like

    21 21 6(1, 0.4, 3.14, 0, 0, 0)

    I use the TCP protocoll to send the Data.
    Have you an idea why it doesn't work. The Port is 30000.
    Thank you!

    Reply
    1. zacopressadmin Post author

      Hi Peter

      There are several things to check.

      1.
      You need full control over what is send to the robot – if there is automatically extra data or characters inserted – then it is very likely the robot does not understand the data – and therefore do nothing.

      If that’s the case you need to design the program on the robot side to be able to accept or discard such extra data and I think that’s what you are trying to do.

      2.
      There are different ways to send data to the robot over the TCP socket either raw script code or your own data to a program on the robot.

      It looks like you are trying to use a modified version of the example here on the Forum – which is good and then it will be easier to design the robot program to accept exactly the data you send.

      No you do not need to send the “” – that’s due to Python in my case on the sender side.

      I do not think you need to put the 6 by your self because the first position in the received array will be the value for the number of received data.

      So if you exclude the 6 – then the number of elements in your transmitted array is 8 – and position 3 is the first element containing position data.

      So keep the “while pointer < Receive_Data[0]” , but try at set pointer=2 instead of pointer=0 because then you start reading from the array at position 3 in the array (because of pointer=pointer+1) and it will read all elements up to pointer =8.

      However there is one thing you need to handle – does your external device send the parentheses () ? because then you need to count then as elements in the array and you might need to change the value of the initial pointer.

      Regards
      Lars

      Reply
  59. Peter L.

    Hello,
    is it possible to send a Bit or a Byte to a defined variable in the PLC? I think it shoul be possible with socket_senc_byte()
    What does the socket_name stand for ans where it is defined? Can it be defined in the PLC?
    Thank you

    Reply
    1. zacopressadmin Post author

      Hi Peter

      Thanks for your question.

      By PLC I assume you mean an external PLC. I am not so familiar with PLC so I will call it an external device which can be PLC or PC.

      One way to do it is to have a server on the external device.

      Then on the UR You define the socket by a socket open with the IP address and port number

      socket_open(“192.168.0.100″, 30000)

      Then you can send a Byte to that port

      socket_send_byte()

      and then store it in the desired variable on the external device.

      Regards
      Lars

      Reply
  60. Peter L.

    Hello Lars,
    thank you for your tutorial, it helped a lot, but there are a few things I didn’t understand, perhaps you can help me.
    1. When I tried to understand the code under “def receive_3_coordinates_from_host():” I didn’t understand the while function with the pointer.
    The pointer is compared with an integer in Receive_Data[0]. That means that this int says how many numbers are in the Pose. Shouldn’t there be 7 int. Becaus the first one says just that 6 number are to Transfer to the adresses of Move_To_Pose.
    That means that Recerive_Data should be socket_read-ascii_float(7). Because in my Manual i read that it doesn’t Count from 0 but by 1. I am a Little bit confused by that while Loop .

    2. In my Manual I couldn’t found “varmsg” and get_forward_kin(). What do they stand for?

    Thank you very much
    Peter

    Reply
    1. Peter L.

      O.k. the first question is cleared! I didn’t know that this function automatically list the amount of numbers on the first [0] adress.

      Reply
      1. zacopressadmin Post author

        Hi Peter

        get_forward_kin()

        was used in previous software version

        Has now been changed to

        get_inverse_kin(x)

        Regards
        Lars

        Reply
    2. zacopressadmin Post author

      Hi Peter

      Thank you very much.

      1.
      Yes I see that you have figured this one out – the first element is information for how many elements follow.

      2.
      The Varmsg will display the value of the variable inside the Variables screen and it will be broadcasted out on port 30001.

      Example:
      varmsg(“Pointer”,Pointer)

      This statement will display the text – Pointer – and the value of Pointer

      When you start using Variables – and extra “Variable” Tab appear – see this link for info.

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/variables/

      Regards
      Lars

      Reply
      1. Mohamed

        Hello Lars,
        Here above, I noticed in the second point you’ve mentioned :
        2.
        The Varmsg will display the value of the variable inside the Variables screen and it will be broadcasted out on port 30001.
        Now, I’m considering the robot runs as a server and my PC runs as client, my question is how to get the variable via the port 30001? which command should I send or use?
        Thank you
        Best regards

        Reply
        1. zacopressadmin Post author

          Hi Mohamed

          Thanks for your question.

          The data is streamed out automatically. If you read on port 30001 you can see a flow of data. If you use the program sockettest you can see the data. I do not have any documentation how the data is organised.

          Alternatively you can make your own socket communication and exchange only the data you need in your own protocol.

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

          Reply
  61. Romana

    Hi all!

    My problem is as follows:
    I’d like to create two sockets from a UR script, one for sending values, and one for receiving values.
    Is there a possibility to create two sockets from a UR script? Because the line “socket_open(HOST, PORT)” gives no reference to a socket object, an the method socket_send_int addresses a globally socket reference.

    Thanks in advance,
    Regards,
    Romana

    Reply
    1. zacopressadmin Post author

      Hi Romana

      Thanks for your question.

      Yes since UR software version 1.6 multiple Socket ports are supported.

      On the robot side you can indicate each port like this

      socket_open(“192.168.0.100″, 30000)

      On the PC side (if Python) you can indicate the port like this

      HOST = “192.168.0.100″
      PORT = 30000

      s = socket.socket()

      s.bind((HOST, PORT))

      Then for example create Host_1, Port_1 and Host_2, Port_2 (or other combination of host)

      Regards
      Lars

      Reply
  62. Matt

    Hello Lars,

    great jopb on these tutorials, they really helped me along.
    I have a question regarding the connection between a host and the UR10. I am sending position data to the robot every time the robot sends a newline, like you do in this tutorial (on port 30000), but at rate of approximately every 0,2 s. I use the servoj funtion to move the robot accordingly (in another thread). 90% of the time his does work ok, but sometimes, there is a communiation error and the arm “jumps” a bit.
    Any idea how I could incorporate high speed communication (25-50 Hz) with a host ? The errors are very unpredictable, which makes it even more annoying….
    My communication is basically one way, so would you think sending data to port 30002 cold help because it bypasses the Polyscope software ?

    Thanks,

    Matt

    Reply
    1. zacopressadmin Post author

      Hi Matt

      Thank you very much and thanks for your question.

      Maybe the jump is because you send a new position before the previous is fully executed ?

      I would consider making the communication two way so you create a handshake and verification check that the robot has reached the positions you command before moving on.

      The port 30002 I consider to be used for test to see the robot is moving and communication is working, but for production I would create a more solid two way hand shake.

      You can consider if it is possible to send more than one command at the time and receive that on the robot in different variables and then let the robot execute such bulk of commands.

      Regards
      Lars

      Reply
  63. Pablo

    Hi,
    I am trying to do a while sentece with string condition but seem that doesnt work, always jump this condition, Anybody could tell me what i am doing wrong?

    While conex != “CONECTOK”
    socket_open(“192.168.0.10″,30000″)
    socket_send_string(“WCONECT”)
    conex=socket_read_string()
    varmsg(“conex”,conex)

    I have a VB.NET application that send “CONECTOK” and I know this work fine when I dont use while sentence (conex variable load with “CONECTOK)

    Thanks

    Reply
  64. alberto

    Hello Lars,

    I am connecting to the robot using several socket connections. Each socket connection is handled by a thread. I use the following code to receive data from the pc for each thread:

    thread robotThread1():

    while(not (socket_open(ip_address, port_robot1, socket_name = “socket1″))):
    sync()
    end

    while True:
    sync()
    # wait to receive data from the PC
    data = socket_read_ascii_float(dataLength, socket_name = “sokect1″)
    # do something with this data …
    end

    end

    All the threads connect to the PC server, using the same IP address and different port numbers. I have not problems with the connection of each thread. But I have problems receiving the data with the “socket_read_ascii_float” function, it seems like they interfer each other becouse if I run any one thread separately it works OK.

    Do you have any suggestion?
    Thanks in advance.
    Aberto

    Reply
    1. zacopressadmin Post author

      Hi Alberto

      Thanks for your question.

      Threads are virtually running and the same time – so when having several threads there is a risk of conflicts.

      Can you use Sub routines instead ? – then you have better control over the timing when each of the are executed one by one.

      Regards
      Lars

      Reply
  65. Robbert

    Hey Lars,

    Yeah i thought the same thing so i already tried every port from 30000 to 30005.
    I’m getting the same error everytime.
    Also on the client test i only get some really strange code back from the robot. Do you know what kind of format that is and if i can convert that to something i could use?

    regards,
    Robbert

    Reply
    1. zacopressadmin Post author

      Hi Robbert

      I can also create a situation where I get the error you are experiencing – for example if I use other IP addresses or ports.

      Make sure the IP addresses is the server IP address i.e. the PC.

      Consider to try another IP Subnet.

      Regards
      Lars

      Reply
  66. Robbert

    Hey Lars,

    Currently i’m using 169.254.57.81 for the pc and 169.254.57.80 for the robot.
    And i’m communicating through port number 30003

    Regards,
    Robbert

    Reply
    1. zacopressadmin Post author

      Hi Robbert

      Can you try to use port 30000 ?

      If the port is reserved or in use I think you will get this error.

      Regards
      Lars

      Reply
  67. Robbert

    Hey Lars,

    you were right the apostrophe was missing! Must have overlooked that..
    Now im getting the error that the variables ( Move_To_Pose, Receive_Data and Pointer arent initialized)

    Regards,
    Robbert

    Reply
    1. zacopressadmin Post author

      Hi Robbert

      In the Init variables section set the variables to a value

      Move_To_Pos=p[0, 0.4, 0.4, 0, 3.14, 0]
      Pointer=0
      Receive_Data=[0, 0, 0, 0, 0, 0, 0]
      Socket_Closed=True

      Regards
      Lars

      Reply
      1. Robbert

        Hey Lars,

        Thanks that solved the issue!
        Still i get an error when i try to use the sockettest program (i’m using the same one as u are)
        When i try to connect as client i get only computer language. But when i try to connect as server i get the following error: cannort assign requested adress: JVM_Bind
        I dont know why it gives me this error when it works perfectly fine when i try to connect as client.
        Hope u can help me with this final step.

        Regards,
        Robbert

        Reply
        1. zacopressadmin Post author

          Hi Robbert

          Use only the “Server” screen and type in the IP address and port number.

          Click ”Start listening”

          Make sure this is cone before starting the Program on the robot side.

          Then start the program on the robot side – and send the coordinates from the PC as shown and click ”send”

          ur-script-client-server-receive-3-coordinates

          Regards
          Lars

          Reply
          1. Robbert

            Hey Lars,

            Yeah thats the way i tried it but i still get the jvm_bind error.
            So i cant start listening

            regards,
            Robbert

  68. Robbert

    Hi,

    Your guides has been of so much help so thank you for that.
    Still I got a couple of questions..
    I got the communication up and running with a java/robot connection. I can control the robot and put outputs on and off. Now i am trying to get the robot to tell me about its current location and which inputs are high and low. Is is possible to receive information about the robot current location and the inputs without a program running on the robot? And which command do i need to send to the robot to get the input info.(For the current position its c.recv(1024 if i understand your program.. also what does that command stand for?)

    Keep up the good work and many thanks!
    Robbert

    Reply
    1. zacopressadmin Post author

      Hi Robbert

      Thank you.

      To receive data from the robot I would use the example called ”Client-Server” on this forum, and then yes you need a program to run on the robot to serve those data for you on the host (PC).

      The python command c.recv(1024) does receive data from the robot on port 30002 as used in the ”Script via socket connection” which are valid status data from the robot, but I have no experience in using these data.

      I will categories the example ”Script via socket connection” as a kind of one way communication i.e. you can set I/O ports and make moves, but it is not easy to use to receive data from the robot.

      To receive data from the robot it is better to use the ”Client-Server” example because then you can have a two way communication to get I/O status and position information and you can define your own protocol for the exact data you need to exchange.

      Regards
      Lars

      Reply
      1. Robbert

        Hi,

        Thanks for responding.
        So if im correct there isnt a simple way just to get I/O status from the robot?

        Regards
        Robbert

        Reply
        1. zacopressadmin Post author

          Hi Robbert

          You’re most welcome

          I think the Client-Server method is quite simple :) :)

          There might be a way to read directly from the registers, but I have no experience in that. If you find out – let me know.

          Regards
          Lars

          Reply
          1. Robbert

            Hey Lars,

            I will if i do. Because in my opinion it should be possible. As a start i’m trying it your way. So i put in the program by the example trough the touchscreenpanel.
            But i get an SyntaxError: line 1 def *Programname*():

            i was hoping you could help me with that problem.
            I’ve saved my programm on a usb and opend the script file in a notepad. the program is as such:

            def clientserver():

            set_analog_inputrange(0, 0)

            set_analog_inputrange(1, 0)

            set_analog_inputrange(2, 0)

            set_analog_inputrange(3, 0)

            set_analog_outputdomain(0, 0)

            set_analog_outputdomain(1, 0)

            set_tool_voltage(0)

            set_runstate_outputs([])

            set_payload(2.5)

            set_gravity([0.0, 0.0, 9.82])

            Gereedschap=get_forward_kin()

            $ 1 “VoorStart”

            $ 2 “BewegenJ”

            $ 3 “Waypoint_1″
            movej([1.920437743829078, -1.7750072509423163, 1.6970863253375148, -1.7767565448327556, -1.3298897371296272, 0.13150940732653288], a=1.3962634015954636, v=1.0471975511965976)

            while (True):

            $ 4 “Robotprogramma”

            $ 5 “Move_To_Pos:=Move_To_Pos”

            global Move_To_Pos = Move_To_Pos

            varmsg(“Move_To_Pos”,Move_To_Pos)

            $ 6 “Receive_Data:=Receive_Data”

            global Receive_Data = Receive_Data

            varmsg(“Receive_Data”,Receive_Data)

            $ 7 “Pointer:=Pointer”

            global Pointer = Pointer

            varmsg(“Pointer”,Pointer)

            $ 8 “Als Socket_Closed= True ”

            if (Socket_Closed == True ):

            $ 9 “socket_open(’169.254.57.81, 30000)”

            socket_open(“169.254.57.81, 30000)

            $ 10 “Socket_Closed:= False ”

            global Socket_Closed = False

            varmsg(“Socket_Closed”,Socket_Closed)

            end

            $ 11 “pose_position = get_forward_kin()”

            pose_position = get_forward_kin()

            $ 12 “joint_position = get_joint_positions()”

            joint_position = get_joint_positions()

            $ 13 “socket_send_string(pose_position)”

            socket_send_string(pose_position)

            $ 14 “Wachten: 1.0″
            sleep(1.0)

            $ 15 “socket_send_string(joint_positions)”

            socket_send_string(joint_positions)

            $ 16 “Wachten: 1.0″
            sleep(1.0)

            $ 17 “socket_send_string(‘Asking_Waypoint_1′)”

            socket_send_string(“Asking_Waypoint_1″)

            $ 18 “Wachten: 3.0″
            sleep(3.0)

            $ 19 “Receive_Data = socket_read_ascii_float(6)”

            Receive_Data = socket_read_ascii_float(6)

            $ 20 “Pointer:=0″
            global Pointer = 0

            varmsg(“Pointer”,Pointer)

            $ 21 “Als Pointer < Receive_Data[0]"

            global thread_flag_21 = 0

            thread Thread_if_21():

            $ 22 "Move_To_Pos[Pointer]=Receive_Data[Pointer+1]"

            Move_To_Pos[Pointer]=Receive_Data[Pointer+1]

            $ 23 "Pointer:=Pointer+1"

            global Pointer = Pointer+1

            varmsg("Pointer",Pointer)

            thread_flag_21 = 1

            end

            if (Pointer < Receive_Data[0]):

            global thread_handler_21 = run Thread_if_21()

            while (thread_flag_21 == 0):

            if (not(Pointer < Receive_Data[0])):

            kill thread_handler_21

            thread_flag_21 = 2

            else:

            sync()

            end

            end

            else:

            thread_flag_21 = 2

            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 "Wachten: 3.0"
            sleep(3.0)

            $ 28 "Receive_Data = socket_read_ascii_float(6)"

            Receive_Data = socket_read_ascii_float(6)

            $ 29 "Pointer:=0"
            global Pointer = 0

            varmsg("Pointer",Pointer)

            $ 30 "Als Pointer<Receive_Data[0]"

            global thread_flag_30 = 0
            thread Thread_if_30():

            $ 31 "Move_To_Pos[Pointer]=Receive_Data[Pointer+1]"

            Move_To_Pos[Pointer]=Receive_Data[Pointer+1]

            $ 32 "Pointer:=Pointer+1"

            global Pointer = Pointer+1

            varmsg("Pointer",Pointer)

            thread_flag_30 = 1

            end

            if (Pointer <Receive_Data[0]):

            global thread_handler_30 = run Thread_if_30()

            while (thread_flag_30 == 0):

            if (not(Pointer <Receive_Data[0])):

            kill thread_handler_30

            thread_flag_30 = 2

            else:

            sync()

            end

            end

            else:

            thread_flag_30 = 2

            end

            $ 33 "varmsg('Move_To_Pos',Move_To_Pos)"

            varmsg("Move_To_Pos",Move_To_Pos)

            $ 34 "movel(Move_To_Pos)"
            movel(Move_To_Pos)

            $ 35 "socket_send_string('Asking_Waypoint_3')"

            socket_send_string("Asking_Waypoint_3")

            $ 36 "Wachten: 3.0"

            sleep(3.0)

            $ 37 "Receive_Data = socket_read_ascii_float(6)"

            Receive_Data = socket_read_ascii_float(6)

            $ 38 "Pointer:=0"

            global Pointer = 0

            varmsg("Pointer",Pointer)

            $ 39 "Als Pointer<Receive_Data[0]"

            global thread_flag_39 = 0

            thread Thread_if_39():

            $ 40 "Move_To_Pos[Pointer]=Receive_Data[Pointer+1]"

            Move_To_Pos[Pointer]=Receive_Data[Pointer+1]

            $ 41 "Pointer:=Pointer+1"

            global Pointer = Pointer+1

            varmsg("Pointer",Pointer)

            thread_flag_39 = 1

            end

            if (Pointer <Receive_Data[0]):

            global thread_handler_39 = run Thread_if_39()

            while (thread_flag_39 == 0):

            if (not(Pointer <Receive_Data[0])):

            kill thread_handler_39

            thread_flag_39 = 2

            else:

            sync()

            end

            end

            else:

            thread_flag_39 = 2

            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

            Hope to hear from you soon and keep up the good work!
            Regards,
            Robbert

          2. zacopressadmin Post author

            Hi Robbert

            I find this to be an issue to look at

            socket_open(“169.254.57.81, 30000)

            Either an apostrophe missing or one too much

            I am not sure how you typed in and where the ”Threads” are coming from.

            If you are not sure where the syntax error is then it is better to move forward a little slower and test run the program often – because using script there is not much information where the error is.

            Regards
            Lars

  69. Katharina

    Hello Lars,

    thanks for this great support site! I find a lot of hints that are useful for me.

    There’s one thing I can’t figure out, though. I am using threads to read values from the robot at the same time as I am sending commands by using the movej command. It works well so far, except for the following problem:
    1.) When I am sending: self.sock.send(‘movej(p[0.6, 0.6, 0.2, 0.62, 5.25, 0.17])\n’) then the position that the robot robot ends up is: [0.6, 0.6, 0.2, -0.1166, -0.986, -0.031], where the vector defines the tool position [X, Y, Z, Rx, Ry, Rz]. So the question is:
    Q.) Why is the measured value of Rx, Ry, Rz different from the send values? It works well with X, Y, Z, i.e. the robot follows the values I give in. But the rotation values of the tip are not consistent. Do you have any idea why this happens?

    Best,
    Katharina

    Reply
    1. zacopressadmin Post author

      Hi Katharina

      Thanks for your question.

      Your understanding of the coordinates seems correct, but I am wondering if p[0.6, 0.6, 0.2, 0.62, 5.25, 0.17]) is a valid pose for the robot ?

      Can you manually put the robot in this position ?

      A good test is to put the robot in a desired pose (position) and the readout the X, Y, Z, Rx, Ry, Rz from the move screen and then see if you can move there with your command.

      Are you calculating the coordinates based on the robot physics ?

      The 6 elements must be somewhere the robot physically can go to.

      Regards
      Lars

      Reply
  70. pascal

    Hello

    I dont really know how to start writing. Trying to understand the way the scripts needs to be writed. In java we declare the connection to a new object. Then use a printwriter as a new object to write to the port. How can I do that in the script for the robot?

    If I want to open a communication on the robot that only sends a message to my pc, the script should it look like this?:

    Socket_connection = socket_open(127.0.0.1, 30000) // Do I have to connect to a server or a
    //client?
    Writing_socket = socket_send_string(Hello Hello, 30000) // Sending over port 30000
    sleep(4000)

    Or can I just say in a scriptfile/line :
    socket_open(xxxx)
    socket_send_string(hello hello, XXX)

    Im keep getting Syntaxerror: line 1. Im not aware of what Im doing wrong actually neither if I do it right.

    On the computer I use the socketTest api to start a server that listens on IP 127.0.0.1 Port 30000.

    Thanks for the great help.

    Reply
    1. zacopressadmin Post author

      Hi Pascal

      I recommend that you get familiar with the robot GUI programming first. Put your PC aside for a short while and focus just on the robot teach pendant first.

      Try to make a simple program in the robot GUI for example with two waypoints first. When you save the file on the robot – actually 3 files is created at the same time.

      You can save the files on a USB drive on the robot – and take the USB drive to your PC and open the files with a simple editor e.g. Notepad and see what is inside the files.

      x.urp file is a binary file that the robot use for execution and this file looks like many random characters in a mix.

      x.txt files is a very simple text representation for your program which is very good for documentation.

      x.script file is also created. This is great because in this x.script is actually the script program for the program you made in the GUI – and study this file for how the robot expect the script commands to be.

      Then your second program you try to set an output e.g. set output 8 high in the beginning of the program and set it low again at the end of the program – and then look again in the script program for how the robot has inserted this as script command.

      You should find something like this in the script file

      set_digital_out(8,True)

      Now make your third program on the robot – try to delete the GUI line that set the output 8 high -and replace it with a Script line and in the script line you write

      set_digital_out(8,True)

      And then run the program and confirm that it is working as before – so these two programs does exactly the same, but has been made in two different ways.

      Then consult the script manual and verify that the command you made is how the script manual describe.

      When the robot make these script files it is a great help to use when you wish to learn about the script commands and how the robot expect them to be.

      Try to get some small success by having just very small programs that are working and study the script files.

      Then you will see that you cannot use something that looks like Java syntax on the robot. The robot script syntax is something more like Python – so when you are on the robot – then don’t think Java.

      Then move on to the PC side.
      Here you can think Java for your program on the PC (I assume you are using Java) or you can use almost any other language or test program you like.

      But over on the robot you still have to think like Python.

      For sending from the robot to the PC:
      Your second idea is almost correct – you will need to open a socket like in the client server example which means that on the robot you need to do like this.

      socket_open(“192.168.0.100″, 30000)
      socket_send_string(“Hello Hello”)

      (Note you need to put in the IP address of your PC and the IP address of the robot needs to be in the same Subnet i.e. make sure the IP addresses are close to each other – I use 198.168.0.9 on the robot).

      Use proper IP addresses – maybe it is just example you mention, but IP address 127.0.0.1 seems just to be the loop back kind of dummy address – us a proper IP address on both machines on the same network.

      For sending from the PC to the robot:
      Now you can move forward and you can send the same command

      set_digital_out(8,True)

      via the TCP port 30002 and verify that the robot actually set output 8 high

      and to set it low

      set_digital_out(8,False)

      For the commands – try not to guess – look at the examples and consult the script manual and use small step by step and see something working before moving on to next.

      Regards
      Lars

      Reply
  71. pascal

    Hello

    Is there a way to convert the scriptcode to urp files? As far as I can see and know is using a part of a scriptcode right after a waypoint. But how can we implement a writin script directly to the GUI of the robot? Like doing with the P040413_sockettest_receive_3_coordinates(): program and just implement it in de UR GUI and see it as a common robot program.

    I might have overlooked it.

    Thanks again
    Kind regards
    Pascal

    Reply
    1. zacopressadmin Post author

      Hi Pascal

      Yes you can write script commands directly into the GUI inside Polyscope.

      You can mix the normal GUI way of programming with direct script commands. Choose the ”Script” object from the GUI and write the script command manually. You can do that line by line or you can import a file with many script commands.

      There is an example on the forum at this link

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/513-2/

      Regards
      Lars

      Reply
  72. Khattak

    Hey Lars,

    I hope all is well. Thank you for your help so far! I am really close. I have been able to map out the robot and the static environment around it. On the computer side, I can tell when a part of the robot is close to the obstacle. I am trying to get the robot to stop now. I have tried the stopj and stopl commands but they don’t seem to halt the robot. I have tried putting them as a thread and in the main program to work when the computer gives a flag but the robot still keeps moving. If you have any ideas, that would be amazing. Thanks!

    Reply
    1. zacopressadmin Post author

      Hi Khattak

      Thanks for your question and good to hear that you are successful and near the goal.

      ”stopj(a)” and ”stopl(a)” does not stop the program execution – as soon these commands has been executed i.e. they stop the robot ok, but the program execution continues after that.

      Instead you can think about using the ”Halt” command, but that terminates your program execution and I am not sure if you want that.

      Or you can use a ”Popup” messages when the incident occur – which stops the program and you can display a messages for what the operator needs to de.

      Notice:
      If you really want to use a way of using ”stopx(a)” them I think you need to change the program logic and not use Thread because then the robot will complain and display an error messages like ”Another Thread is already controlling the robot” – this does not work. Easier to understand this way – if you have a waypoint in your main program – and then you have another waypoint in the Thread that is different than the waypoint in the main program – this does not make sense because the main program and Thread runs parallel – and the robot cannot be a two different physical location at the same time – hence there is an error messages.

      Great idea you and program you got – share the program.

      Regards
      Lars

      Reply
  73. Khattak

    Hey Lars,

    Thanks for your specs. I am very close. I just have trouble figuring the tool pose coordinates now (if both w1 and w2 are not 0). I will let you know how that goes.

    Khattak

    Reply
  74. Khattak

    Hey Lars,

    I have figured out the geometry to determine the joint angles. My calculations are off because of my measurements. I have looked online but cannot seem to find any manuals that give the length between the joints in UR5. My length measurement physically seems off and the calculations using length values from the touch screen (setting all axes but one to 0) also fives off numbers. I was hoping you could help with that. Are there any spec info on the robot available? Thanks!

    Khattak

    Reply
    1. zacopressadmin Post author

      Hi Khatak

      Thanks for your question.

      See if you can use the dimension from this drawing.

      Regards
      Lars

      Reply
      1. Daniel

        Hello,
        Do you know where I might find a similar dimensioned drawing for the UR10 ?
        thanks,

        Daniel

        Reply
        1. zacopressadmin Post author

          Hi Daniel

          Thanks for your question. See the dimension of UR 10 below.

          universal-robots-zacobria-ur10-dimensions

          Regards
          Lars

          Reply
  75. Khattak

    Hey Lars,

    I would like to avoid collision not just with the tool but the entire robot. This means I don’t want any part of the wrist, shoulder, elbow, even their lengths hitting the obstacles when moving. I am thinking of using the joint positions and mapping out the robot but is there any other way or technique that would be simpler?

    Thanks!

    Khattak

    Reply
    1. zacopressadmin Post author

      Dear Khattak

      Thanks for your comments.

      Your idea is very good and it should be possible to create a 3D model of the robot while moving – and also create a 3D model of the obstacles – and then make sure these models does not collide while moving by means of not sending the robot model into touch with the obstacle model.

      I was also thinking that – As standard the robot gives you the X, Y, Z which is the end of tool head position. Maybe you can mathematically create a X, Y, Z position for each of the 6 joints positions based on the joint angle position and then also mathematically create a line in between these joint X, Y and Z position making up 6 lines representing the robot – and then thereby mathematically know each X, Y, Z position on these 6 lines. You do not need to know each X, Y, Z position dot by dot within millimetres on these line of the structure – because you will need some gap to the obstacle anyway – so if a dot on the line is near the obstacle – then a dot 50mm away from your test dot is also near the obstacle which is good enough to know and then not get any closer – depending on how accurate you want your avoidance systems to work.

      Keep in mind that the X, Y, Z position the robot gives you as standard – is the position of the end of tool head – which does not directly tell you the pose of the robot. The robot can have many pose for the same X, Y, Z position, the position of the arms can be different and therefore you are right that one kind of pose could possible conflict with an obstacle – whereas another pose would be fine.

      You can get better knowledge of the robot pose by using the rotation vectors as well called Rx, Ry, Rz and you can study that on this page

      http://en.wikipedia.org/wiki/Axis_angle

      Good luck with your equations and vectors – there is a lot of calculation to do :)

      Regards
      Lars

      Reply
      1. Khattak

        Hey Lars,

        Thanks for the heads up! I really appreciate your assistance. I will let you know how it progresses.

        Khattak

        Reply
  76. Khattak

    Hey Lars,

    I hope all is well. I am starting to figure some parts out. I am thinking about doing some collision avoidance stuff with this robot. The idea is for the robot to know positions where there are objects, and if the objects are in the path when movel command is used, the robot should stop close to the object and go around it. Are there any examples or starting point on which I can build on?

    Thanks for all your help!

    Khattak

    Reply
    1. zacopressadmin Post author

      Hi Khattak

      Thanks for your question.

      There are different ways to handle this according to your situation.

      1.
      If you know the obstacles and thereby know (or calculate) their X, Y, Z positions – it is fairly easy to make sure the robot does not go there by making sure there is no waypoints beyond the obstacle.

      If the obstacles are dynamic and can move – you will need an external method to tell you where the obstacles are e.g. a vision camera that provides you the X, Y and Z position of the obstacle and then make conditional check on the X, Y or Z position in your robot program and spilt your waypoints up in zones.

      Using the X axis as an example. For example if you get information that there is an obstacle at 300mm out on the X axis you can make sure your waypoints that is further out than 300mm is under a conditional check. Create a variable where you store the X position for the obstacle and then make a check on the obstacle position.

      If Obstacle > 300
      Waypoint (Under here only waypoint in zone before 300mm on X axis.

      2.
      You can also do it the other way around i.e. tell other equipment (maybe a second) robot where you are – and therefore telling the other robot not go into a zone while you are there.

      The can be done by simply setting an output when you are in a specific zone. The program example below shows this.

      So when this output is high – can be used as an input on the other robot as a signal and information for where this robot is i.e. a dynamic position check – e.g. for Safety Envelope.

      By using a thread it is possible dynamically to set an output if the position of TCP (Tool Centre Point) exceeds a given value.
      The position of TCP can be defined either as Joint positions or in Cartesian coordinates (XYZ)

      The output can for example also be used as an interrupt to a moulding machine, CNC machine or other machinery, to prevent them from starting, when the robot is inside their working area.
      In this example, the robot moves between two waypoints.

      As long as the position of Base joint is less than 0 radians, output DO[0] is low.
      If the position of Base joint exceeds 0 radians, the output will be set to high.

      universal-robots-position-detection

      universal-robots-position-detection-program

      def Dynamic_joint_pos_check():
      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(24)
      set_runstate_outputs([])
      set_payload(0.0)
      set_gravity([0.0, 0.0, 9.82])
      $ 5 “Thread_1″
      thread Thread_1():
      while True:
      global CurrentPose = get_joint_positions()
      varmsg(“CurrentPose”,CurrentPose)
      global Joint0 = CurrentPose[0]
      varmsg(“Joint0″,Joint0)
      if (Joint0>0.0):
      set_digital_out(2,True)
      else:
      set_digital_out(2,False)
      end
      sync()
      end
      end
      threadId_Thread_1 = run Thread_1()
      while (True):
      $ 1 “Robot Program”
      $ 2 “MoveJ”
      $ 3 “Waypoint_1″
      movej([2.4537650128008273, -1.4889169386112515, -2.0767361840091203, -1.1475477422542704, 1.5697192686207784, 4.969060686087193], a=1.3962634015954636, v=1.0471975511965976)
      $ 4 “Waypoint_2″
      movej([-0.1742819616831639, -1.4887997488706437, -2.076755039189638, -1.147563944926343, 1.569897498013579, 4.969214168055562], a=1.3962634015954636, v=1.0471975511965976)
      end
      end

      3.
      Or you can also us the script mode and move the robot by MoveJ commands and use Pose coordinates and since you know where the obstacles are – then make sure you are not sending your robot there with your MoveJ commands (Can also be MoveL etc. commands).

      4.
      Or you can mount some sensor on the robot head that can detect objects – and if it detects something then stop or move in another direction.

      Regards
      Lars

      Reply
  77. Khattak

    Hello Lars,

    Let me start by thanking you for all your help and support. You have been awesome so far and your tips have been extremely important in helping with the robot. I have another question. Using the shoulder elbow and wrist 1, I am trying to make the robot go in a circular motion around a fixed object. The wrist 1 movement allows the tool rotate while the elbow and shoulder also allow the tool to rotate around the object. I am using script code and TCP/IP so that I can give the robot positions via a personal computer. The problem is that the robot moves in a circle but the motion is not steady. What can I do to make the motion more steady? I have reduced the speed and kept the acceleration high and this has helped reduce the shaking of the robot.

    Thank you once again for all your help and support. It is highly appreciated.

    Reply
    1. zacopressadmin Post author

      Hello Khattak

      Thanks for your question and support.

      I need to know a little more details for what kind of uneven move you are experiencing.

      Is the variation in terms of speed i.e. you see the robot accelerate and decelerate between waypoints?

      Or is the variation in position – variations off from the intended path/waypoint?

      How much is the variation?

      How many waypoints do you have in a full circle move?

      Are you using the circle move function?

      Is your move a true round perfect circle?

      Or is it an uneven rounded path e.g. elliptical or even more random?

      Regards
      Lars

      Reply
      1. Khattak

        Hey Lars,

        Sorry for the late reply. I send the calculated coordinates for a circle continuously using PC to the robot and use the movep command to get the robot to move in a circle. I have read over the manual, but I have a hard time figuring out the movec command. My application involves the robot receiving coordinates continuously from the PC and moving to the position

        Thanks
        Khattak

        Reply
        1. zacopressadmin Post author

          Hi Khattak

          Thanks for your question.

          For a Circle move it is necessary to have a starting point i.e. a waypoint before the circle move because the circle move describes the via point and the end point from the last waypoint – this also counts for the movec command.

          You can see the movec command used here in this forum – it is in the example where there is a circle drawn.

          Regards
          Lars

          Reply
          1. Min Xiang

            Hi Lars,

            I am a new user of UR5 and I am able to program it with simple commands. I want to move the TCP in a circle, but I can not find any command or function to do that. Now I see you and Khattak talking about the command “movec”. Will you please tell me where to find the command “movec” and how to use it?

            Thanks
            Min

  78. Khattak

    Hey Lars,

    Thanks for all your help so far. I am using script code to run a main program and then using threads to run 3 threads. Whenever I hit the run button, I get the error SyntaxError: line 1 def prog(): where prog is the name of my program. Any comments on how to proceed? Thanks once again!

    Khattak

    Reply
    1. zacopressadmin Post author

      Hi Khattak

      Thanks for your question. I will need to see your code to get an idea of the syntaks used.

      Regards
      Lars

      Reply
      1. Khattak

        Hey Lars,

        Below is my code. I have tried using a main script and then separate scripts for each of the threads as well. Neither seems to be working. I want to be able to simultaneously send and receive positions.

        point=[0, 0, 0, 0, 0, 0, 0]
        pos1=p[0.1, 0.4, 0.5, 0.01, 3.14, 0.01]

        socket_open(“192.168.0.5″, 30000)

        thread send_to_pc():
        pos = get_forward_kin()
        socket_send_string(pos)
        sleep(0.1)
        return
        end

        thrd1 = run send_to_pc()

        thread receive_from_pc():
        point = socket_read_ascii_float(6)
        pos1[0] = point[1]
        pos1[1] = point[2]
        pos1[2] = point[3]
        pos1[3] = point[4]
        pos1[4] = point[5]
        pos1[5] = point[6]
        sleep(0.5)
        return
        end

        thrd2 = run send_to_pc()

        thread send_pos1():
        socket_send_string(pos1)
        sleep(0.1)
        return
        end

        thrd3 = run send_pos1()

        Reply
        1. zacopressadmin Post author

          Hi Khattak

          Thanks for your information’s. A few things I would like to comment.

          In this line

          socket_open(“192.168.0.5″, 30000)

          Maybe I think a wrong apostrophe used after the 5 or both – try instead ”
          (It could be caused by your cut and paste into this forum, but try and check at your end).

          Maybe you can succeed to use Threads method, but bare in mind that Threads tend to run virtually at the same time – so if you are trying to send more things at the same time (which I know is what you wish to do) then be careful with the timing of the variables send – especially if they are send on the same port.

          Maybe consider to use Sub Routines – so you better can control when they are executed. Although it might not be exactly simultaneously – but run each after each other will be very fast and within milliseconds – if your application can accept that.

          Or maybe consider using different ports for different variables.

          Just some hints that I hope can bring you a step further.

          Regards
          Lars

          Reply
          1. Khattak

            Hello Lars,

            I have tried using the apostrophe from the GUI itself, still no change. It keeps giving me that error message. I think it has more to do with syntax than anything else. I am able to send and receive without threads but on the log it gives me an error message of not being able to connect to the port (I still get to send and receive). I know there is a script manual and the software manual but is there any place to check for syntax errors? Thanks!

            Khattak

          2. zacopressadmin Post author

            Hi Khattak

            OK good that the apostrophe is checked that’s on step further.

            Yes the script manual is good to consult when using script commands and the way I move forward is to insert or comment out line by line and check program execution in order to narrow down where a syntax error is located.

            What I found in your case.

            If the return statement is used then it must have a value although the value is discarded.

            I tried your program and instead used this statement

            return point

            and then the program could be executed without a syntax error messages.

            If you cannot use the variable ”point” then consider to create a dummy variable to use as the return value or remove the return statement.

            For the log entry about not being able to connect to port – I am not able to reproduce as you describe. Maybe check the Ethernet settings and connectivity or the program you communicate with.

            Regards
            Lars

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>