UR Script: Commands via Socket connection

Also checkout the new CB3 forum

UR Script program by Socket connection

Host computer to UR robot #1.

The previous chapter used the “Script:” function available in the teaching pendant to import blocks of Script code or entire program into the robot and run from the teaching pendant.

In this chapter we will focus on making a script that entirely control the robot remotely from a host computer by Script programming.

The format is the same as in previous chapter and as documented in the Script manual, but since we are not using the teaching pendant we need to send the Script file to the Robot control through an already prepared open port on the Robot which is TCP port 30002.

In this case we are using the program language Python and the Python environment to communicate with the Robot. The Script file can still be edited in a Notepad.

The first program example is just to illustrate how to send a script file through via the Ethernet to the TCP port 300002 on the robot.

In this case the robot has already been configured to IP address 192.168.0.9 and our host must be in the same subnet e.g. defined as 255.255.255.0

The first Program 1 just turns digital output number 2 ON and the robot does not move at all and the program looks like this.

# Echo client program
import socket
HOST = “192.168.0.9″    # The remote host
PORT = 30002              # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send (“set_digital_out(2,True)” + “\n”)
data = s.recv(1024)
s.close()
print (“Received”, repr(data))

 

The program is run from the host computer and will only have one passage because there is no loop in the program.

The library “socket” in imported into the program so the Socket connection is available. The “Host” in this case is the Robot and “PORT” is the open port on the Robot that listens for Script code.

Then the Script code necessary to connect and send on the Socket. The “s.send” command send that actual script code for the robot to execute which in the case is (“set_digital_out(2,True)” Which is like previous chapter. The + “\n”) at the end of the line is a linefeed because the Robot need a linefeed after each command. The Socket connection needs to be closed again with the s.close() command. The print (“Received”, repr(data)) command prints the output from the robot on the Host or PC monitor – in this case  acknowledgement code.

The second Program 2 is similar and just turn digital out number 2 OFF again and the robot does not move at all.

# Echo client program
import socket

HOST = “192.168.0.9″    # The remote host
PORT = 30002              # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send (“set_digital_out(2,False)” + “\n”)
data = s.recv(1024)
s.close()
print (“Received”, repr(data))

 

Script program for Socket connection

Host computer to UR robot #2.

This program send in Script mode via socket port runs through 7 Waypoints. See next page for comments.

 

# Echo client program
import socket
import time
HOST = “192.168.0.9″    # The remote host
PORT = 30002              # The same port as used by the server
print “Starting Program”
count = 0
while (count < 1):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
time.sleep(0.05)
s.send (“set_digital_out(2,True)” + “\n”)
time.sleep(0.1)
print “0.2 seconds are up already”
s.send (“set_digital_out(7,True)” + “\n”)
time.sleep(2)
s.send (“movej([-0.5405182705025187, -2.350330184112267, -1.316631037266588, -2.2775736604458237, 3.3528323423665642, -1.2291967454894914], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(2)
s.send (“movej([-0.7203210737806529, -1.82796919039503, -1.8248107684866093, -1.3401161163439792, 3.214294414832996, -0.2722986670990757], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(2)
s.send (“movej([-0.5405182705025187, -2.350330184112267, -1.316631037266588, -2.2775736604458237, 3.3528323423665642, -1.2291967454894914], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(2)
s.send (“movej([-0.720213311630304, -1.8280069071476523, -1.8247689994680725, -1.3396385689499288, 3.215063610324356, -0.27251695975573664], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(2)
s.send (“movej([-0.540537125683036, -2.2018732555807086, -1.0986348160112505, -2.6437150406384227, 3.352864759694935, -1.2294883935868013], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(2)
s.send (“movej([-0.5405182705025187, -2.350330184112267, -1.316631037266588, -2.2775736604458237, 3.3528323423665642, -1.2291967454894914], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(2)
s.send (“movej([-0.7203210737806529, -1.570750000000000, -1.570750000000000, -1.3401161163439792, 3.2142944148329960, -0.2722986670990757], t=4.0000000000000000, r=0.0000000000000000)” + “\n”)
time.sleep(4)
s.send (“set_digital_out(2,False)” + “\n”)
time.sleep(0.05)
print “0.2 seconds are up already”
s.send (“set_digital_out(7,False)” + “\n”)
time.sleep(1)
count = count + 1
print “The count is:”, count
time.sleep(1)
data = s.recv(1024)
s.close()
print (“Received”, repr(data))
print “Program finish”

Same program as above i.e. send in Script mode via socket port runs through 7 Waypoints. Here with comments.

# Echo client program
import socket

(Import the library for Socket connections)
import time
(Import the library for Time function)
HOST = “192.168.0.9″    # The remote host
(IP address of the robot)
PORT = 30002              # The same port as used by the server
(The port socket open on the robot for script programming)
print “Starting Program”
(This is printed on the PC Computer from where the script program is run).
count = 0
(set the variable “count” to value 0)
while (count < 1):
(Loop unitl count is smaller than 1, but not 0)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
(All line that is indented under the While statement is executed in the loop).
s.connect((HOST, PORT))
(Connect to the robot port)
time.sleep(0.05)
(Wait 0.05 seconds because the robot communication speed is 125 Hz = 0.008 seconds)
s.send (“set_digital_out(2,True)” + “\n”)
(Set digital output 2 high )True))
time.sleep(0.1)
(Wait for communication speed)
print “0.2 seconds are up already”                                                             (Print messages on PC Computer screen)
s.send (“set_digital_out(7,True)” + “\n”)
time.sleep(2)
s.send (“movej([-0.5405182705025187, -2.350330184112267, -1.316631037266588, -2.2775736604458237, 3.3528323423665642, -1.2291967454894914], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
a = joint accleration      v = joint speed
time.sleep(2)

(Wait for robot to move to Waypoint)
s.send (“movej([-0.7203210737806529, -1.82796919039503, -1.8248107684866093, -1.3401161163439792, 3.214294414832996, -0.2722986670990757], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(2)
s.send (“movej([-0.5405182705025187, -2.350330184112267, -1.316631037266588, -2.2775736604458237, 3.3528323423665642, -1.2291967454894914], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(2)
s.send (“movej([-0.720213311630304, -1.8280069071476523, -1.8247689994680725, -1.3396385689499288, 3.215063610324356, -0.27251695975573664], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(2)
s.send (“movej([-0.540537125683036, -2.2018732555807086, -1.0986348160112505, -2.6437150406384227, 3.352864759694935, -1.2294883935868013], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(2)
s.send (“movej([-0.5405182705025187, -2.350330184112267, -1.316631037266588, -2.2775736604458237, 3.3528323423665642, -1.2291967454894914], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
time.sleep(2)
s.send (“movej([-0.7203210737806529, -1.570750000000000, -1.570750000000000, -1.3401161163439792, 3.2142944148329960, -0.2722986670990757], t=4.0000000000000000, r=0.0000000000000000)” + “\n”)

(Second joint at -90 deg                                                                                                                                      t = (time to reach this     r = (Blend radius is set to 0)    .

waypoint is 4 sec)                                                            .

(In robot Move Screen the jopint positions expressed in degrees i.e. -360 to 360 degrees. Here the joint positions are expressed as radians where -360 = -6.283, -180= -3.14,

-190 = -1.57075, 0 = 0, 90 = 1.57075, 180 = 3.1415, 360 = 6.283)
time.sleep(4)
(Program waits 4 second because it takes 4 seonds for the robot to move to the waypoint).

s.send (“set_digital_out(2,False)” + “\n”)
time.sleep(0.05)
print “0.2 seconds are up already”
s.send (“set_digital_out(7,False)” + “\n”)
time.sleep(1)
count = count + 1
print “The count is:”, count
time.sleep(1)
data = s.recv(1024)
s.close()
print (“Received”, repr(data))
print “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



311 thoughts on “UR Script: Commands via Socket connection

  1. sreekrishnan

    I am using UR3 robot for my work. Thanks for your tutorial on how to program UR using python, i am now able to send moveJ commands for UR3 robot using python socket programming. But i need to send lots of movej commands from the python script to send i need to measure the time of the robot movement and add a time.sleep(arg) statement between every movej command.

    Is there any way to receive information from the Robot when a movej command completed executing successfully ? So that after checking the received information i can send another movej command from the script.

    Reply
    1. zacopressadmin Post author

      Hi sreekrisnan

      Thanks for the question.

      There are various ways to follow the robot movement by receiving position informations.

      For example by the Matlabdata. Some more informations about receiving positions via Matlab at this link

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

      Or by using MODBUS. More informations about receiving positions via MODBUS at this link.

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

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

      Also check out the CB3 forum



      Reply
  2. CT

    Hi Lars,

    We have generated and uploaded a number of UR scripts to our UR robot using FTP. We are trying to get the robot to play a particular script by sending the script name via a string using the server-client approach. The active urp program is a simple program that waits for a string input and load/play the script required. Our approach works if we hard code the script name in the script command. However is it possible to make the script command accept a variable (string containing the script name) and load the script.

    We are trying to minimize the usage of the teaching pendant; hence we are trying to make the urp program as generic as possible so as not to update it frequently. We do not know how to code urp on a pc.

    Hope what we are trying to do make sense and thanks in advance for looking into our query.

    Regards,
    CT

    Reply
    1. zacopressadmin Post author

      Hi CT

      Thanks for the question.

      A script becomes an embedded part of the Polyscope program – similar to being compiled together when executed and therefore it might be difficult to use a variable for the script name.

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

      Also check out the CB3 forum



      Reply
  3. Gavin

    Hi Lars,

    I control the UR10 with PC, But I have a trouble of that how can I control robot smoothly move when I pressed mouse down (not release ) with GUI view a long time.

    It means how can I send a robot command with frequent time (It may be robot is moving when a command send .)

    expect your reply!
    thanks .

    Reply
    1. zacopressadmin Post author

      Hi Gavin

      Sure there is a reply.

      Are the mouse connected directly to the teach pendant USB port ?

      Here the robot runs smoothly when using a mouse.

      The acceleration and deceleration are important to control in order to acheive a smooth trajectory depending on the nature of move and strong turns are made or even stop and move in the other direction – then the acceleration and deceleration will need to be adjusted to fit the path and speed which might be need to tested case by case.

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

      Also check out the CB3 forum



      Reply
  4. Luis

    Hello!
    I am trying to connect my PC to my UR10 by using the simple code in Python:
    import socket
    HOST = “192.168.1.100″ # The remote host
    PORT = 30002 # The same port as used by the server
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))

    However the connection keps on failing.
    What do I need to do ? I suppose I have to do something in the polyscope or in the PC but dont know what.

    Thanks in advance.

    Luis Castro

    Reply
    1. zacopressadmin Post author

      Hello Luis

      Thanks for the question.

      What do you mean by the connection keeps failing ? – what is the symptoms ?

      It looks like lines from the example are missing in your code.

      There are different ways to use a socket connection depending what is the intention.

      You can send commands without having a Polyscope program on the robot – more informations 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/

      Or you can also send commands with a Polyscope program on the robot – more informations at this link

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

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

      Also check out the CB3 forum



      Reply
  5. Julia W.

    Hi!
    I started programming UR via TCP/IP three months ago. (But I am using the program language C#) Now I have a question about the “Forcemode”. To use the Forcemode I have to send three commands:
    force_mode(…)
    movej(…)
    end_force_mode()

    The problem: the controller “understands” only one command after another. But for using the Forcemode the three commands have to worke together. Is there anybody who knows, how I can send them, so the Controller understands, that they belong together?

    Regards
    Julia

    Reply
    1. zacopressadmin Post author

      Hi Julia

      Thanks for the question.

      The force mode need to best to be used in a Polyscope program because as you mention the commends needs to be together.

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

      Also check out the CB3 forum



      Reply
      1. Julia W.

        Hi Lars,

        thanks for the answer.

        “Need to best to be used” sounds like it isn’t impossible to send the force mode comment via TCP. It isn’t scheduled to use PolyScope in the project I work on. Have you any idea or hint how it could work, like described in the comment above? Because writing a ScriptCode in PolyScope with the three commands does move the Robot in ForceMode.

        Julia

        Reply
        1. zacopressadmin Post author

          Hi Julia

          There is a substantial difference in using script code in Polyscope programming or using script commands from an external device. When used inside the Polyscope some functions like Force mode works better because the script code become embedded and compiled together with rest of the Polyscope program and therefore the timing is taken care of by Polyscope.

          Whereas sending script commands from an external device then it is the programmer that need to control the timing. I have not seen any examples of using the force mode by sending the commands from an external device.

          Some more informations about timing when sending script commands from an external device.

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

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

          Also check out the CB3 forum



          Reply
  6. amaury

    Hello zacobria

    How can I make it to move the 1.2 or 3 wrist, via socket, ethernet connection, what happens I want to tell you how many degrees or radians I want to be meva, control more than anything the rotations or degrees, the wrists , Or something that I recommend that is through communication, ethernet.

    Reply
    1. zacopressadmin Post author

      Hello amaury

      Thanks for the question.

      Maybe this post can provide some hints.

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/x-y-and-z-position/#comment-158044

      And this article for sending move position through ethernet communication.

      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
  7. Mohammed Sharafath

    Hi zacopressadmin,

    Can the variable value be sent to an external device (PC) directly using the socket Connection? I am working with LabVIEW and would like to send the Counter value running on the Robot (unique number of the part loaded into machine) from the Robot UR3 to the PC. Is this possible using any method other than socket Connections?

    Thanks,
    Mohammed Sharafath

    Reply
    1. zacopressadmin Post author

      Hi Sharafath

      Thanks for the question.

      Not directly, but there are various ways to acheive something similar.

      One option is the establish a Client-Server solution and an example can be found at this link.

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

      Or if the variable data are numeric they can be stored in a MODBUSA register from the Polyascope program – and then the same MODBUS register can be read from an external device.

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

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

      Also check out the CB3 forum



      Reply
      1. Mohammed Sharafath

        Hi Zacopressadmin,

        I have established the connections and have sent the strings from the Robot to the labview. But the Problem is that the TCP/IP Connection in Labview can only receive string data.
        The data the Robot sends is in Bytes Format. When I used python for Connection, python had a code to convert the Bytes to integers. But the same is not possible with LabVIEW.

        So can the data (bytes) be converted to decimal number and then to string using script codes? Any help on this matter would help me a lot in solving my Problem!!!

        Thanks and regards,
        Mohammed Sharafath

        Reply
        1. zacopressadmin Post author

          Hi Mohammed

          Thanks for the question.

          Have you tried to use “socket_send_string” script command ?

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

          Also check out the CB3 forum



          Reply
          1. Mohammed Sharafath

            Hi Lars,

            Infact I tried the same yesterday and found it was transmitting the data directly albeit in string Format.
            I used the code: socket_send_string(var_1)

            This directly transmitted the data. But the Problem is, the data Transfer is not instantaneous. Like I said before the value I am sending is of a Counter and there is always a delay of one Count, which is sent only when the Connection opens the next time in Loop. For example if the current value is 10, the data received by the labView is 9. and 10 is updated only when the Connection opens again for sending 11. But then it is again in delay. Is there a remedy for this?

            Thanks,
            Sharafath.

          2. zacopressadmin Post author

            Hi Mohammed

            Maybe the buffers are out of sync. It can be consider to close and open the socket on each side or on both sides so there is only one outstanding in the socket buffers.

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

            Also check out the CB3 forum



          3. Mohammed Sharafath

            Hey Lars,

            I found a way to transmit the data instantaneously. It was a Problem with my order of the script codes. I have now placed the Counter update (increment) right before the “socket_send_string()” code.
            Thanks a lot for your Support in helping me overcome These hurdles.

            Best regards,
            Sharafath

  8. alexander

    hi zacobria.

    I did what he told me about the speedl command and I was able to move base, shoulder and elbow, thank you.
    There is some command that allows you to move each joint separately but using degrees either radians or degrees mediane socketTest, I would appreciate the help.

    Reply
    1. zacopressadmin Post author

      hi alexander

      Thanks for the question.

      This post is similar – moving only base joint 45 degrees.

      http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/x-y-and-z-position/#comment-158044

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

      Also check out the CB3 forum



      Reply
  9. Mohammed Sharafath

    Hi zacopressadmin ,
    I have a doubt. I am trying to Switch the digital Input on the polyscope using the SocketTest v3.0.0. I am able to Switch the Outputs using the code set_digital_out(0, True). Is there a simlar code I can use to Switch the digital Inputs.

    PS: I had asked the same question under another comment. Please ignore it.

    Thanks in advance
    Sharafath

    Reply
    1. zacopressadmin Post author

      Hi Mohammed

      Thanks for the question.

      Yes output can be set as you mention, but physical inputs cannot be set woth a command – because that could create a conflict because an Input is normally connected to a sensor or an output of another device e.g. a Photo sensor or a PLC output.

      So if the connected device is having the state “1″ (high) then it is applied as an electrical signal voltage – and then if the input was forced to opposite state – then there is a conflict where the external device is setting it high whereas as if a command was allowed would try to set it low and therefore an undefined state.

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

      Also check out the CB3 forum



      Reply
      1. Mohammed Sharafath

        Dear zacopressadmin,

        Thank you for the Feedback. I am now trying to the Information from the Robot regarding the states of the digital Outputs using the code ” get_digital_out(n)”.

        Program

        HOST = “192.168.0.9″
        PORT = 30002
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((HOST, PORT))
        s.send (“get_digital_out(7)” + “\n”)
        data = s.recv(1024)
        s.close()
        print (“Received”, repr(data))

        The reply got has the date and time of when the Software update was installed on the polyscope and not the current values as per expectation. ´What could be the possible causes?

        Thanks,
        Mohammed Sharafath

        Reply
        1. zacopressadmin Post author

          Dear Mohammed

          Thanks for the question.

          The data received is properly Matlab data that is returned as described at this link

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

          To get status back from the robot on request for specific data like such raw script command send to port 30001, 30002 and 30003 is not possible.

          Much more informations on this and ideas can be found at this link.

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

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

          Also check out the CB3 forum



          Reply
          1. Mohammed Sharafath

            Thank you Zacopressadmin,

            That saved me lot of confusion. But still I havent got my solution. I am trying to read the value of variables running on the polyscope program from an external PC (Python/LabVIEW).
            Is there anyway to send the data of the variable Count to the PC. Is there any code/command that can be given from the PC (Python/LabVIEW) to get the data Count of the variable.

            Thanks and regards,
            Sharafath

          2. zacopressadmin Post author

            Hi Sharafath

            Thanks for the question.

            Not directly, but there are various ways to acheive something similar.

            One option is the establish a Client-Server solution and an example can be found at this link.

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

            Or if the variable data are numeric they can be stored in a MODBUSA register from the Polyascope program – and then the same MODBUS register can be read from an external device.

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

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

            Also check out the CB3 forum



      2. Mohammed Sharafath

        Hello zacopressadmin,

        I am now in a Situation where I have to transmit data through only LAN. How do you propose that I set the Digital Input values to “High and Low”, through LAN cable. What accessories additionally do I require. Can you help me out with this?

        Thanks
        Sharafath

        Reply
        1. zacopressadmin Post author

          Hi Mohammed

          Thanks for the question.

          Normally an input is not to be set by software because is connected to a physical sensor and therefore there might be a conflict if the sensore is high while the command say the input should be low.

          Maybe it can be considdered to connect the iput to an output on the robot and then control the output high or low and thereby the input follows.

          The outputs can be set via MODBUS. More informations at these links

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

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

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

          Also check out the CB3 forum



          Reply
          1. Mohammed Sharafath

            Hello Lars Skovsgaard,
            Thank you for your reply. I will try it by connecting the Robot Output and Input.
            If that doesnt work I guess ModBus is the only Option available.

            Thanks
            Sharafath

  10. alexander

    Hi.
    thank you for tha information, I have been able to make the comunicate with my PC and UR5 and I have sent coordinates to my UR5 by means of socketTest , but I have a question; How can I move a single robot axis, for example just the base ?

    Reply
    1. zacopressadmin Post author

      Hi alexandre

      The speedl command is able to move the robot in one axis at the time.

      For example this command

      speedl([0.1,0,0,0,0,0.0], 1.0,0.5)
      stopl(1)

      moves the robot in X axis with the speed of 0.1 and acceleration of 1.0 and for 0.5 seconds. And then stops the robot.

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

      Also check out the CB3 forum



      Reply
  11. Mohammed Sharafath

    I went through almost all of the comments in this section. But I am unable to find Connection Information using LabVIEW. I am a newbie to communication protcols and any help will highly appreciated.
    The Situation I am in right now is that I have few programs in the polyscope. But I Need to select the program from a remote PC using LabVIEW. I insist on LabVIEW because there are other important functions that it performs.

    Reply
    1. Mohammed Sharafath

      I am using a UR3 Robot. I tried connecting with the simple TCP/IP program but it doesn’t seems to work.

      Reply
      1. zacopressadmin Post author

        Hi Mohammed

        Thanks for the question.

        How is your program ?

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

        Also check out the CB3 forum



        Reply
    2. zacopressadmin Post author

      Hi Mohammed

      Thanks for the question.

      I am not familiar with Labview, but the UR robot has several different ways to get connected from an external device for example.

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

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

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

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

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

      Also check out the CB3 forum



      Reply
      1. Mohammed Sharafath

        Hey zacopressadmin,
        Thanks for your comments.

        The way I was trying to connect it was:
        LabVIEW–>Python–>Polyscope.

        I guess this method is very complex. Hope I find something simpler in your reply.

        Thanks,
        Mohammed Sharafath

        Reply
        1. zacopressadmin Post author

          Hi Mohammed

          The Client-Server example is based on Python and Polyscope.

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

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

          Also check out the CB3 forum



          Reply
          1. Mohammed Sharafath

            hi Zacobria Lars Skovsgaard,
            I am now able to load, start and stop programs using Labview directly on the Robot. Thanks to you.

            But now I am trying to send and receive further Information between the labview and Robot. I have found the Manual for urScript code and hopefully will be able to connect them. Thanks a lot for your support.

            Regards,
            Sharafath

  12. Da Ho

    Hello Zacobria,

    i try to make a program for converting a program plan( XML) into a robotscript in c#.
    Therefor i need the UR script language, and i found the API Reference for URScript in pdf.
    Is there an existing API in C# or something similar (so that i dont need to write this API from pdf to C#)?
    Ross is allready working with a kind of Api, but i cant find out where i can get it from ?!

    Thank you,

    Da Ho

    Reply
    1. zacopressadmin Post author

      Hello Da Ho

      Thanks for your question.

      I haven´t seen such API and I am not familiar with C#

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

      Also check out the CB3 forum



      Reply
  13. khushboo

    Hi All,
    I am trying moving UR-Robot remotely through socket using UR Simulator 3.3.4 using “MOVEj” command.

    In “MOVEj” command, along with position co-ordinates i am passing joint acceleration and velocity parameters as well.

    First time i am sending following values and monitoring robot movement and speed:
    1. a=8, v=4

    Second time i have increased the acceleratio nand velocity parameters 10 times with other values remains same.:
    2. a=80, v=40

    But against what i was expecting, i could not see any increase in robot speed in second case. The speed at which robot move was almost same.

    I am not able to understand this behaviour of robot. I want to have different programs to make robot perform same operation in different speeds, but got stuck here.

    Can anybody please help and explain, how these joint “acceleration” and “velocity” parameter values of “MOVEj” command are actually used? And why robot is not behaving as expected?

    Thanks
    Khushboo

    Reply
    1. zacopressadmin Post author

      Hi Khusboo

      Thanks for the question.

      Maybe the values are too high and then they are ignored by the robot.

      Maybe consider to try values below 1 for example

      a=0.5, v=0.01

      a=0.1, v=0.1

      a=0.5, v=0.5

      a=0.01, v=0.01

      And there is a big difference in the acceleration and velocity.

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

      Also check out the CB3 forum



      Reply
  14. Taylor

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

    Thank you so much.
    Best wishes,
    Taylor

    Reply
    1. zacopressadmin Post author

      Hi Taylor

      Thanks for the question.

      There needs to be a server listening to the connection from the robot. The robot is the client and the server can be the SocketTest program (The program needs to be configured as a “Server”) – or it can be a customized program with a server function.

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

      Also check out the CB3 forum



      Reply
      1. Pretlous

        Hello, I wanted to know if it was possible to programming an Universal Robot since a computer, from a VNC?

        Thank you in advance.

        Loris

        Reply
        1. zacopressadmin Post author

          Hello Pretlous

          Thanks for the question.

          I have not seen a VNC solution – instead the simulator which has the Polyscope GUI might be considered and then transfer the program to a real robot.

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

          Also check out the CB3 forum



          Reply
          1. Pretlous

            Hello zacopressadmin

            Thanks for the answer.

            I have found the solution.

            Just for information if anyone need this :

            Connect the robot to the internet and make sure it has an IP adress configured (DHCP/Static). Connect to the SSH shell using putty (user:root / pass:easybot)

            Run “apt-get update” and after “apt-get install x11vnc”.

            Run “x11vnc -storepasswd YOURPASSWORD /etc/x11vnc.pass”Edit ~/xsession and adding: “/usr/bin/x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :0 -rfbauth /etc/x11vnc.pass -rfbport 5900 -forever -auth root -bg -o /var/log/x11vnc.log” at the beginning of the file (after the #!/bin/bash).

            This starts a x11 VNC server, with all the necessary options to make it run on background forever.

            Have a good day !

          2. zacopressadmin Post author

            Hello Pretlous

            Thanks for contributing to the forum.

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

            Also check out the CB3 forum



  15. tali

    Hi Lars,
    I’m planning a client server program, but first I want to see if I can debug it.
    I’m trying the “textmsg” and $ (label).

    I sent the program via port 30003, and I read the messages from port 30001.

    The program:
    $ 1 “messaging starting”
    textmsg(“starting)
    $ 2 “messaging ending”
    textmsg(“ending”)

    Result:

    In polyscope I see

    Program textmsg started
    ending
    Program textmsg stopped

    In my thread I sometimes get the same as polyscope, , sometimes only “ending”

    If I remove the textmsgs from the program, then I get the label messages.

    Is there a way to use the labels or the textmsgs in order to debug a program? It seems that only part of the debug messages are sent by the controller.

    Reply
    1. zacopressadmin Post author

      Hi tali

      Thanks for the question.

      It might be because of timing of the commands send to the robot – because if the program is send too fast to the port 30003 because such line are executed immediately and if one command is not finished execution when the next command are send – then it will not finish and be overwritten which might result in missing execution of commands.

      Therefore it might be nessecary to insert a wait before each command line like is shown in the example at this link.
      https://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-from-host-to-robot-via-socket-connection/

      Also the example at this link describe the need for inserting wait in order to be sure the command is fully executed.
      https://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/functions-1/

      When sending raw commands to the ports 30001-30002 and 30003 without a counterpart program made inside the Polyscope enviorment – then there are no handshake and therefore the timing needs to be controlled by the programmer.

      A client-server program scenario is more elegant because of a client part running in the Polyscope enviorment and a server part running on a external device then it is possible to build a good handshake. An example of a client-server scenario is shown at this link
      https://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-client-server/

      I have not seen any documentation describing that this can be used for debugging purposes. It might also be considered to look at the real time interface at port 30004. I have not used that myself.

      There are some more informations about the real time interface at this link
      https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/real-time-data-exchange-rtde-guide-22229/

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

      Also check out the CB3 forum



      Reply
      1. tali

        Hi Lars,
        Thanks a lot for your help.
        I now have a robot moving according to a script sent to the server,
        and I would like to add a button to my client that stops the robot immediately.
        What is the command that I should send the robot when the button is pressed?
        I tried “halt” but it didn’t work.
        Thanks,
        Tali.

        Reply
        1. zacopressadmin Post author

          Hi tali

          Thanks for the question.

          Maybe it can be considered to use the dasbboard server at port 29999 – and send “stop” or “pause”. More information on the dash board server at this link

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

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

          Also check out the CB3 forum



          Reply
  16. Arunava Nag

    I am trying to pair my Cognex camera with ur10 and have it programmed using tcp/ip. I was reading this forum, where I have figured that I need to be using the 30001 port. I am trying to use C++. However, as most of the scripting done here is in python, could you point me towards some samples where they have used C++.
    Also could you advise me upon how to get the camera paired with the UR10?

    Reply
    1. zacopressadmin Post author

      Hi Arunava

      Thanks for the question.

      Actually it is not necessary to use Python or C++ when connecting a camera – it can be done from within Polyscope.

      Other ports can also be used – and actually port 30001 is maybe not advisable to use for a camera because it is already used for streaming Robot state and messages data out from the robot.

      Normally a camera that has Ethernet TCP can resond to requests from Polyscope directly. Typically a command is send to the camera in order to get the cordinates back from the camera where it has seen an item to pick. The command for the request to the camera and the reply from the camera is different from camera vendor to vendor.

      I have not seen C++ examples, but at this link below there is an example on the Polyscope side for how communication to a camera can be made.

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

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

      Also check out the CB3 forum



      Reply
      1. Arunava Nag

        Hello,
        Thanks for your response. So is it just you are writing those above scripts and copying it to the pendant and running from there? I thought I could run them without using the polyscope pendant. My idea is to use my PC to control the UR10 completely.

        Yes you are right, I checked again it should be 30002. Thanks for the pointer, reading through it.

        Reply
        1. zacopressadmin Post author

          Hello Arunava

          I am not using the above scripts for communicating to a camera, but instead following the method as shown in the link in the earlier answer.

          It is also possible to receive the data from the camera on a PC and then send command to the robot to make it move accordingly, but that might not be ideal because it would require substantial more programming efforts and I have not seen examples on such solution.

          Port 30002 is also already used for robot status and messages. A port like 30000 or 12345 or many other port numbers might be considered if they are not already being used for something else.

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

          Also check out the CB3 forum



          Reply
          1. Arunava Nag

            Hi Carl,

            I got started and got my robot working through scripting. But facing some real difficulties in integrating camera. I have assigned static IPs for both camera and robot. Just wondering do I need to register the camera through my pendant? I totally want to avoid using the pendant.

            Also, I realized that from one move instruction to other, if the right acceleration and velocity are not assigned it certainly doesn’t complete the action and does it partially.
            Another point to bring into attention, is sometimes if the velocity is higher and if i have sleep times between the waypoints the smooth traversing from one point to other is sacrificed and a arm goes like hits the point 1 with a force and then move towards point 2.

            However, really trying to interface the cognex module. I have an insight 7000.

  17. Can Tgrl

    We try to read position from Labview. First, the following program that I copied from another webpage was written to robot.
    Program
       BeforeStart
         open≔socket_open(“ip address”,port no)
         Loop open≟ False
           open≔socket_open(“ip address”,port no)
         targetPos≔p[0,0,0,0,0,0]
         counter≔0
       Robot Program
         sendToServer≔’send to server’
         socket_send_string(sendToServer)
         receiveFromServ≔socket_read_ascii_float(6)
         Loop receiveFromServ[0]≠6
           Wait: 0.3
           receiveFromServ≔socket_read_ascii_float(6)
         Loop counter<6
           targetPos[counter]=receiveFromServ[counter+1]
           counter≔counter+1
         MoveJ
           targetPos
         counter:=0
    Then I pushed the play button and gave me syntax error.
    Error: Syntax error on line 707: open:=socket_open("ip address",port number)
    I assigned a ip address and port no. There is not connection issue.
    Robot ver. 3.3.0.145-UR5
    I need help here. As ı understood, it is not a complicated error.

    Reply
    1. zacopressadmin Post author

      Hi Can

      Thanks for the question.

      Is the program lines you show – all the lines or are there more lines in the program ?

      Can you show the code from the .txt file created ?

      Are the quote symbols (apostrophe) copied and paste or typed in ?

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


      Reply
    2. Can Tgrl

      Hi,
      Thanks for the quick reply.
      This program is written for client. I am a beginner of UR platforms. So, I add the link that includes the whole script code.
      Link: https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/ethernet-socket-communication-via-urscript-15678/

      Actually, I want to communicate UR5 and Labview. The main problem is this.
      It will be useful for me as well as for other users who will have the same problem if you can explain the steps so that the beginners understand.

      Thanks.

      Reply
      1. zacopressadmin Post author

        Hi Can

        In order to be able to troubleshoot – Can you show the code that is generated in the .txt file after you have run the program on the robot ?

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

        Also check out the CB3 forum


        Reply
        1. Can Tgrl

          Hi!
          I can not find the generated txt file. Is there a specific location? As I understood, robot can not generate a code due to socket error.

          Reply
          1. zacopressadmin Post author

            Hi Can

            If you insert a USB thumb drive into the robot – and then save the polyscope program on the USB drive – and then move the USB drive to a computer and look inside the folder where the polyscope program was saved. The robot save the program as .urp and as .script and as .txt.

            Open the .txt file in an editor e.g. notepad and copy the contents into here.

            Maybe also open the .script file and copy the contents into here.

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

            Also check out the CB3 forum


          2. Can Tgrl

            Thanks for the detailed explanation :)

            The file that use asked is below,

            Program
            BeforeStart
            open:=socket_open(“192.168.1.11″,30004)
            Loop open≟False
            open:=socket_open(“192.168.1.11″,30004)
            targetPos:=p[0,0,0,0,0,0]
            counter:=0
            Robot Program
            sendToServer:=’send to server’
            socket_send_string(sendToServer)
            receiveFromServ:=socket_read_ascii_float(6)
            Loop receiveFromServ[0]≠6
            Wait 0.3
            receiveFromServ:=socket_read_ascii_float(6)
            Loop counter<6
            targetPos[counter]=receiveFromServ[counter+1]
            counter=counter+1
            MoveJ
            targetPos
            counter:=0
            You may need to see the script,
            def line_script():
            set_standard_analog_input_domain(0, 1)
            set_standard_analog_input_domain(1, 1)
            set_tool_analog_input_domain(0, 1)
            set_tool_analog_input_domain(1, 1)
            set_analog_outputdomain(0, 0)
            set_analog_outputdomain(1, 0)
            set_tool_voltage(0)
            set_standard_digital_input_action(0, "default")
            set_standard_digital_input_action(1, "default")
            set_standard_digital_input_action(2, "default")
            set_standard_digital_input_action(3, "default")
            set_standard_digital_input_action(4, "default")
            set_standard_digital_input_action(5, "default")
            set_standard_digital_input_action(6, "default")
            set_standard_digital_input_action(7, "default")
            set_tool_digital_input_action(0, "default")
            set_tool_digital_input_action(1, "default")
            set_tcp(p[0.0,0.0,0.0,0.0,0.0,0.0])
            set_payload(0.0)
            set_gravity([0.0, 0.0, 9.82])
            global i_var_2=0
            global i_var_1=4
            global Almanoktasi_1=p[-0.5974388017924923,0.10870392624910537,0.3860631431123778,-1.8845002785731966,-1.9222469660580965,0.5782661193479793]
            global Base=p[0.0,0.0,0.0,0.0,0.0,0.0]
            global Point_1=p[-0.597436978016533,0.1086798677142119,0.38606106101738125,-1.8844036867819323,-1.9222763306727026,0.5782873112003742]
            global Point_2=p[-0.20318960354180976,-0.13530519592601362,0.5237770273045608,-1.3685838037537368,-1.7417588109410014,0.8095019007100775]
            rtde_set_watchdog("speed_slider_mask", 10.0, "ignore")
            ###############################################################
            # Script file used to communicate with Robotiq's ft sensor
            # Version: 0.0.1
            ###############################################################

            def rq_move_relative(P_from, P_to, Pi):
            return pose_trans(P_to, pose_trans(pose_inv(P_from), Pi))
            end

            def rq_elementWiseSub(list1, list2):
            global rq_return_list=list1
            i=0
            while i<length(list1):
            rq_return_list[i]=list1[i] – list2[i]
            i=i+1
            end
            return rq_return_list
            end

            if (not socket_open("127.0.0.1",63351,"stream")):
            popup("Can't connect to the sensor driver", "Robotiq's FT Sensor", error=True)
            end

            ###########################################
            #######Vision urcap preamble start########

            # Converts a pose relative to the flange in the base frame.
            def get_T_in_base_from_flange(T_x_in_flange):

            T_flange_in_base = get_actual_tool_flange_pose()

            T_x_in_base = pose_trans(T_flange_in_base, T_x_in_flange)

            return T_x_in_base
            end

            # Search pose cartesian (camera pose)
            Almanoktasi_1 = p[-0.665116, 0.145728, 0.264052, -1.97134, -1.95731, 0.495909]
            Point_1 = p[-0.583284, 0.102841, 0.413826, -1.84933, -1.89637, 0.593191]
            T_camera_in_flange = p[0.0, 0.05, 0.05, -0.5, 0.0, 0.0]
            snapshot_position_offset = p[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
            ignore_snapshot_position = False

            # Open connection with vision service
            xmlrpc_server=rpc_factory("xmlrpc","http://127.0.0.1:4242&quot;)

            #######Vision urcap preamble end##########
            ###########################################

            ###########################################
            #######Gripper urcap preamble start########
            #######Version 1.0.2########

            #aliases for the gripper variable names
            ACT = 1
            GTO = 2
            ATR = 3
            ARD = 4
            FOR = 5
            SPE = 6
            OBJ = 7
            STA = 8
            FLT = 9
            POS = 10
            PRE = 11

            def rq_init_connection(gripper_sid=9, gripper_socket="gripper_socket"):
            socket_open("127.0.0.1",63352, gripper_socket)
            socket_set_var("SID", gripper_sid, gripper_socket)
            ack = socket_read_byte_list(3, gripper_socket)
            end

            def rq_activate(gripper_socket="gripper_socket"):
            rq_gripper_act = 0
            rq_set_var(ACT,1, gripper_socket)
            end

            def rq_activate_and_wait(gripper_socket="gripper_socket"):
            rq_activate(gripper_socket)

            while(not rq_is_gripper_activated(gripper_socket)):
            # wait for activation completed
            end
            end

            def rq_stop(gripper_socket="gripper_socket"):
            rq_set_var(GTO,0, gripper_socket)
            end

            def rq_reset(gripper_socket="gripper_socket"):
            rq_gripper_act = 0
            rq_obj_detect = 0
            rq_mov_complete = 0

            rq_set_var(ACT,0, gripper_socket)
            rq_set_var(ATR,0, gripper_socket)
            end

            def rq_auto_release_open_and_wait(gripper_socket="gripper_socket"):

            rq_set_var(ARD,0, gripper_socket)
            rq_set_var(ACT,1, gripper_socket)
            rq_set_var(ATR,1, gripper_socket)

            gFLT = rq_get_var(FLT, 2, gripper_socket)

            while(not is_FLT_autorelease_completed(gFLT)):
            gFLT = rq_get_var(FLT, 2, gripper_socket)
            end
            end

            def rq_auto_release_close_and_wait(gripper_socket="gripper_socket"):
            rq_set_var(ARD,1, gripper_socket)
            rq_set_var(ACT,1, gripper_socket)
            rq_set_var(ATR,1, gripper_socket)

            gFLT = rq_get_var(FLT, 2, gripper_socket)

            while(not is_FLT_autorelease_completed(gFLT)):
            gFLT = rq_get_var(FLT, 2, gripper_socket)
            end
            end

            def rq_set_force(force, gripper_socket="gripper_socket"):
            rq_set_var(FOR,force, gripper_socket)
            end

            def rq_set_speed(speed, gripper_socket="gripper_socket"):
            rq_set_var(SPE,speed, gripper_socket)
            end

            def rq_open(gripper_socket="gripper_socket"):
            rq_move(0, gripper_socket)
            end

            def rq_close(gripper_socket="gripper_socket"):
            rq_move(255, gripper_socket)
            end

            def rq_open_and_wait(gripper_socket="gripper_socket"):
            rq_move_and_wait(0, gripper_socket)
            end

            def rq_close_and_wait(gripper_socket="gripper_socket"):
            rq_move_and_wait(255, gripper_socket)
            end

            def rq_move(pos, gripper_socket="gripper_socket"):
            rq_mov_complete = 0
            rq_obj_detect = 0

            rq_set_pos(pos, gripper_socket)
            rq_go_to(gripper_socket)
            end

            def rq_move_and_wait(pos, gripper_socket="gripper_socket"):
            rq_move(pos, gripper_socket)

            while (not rq_is_motion_complete(gripper_socket)):
            # wait for motion completed
            sleep(0.01)
            sync()
            end

            # following code used for compatibility with previous versions
            rq_is_object_detected(gripper_socket)

            if (rq_obj_detect != 1):
            rq_mov_complete = 1
            end
            end

            def rq_go_to(gripper_socket="gripper_socket"):
            rq_set_var(GTO,1, gripper_socket)
            end

            # reset the rGTO to prevent movement and
            # set the position
            def rq_set_pos(pos, gripper_socket="gripper_socket"):
            rq_set_var(GTO,0, gripper_socket)

            rq_set_var(POS, pos, gripper_socket)

            gPRE = rq_get_var(PRE, 3, gripper_socket)
            pre = (gPRE[1] – 48)*100 + (gPRE[2] -48)*10 + gPRE[3] – 48
            sync()
            while (pre != pos):
            rq_set_var(POS, pos, gripper_socket)
            gPRE = rq_get_var(PRE, 3, gripper_socket)
            pre = (gPRE[1] – 48)*100 + (gPRE[2] -48)*10 + gPRE[3] – 48
            sync()
            end
            end

            def rq_is_motion_complete(gripper_socket="gripper_socket"):
            rq_mov_complete = 0

            gOBJ = rq_get_var(OBJ, 1, gripper_socket)
            sleep(0.01)

            if (is_OBJ_gripper_at_position(gOBJ)):
            rq_mov_complete = 1
            return True
            end

            if (is_OBJ_object_detected(gOBJ)):
            rq_mov_complete = 1
            return True
            end

            return False

            end

            def rq_is_gripper_activated(gripper_socket="gripper_socket"):
            gSTA = rq_get_var(STA, 1, gripper_socket)

            if(is_STA_gripper_activated(gSTA)):
            rq_gripper_act = 1
            return True
            else:
            rq_gripper_act = 0
            return False
            end
            end

            def rq_is_object_detected(gripper_socket="gripper_socket"):
            gOBJ = rq_get_var(OBJ, 1, gripper_socket)

            if(is_OBJ_object_detected(gOBJ)):
            rq_obj_detect = 1
            return True
            else:
            rq_obj_detect = 0
            return False
            end
            end

            def rq_current_pos(gripper_socket="gripper_socket"):
            rq_pos = socket_get_var("POS",gripper_socket)
            sync()
            return rq_pos
            end

            def rq_print_gripper_fault_code(gripper_socket="gripper_socket"):
            gFLT = rq_get_var(FLT, 2, gripper_socket)

            if(is_FLT_no_fault(gFLT)):
            textmsg("Gripper Fault : ", "No Fault (0×00)")
            elif (is_FLT_action_delayed(gFLT)):
            textmsg("Gripper Fault : ", "Priority Fault: Action delayed, initialization must be completed prior to action (0×05)")
            elif (is_FLT_not_activated(gFLT)):
            textmsg("Gripper Fault : ", "Priority Fault: The activation must be set prior to action (0×07)")
            elif (is_FLT_autorelease_in_progress(gFLT)):
            textmsg("Gripper Fault : ", "Minor Fault: Automatic release in progress (0x0B)")
            elif (is_FLT_overcurrent(gFLT)):
            textmsg("Gripper Fault : ", "Minor Fault: Overcurrent protection tiggered (0x0E)")
            elif (is_FLT_autorelease_completed(gFLT)):
            textmsg("Gripper Fault : ", "Major Fault: Automatic release completed (0x0F)")
            else:
            textmsg("Gripper Fault : ", "Unkwown Fault")
            end
            end

            def rq_print_gripper_num_cycles(gripper_socket="gripper_socket"):
            socket_send_string("GET NCY",gripper_socket)
            sync()
            string_from_server = socket_read_string(gripper_socket)
            sync()

            if(string_from_server == "0"):
            textmsg("Gripper Cycle Number : ", "Number of cycles is unreachable.")
            else:
            textmsg("Gripper Cycle Number : ", string_from_server)
            end
            end

            def rq_print_gripper_driver_state(gripper_socket="gripper_socket"):
            socket_send_string("GET DST",gripper_socket)
            sync()
            string_from_server = socket_read_string(gripper_socket)
            sync()

            if(string_from_server == "0"):
            textmsg("Gripper Driver State : ", "RQ_STATE_INIT")
            elif(string_from_server == "1"):
            textmsg("Gripper Driver State : ", "RQ_STATE_LISTEN")
            elif(string_from_server == "2"):
            textmsg("Gripper Driver State : ", "RQ_STATE_READ_INFO")
            elif(string_from_server == "3"):
            textmsg("Gripper Driver State : ", "RQ_STATE_ACTIVATION")
            else:
            textmsg("Gripper Driver State : ", "RQ_STATE_RUN")
            end
            end

            def rq_print_gripper_serial_number():
            #socket_send_string("GET SNU",gripper_socket)
            #sync()
            #string_from_server = socket_read_string(gripper_socket)
            #sync()
            #textmsg("Gripper Serial Number : ", string_from_server)
            end

            def rq_print_gripper_firmware_version(gripper_socket="gripper_socket"):
            socket_send_string("GET FWV",gripper_socket)
            sync()
            string_from_server = socket_read_string(gripper_socket)
            sync()
            textmsg("Gripper Firmware Version : ", string_from_server)
            end

            def rq_print_gripper_driver_version(gripper_socket="gripper_socket"):
            socket_send_string("GET VER",gripper_socket)
            sync()
            string_from_server = socket_read_string(gripper_socket)
            sync()
            textmsg("Gripper Driver Version : ", string_from_server)
            end

            def rq_print_gripper_probleme_connection(gripper_socket="gripper_socket"):
            socket_send_string("GET PCO",gripper_socket)
            sync()
            string_from_server = socket_read_string(gripper_socket)
            sync()
            if (string_from_server == "0"):
            textmsg("Gripper Connection State : ", "No connection problem detected")
            else:
            textmsg("Gripper Connection State : ", "Connection problem detected")
            end
            end

            # Returns True if list_of_bytes is [3, 'a', 'c', 'k']
            def is_ack(list_of_bytes):

            # list length is not 3
            if (list_of_bytes[0] != 3):
            return False
            end

            # first byte not is 'a'?
            if (list_of_bytes[1] != 97):
            return False
            end

            # first byte not is 'c'?
            if (list_of_bytes[2] != 99):
            return False
            end

            # first byte not is 'k'?
            if (list_of_bytes[3] != 107):
            return False
            end

            return True
            end

            # Returns True if list_of_bytes is not [3, 'a', 'c', 'k']
            def is_not_ack(list_of_bytes):
            if (is_ack(list_of_bytes)):
            return False
            else:
            return True
            end
            end

            def is_STA_gripper_activated (list_of_bytes):

            # list length is not 1
            if (list_of_bytes[0] != 1):
            return False
            end

            # byte is '3'?
            if (list_of_bytes[1] == 51):
            return True
            end

            return False
            end

            # Returns True if list_of_byte is [1, '1'] or [1, '2']
            # Used to test OBJ = 0×1 or OBJ = 0×2
            def is_OBJ_object_detected (list_of_bytes):

            # list length is not 1
            if (list_of_bytes[0] != 1):
            return False
            end

            # byte is '2'?
            if (list_of_bytes[1] == 50):
            return True
            end

            # byte is '1'?
            if (list_of_bytes[1] == 49):
            return True
            end

            return False

            end

            # Returns True if list_of_byte is [1, '3']
            # Used to test OBJ = 0×3
            def is_OBJ_gripper_at_position (list_of_bytes):

            # list length is not 1
            if (list_of_bytes[0] != 1):
            return False
            end

            # byte is '3'?
            if (list_of_bytes[1] == 51):
            return True
            end

            return False
            end

            def is_not_OBJ_gripper_at_position (list_of_bytes):

            if (is_OBJ_gripper_at_position(list_of_bytes)):
            return False
            else:
            return True
            end
            end

            def is_FLT_no_fault(list_of_bytes):

            # list length is not 2
            if (list_of_bytes[0] != 2):
            return False
            end

            # first byte is '0'?
            if (list_of_bytes[1] != 48):
            return False
            end

            # second byte is '0'?
            if (list_of_bytes[2] != 48):
            return False
            end

            return True

            end

            def is_FLT_action_delayed(list_of_bytes):

            # list length is not 2
            if (list_of_bytes[0] != 2):
            return False
            end

            # first byte is '0'?
            if (list_of_bytes[1] != 48):
            return False
            end

            # second byte is '5'?
            if (list_of_bytes[2] != 53):
            return False
            end

            return True
            end

            def is_FLT_not_activated(list_of_bytes):

            # list length is not 2
            if (list_of_bytes[0] != 2):
            return False
            end

            # first byte is '0'?
            if (list_of_bytes[1] != 48):
            return False
            end

            # second byte is '7'?
            if (list_of_bytes[2] != 55):
            return False
            end

            return True
            end

            def is_FLT_autorelease_in_progress(list_of_bytes):

            # list length is not 2
            if (list_of_bytes[0] != 2):
            return False
            end

            # first byte is '1'?
            if (list_of_bytes[1] != 49):
            return False
            end

            # second byte is '1'?
            if (list_of_bytes[2] != 49):
            return False
            end

            return True

            end

            def is_FLT_overcurrent(list_of_bytes):

            # list length is not 2
            if (list_of_bytes[0] != 2):
            return False
            end

            # first byte is '1'?
            if (list_of_bytes[1] != 49):
            return False
            end

            # second byte is '4'?
            if (list_of_bytes[2] != 52):
            return False
            end

            return True

            end

            def is_FLT_autorelease_completed(list_of_bytes):

            # list length is not 2
            if (list_of_bytes[0] != 2):
            return False
            end

            # first byte is '1'?
            if (list_of_bytes[1] != 49):
            return False
            end

            # second byte is '5'?
            if (list_of_bytes[2] != 53):
            return False
            end

            return True

            end

            def rq_set_var(var_name, var_value, gripper_socket="gripper_socket"):

            sync()
            if (var_name == ACT):
            socket_set_var("ACT", var_value, gripper_socket)
            elif (var_name == GTO):
            socket_set_var("GTO", var_value, gripper_socket)
            elif (var_name == ATR):
            socket_set_var("ATR", var_value, gripper_socket)
            elif (var_name == ARD):
            socket_set_var("ARD", var_value, gripper_socket)
            elif (var_name == FOR):
            socket_set_var("FOR", var_value, gripper_socket)
            elif (var_name == SPE):
            socket_set_var("SPE", var_value, gripper_socket)
            elif (var_name == POS):
            socket_set_var("POS", var_value, gripper_socket)
            else:
            end

            sync()
            ack = socket_read_byte_list(3, gripper_socket)
            sync()

            while(is_not_ack(ack)):

            textmsg("rq_set_var : retry", " …")
            textmsg("rq_set_var : var_name = ", var_name)
            textmsg("rq_set_var : var_value = ", var_value)

            if (ack[0] != 0):
            textmsg("rq_set_var : invalid ack value = ", ack)
            end

            socket_set_var(var_name , var_value,gripper_socket)
            sync()
            ack = socket_read_byte_list(3, gripper_socket)
            sync()
            end
            end

            def rq_get_var(var_name, nbr_bytes, gripper_socket="gripper_socket"):

            if (var_name == FLT):
            socket_send_string("GET FLT",gripper_socket)
            sync()
            elif (var_name == OBJ):
            socket_send_string("GET OBJ",gripper_socket)
            sync()
            elif (var_name == STA):
            socket_send_string("GET STA",gripper_socket)
            sync()
            elif (var_name == PRE):
            socket_send_string("GET PRE",gripper_socket)
            sync()
            else:
            end

            var_value = socket_read_byte_list(nbr_bytes, gripper_socket)
            sync()

            return var_value
            end

            ############################################
            # normalized functions (maps 0-100 to 0-255)
            ############################################
            def rq_set_force_norm(force_norm, gripper_socket="gripper_socket"):
            force_gripper = norm_to_gripper(force_norm)
            rq_set_force(force_gripper, gripper_socket)
            end

            def rq_set_speed_norm(speed_norm, gripper_socket="gripper_socket"):
            speed_gripper = norm_to_gripper(speed_norm)
            rq_set_speed(speed_gripper, gripper_socket)
            end

            def rq_move_norm(pos_norm, gripper_socket="gripper_socket"):
            pos_gripper = norm_to_gripper(pos_norm)
            rq_move(pos_gripper, gripper_socket)
            end

            def rq_move_and_wait_norm(pos_norm, gripper_socket="gripper_socket"):
            pos_gripper = norm_to_gripper(pos_norm)
            rq_move_and_wait(pos_gripper, gripper_socket)
            end

            def rq_set_pos_norm(pos_norm, gripper_socket="gripper_socket"):
            pos_gripper = norm_to_gripper(pos_norm)
            rq_set_pos(pos_gripper, gripper_socket)
            end

            def rq_current_pos_norm(gripper_socket="gripper_socket"):
            pos_gripper = rq_current_pos(gripper_socket)
            pos_norm = gripper_to_norm(pos_gripper)
            return pos_norm
            end

            def gripper_to_norm(value_gripper):
            value_norm = (value_gripper / 255) * 100
            return floor(value_norm)
            end

            def norm_to_gripper(value_norm):
            value_gripper = (value_norm / 100) * 255
            return ceil(value_gripper)
            end

            def rq_get_position():
            return rq_current_pos_norm()
            end
            #########################################
            rq_obj_detect = 0
            socket_open("127.0.0.1",63352,"gripper_socket")

            #######Vision urcap preamble end##########
            ###########################################

            $ 1 "BeforeStart"
            $ 2 "open:=socket_open('192.168.1.11',30004)"
            open:=socket_open("192.168.1.11",30004)
            $ 3 "Loop open≟False"
            Loop open == False
            $ 4 "open:=socket_open('192.168.1.11',30004)"
            open:=socket_open("192.168.1.11",30004)
            $ 5 "targetPos:=p[0,0,0,0,0,0]"
            targetPos:=p[0,0,0,0,0,0]
            $ 6 "counter:=0"
            counter:=0
            while (True):
            $ 7 "Robot Program"
            $ 8 "sendToServer:='send to server'"
            sendToServer:='send to server'
            $ 9 "socket_send_string(sendToServer)"
            socket_send_string(sendToServer)
            $ 10 "receiveFromServ:=socket_read_ascii_float(6)"
            receiveFromServ:=socket_read_ascii_float(6)
            $ 11 "Loop receiveFromServ[0]≠6"
            Loop receiveFromServ[0] != 6
            $ 12 "Wait 0.3"
            Wait 0.3
            $ 13 "receiveFromServ:=socket_read_ascii_float(6)"
            receiveFromServ:=socket_read_ascii_float(6)
            $ 14 "Loop counter<6"
            Loop counter<6
            $ 15 "targetPos[counter]=receiveFromServ[counter+1]"
            targetPos[counter]=receiveFromServ[counter+1]
            $ 16 "counter=counter+1"
            counter=counter+1
            $ 17 "MoveJ"
            MoveJ
            $ 18 "targetPos"
            targetPos
            $ 19 "counter:=0"
            counter:=0
            end
            end

          3. zacopressadmin Post author

            Hi Can

            Is the second open:=socket_open(“192.168.1.11″,30004) inside the Loop statement ?

            Because it should be indented

            In your code it looks like this
            BeforeStart
            open:=socket_open(“192.168.1.11″,30004)
            Loop open≟False
            open:=socket_open(“192.168.1.11″,30004)

            But in the example page it looks like this

            Loop open≟ False
            open≔socket_open(“127.0.0.1″,21) This line is indented

            What is the IP address of the robot ?

            And what is the IP address of the computer with Lab View ?

            When you typed in the command open:=socket_open(“192.168.1.11″,30004) – did you use the Assignment or a Script entry to insert it into the Polyscope program ?

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

            Also check out the CB3 forum


          4. zacopressadmin Post author

            Hi Can

            Maybe consider to use Assignment entry.

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

            Also check out the CB3 forum


          1. hyerim

            Hi Can and Author,

            I have a same purpose with Can and met same problem.
            My purpose is to control UR3 by using client(UR3)-server(PC with Labview) TCP/IP communication.
            First, I try to check client-server connection by SocketTest.
            SocketTest is listening on 192.168.0.13(My PC IP) with port 30000
            UR3 script is also trying to open socket on 192.168.0.13 with port 30000

            BeforeStart
            conn:=False >> assignment
            Robot Program
            Loop conn≟False
            conn:=socket_open(“192.168.0.13″,30000) >> assignment
            Wait: 0.1

            However, SocketTest couldn’t connect any client.
            the variable conn also remaining false

            Please, give me advice about above problem?
            And, can you show me the your success vi, Can?

            Thanks!

          2. zacopressadmin Post author

            Hi hyerim

            Thanks for the question.

            Is the “Sockettest” set to be a Server ?

            The apostrophes in the IP assignement looks a little odd “192.168.0.13″ – maybe consider to check that they are apostrophes and typed in via the teach pendant keyboard.

            What is the IP address of the robot ?

            Can the PC ping the robot and get a positive reply ?

            An example of a client_server TCP socket and test with Sockettest can also be found 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



          3. hyerim

            Hello,

            Sockettest set to be server and my robot IP is “192.168.0.2″
            Two device(robot, PC) share IPTIME wifi.
            Also, robot reply on ping test.

            I already successfully check client(PC)-server(UR3) connection using port 30002.
            However, reverse connection, client(UR3)-server(PC), was failed.

            Please, let me know what’s the problem of me.

            Thanks!

          4. zacopressadmin Post author

            Hello hyerim

            What is the IP address and port number set in the Sockettest as server ?

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

            Also check out the CB3 forum



  18. Dan Ho

    Hi Lars,

    i have a python programm from where i want to change a variable in my UR-program.
    Is there a way like “send(“turn_right:= True\n”)”, so that i can change the value of the variable ?
    I need this because i need to react to an event happening in my external program.
    Thanks,

    Dan

    Reply
    1. zacopressadmin Post author

      Hi Dan

      Thanks for the question.

      I assume you need to change the variable that is used in a Polyscope program. It is no possible to change in the way you describe – but another method that can be considered is to use a MODBUS register in the UR.

      A MODBUS register can be set from external via port 502 – and the same register can be read from within a Polyscope program – and it can also be used the other way arround.

      An example similar to this can be found at thin link below. Scroll down to the palce where MODBUS register 128 and 129 are used.

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

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

      Also check out the CB3 forum


      Reply
  19. Rahul

    Hello,
    Is it possible to run scrips or urp files saved in the controller from an external computer connected to the controller?

    Reply
    1. zacopressadmin Post author

      Hello

      Thanks for the question.

      It is possible to load .urp files that is saved on the controller – from a PC connected over the Ethernet via port 29999.

      More informations at this link.

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

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

      Also check out the CB3 forum


      Reply
  20. Nicholas Pestell

    Hi Lars,

    In my application it’s necessary to make sequential moves in a straight line with the tool. I have tried using “movel” command which works nicely for straight line motion, however it seems a command is overridden by the subsequent one if the the subsequent command is send before the previous one has finished executing. In order to solve this I would hope there is a sort of confirmation message send back over the TCP/IP connection so that I can wait for this message to be received before sending the next command to the controller. It seems that this is not the case however? Or am I missing something? Is there a something that you could suggest that would enable my code to hang until a particular command has been fully executed?

    Ideally, I’d like something more robust than using a sleep or wait function.

    Many thanks,

    Nick

    Reply
    1. zacopressadmin Post author

      Hi Nick

      I assume you send the commands from an external host to either port 30001 or 30002 or 30003 on the robot – and Yes your observation is correct that an unfinished command will be overwritten by the next command.

      You might consider to use the realtime Matlab data that are streamed out of port 30003. This data contains the position (and other data) of the robot – and therefore it might be possible to read this data and verify that the robot has arrived at a desired position before sending a new command. The Matlab data is streamed out from port 30003 continuously (without having to ask for it) and the program on the host needs to be able to swallow the data and look at the data to determine when the robot has arrived.

      I have not used this data much myself, but I have tested a small program that reads the position data.

      You might consider to read the notes about realtime interface at the link below and especially the file “Client_Interface.xls” that can be downloaded – and the tab “RealTime_3.2″ has some informations for the position of the data.

      https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/remote-control-via-tcpip-16496/

      I tested the position data using a small Python program that reads the datastream every 1 second.

      # Echo client program
      import socket
      import time
      import struct

      HOST = “192.168.0.9″ # The remote host
      PORT_30003 = 30003

      print “Starting Program”

      count = 0
      home_status = 0
      program_run = 0

      while (True):
      if program_run == 0:
      try:
      s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      s.settimeout(10)
      s.connect((HOST, PORT_30003))
      time.sleep(1.00)
      print “”
      packet_1 = s.recv(4)
      packet_2 = s.recv(8)
      packet_3 = s.recv(48)
      packet_4 = s.recv(48)
      packet_5 = s.recv(48)
      packet_6 = s.recv(48)
      packet_7 = s.recv(48)
      packet_8 = s.recv(48)
      packet_9 = s.recv(48)
      packet_10 = s.recv(48)
      packet_11 = s.recv(48)

      packet_12 = s.recv(8)
      packet_12 = packet_12.encode(“hex”) #convert the data from \x hex notation to plain hex
      x = str(packet_12)
      x = struct.unpack(‘!d’, packet_12.decode(‘hex’))[0]
      print “X = “, x * 1000

      packet_13 = s.recv(8)
      packet_13 = packet_13.encode(“hex”) #convert the data from \x hex notation to plain hex
      y = str(packet_13)
      y = struct.unpack(‘!d’, packet_13.decode(‘hex’))[0]
      print “Y = “, y * 1000

      packet_14 = s.recv(8)
      packet_14 = packet_14.encode(“hex”) #convert the data from \x hex notation to plain hex
      z = str(packet_14)
      z = struct.unpack(‘!d’, packet_14.decode(‘hex’))[0]
      print “Z = “, z * 1000

      packet_15 = s.recv(8)
      packet_15 = packet_15.encode(“hex”) #convert the data from \x hex notation to plain hex
      Rx = str(packet_15)
      Rx = struct.unpack(‘!d’, packet_15.decode(‘hex’))[0]
      print “Rx = “, Rx

      packet_16 = s.recv(8)
      packet_16 = packet_16.encode(“hex”) #convert the data from \x hex notation to plain hex
      Ry = str(packet_16)
      Ry = struct.unpack(‘!d’, packet_16.decode(‘hex’))[0]
      print “Ry = “, Ry

      packet_17 = s.recv(8)
      packet_17 = packet_17.encode(“hex”) #convert the data from \x hex notation to plain hex
      Rz = str(packet_17)
      Rz = struct.unpack(‘!d’, packet_17.decode(‘hex’))[0]
      print “Rz = “, Rz

      home_status = 1
      program_run = 0
      s.close()
      except socket.error as socketerror:
      print(“Error: “, socketerror)
      print “Program finish”

      The output is shown below.

      >>>
      Starting Program

      X = -144.53373083
      Y = 300.001654484
      Z = 299.979314593
      Rx = -2.09526134911e-05
      Ry = 3.13994079182
      Rz = 1.09322018721e-05

      And this is also the position of the robot.

      Notice: Data of a very small value is written as exponent of 10 – and a value of 10-05 is very small – and is virtual 0.

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

      Also check out the CB3 forum

      Reply
      1. Nicholas Pestell

        Wow! once again thank you for such an in depth response. Yes I’m connecting to the controller from an external host. I will try coding this up to see if I can use it practically. If I were to use port 30003 for sending commands, could I use this same connection for receiving the Matlab data?

        I’ve also had a quick look at some alternatives, including this “client-server” technique;

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

        Do you think it’s feasible to use this technique for online control of the arm using moveL commands where the the previous command is fully executed before sending the next command?

        Thanks,

        Nick

        Reply
        1. zacopressadmin Post author

          Hi Nick

          Yes to send commands to port 30001, 30002 and 30003 is the same method, but the data stream automatically send out from the robot from these ports is different which can be seen in the Client_Interface.xls document.

          Yes the client-server technique is in a way a more clean approach because you as programmer can control the data flow and design your own protocol of data exchange between the robot and host. It requires a program on the robot – which the above method doesnt.

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

          Also check out the CB3 forum

          Reply
      2. Stefan

        Hello,

        I tested the code that you shared to get the position of the robot and it worked as expected and according to the obtained values in the polyscope. However, I tried to adapt this same code to get the torques with the help of the file “Client_Interface.xls” and the values obtained no longer correspond with the values obtained in the polyscope.

        This is the part of the code that I changed to isolate the torques.

        (…)

        packet_1 = s.recv(4)
        packet_2 = s.recv(8)
        packet_3 = s.recv(48)
        packet_4 = s.recv(48)
        packet_5 = s.recv(48)
        packet_6 = s.recv(48)

        packet_7 = s.recv(8)
        packet_7 = packet_7.encode(‘hex’)
        x = str(packet_7)
        x = struct.unpack(‘!d’, packet_7.decode(‘hex’))[0]
        print ‘A = ‘, x

        (…)

        In the polyscope I use the get_joint_torques () command to compare the values obtained by the script. Am I reading the wrong values or decrypting the data in the wrong way in the script?

        Another question:

        I tried to get the data through the RTDE protocol obtained on the site

        https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/real-time-data-exchange-rtde-guide-22229/

        But is giving the following errors

        ERROR:root:RTDE_GET_URCONTROL_VERSION: Wrong payload size
        ERROR:root:Server message: Parse Error: package type not supported or package invalid, package type: V data:

        Is it necessary to make any changes to the files provided?

        Thanks,

        Stefan

        Reply
        1. zacopressadmin Post author

          Hi Stefan

          Thanks for the question.

          I have not tried to use the data for the torques nor the RTDE examples, but maybe some others on the forum have. There is also data streamed out on port 30001 and 30002.

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

          Also check out the CB3 forum


          Reply
          1. zacopressadmin Post author

            Hello Stefan

            Sounds great – thanks for the update.

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

            Also check out the CB3 forum


  21. Joris Guérin

    Hi,

    I am working on a UR10 with CB2. I would like to control the robot real time.
    That is send desired angular positions and read informations at 125Hz. I found that this can be done with the port 30004 but that it does not work on CB2.
    Can this be done with CB2 on port 30003? I found many things about how to read robot states on this port but nothing on how to send commands?
    Is it possible and if yes where can I find info about that?

    Thank you in advance,

    BR,

    Joris

    Reply
  22. Mary

    Hi,
    I currently have a program where I want to use the force function to close a door on a CNC machine. I tried applying just a simple force to go between two horizontal waypoints (from door open to door close). Every time I try to run the program I am getting the popup “Force mode not possible in singularity.” Do you know the best way to fix this or change it?
    Thanks!
    Mary

    Reply
    1. zacopressadmin Post author

      Hi Mary

      Thanks for the question.

      It might be the waypoint positions and the trajectory between them that creates a singularity. And the force function is intended to be used where constant force is to be applied on a surface – for example polishing or deburring.

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

      Also check out the CB3 forum

      Reply
  23. Antoine

    Hello Lars,

    In these programs you only send one instruction at a time through the connexion then you wait for the instruction to complete. This is painful because you need to know about the time the instruction takes. Is there a way to send multiple instructions (or say a whole program) at a time?

    Kind regards,

    Antoine.

    Reply
    1. zacopressadmin Post author

      Hello Antoine

      Thanks for the question.

      Your observation is correct and thats why this method of programming is a kind of one way communication and each command typical needs to finish before a new command can be send. It depends on the nature of program that can be send in one bulk. If the program works in a way that controls the robot in small chuncks – meaning that every new command is allowed to terminate the previous command and execute the new command – then an entire “program” which is a list of script commands can be streamed to the robot and the robot will execute while the commands are being streamed. But it is not possible to send all the script commands first – and then start the program in this method. Instead the program (commands) will be executed as the stream flows. And it is not ideal to read inputs or use loops with this method.

      It is possible to develop a .urp program (Polyscope program) on another robot and then FTP the .urp program to the robot and then start this new program through the dashboard server.

      Another possibility is to program “functions” which can be a “script file” which can be FTP to the robot, but such functions will need to be embedded into the Polyscope program – and some examples are shown at this link. Its important to read the text about importing the script files into the Polyscope program before they will be executed.

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/functions-1/

      You might also consider a Client-Server solution – which has an example at this link

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

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

      Also check out the CB3 forum

      Reply
      1. Antoine

        Lars, your answer is interesting. Now what about sending a script in a single TCP send() and with multiple movej / movel one after another in the script? Will the URC execute the commands one after another like in the polyscope?

        Kind regards,

        Antoine.

        Reply
        1. zacopressadmin Post author

          Antoine

          That is not likely to work – because if the commands are in one TCP send() then there is no delay time in between the commands and they are not likely to be executed. Maybe the very last command might be executed, but not sure because if many commands are “flooding” the port then they can be rejected.

          This is not the intended way of sending commands.

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

          Also check out the CB3 forum

          Reply
          1. Antoine

            Ha, that’s interesting! This explains the behaviors I have observed so far.

            Now does this mean the polyscope has got a way to know when a command is finished (in order to start the next command)?

            And for us (sending commands over TCP) Is there a signal sent over the client interfaces for us to intercept and know when the current command is finished?

            Another way to put it is, currently I wait after each command for it to finish. Determining the completion time for each command is a real pain (I do it by trial and error and it takes ages), is there another way?

            Thanks,

            Antoine.

        2. Andreas

          Hi,
          when i want to send multiple movej or movel commands in one byte array i use the following trick:

          TCP/IP command: “while(True): movej(…) movej(…) movej(…) sleep(0.01) break end”

          It is really ugly, but it is the only way i found to send more then one command!

          Reply
          1. zacopressadmin Post author

            Hi Andreas

            Can you share the entire command ?

            Is it send from an external device or is it from inside Polyscope ?

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

            Also check out the CB3 forum


          2. Andreas

            Hi,
            Lars, i’m not able to reply to your post. So i create a new one.

            I use the Qt framework in C++: http://www.qt.io. Source code:

            QString pose1 = “p[0.0, 0.3, 0.2, 0.0, 3.1415, 0.0]“;
            QString pose2 = “p[0.3, 0.3, 0.2, 0.0, 3.1415, 0.0]“;
            QString pose3 = “p[0.3, 0.0, 0.2, 0.0, 3.1415, 0.0]“;

            QString tempUrCommand = “while(True): %1 %2 %3 sleep(0.01) end”; // Endless loop. For an only once loop add break after sleep
            QString urCommand = tempUrCommand.arg(pose1).arg(pose2).arg(pose3); // Replace %1, %2 and %3 with pose1, pose2 and pose3
            urCommand.append(“\n”); // Add newline

            QTcpSocket socket;
            socket.connectToHost(“192.168.0.6″, 30002);
            socket.waitForConnected();

            socket.write(urCommand.toLocal8bit()); // Write command to socket
            socket.waitForBytesWritten();

            I also need to send more then one command to the ur controller. I recognized that the controller is able to handle a while(True) – loop. In this loop the move-commands running in sequence. To quit the loop you can call the break statement.

            I think this method is not the correct way to send multiple commands, but it is the only working solution if found so far.

          3. Andreas

            Hups,
            there is a mistake in my source code (sorry, the code was written from my mind and i cannot edit my post)

            Of course you are not able to send only the pose. You need to use the move command. For example:

            QString move1 = “movel(p[0.0, 0.3, 0.2, 0.0, 3.1415, 0.0]);
            QString move2 = “movel(p[0.3, 0.3, 0.2, 0.0, 3.1415, 0.0]);
            QString move3 = “movel(p[0.3, 0.0, 0.2, 0.0, 3.1415, 0.0]);

            QString tempUrCommand = “while(True): %1 %2 %3 sleep(0.01) end”; // Endless loop. For an only once loop add break after sleep
            QString urCommand = tempUrCommand.arg(move1).arg(move2).arg(move3); // Replace %1, %2 and %3 with move1, move2 and move3

            And to clarify, the commands are not send from the polyscope.

  24. Arthur

    Dear Lars,

    I am trying to use the Universal Robot UR10 in order do get the real time joint configuration feedback via socket and using the s.recv(1024) command. But when I connect with Ethernet in Port 30003 all I am getting is hex characters with special characters such as \, < and ^.
    Do you have any idea how to decode these ?

    Regards,
    Arthur

    Reply
    1. zacopressadmin Post author

      Dear Arthur

      Thanks for the question.

      These data are Matlab data and some more information can be found at this link below – where there is a document “Client_Interfaces.xlsx” that can be downloaded.

      https://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/remote-control-via-tcpip-16496/

      I have not tried to decode the data.

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

      Also check out the CB3 forum

      Reply
  25. Pawel

    Hello Lars,

    I am currently trying to parse the output from a UR5 when using the s.recv(1060) command on port 30003. I tried following the format mentioned in the following universal robotics link…
    http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/remote-control-via-tcpip-16496/

    The problem is that when I read the raw data being sent they appear to be delimited by ‘\’ and at different packet sizes. The majority of the characters appear to be hex, but there are also special characters. Anything I have tried to decode this message does not provide any values that match the readout from the teaching pendant.

    Here is a small sample of the raw output I am getting from the arm…

    \x00\x00\x00\x18\x14\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x0c\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x05\x1a\x10\x00\x00\x00.\x00\x00\x00\x00\x01#0\xec\x00\x01\x01\x01\x00\x00\x00\x00\x07\x00?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfb\x01?\xf9\x1e\xa3\xa0\x00\x00\x00?\xf9\x1e\xb8Q\xeb\x85 \x00\x00\x00\x00\x00\x00\x00\x00\xbe\xb5Z\x7fB>\x0eVA\xe8fbA\xed\xe2\xf3\xfd\xbf\xf0\xc1zQ\

    Do you have any example or information on how to decode the information being sent back from the ur5 from port 30003?

    Regards,

    Pawel

    Reply
    1. zacopressadmin Post author

      Hi Pawel

      On the link you mention there is also a file “Client_Interface.xlsx” that can be downloaded with some further informations about the Primary and secondary client data. I have not tried to decode the data. Maybe some special characters data needs to be converted between binary and Ascii.

      There are also some more informations at this link

      http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/real-time-data-exchange-rtde-guide-22229/

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

      Also check out the CB3 forum

      Reply
  26. Evgueni

    Dear Lars,
    I have not tried to remove comments completely, but I can confirm that URscript with comments (lines starting with #) works fine with shorter URscript files. So it is not that UR5 fundamentally cannot digest comments in URscript. I will strip out comments and try.
    Eugene.

    Reply
  27. Evgueni

    Dear Lars,
    I have run into an intermittent problem when transmitting URscript program to UR5 over TCP/IP socket. The program is apparently sometimes incompletely received by UR5, in which case it is ignored. This seems to be related to the size of URscript – with a short program (a few lines) there is almost never a glitch. If I simply add padding to the same program, e.g. many lines starting with # (comments) then I get much more frequent transmission failures. At the application level TCP/IP socket is handled by LabVIEW and this reports no errors even when there is a failure. But I can see from Wireshark logs that the URscript transmission to UR5 is terminated partway. So it seems like the problem is at the interface between OS and UR5. My PC runs Win 7 (64bit). I have tried a different PC (with the same OS) – this did not eliminate the intermittent problem, in fact the other PC seemed worse because even short URscript programs were frequently not received by UR5. When I redirect the TCP stream to SocketTest running on another machine on the LAN, transmission is reliable regardless of URscript size.

    Are you aware of any limitations of URx TCP/IP socket interface that would cause this behaviour? Has anyone else reported something like this?

    Thank you in advance,
    Evgueni.

    Reply
      1. Evgueni

        Dear Lars,
        I have just tried with every single comment stripped out from URscript file. The problem is still there. The problem is intermittent in the sense that when I send the exact same URscript file several times, sometimes it is received properly and executed and sometimes it is not properly received by UR5. I wait until previous execution stops before sending URscript again (I use dashboard server ‘running’ command to poll UR5).
        Best regards,
        Eugene.

        Reply
        1. zacopressadmin Post author

          Dear Eugene

          Does the script contain waypoints and move of the robot ? or other commands that might take time to perform for example wait commands etc ?

          Then it might be necessary to wait between sending over the socket until each such commands are finish and also the performing of the command is finish before the next command is send. In the Python example here on the forum there are “sleep” time in between commands. The “sleep” itself is not send to the robot, but the sleep on the host side make sure there is time to perform the command and also the move if it is a move that take time to perform on the robot side.

          I am not sure I understand the difference of your “wait until previous execution stops before sending URscript again” – is that wait in between single command lines – or wait in between a bunch of command lines ? – Does you “URscript” contain several command lines ?

          The wait might need to be in between each single command lines.

          Regards
          Lars

          Reply
          1. Evgueni

            Dear Lars,
            Yes I have move commands in the program. I send a complete URscript program enclosed within “def MyProg():” and “end” statements. Programmatically, I then poll at 100ms intervals on the dashboard interface (port 29999) until I detect that the response from UR5 changes from “Program running: true” to “Program running: false”. Only then I send the next URscript. Crucially, I can reproduce the same intermittent fault by manually initiating the sending of URscript so I can ensure first that the robot is no longer moving, and wait some seconds just to be on the safe side. Also sometimes the transmission fails on the very first attempt to send URscript. I am convinced this is not a case of not waiting long enough.
            Best regards,
            Eugene.

          2. zacopressadmin Post author

            Dear Eugene

            Can you list the script you are sending to the robot.

            Which port are you sending the script ?

            Regards
            Lars

          3. Evgueni

            Dear Lars,
            sure – below is the ‘short’ URscript that almost always works fine. I use port 30002, but have tried 30001 and 30003 also, with the same results.
            Best regards,
            Eugene.

            def weldProg():
            blade_in_tray_x = 0.409000
            blade_in_tray_y= 0.291500
            tcp_z = 0.1
            set_tcp(p[0.0,0.0,tcp_z,0.0,0.0,0.0])
            set_payload(0.2, [0.0, 0.0, 0.018])
            set_gravity([0.0, 0.0, 9.82])

            # Rotation Vector angles for blade tray, obtained empirically
            tcp_tray_rvx = 2.2126
            tcp_tray_rvy = -0.0193
            tcp_tray_rvz = 2.2126
            # TCP Z for blade scan / drop height
            tcp_z_scan = 0.350
            movel(p[blade_in_tray_x, blade_in_tray_y, tcp_z_scan, tcp_tray_rvx, tcp_tray_rvy, tcp_tray_rvz], a=1, v=1)
            sleep(0.1)
            end

          4. zacopressadmin Post author

            Dear Eugene

            If this one works – is there another one that fails ?

            Need to see the one that fails.

            Is there any Polyscope program running on the robot ?

            Regards
            Lars

          5. Evgueni

            Dear Lars,
            they all fail, including the one I posted. The only difference is how often they fail – the more lines in the URscript, the more often I see a failure, even if the extra lines are just comments. Examining Wireshark and Microsoft Network Monitor logs of TCP traffic between UR5 and the PC I can see that when a failure occurs, the URscript transmission from PC to UR5 does not complete. The TCP socket connection is terminated from the PC side when the Reset flag is sent in the middle of the transmission. For successful transmissions, the Reset flag comes after the Fin (End of Data) flag is sent. I do not know what causes the PC to decide to reset the connection..
            Best regards,
            Eugene.

          6. zacopressadmin Post author

            Dear Eugene

            I have tried your script on my real robot by sending it from a Python application from my PC (because I dont have LabView). And when sending all the script lines in one go (except the comments which I filter out) then the script executes and performes every time I have run it on the robot.

            What next you might consider to check is.

            1.
            Anti virus software. I have not had problems with this – but I have heard from others that they needed to turn it off.

            2.
            Firewall. Same as Anti virus software I have not had problems with this – but I have heard from others that they needed to turn it off.

            3.
            \n (Linefeed). I am sending \n (which is a linefeed) after each line i.e I send 14 \n (one after each line).

            4.
            Labview. I am not familiar with LabView, but maybe it insert some wrapping like the Reset flag you mention – or other hidden data that interfere with the TCP scocket connection.

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

            Also check out the CB3 forum

          7. Evgueni

            Dear Lars,
            I have investigated further with Wireshark and found that the apparent cause of the problem is the unsolicited data arriving from UR5 whilst PC is transmitting URscript to it. As you know UR5 broadcasts robot state messages at regular intervals to any TCP client that connects to ports 30001, 30002, 30003 or 30004. With shorter URscript the chance of collision is less, this is what was happening. My inelegant workaround is to time the URscript transmission to occur in between UR5 broadcasts.. But it would be nice to turn off these broadcasts, or figure out a way to tell the PC to ignore them and carry on! Do you have any thoughts?
            Best regards,
            Eugene

          8. zacopressadmin Post author

            Hi Eugene

            Interesting investigation. Yes the “Matlab” data is constantly send out from the robot on these ports.

            My thoughts are

            1.
            Normally Ethernet can handle collisions – actually on Ethernet there are collisions many times – and a part of most Ethernet protocol is “CD” (collision detection) – and Ethernet is just designed to resend. So if collisions are a cause then it might be the application layer on the PC (maybe LabView buffers) that has issue to handle (“swallow”) this traffic – so your workaround might help the application on the PC to handle the data because you have freed up some time for the application. Do you have another way than LabView to send your script ?

            2.
            I tried your script (with Python) and it performed every time I tried it – no sign of collisions. And I have also made programs where there are send much more script data and I have not experienced any interference or collision issues – which makes me I think the Ethernet layer TCP ports on a normal PC can handle this traffic. I even tried to send script commands over the Internet from a PC in Singapore to a real robot in Denmark without any sign of missing data.

            3.
            I think port 30003 send a little less data out from the robot than the other ports, but I don´t know if it can be completely stopped.

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

            Also check out the CB3 forum

          9. Evgueni

            Hello Lars,
            yes I was also surprised to find that UR5′s unsolicited data were causing a problem. My first thought was that LabVIEW is not handling this properly, however LabVIEW is not in control of the TCP/IP stack and it simply hands the data over to the OS. My application does not even read the Rx buffer – perhaps it is the Rx buffer filling up that causes the OS to abort.
            In your Python code that handles URscript transmission to URx, do you read the Rx buffer in parallel with transmitting URscript?
            Best regards,
            Eugene.

          10. zacopressadmin Post author

            Hello Eugene

            In the test of your script with Python code – I do not read the RX buffer – I just send the script only.

            My thoughts are still to consider to send the same script with another application instead of LabView – and also maybe with another PC – and then also consider to check the network connectivity – both physically like cabling etc, but also settings such as IP address – Subnet on PC – router – hub – switch (if any).

            I find it better to have a hub or switch in between instead of only one cable connecting the PC and robot directly.

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

            Also check out the CB3 forum

          11. Evgueni

            Hello Lars,
            most of my testing is done with a normal LAN network between PC and UR5 – both router and switches present. However I did try a direct connection and this did not change anything for me. The direct connection was just with Ethernet cable – no hub. Both cross-over cable and normal cable worked fine (I guess one of both NICs are smart enough). Regardless whether direct or routed connection is in place, I have to add an entry for UR5 to the HOSTS file on the PC in order to eliminate a delay of 1-2 seconds when connecting to UR5 which I think is caused by reverse DNS lookup timeout. Just to check I reversed this fix but it also made no difference – I still had intermittent aborted connections.
            I can live with my workaround for now but I hope some day I can understand what’s going on..
            Best regards,
            Eugene.

          12. Evgueni

            Hello Lars,
            I had a chance to compare TCP streams – successful transmission versus failed one. It looks like there is a valid reason for PC to reset connection. During an unsuccessful transmission, only every other TCP frame is acknowledged by the UR5 back to the PC. During a successful transmission, all TCP frames are acknowledged. It looks like a bug in UR5, like UR5 is unable to receive the data stream properly at the same time as it sends out its own data. It seems the problem occurs at the OS TCP/IP stack level but I would think LabVIEW should be aware of it – I do not understand why no error messages are seen.

            I would like to try using a Python script instead of LabVIEW to try and reproduce the problem but I do not have anything ready-made for reading in URscript from a file and sending it out over a TCP socket. Is there example Python code I can quickly adapt?

        2. Evgueni

          Hello Lars,
          I have further information. I noticed that even at the end of a successful transmission (that is to say UR5 receives the URscript and executes it), the termination is abnormal – PC sends a RST frame. I did a quick experiment by redirecting the TCP/IP socket connection from my LabVIEW program to SocketTest on another PC (instead of to UR5). Wireshark capture from this shows that the (successful) transmission is terminated with a mutual exchange of FIN,ACK frames. However UR5 never responds with FIN,ACK at the end of ‘successful’ transmission and instead the connection is reset by the PC the next time UR5 sends its status data. I cannot easily verify if this is because the TCP/IP stack is implemented differently on UR5 or some other possibility (data arriving too fast? limitations of RTOS?).

          I think the experiment shows that it is unlikely that LabVIEW/PC is mishandling the connection. It would be nice to try the same with Python.

          Best regards,
          Eugene.

          Reply
          1. Evgueni

            Hello Lars,
            I have reproduced the problem with Python. Wireshark log shows a similar pattern as before – UR5 happens to transmit robot status data to PC at the same time as PC is transmitting URscript to UR5, the PC decides something is not right and terminates early with a RST frame.

            Also, successful transmissions to UR5 are abnormally terminated by a RST frame from the PC same as when I send URscript via LabVIEW.

            This is my Python code:

            import socket
            import time
            HOST = ’192.168.4.29′ # UR5 IP addr
            PORT = 30002
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((HOST, PORT))
            f = open(‘myURscript.txt’)
            line = f.readline()
            # If the file is not empty keep reading one line at a time
            while line:
            data = bytes(line, ‘utf-8′)
            s.send (data)
            line = f.readline()
            f.close()
            s.shutdown(socket.SHUT_RDWR)
            s.close()

            What do you do differently in your Python implementation?
            Best regards,
            Eugene.

          2. zacopressadmin Post author

            Hello Eugene

            Thanks for your question.

            1. The first Python program I made and tested – was this program below. Notice your script commands are in the s.send command string. When I tested this I moved the robot manually between each time I started the program and send the scripts over because I wish to see the robot move to the commanded position – in order to observe and be sure that the robot received and executed the commands – and the robot does perform the correct move every time I try. Notice also that in this test I do not have your script commands in a file.

            import socket
            import time

            HOST = “192.168.0.9″ # The remote host
            PORT = 30002 # The same port as used by the server

            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((HOST, PORT))
            s.send (“def weldProg():” + “\n” + “blade_in_tray_x = 0.409000″ + “\n” + “blade_in_tray_y= 0.291500″ + “\n” + “tcp_z = 0.1″ + “\n” + “set_tcp(p[0.0,0.0,tcp_z,0.0,0.0,0.0])” + “\n” + “set_payload(0.2, [0.0, 0.0, 0.018])” + “\n” + “set_gravity([0.0, 0.0, 9.82])” + “\n” + “tcp_tray_rvx = 2.2126″ + “\n” + “tcp_tray_rvy = -0.0193″ + “\n” + “tcp_tray_rvz = 2.2126″ + “\n” + “tcp_z_scan = 0.350″ + “\n” + “movel(p[blade_in_tray_x, blade_in_tray_y, tcp_z_scan, tcp_tray_rvx, tcp_tray_rvy, tcp_tray_rvz], a=1, v=1)” + “\n” + “sleep(0.1)” + “\n” + “end” + “\n”)
            time.sleep(0.1)

            2. Then I made a change to the python program so there are two positions (“tcp_z = 0.1″ and “tcp_z = 0.05″) in the script and also a counter so the script commands can be send many times and I can observe the robot move. The program still does not use a file to fetch the script commands, but it sends the script commands 100 times to the robot – and I observed and it performs 100 moves every time I try. Notice there is a delay (sleep) in between each move in order to be sure the robot is finish the move before a new command for move is send.

            import socket
            import time

            HOST = “192.168.0.9″ # The remote host
            PORT = 30002 # The same port as used by the server

            counter = 0
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((HOST, PORT))

            s.send (“def weldProg():” + “\n” + “blade_in_tray_x = 0.409000″ + “\n” + “blade_in_tray_y= 0.291500″ + “\n” + “tcp_z = 0.1″ + “\n” + “set_tcp(p[0.0,0.0,tcp_z,0.0,0.0,0.0])” + “\n” + “set_payload(0.2, [0.0, 0.0, 0.018])” + “\n” + “set_gravity([0.0, 0.0, 9.82])” + “\n” + “tcp_tray_rvx = 2.2126″ + “\n” + “tcp_tray_rvy = -0.0193″ + “\n” + “tcp_tray_rvz = 2.2126″ + “\n” + “tcp_z_scan = 0.350″ + “\n” + “movel(p[blade_in_tray_x, blade_in_tray_y, tcp_z_scan, tcp_tray_rvx, tcp_tray_rvy, tcp_tray_rvz], a=1, v=1)” + “\n” + “sleep(0.1)” + “\n” + “end” + “\n”)
            time.sleep(1.0)

            while counter < 100:
            counter = counter + 1
            s.send ("def weldProg():" + "\n" + "blade_in_tray_x = 0.409000" + "\n" + "blade_in_tray_y= 0.291500" + "\n" + "tcp_z = 0.1" + "\n" + "set_tcp(p[0.0,0.0,tcp_z,0.0,0.0,0.0])" + "\n" + "set_payload(0.2, [0.0, 0.0, 0.018])" + "\n" + "set_gravity([0.0, 0.0, 9.82])" + "\n" + "tcp_tray_rvx = 2.2126" + "\n" + "tcp_tray_rvy = -0.0193" + "\n" + "tcp_tray_rvz = 2.2126" + "\n" + "tcp_z_scan = 0.350" + "\n" + "movel(p[blade_in_tray_x, blade_in_tray_y, tcp_z_scan, tcp_tray_rvx, tcp_tray_rvy, tcp_tray_rvz], a=1, v=1)" + "\n" + "sleep(0.1)" + "\n" + "end" + "\n")
            time.sleep(0.5)
            s.send ("def weldProg():" + "\n" + "blade_in_tray_x = 0.409000" + "\n" + "blade_in_tray_y= 0.291500" + "\n" + "tcp_z = 0.05" + "\n" + "set_tcp(p[0.0,0.0,tcp_z,0.0,0.0,0.0])" + "\n" + "set_payload(0.2, [0.0, 0.0, 0.018])" + "\n" + "set_gravity([0.0, 0.0, 9.82])" + "\n" + "tcp_tray_rvx = 2.2126" + "\n" + "tcp_tray_rvy = -0.0193" + "\n" + "tcp_tray_rvz = 2.2126" + "\n" + "tcp_z_scan = 0.350" + "\n" + "movel(p[blade_in_tray_x, blade_in_tray_y, tcp_z_scan, tcp_tray_rvx, tcp_tray_rvy, tcp_tray_rvz], a=1, v=1)" + "\n" + "sleep(0.1)" + "\n" + "end" + "\n")
            time.sleep(0.5)

            3. Then I made a python program similar to your python program below - I added a sequence so I also in this example can observe that the robot receive and executes the moves. Notice I made it so there are two script files each with a position that only differs by the line ("tcp_z = 0.1" in first script file and "tcp_z = 0.05" in second script file). And I also made a counter so the scripts files can be loaded several times. Again I tried to run 100 loops and the robot performs all 100 moves every time I try. My python complain this line in your program "data = bytes(line, 'utf-8')" - so instead I just send the "line" variable over as data which works ok. I use Python 2.7 and thats maybe why the python complain this syntax.

            Maybe what can be checked is - depending on the method of sending scripts (single lines of several lines in a function) - in this case as a function - commands might need to be finish before new move commands are send in order to get commands the robot understands. When sending as function - the robot needs to receive the entire function in order to understand and the entirety of the combined function commands - whereas when sending as single line commands - for example a single line move command then the robot just need to receive this single line to execute this command, but this command will be interrupted if a new command is send before the robot has finished the execution of previous command. So there is a difference in sending several lines that constitutes a task (function) where all lines needs to be received - compared to a single line that can be executed as standing alone. So if several lines are send as a function and if the robot is interrupted (maybe by a new batch of sending data or something the sending PC does) then the function is not likely to be executed at all - compared to if several single line commands are send and if the robot is interrupted - then it is likely that only the last line will be executed because the robot understand that line in its entirety and can executed it whereas the previous single lines in such a batch has been overwritten. There will be difference in the behavior because in programming functions and single lines can contain many different design of commands - and there can be timing involved if a command take longer time as other commands like a short distance move compared to a long distance move - or different time delay commands.

            When observing the robot - the robot perform as expected - also when sending data regardless of the timing of the returned Matlab data. The robot needs to be finish executing a entire function and commands before a new command should be send otherwise there can be conflict.

            import socket
            import time
            HOST = '192.168.0.9' # UR5 IP addr
            PORT = 30002
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((HOST, PORT))

            counter = 0
            while counter < 100:
            counter = counter + 1

            f = open('myURscript.txt')
            line = f.readline() # If the file is not empty keep reading one line at a time

            while line:
            print line
            # data = bytes(line, 'utf-8')
            s.send (line)
            # s.send (data)
            line = f.readline()

            time.sleep(0.5)

            f = open('myURscript_2.txt')
            line = f.readline() # If the file is not empty keep reading one line at a time

            while line:
            print line
            # data = bytes(line, 'utf-8')
            s.send (line)
            # s.send (data)
            line = f.readline()
            time.sleep(0.5)

            f.close()
            s.shutdown(socket.SHUT_RDWR)
            s.close()

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

            Also check out the CB3 forum

          3. Evgueni

            Hello Lars,
            the issue is definitely not related to execution of the URscript. The problem is definitely caused by failure to complete the URscript transmission to UR5 during TCP/IP socket connection. This is evident from Wireshark and MS Network Monitor logs (shame I cannot post these here).
            In my experience a short URscript fails very rarely so it is possible that it executes 100 times without a glitch. Also I noticed that the frequency of failures depends on the PC I use, perhaps your set-up is more robust than any of the ones I have tried so far.

            In order to provoke failures frequently on my system, I add a section that is ~70 lines long from another URscript, each line preceeded by # to make it a comment. This is inserted before the last ‘end’ statement. I suppose instead of ‘comments’ you can insert a bunch of commands that do not need ‘physical time’ to execute e.g. setting IO state. The size of my ‘padded’ URscript file is 4,862 bytes (as reported by Windows). I also have a real URscript that is even longer than that but is not suitable for repeated testing because it has many move commands and takes a long time to execute. It does however cause the same issues with TCP/IP connection.

            When the PC initiates the TCP/IP socket connection to UR5 on port 30002, after some initial delay (I no not know if this delay is always the same amount) the UR5 transmits 2018 bytes of data to the PC. If the URscript transmission to UR5 is completed before UR5 starts to send these data, there is no problem. So you can see how a slower PC and a more congested LAN could make failure more likely, and vice versa. A longer URscript is another way to increase the chance of the two transmissions overlapping.

            Perhaps with a sufficiently long URscript file you can replicate the issue.

          4. zacopressadmin Post author

            Hi Eugene

            I have made some further tests.

            1.
            I inserted more than 100 lines into each of the 2 files (myURSript.txt and myURScript_1.txt) by copying the 10 lines of variable assignments and insert them 10 times before the move command – which means all these 100 lines will be send before the move command.

            Then instead of 100 loops in the python program – I run 1000 loops in the Python program that load and send the 2 myURScript.txt and myURScript_1.txt files to the robot.

            And the robot moves all 1000 times – of cause there is a slight delay in between the moves now – because it takes longer time transmit 100 lines instead on only 10. So in this test irregardless the amount of data to be send and the extend of time doing it – seems to work well with no interruptions.

            2.
            Then I wanted to see if the “sleep(x.x)” command is actually being performed (because I suspected that it actually does not in this method) – so I inserted this code after the move command

            set_digital_out(1,True)
            sleep(1.0)
            set_digital_out(1,False)
            sleep(1.0)

            So I can observe that the output actually blinks on/off. Then I would be able to see the 1 second between the changes of state of output 1.

            What happened is that the output does not blink. With only one line of “set_digital_out(1,True)” the output indeed goes high as expected. So I conclude the sleep command is not being executed in this method.

            Notice also when I need a delay in sending in between the 2 myURScript files – the delay is in the python code and therefore the delay is executed on the sending PC and not on the robot.

            3.
            So I turned my attention on the method you are using the “function” (or maybe also can called it “procedure”) of

            def():
            some code….
            end.

            Although your myURScript.txt file is being executed on the robot when send to port 30002 – I am not sure this is the intended method of using a function (procedure). As mentioned earlier and also in the main article on the forum – To send script commands to port 30002 is kind of one way communication – and once the commands are send and executed the commands needs to be send again if they are to be executed again.

            Instead a function is intended to be used locally on the UR robot and to be embedded into the Polyscope code. I created a script file with two functions inside the same script file because I wanted to test the sleep(x.x) command as part of a local script file – and also test a call to a separate function within the same script file.

            The script file looks like this below with a good part of your code inside, but also one more function that can perform an old fashion type of pause that runs as a counter. Notice the two sets of “def(): and end”. And also the use of “sleep(x.x) inside the script file.

            def pause_1(counter):
            while counter < 1000:
            varmsg("Counter", counter)
            counter = counter +1
            sleep(0.001)
            end
            return counter
            end

            def weldProg():

            blade_in_tray_x = 0.409000
            blade_in_tray_y = 0.291500
            tcp_z = 0.1
            set_tcp(p[0.0,0.0,tcp_z,0.0,0.0,0.0])
            set_payload(0.2, [0.0, 0.0, 0.018])
            set_gravity([0.0, 0.0, 9.82])
            tcp_tray_rvx = 2.2126
            tcp_tray_rvy = -0.0193
            tcp_tray_rvz = 2.2126
            tcp_z_scan = 0.350

            movel(p[blade_in_tray_x, blade_in_tray_y, tcp_z_scan, tcp_tray_rvx, tcp_tray_rvy, tcp_tray_rvz], a=1, v=1)
            sleep(0.1)
            set_digital_out(2,True)
            sleep(1.0)
            set_digital_out(2,False)
            sleep(1.0)

            end

            I named the file “myURscript_embedded_1a.txt” – and then I coppied this file onto a USB drive and inserted this drive into the UR.

            Then I went into Polyscope in order to use this script file from within Polyscope.

            I created this Polyscope program below. Notice the first line in the program is the “import” of the script file above by selecting the Script object and open the myURscript_embedded_1a.txt. So now the script file is loaded into Polyscope and the functions can be called from the Polyscope program.

            The Polyscope program.

            Robot Program
            Script: myURscript_embedded_1a.txt
            Movej
            Wait: 0.01
            weldProg()
            Set DO[1]=On
            pause_1(0)
            Set DO[1]=On
            pause_1(0)

            Notice: There are no Waypoints in the Polyscope program. The lines “Script…” and “weldProg()” and “pause_1(0)” are made by selecting a “Sript_code” entry from the Advanced menu. Also notice the difference in using both Output 1 (in Polyscope) and Output 2 (in Script file).

            When I run this program - the robot moves to the position in the Script file – and it flashes digital out put 1 and also flashes digital output 2. Which means the two functions inside the Script file are being executed – and the sleep(x.x) is being executed inside the Script file – and also the “pause” (by using a counter) inside the Script file is being executed.

            Conclusion:
            I am guessing that this is properly not the way you wish to use the function, but this is how it is intended to be used.

            I do not think the amount of data nor the congestion of the network is an issue – and also mentioned before I have send “one way” script code over the internet at great distances and it work well and no interruptions.

            Flow controls like “If” and “While” also does not execute when they are send to port 30002 from an external device.

            So again by sending to port 30002 is a kind of one way communication and all the (valid) command lines are being executed immediately – and the is why for example sleep(x.x) does not work this way – and this is also why “time that need to pass” before a new command can be send – this passing of time (delay) has to be executed by the sender – in this case the python program.

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

            Also check out the CB3 forum

          5. Evgueni

            Hello Lars,
            Thank you for doing this. I think the reason you observe the odd behaviour – sleep() statements and if / while /set_IO statements apparently not executing etc, is simple – unless you encapsulate your URscript program within “def ():” and “end” statements, each new line of code is executed as soon as it is received. This is also why time.sleep() statements in the Python code become necessary to allow each move() command time to execute before the next one arrives. Try changing the order of commands – I think you will see that the last one you send always executes, although you cannot check this in the case of sleep().

            Encapsulating your program within “def” and “end” statements is the intended method – just save any Polyscope program to a USB stick and examine the .script file.

            Anyway I think we have gone round in circles. On a practical level I have a 100% reliable solution – I time my transmission of URscript to UR5 to occur in between transmissions of data from UR5. The longest URscript file I have so far is ~17kB and this takes just 6ms to transmit leaving plenty of margin within the 100ms available window. But I find this unsatisfactory because it is merely a workaround and does not address the actual problem. Since you are not able to reproduce the problem, nor has anyone else reported something similar, it could even be peculiar to my setup. But TCP/IP traffic logs suggest that UR5 is not observing TCP protocol correctly.

            Here is a Python script that generates a URscript of variable length that only tells the robot to do one thing – connect back to the PC on a TCP/IP socket, in a loop. The socket.accept() call is blocking so execution stops when URscript is not received by the robot – you know then something is wrong. I am afraid the syntax is Python 3 so you will need to adapt it if you want to try it. When I experiment with this I notice that two parameters affect the likelhood of a problem – the length of URscript and the pause between connections (sleep statement). For example on my system the transmission seems reliable with sleep(1) and fails on the second iteration with sleep(0.67).

            import socket
            import time
            import select

            HOST_PC = “192.168.4.11″ # IP addr of PC that connects to URx
            PORT_PC = 6340 # port number for return TCP socket connection

            #listen for connection from URx
            mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            mySocket.bind((HOST_PC,PORT_PC))
            mySocket.listen(1)

            # send URscript to URx
            HOST_UR = ’192.168.4.29′ # UR5
            PORT_UR = 30002 # Secondary client interface
            while True:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((HOST_UR, PORT_UR))
            s.send (b’def MyProg():\n’)
            for x in range (1,100): # increase the range for longer URscript
            s.send (b’ # Time flies like an arrow but fruit flies like a banana\n’)
            s.send (b’ socket_open(“192.168.4.11″, 6340,1)\n’) # IP addr of PC and port for backchannel
            s.send (b’ socket_send_line(“OK”, 1)\n’)
            s.send (b’ socket_close(1)\n’)
            s.send (b’end\n’)
            s.shutdown(socket.SHUT_RDWR)
            s.close()
            # this provides a way of breaking out with Ctrl-C when socket.accept() blocks
            while True:
            ready = select.select((mySocket,), (), (), 0.5)
            if (ready[0]):
            try:
            conn, addr = mySocket.accept() # receive message from URx
            except socket.error as details:
            print (‘Ignoring socket error:’, repr(details))
            continue
            if conn:
            break

            print (“Incoming connection from ” + str(addr[0]))
            while True:
            data = conn.recv(1024).decode()
            if not data:
            break
            print (str(addr[0]) + ” says: ” + str(data))
            conn.close()
            time.sleep(1) # shortening this (e.g. 0.33 or 0.67) makes UR5 more likely to fail to receive URscript

            Best regards,
            Eugene

          6. zacopressadmin Post author

            Hi Eugene

            Great and good to hear you have a 100% reliable solution.

            Yes the sleep and setting of output commands was indeed encapsulated within “def” and “end” statements when I tested the 1 second sleep function (they were added to your script example) which was send from an external PC to the robot.

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

            Also check out the CB3 forum

    1. zacopressadmin Post author

      Dear Eugene

      Yes it will be good to know the result if all # comment are removed. Maybe it takes time to process and ignore such comments – then a few might not interfere whereas many might cause delay and miss the real commands – especially in case the program commands maybe already are time critical – then an unnecessary “sending time of comments” over the socket might be a delay of execution of real commands.

      I don´t think # “comments” is necessary to be send through TCP. I normally filter comments out when sending and only send the real commands through the socket.

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

      Also check out the CB3 forum

      Reply
  28. Gavin

    Hi Lars,
    We have a confused problem when we use the UR5 through TCP/IP with port 30003, we receive the data real time and show it rightly, but we send command data to UR robot , such as :
    movej([0.0, 0.0, 0.0, 0.0, 0.0, 0.0], a=0.2, v=0.2), but we receive the data of ur robto TCP Pose like this :
    [-0.816357, -0.194181, -0.00451029, 1.56495, 0.00214284, 0.00187608], the result is not correct obviously, so We are confusing that is the coordinate system problem ? or other problem ?

    so , how we can deal this problem rightly?

    respect your reply , thanks.

    Reply
    1. zacopressadmin Post author

      Hi Gavin

      Thanks for your question.

      I just tried on my robot and it shows some very small figures for the j0,j1,j2,j3,j4,j5 for example it shows 7.190535E-5 for j0 which is litteraly 0 because it is 10 to the -5 potens (E-5) and this is normal behavior.

      Can you check if your data also show such small values ?

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

      Also check out the CB3 forum

      Reply
      1. Gavin

        Hi Lars ,
        As your test, is the TCP Pose right? As my test, the TCP Pose isn’t correct .
        I don’t know how to paste image to the comment .
        I send the command movej([0, 0, 0, 0, 0.0, 0.0], a=0.2, v=0.2) to ur robot , and the ur robot screen shows in base coordinate system like:
        x = -816.34mm
        y = -194.19mm
        z = -4.53mm
        Rx = 1.5650
        Ry = 0.0021
        Rz = 0.0020

        Reply
        1. zacopressadmin Post author

          Hi Gavin

          Yes when providing the command “movej([0, 0, 0, 0, 0.0, 0.0], a=0.2, v=0.2)” my robot does move to joint positions 0,0,0,0,0,0 – which is the same position expressed as Cartesian position X=-457.02mm, Y=-194.01mm, Z=2.52mm, Rx=91.16 deg (1.5910 Rad), Ry=0.01 deg (0.0062 Rad), Rz=0.43 deg (0.0056 Rad).

          Notice the difference in Joint positions and Cartesian position (Pose) way expressing a position.

          It is not possible to put the robot into Pose 0,0,0,0,0,0 because that will mean the robot move into itself – whereas it is possible to put the robot into joint position 0,0,0,0,0,0 which is with the arm at a horizontal stretch where the writs 3 is pointing downwards.

          To move the robot in Cartesian coordinates there needs to be a “p” in front of the list like this movej(p[X, Y, Z, Rx, Ry, Rz]), but again the robot cannot move to X=0, Y=0, Z=0 because that’s inside itself.

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

          Also check out the CB3 forum

          Reply
          1. Gavin

            Hi Lars:
            Thanks Very much , As your suggestion , It works correctly.
            So, I can’t understand the joints coordinates and Cartesian coordinates previous,
            So that I tested, and set the pose [0,0,0,0,0,0] , it worked unexpectedly.

            thanks.

  29. Michael

    Hello,

    I have a question about communication via Ethernet cable with laptop. I have plugged PC into UR via ethernet cable, but UR5 doesn’t recognize PC and the small indicate point lights in yellow color, which says that no hardware was plugged. (why doesn’t it light to green?) I have set on robot configuration an IP adresse ,,192.168.0.9″ and mask “255.255.255.0″, and on laptop IP 192.168.0.10 and mask the same as on the robot.

    I have a small program on PC ,,Socket Test” where I wrote an IP and port (30002) into, and I can send ,,messagges” to the robot. For example, when I send ‘set_digital_out(5, True)’, it goes well and DO5 really turns to ON, BUT robot always stops. It stops everytime, when I send him some known script like this DO5 or var_1=2 and so on.. I think there must be some script, where UR will wait for some signal, variable or whole script. It is important to know it to the future, for example when I’ll want to make some application where a computer rules which UR program to play through some variable..

    I’m doing with URs not so long, so it’s possible that I’m doing these things wrong :-)

    Thanks for advice,
    Michael.

    Reply
    1. zacopressadmin Post author

      Hi Michael

      Thanks for your question.

      1.
      For the green light on the Ethernet you might consider to insert a hub between the PC and the robot because I find that a more proper Ethernet configuration. It might also be the type of hardware you are using. If the communication works as it looks like – then maybe it is ok without the green light.

      2.
      The communication seems to work as expected when you can turn outputs on and off. The reason for the robot stops is because when running a program made in the Polyscope GUI and when at the same time a command is received on port 30002 – then there is a conflict because two different programs are trying to control the robot and therefore the robot stops.

      So it is either a Polyscope program – or raw commands send through port 30002 – that can control the robot – not both methods like this.

      3.
      But it is possible to send data from an external host to trigger events on the robot for example to set outputs. For example the host can be a PC that via a socket port over the Ethernet send data to the robot – and then use these data inside a Polyscope GUI program – for example to trigger an output to change state or other program events. This can be done by using a Client–Server method – where an external host (e.g. PC) is the Server and the robot is the Client.

      An example of such client server communication over Ethernet is shown here.

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

      4.
      Another method to exchange data is by using the MODBUS protocol and read/write data into the robots MODBUS registers at port 502 and then read/write these internal registers from the Polyscope GUI program and use these data to trigger events in the Polyscope program.

      The internal MODBUS registers 128 – 255 are for general purpose.

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

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

      Also check out the CB3 forum

      Reply
  30. Eddie

    Hi,

    Thanks for this great article.
    I’m running UR5, and used your command to turn on output 2 in order to move the robot to a waypoinf, the things I did:
    1) ran s.send (“set_digital_out(2,True)” + “\n”)
    2) created an infinite loop that contains an “if”:
    if output 2 == true, then move to waypoint.

    I works great but I have only 8 outputs, I can create a 8 bit address from them and have more, but I’m wondering if there an easier way to move the robot to a waypoint that I saved via the robot GUI?

    ( Using a simple python command)

    Thanks!

    Reply
    1. zacopressadmin Post author

      Hi Eddie

      Thanks for your question.

      You might consider different methods:

      1.
      It is possible to send over waypoint coordinates as Pose data (MoveP) or Joint angles (MoveJ). Some examples 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/

      2.
      It is also possible to send over a number which you can use on the robot side to choose the waypoint. Something similar is used in this Client-Server example to send a form of position data. The form of position data can be constructed different to suit the application. Some examples at this link.

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

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

      Also check out the CB3 forum

      Reply
  31. Yongxiang Fan

    Hi There, Thanks for the posting. I would like to ask several questions.
    1. Is there any way to do velocity control from server side? I am working on tracking problem, every timestep, I calculate a joint velocity command vector, and I wish to give this command to UR3 in real-time.

    2. What’s the time delay for a typical communication by socket? Is it possible to make the delay below 30ms?
    3. Is it possible to use matlab in server side? Matlab can provide socket.

    Thanks,
    Best regards,

    Reply
    1. zacopressadmin Post author

      Hi Yongxiang Fan

      Thanks for your question.

      1. Speed.
      Various UR Script commands has the option to set acceleration and speed – for example the commands

      Movej, Movel, Movec, Movep, Servoj, Speedl

      2. Time.

      The script manual mention that the control frequency is 125 Hz (0.008 sec).

      3. Matlab:

      I have seen an example on the web for controlling a UR with Matlab, but I have not tried it.

      http://www.mathworks.com/matlabcentral/fileexchange/50655-ur5-control-using-matlab

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

      Also check out the CB3 forum

      Reply
  32. Tjipke

    Alright, i have a question i hope someone can answer.
    If i follow the tutorial here, and use c++ instead of python, i move my ur5 to a position using the following piece of code:
    writeToSocket(sockfd, “movel([-1.95, -1.58, 1.16, -1.15, -1.55, 1.18], a=0.9, v=0.1)”);
    int writeToSocket(int socket, std::string message)//send a message to a socket
    {
    bzero(buffer,512);
    int TempNumOne = message.size();
    for (int a=0;a<=TempNumOne;a++)
    {
    buffer[a]=message[a];
    }
    int n = write(socket,buffer,strlen(buffer));
    return n;
    }
    now what i want to know is, is there a way to check if the robot reached it's destination?
    for example is there a different port i can send a message to to get the robot's current position returned?
    please not i am not using the ur driver, since i have my own driver.

    Reply
    1. zacopressadmin Post author

      Hi Tjipke

      Thanks for your question.

      The MODBUS server at port 502 on a UR robot has registers with various informations. Register 400-405 hold information about the position and it might be possible to fetch the position from there. More informations about the MODBUS server can be found here

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

      Or if possible – design the program so using the command “get_actual_tcp_pose” to retrive the position.

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

      Also check out the CB3 forum

      Reply
  33. Don

    Hi Lars,
    Thanks for writing these tutorials for communicating with the UR3 through python. I would not be to do this without you. I do have a question that I hope you can help me out with. I’m trying to store a particular joint position so I can return to it later in the program. I’m having using the variable through the send() function. I can define it and assign a value to it but I just can’t use it. My code looks like this.

    The issue I’m having is that the movej(current_pos) does not do anything. I can see on the teach pendant that the current_pos does get defined with position data but when I try to reference it, nothing happens. Am I missing something?


    s.send("global current_pos = get_actual_joint_position()"+"\n")
    time.sleep(0.2)
    s.send("movej([-4.436072065494562, -1.3509294688607585, -1.5898662740424647, -1.7720278195761425, 1.5692639625048612, -2.8652732472940476], a=1.3962634015954636, v=1.0471975511965976)"+"\n")
    time.sleep(5)
    s.send("movej(current_pos)"+"\n")

    Thanks!

    Don

    Reply
    1. zacopressadmin Post author

      Hi Don

      Thanks for your question.

      Are you sending these commands to port 30001 or 30002 or 30003 ?

      Then it is because variable assignment cannot be used in this way

      s.send(“global current_pos = get_actual_joint_position()”+”\n”)

      The variable is not stored anywhere.

      Also the commands are just executed one time and the program does not iterate – so it is not really a program and it is a one way communication.

      Instead it is better to establish a client- server situation where there is a program running on the robot as well to receive data and to store variables and send back data to a host.

      Some examples at these links.

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

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

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

      Also check out the CB3 forum

      Reply
  34. pulkit

    Hello,
    I am new to programming and universal robot. I am trying the following code just to get to move the robot; however nothing is working and the robot is not moving. Please help. I have already set a TCP/IP connection with the robot.
    Here is my python code:

    #!/usr/bin/env python
    #Echo client program
    import socket
    import time
    HOST = “192.168.128.50″ # The remote host
    PORT = 30002 # The same port as used by the server
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((HOST, PORT))
    s.send (“movej([-0.08014794860691943, -1.3669091437944667, 1.644359519426854, -1.994201338108077, -1.5746014618109498, 1.5171476741784307], a=1.3962634015954636, v=0.2471975511965976)” + “\n”)
    time.sleep(2)
    (“movej([-0.7203210737806529, -1.82796919039503, -1.8248107684866093, -1.3401161163439792, 3.214294414832996, -0.2722986670990757], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
    data = s.recv(1024)
    s.close()
    print (“Received”, repr(data))

    It is giving the following error:
    Traceback (most recent call last):
    File “test.py”, line 9, in
    s.send (“movej([-0.08014794860691943, -1.3669091437944667, 1.644359519426854, -1.994201338108077, -1.5746014618109498, 1.5171476741784307], a=1.3962634015954636, v=0.2471975511965976)” + “\n”)
    socket.error: [Errno 32] Broken pipe

    Please help

    Reply
    1. zacopressadmin Post author

      Hi Pulkit

      Thanks for your question.

      The error shown indicates that it is in the Python program and not the robot – this has to be corrected first otherwise the robot won’t move.

      Which Python version are you using. The examples are made with Python 2.7 and might not be able to use directly in Python 3.x.

      The port 30002 on the robot is a server so if that the target the python program needs to be a client, but it looks like there are part server related statements in the code.

      Have you tried to use the code like it is shown here in the forum and with the IP addresses for the robot?

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

      Also check out the CB3 forum

      Reply
      1. pulkit

        Hey,
        Thanks for the reply.
        I am currently using python 3.4.0.
        And i have used the sample programs available in this forum with the robot IP address but i am getting the same error as mentioned above. I am using python on my mac pc. Can it be some problem with my system python environment setting or something else?
        Thanks in advance!

        Reply
          1. pulkit

            Hey,

            Actually i tried in Python 2.7 also but the same error (as above) is showing.
            Could there be possibly some other error?

            Thanks in advance!!!!

          2. pulkit

            Hey
            i have installed Ubuntu on parallels desktop and sending commands through it from python. Can this be the problem as there may be some problems related to permissions on a virtual machine.

            Thanks in advance!!!!

  35. MOT

    Hi Lars,

    we are using the UR10 with the software version 3.0.
    I could create a TCP Connection with the port 30002 and get all the info data and can also send Commands to the UR.
    For example “set_digital_out(2,True)” is working, but the following wont do anything.
    “movej([3,141592653589793, -1,570796326794897, 1,047197551196598, -1,047197551196598, 0, 0],a=3, v=0.75,t=1.0,r=0.002)”

    Is there a specific mode necessary to get the movej-Command working? Or is there some error information as return value available?

    Best regards,
    Marcel

    Reply
      1. MOT

        Hi,

        Thanks for your help. The Problem is solved.

        Next question:
        I created a programm with URscript on the robot. Dependent on the digital output [0 to 4] it should trigger a motion wich is a subroutine (teached beforehand).
        I start the programm on the polyscope. But as soon as i send a command through TCP/IP the programm on the UR is stopped.

        How can i set the main programm always running? Or is the method totaly wrong used?

        Best regards,
        Marcel

        Reply
        1. Sascha Horstmann

          Same problem here, when trying to set an output during a movement, the actual program, that is running on polyscope, stops.
          It seems like the set_standard_digit_output(1,True) function, needs to stop the program in order to change the state of the output.

          Is there any other way to change an output-state without interrupting the program?

          Reply
          1. zacopressadmin Post author

            Hi Sascha

            Thanks for your question.

            There are different ways to achieve something like that where outputs are set based on external data.

            One way is to make a program on the robot in Polyscope GUI that exchange data with a host like the client-server example

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

            And then set the outputs in the polyscope program according to the data received.

            This way has the benefit that there is only one machine in control i.e. the robot which might be a more clean approach regarding programming.

            Another way is the manipulate the robot outputs with MODBUS commands at the same time there is a Polyscope program running on the robot. However this is less clean method because then there could be two machines which controls the outputs i.e. the robot program which could set outputs – and then also the external device which also could set the outputs regardless of running the robot program and there is a risk of conflict, but it depends on the design of the programs.

            Below is a python program on an external host that sets an output on the robot off and on with 1 second interval on the robot.

            At this link there are some more informations on MODBUS on Universal-Robots.

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

            At this link there is another example of MODBUS commands.

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

            Python Program with MODBUS commands send to the robot.

            # Echo client program
            import socket
            import time

            HOST = “192.168.0.9″ # The Robot IP address
            PORT_502 = 502 # The MODBUS Port on the robot
            PORT_29999 = 29999 # The Dashboard port on the robot
            PORT_30001 = 30001 # The Primary port on the robot
            PORT_30002 = 30002 # The Secondary port on the robot
            PORT_30003 = 30003 # The Real Time port on the robot

            print “Starting Program”
            count = 0
            home_status = 0
            program_run = 0

            while (True):
            if 1 == 1:
            if program_run == 0:
            try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.settimeout(10)
            s.connect((HOST, PORT_502))
            time.sleep(0.05)
            print “”
            print “Modbus set Outputs to 00″
            print “Sending: x00 x01 x00 x00 x00 x06 x00 x06 x00 x01 x00 x00″
            s.send (“\x00\x01\x00\x00\x00\x06\x00\x06\x00\x01\x00\x00″)
            time.sleep(1.00)
            print “”
            print “Modbus set Outputs to 04 i.e. set output 2 on (third bit)”
            print “Sending: x00 x01 x00 x00 x00 x06 x00 x06 x00 x01 x00 x04″
            s.send (“\x00\x01\x00\x00\x00\x06\x00\x06\x00\x01\x00\x04″)
            time.sleep(1.00)
            s.close()
            home_status = 1
            program_run = 0
            except socket.error as socketerror:
            print(“Error: “, socketerror)
            print “Program finish”

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

            Also check out the CB3 forum

        2. zacopressadmin Post author

          Hi Marcel

          Thanks for your question.

          There are different ways to achieve something like that where outputs are set based on external data.

          One way is to make a program on the robot in Polyscope GUI that exchange data with a host like the client-server example

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

          And then set the outputs in the polyscope program according to the data received.

          This way has the benefit that there is only one machine in control i.e. the robot which might be a more clean approach regarding programming.

          Another way is the manipulate the robot outputs with MODBUS commands at the same time there is a Polyscope program running on the robot. However this is less clean method because then there could be two machines which controls the outputs i.e. the robot program which could set outputs – and then also the external device which also could set the outputs regardless of running the robot program and there is a risk of conflict, but it depends on the design of the programs.

          Below is a python program on an external host that sets an output on the robot off and on with 1 second interval on the robot.

          At this link there are some more informations on MODBUS on Universal-Robots.

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

          At this link there is another example of MODBUS commands.

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

          Python Program with MODBUS commands send to the robot.

          # Echo client program
          import socket
          import time

          HOST = “192.168.0.9″ # The Robot IP address
          PORT_502 = 502 # The MODBUS Port on the robot
          PORT_29999 = 29999 # The Dashboard port on the robot
          PORT_30001 = 30001 # The Primary port on the robot
          PORT_30002 = 30002 # The Secondary port on the robot
          PORT_30003 = 30003 # The Real Time port on the robot

          print “Starting Program”
          count = 0
          home_status = 0
          program_run = 0

          while (True):
          if 1 == 1:
          if program_run == 0:
          try:
          s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          s.settimeout(10)
          s.connect((HOST, PORT_502))
          time.sleep(0.05)
          print “”
          print “Modbus set Outputs to 00″
          print “Sending: x00 x01 x00 x00 x00 x06 x00 x06 x00 x01 x00 x00″
          s.send (“\x00\x01\x00\x00\x00\x06\x00\x06\x00\x01\x00\x00″)
          time.sleep(1.00)
          print “”
          print “Modbus set Outputs to 04 i.e. set output 2 on (third bit)”
          print “Sending: x00 x01 x00 x00 x00 x06 x00 x06 x00 x01 x00 x04″
          s.send (“\x00\x01\x00\x00\x00\x06\x00\x06\x00\x01\x00\x04″)
          time.sleep(1.00)
          s.close()
          home_status = 1
          program_run = 0
          except socket.error as socketerror:
          print(“Error: “, socketerror)
          print “Program finish”

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

          Also check out the CB3 forum

          Reply
          1. MOT

            Hi Lars,

            thanks for your answer.

            I dont need the outputs for my application. I need a way to start Scripts, wich are stored on the URobot/Polyscope, from a external source (e.g. a Laptop wich is connected to the UR through TCP/IP).

            The Scripts are simple movements. Or is there a way how i can transform a teached Script from the UR Polyscope to the URScript Commands through TCP/IP ?

            Thanks a lot for your help and your patience.

            Best Regards,
            Marcel

          2. zacopressadmin Post author

            Hi Marcel

            Thanks for your question.

            Can you explain what the goal is for the function in the application ?

            There are different ways to work with script commands. One way is to send directly to port 30002, but that not so elegant if there also is a Polyscope programming running because then there might be situations where commands are coming from two different sources and create conflict.

            It is also possible to load script file into a Polyscope program. This is done by selecting “Script” in the Polyscope GUI and choose “Line” or “File” which then is merged into the Polyscope program in a static way because the script file becomes embedded into the Polyscope program.

            Do you mean transformation of the xx.script file that the robot generate from a program made in Polyscope GUI ? – because such xx.script file has some overhead that needs to be removed before it can be send to port 30002 which has to be done manually, but the xx.script file is better to use for hints when learning script commands because it shows the format the robot expect.

            It should also be possible to send from the robot itself to its own loopback port 30002 at IP address 127.0.0.1

            An example of that is shown here

            http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/setting-the-speed-slider-from-a-program-15293/

            Can you explain the idea about storing the script file on the robot ?- if it is a simple script file and it is to be started from an external source e.g. a Laptop – can it be consider if the Laptop just send the script file – or what is the obstacle for this method ?

            The client-server approach is another method where the data exchange can be controlled by the robot.

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

            Also check out the CB3 forum

          3. MOT

            HI Lars,

            we found two diffrent ways to solve our problem with our application:
            First – Control the UR through TCP/IP with URScript Commands
            Sec – Use of the Dashbord Server to load and start a specific program on the UR, wich is generated beforehand e.g. through teaching and stored on the UR.
            (http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/dashboard-server-port-29999-15690/)

            With “scripts” in the previous comments i meant the programms in the URPolyscope (.urp).
            Anyway, thanks for your help so far! Now we have some ways to work with UR for our application.

            Best regards,
            Marcel

  36. Sascha Horstmann

    Hi Lars,

    I have some problems controlling the speed of the robot. We have a UR3, it is connected with TCP/IP to a PC and I do have connection, getting all the data from the RTStream and so on. I can send popup messages and moveJ commands and everything is fine.

    Now I want to change the speed, not the JointSpeed nor the TCPSpeed but just the Percentageslider, like seeing an object thats not supposed to be there, decelerate slowly or to full stop, until sensing the object is gone and accelerate again.

    For now I have the waypoints in the Polyscope Panel and my Code is C++. I only found the Command socket_send_line(set speed 0.5) which totally breaks the system down. If sent to the Robot, it stops, giving the error “TargetSpeed sth sth” and when trying to rerun the program, driving the robot to home won’t work anymore. In the protocoll screen it shows “Unknown Joint Status” and I don’t see temperature and current informations anymore. The only way to get it run again is to completely shut it down and restart again.

    Here is the code:

    while ( client_connected == TRUE )
    {
    double speedpercentage;
    char changespeed[40];
    double speed;

    std::cout << "Please type a velocity in % (0-100%)" <> speedpercentage;
    speed=speedpercentage/100;

    printf(“Velocity to Robot: %2.4f\n”, speed);
    snprintf(changespeed,40, “socket_send_line(\”set speed %2.4f\”) \n”,speed);
    Tcp_send(tcp_conn.socketNumber, changespeed ,sizeof(changespeed));
    printf(“Speed changed! \n”);
    }

    Do you know a solution and can you provide me with a list of socket commands, like this “socket_send_line(set speed %f)?
    I know, some of them are in the ScriptManual, but it’s missing all the variables that can be changed with the socket_send_line command.

    Thank you in advance

    Sascha

    Reply
    1. Sascha Horstmann

      The ErrorMessage is code C204A3. Sudden change in target Velocity i think. Even if I put it to 99.9999% Speed it gives me this message.
      I read in the changelog, that UR added this function so that too big changes in speed are not allowed anymore. But a change of 0.0001% is not that big. The problem with the breakdowns is solved, they are not the problem anymore. But it still remains a secret on how to change the overall speed.

      Looking forward for your help

      Reply
      1. zacopressadmin Post author

        I am not sure what you mean is a secret ?

        See the next post for the answer to your question below.

        Reply
    2. zacopressadmin Post author

      Hi Sascha

      Thanks for your question.

      There is an example of the “set speed” at this link – with smaple programs.

      http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/setting-the-speed-slider-from-a-program-15293/

      This is using the “socket_send_string” split into two and then using socket_send_byte to send 10 (line feed). I tested this method and it works good.

      Maybe consider to follow the same method.

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

      Also check out the CB3 forum

      Reply
      1. Sascha Horstmann

        Hi Lars,

        thanks for the advise, found this page too, but still not getting it to work
        I tried several things:

        without the \n at the end of the command, the robot doesn’t react at all:
        snprintf(changespeed1,32, “socket_send_string(\”set speed\”)”);
        snprintf(changespeed2,24, “socket_send_string(%1.1f)”,speed);
        snprintf(changespeed3,21, “socket_send_byte(10)”);

        if the \n is there, we get the same error as yesterday (C204A3):
        snprintf(changespeed1,33, “socket_send_string(\”set speed\”)\n”);
        snprintf(changespeed2,25, “socket_send_string(%1.1f)\n”,speed);
        snprintf(changespeed3,22, “socket_send_byte(10)\n”);

        so i tried this one, in hope of seeing the three lines in the example as one big command but this doesn’t lead to any reaction as well:
        snprintf(changespeed1,32, “socket_send_string(\”set speed\”)”);
        snprintf(changespeed2,24, “socket_send_string(%1.1f)”,speed);
        snprintf(changespeed3,22, “socket_send_byte(10)\n”);

        After all that, maybe he wants everything in one line, so here, the examples above written and send in one line, but same result as above:

        snprintf(changespeed1,80, “socket_send_string(\”set speed\”)\nsocket_send_string(%1.1f)\nsocket_send_byte(10)\n”,speed);

        snprintf(changespeed1,80, “socket_send_string(\”set speed\”)socket_send_string(%1.1f)socket_send_byte(10)\n”,speed);

        snprintf(changespeed1,80, “socket_send_string(\”set speed\”)socket_send_string(%1.1f)socket_send_byte(10)”,speed);

        Thought maybe he has problems reading the %1.1f Value but the console gives me this when I print it out: (1.example without \n, 2.example with \n)

        Datapackage to Robot:
        socket_send_string(“set speed”)socket_send_string(0.6)socket_send_byte(10)

        Datapackage to Robot:
        socket_send_string(“set speed”)
        socket_send_string(0.6)
        socket_send_byte(10)

        Even when sniffing the Bytestream from eth0 via wireshark it shows the right data.

        Is it possible that he needs the value within one “socket_send_string”-message, and whats the “socket_send_byte(10)” for?
        This is also what I meant with secrets, I can’t find any documentation but this help site, that explains, what commands are possible to send via the “socket_send_string”-function and what bytes can be send with what reaction via “socket_send_byte”.

        Thank you for taking your time with this problem.

        Regards

        Sascha

        Reply
        1. zacopressadmin Post author

          Hi Sascha

          I am not familiar with C code, but I tried this in Python and it works – with the robot going to 20% speed and then up to 100% speed while a program with waypoints is running on the robot.

          # Echo client program
          import socket
          import time

          HOST = “192.168.0.9″
          PORT = 30002

          print “Starting Program”

          count = 0
          while (count < 1):
          s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          s.connect((HOST, PORT))
          time.sleep(0.05)

          s.send ("set speed" + "0.2" + "\n")

          time.sleep(2.0)

          s.send ("set speed" + "1.0" + "\n")

          time.sleep(2.0)

          s.close()

          count = count + 1

          print "Program finish"

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

          Also check out the CB3 forum

          Reply
          1. Sascha Horstmann

            Thank you Lars,

            That was the hint I was looking for,

            You don’t send it with the “send_socket_string”, you just have to send cleartext “set speed %1.2f\n”.

            While sending the message with “send_socket_string” he pauses the program abruptly, which then causes the speed error.

            Thank you for the hint.

            Best Regards

            Sascha

  37. Andrei

    Good afternoon,
    I have a slight problem with a server-client application involving an UR5. The server, in Java, running on a laptop, opens a socket for the UR5 client. UR5 asks for a command, the server provides it, and then the server closes the socket and the java application ends. However, UR5 closes the socket ant then restarts the program from the beginning, and goes into the first loop that says “loop here until the “socket open” command becomes true”. The problem is even after I restart the server UR does not reconnect to the socket UNLESS i briefly stop and start the UR program. Is there a way to achieve again the connection without manual intervention?
    Many thanks,
    Andrei

    Reply
    1. zacopressadmin Post author

      Hi Andrei

      Thanks for the question.

      My experience is that it is possible to stop and start the server or client i.e. both sides and they can establish communication. However I have seen the for example virus scanner or firewalls on the PC can block such communication.

      Another good method or troubleshooting is to use Sockettest program on the PC in order to eliminate one software component for example the server in order to establish which side the issue is.

      Maybe also check out this example

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

      Also make sure running the latest version of software on the robot.

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

      Also check out the CB3 forum

      Reply
  38. Aqib Khan

    Hi Lars,

    I have two UR10 arms and I am really a novice in using them and also python. I am trying to make them move at same time by sending commands through the PC via opening up sockets at the same time. I used the program quoted on this forum for opening up a socket. The thing I am doing is to call the functions to execute the arms at the same time if the user wants.

    Now the problem is… the functions execute when we want to run a single arm. You’ll get the idea once you see the program. but If I give the option to invoke both the arms at the same time then, functions execute one after the other, in a sequence, even though they are called at the same time. First one arm executes one full motion and when that ends the other arm executes its motion. But not simultaneously.

    Now I have done another thing, and that is define a bash file ‘Both.sh’ and I call two separate files in that bash file where each file contains the code for the arm motion.The same code which is defined in the function arm() below. Only this way both the Arms execute simultaneously. My problem is that I dont want to call multiple files in a bash file. I want to execute simultaneous motion through function calls. is it possible….? please help

    Below is my code.

    def main():

    return(eval(raw_input(‘Please enter your choice\n\t’)))

    def arm1():
    print (‘Now Arm 1 motion is being launched now’)
    print
    print (‘Be Advised to watch the operation carfeully and be prepared to encounter any mishap and react instantly’)
    print
    print (‘Thank you\n’)

    # Echo client program
    import socket
    import time
    #Postures for movej
    posture1=”[0,-1.57,1.57,-1.57,1.57,0]”
    posture2=”[-1.57,-1.57,1.57,-1.57,1.57,0]”
    posture3=”[-1.56164,-1.40275,1.99724,-1.63731,-0.119222,-1.46024]”
    posture4=”[-1.56165,-1.40488,1.06426,-1.63919,0.523,-1.46022]”
    posture5=”[6,-1.57,1.57,-1.57,-1.57,0]”
    #Postures for movel
    #posture1=”[0,-1.57,1.57,-1.57,1.57,0]”
    #posture2=”[0.165,0.687,0.433,0,0,0]”

    HOST =’192.168.0.9′ # The remote host
    PORT = 30002 # The same port as used by the server
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))

    #s.send (“set_digital_out(2,True)” + “\n”)
    #s.send(“movej([0,-1.57,1.57,-1.57,1.57,0], a=0.3, v=0.04,t=5,r=0)”+ “\n”)
    #string_to_send=”movej(“+posture+”, a=0.3, v=0.04,t=5,r=0)”+ “\n”
    #s.send(string_to_send)

    #movej
    s.send(“movej(“+posture1+”, a=0.3, v=0.05,t=10,r=0)”+ “\n”)
    time.sleep(10)
    s.send(“movej(“+posture3+”, a=0.3, v=0.05,t=5,r=0)”+ “\n”)
    time.sleep(10)
    s.send(“movej(“+posture4+”, a=0.3, v=0.04,t=5,r=0)”+ “\n”)
    time.sleep(10)
    s.send(“movej(“+posture1+”, a=0.3, v=0.05,t=5,r=0)”+ “\n”)
    time.sleep(10)
    s.send(“movej(“+posture5+”, a=0.2, v=0.02,t=20,r=0)”+ “\n”)
    time.sleep(25)
    s.send(“movej(“+posture1+”, a=0.2, v=0.02,t=20,r=0)”+ “\n”)
    time.sleep(20)

    data = s.recv(1024)
    s.close()
    print (“Received”, repr(data))

    def arm2():
    print (‘Now Arm 2 motion is being launched now’)
    print
    print (‘Be Advised to watch the operation carfeully and be prepared to encounter any mishap and react instantly’)
    print
    print (‘Thank you’)

    # Echo client program
    import socket
    import time
    #Postures for movej
    posture1=”[0,-1.57,1.57,-1.57,1.57,0]”
    posture2=”[-1.57,-1.57,1.57,-1.57,1.57,0]”
    posture3=”[-1.56164,-1.40275,1.99724,-1.63731,-0.119222,-1.46024]”
    posture4=”[-1.56165,-1.40488,1.06426,-1.63919,0.523,-1.46022]”
    posture5=”[6,-1.57,1.57,-1.57,-1.57,0]”
    #Postures for movel
    #posture1=”[0,-1.57,1.57,-1.57,1.57,0]”
    #posture2=”[0.165,0.687,0.433,0,0,0]”

    HOST =’192.168.0.10′ # The remote host
    PORT = 30002 # The same port as used by the server
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))

    #s.send (“set_digital_out(2,True)” + “\n”)
    #s.send(“movej([0,-1.57,1.57,-1.57,1.57,0], a=0.3, v=0.04,t=5,r=0)”+ “\n”)
    #string_to_send=”movej(“+posture+”, a=0.3, v=0.04,t=5,r=0)”+ “\n”
    #s.send(string_to_send)

    #movej
    s.send(“movej(“+posture1+”, a=0.3, v=0.05,t=10,r=0)”+ “\n”)
    time.sleep(10)
    s.send(“movej(“+posture3+”, a=0.3, v=0.05,t=5,r=0)”+ “\n”)
    time.sleep(10)
    s.send(“movej(“+posture4+”, a=0.3, v=0.04,t=5,r=0)”+ “\n”)
    time.sleep(10)
    s.send(“movej(“+posture1+”, a=0.3, v=0.05,t=5,r=0)”+ “\n”)
    time.sleep(10)
    s.send(“movej(“+posture5+”, a=0.2, v=0.02,t=20,r=0)”+ “\n”)
    time.sleep(25)
    s.send(“movej(“+posture1+”, a=0.2, v=0.02,t=20,r=0)”+ “\n”)
    time.sleep(20)

    data = s.recv(1024)
    s.close()
    print (“Received”, repr(data))

    #Start of the Program

    input=eval(raw_input (‘\nThis is a program to run a real time simulation for the Universal Arms ……Please Enter “yes” if you wish to continue or Enter “no” if you wish to exit….Enter in quotes\n\t’))

    if input==’yes’:
    print(‘\n\n’)
    print(‘\tPlease read and follow the instructions very carefuly…. for a smooth execution\n’)
    print(‘\n’)

    choice=main()

    if choice==1 or choice==’single’:
    choice2=eval(raw_input(‘Would you like to execute the Right Arm or the left. Please enter right or left in quotes\n\t’))

    if choice2==’right’:
    print
    print(‘Now the right arm is being executed in motion….get ready\n’)
    print
    print (‘Starting……………’)
    print
    time.sleep(3)
    print (‘Go…………………………..\n\n\n’)
    arm1() #function call

    elif choice2==’left’:
    print
    print(‘Now the left arm is being executed in motion’)
    print
    print (‘Starting……………’)
    print
    time.sleep(3)
    print (‘Go…………………………..\n\n\n’)
    arm2() #function call

    if choice==2 or choice==’both’:
    print
    print(‘Now both the arms are being executed in motion…..get ready…..’)
    print
    print (‘Starting……………’)
    print
    time.sleep(3)
    print (‘Go…………………………..\n\n\n’)

    arm1() #Here is the Problem……..
    arm2()

    elif input==’no’:
    print
    print (‘Thankyou very much for doing a test run of the program\n’)
    print
    print (‘The program is exiting now’)

    Reply
    1. zacopressadmin Post author

      Hi Khan

      Thanks for your question and nice program.

      I think the reason for the separate move you see is because after each move command there is a “wait” statement time.sleep(xx)” which is fair to give the robot time to move. And when counting there are a total 85 seconds. So when the first routine for arm 1 is activated then it goes like this – move wait move wait move wait move wait….. and so on – and that’s one first arm only – then when the first arm is finish moving then the second routine only starts at this moment and therefore they run separately.

      There are properly several ways to change this – you might consider to have a routine called “both” and then also have two sockets – one call s1 and one called s2 for each robot and then in the “both” routine you open both sockets and send each move command to both robot just after each other something like this.

      …………………

      HOST1 =’192.168.0.9′ # The remote host
      PORT1 = 30002 # The same port as used by the server
      s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      s1.connect((HOST1, PORT1))

      HOST2 =’192.168.0.10′ # The remote host
      PORT2 = 30002 # The same port as used by the server
      s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      s2.connect((HOST2, PORT2))

      s1.send(“movej(“+posture1+”, a=0.3, v=0.05,t=10,r=0)”+ “\n”)
      s2.send(“movej(“+posture1+”, a=0.3, v=0.05,t=10,r=0)”+ “\n”)
      time.sleep(10)
      s1.send(“movej(“+posture3+”, a=0.3, v=0.05,t=5,r=0)”+ “\n”)
      s2.send(“movej(“+posture3+”, a=0.3, v=0.05,t=5,r=0)”+ “\n”)
      time.sleep(10)
      s1.send(“movej(“+posture4+”, a=0.3, v=0.04,t=5,r=0)”+ “\n”)
      s2.send(“movej(“+posture4+”, a=0.3, v=0.04,t=5,r=0)”+ “\n”)
      time.sleep(10)

      ……………….

      If you wish to make the two robots more differently then you might need to have posture variables unique for each robot.

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

      Also check out the CB3 forum

      Reply
      1. Aqib Khan

        Dear Lars,

        Thank you for the reply and thank you for the compliment. Yes the solution yo sent just worked perfectly. I defined another function both( ) and its executed.
        I have another question, even though my problem is solved, but do you think we could have achieved the same solution by using multi process method for example

        from multiprocessing import Process

        def func1():
        print ‘func1: starting’

        def func2():
        print ‘func2: starting’

        if __name__ == ‘__main__’:
        p1 = Process(target=func1)
        p1.start()
        p2 = Process(target=func2)
        p2.start()
        p1.join()
        p2.join()

        Reply
  39. BEN

    HI
    I want to know how we can control two arms simultaneously because i want to use two arms UR10 for grasping a box .my question is how i can control both of them with UR Script program by Socket connection.(use different IP ).
    Thanks and Regards
    BEN

    Reply
    1. zacopressadmin Post author

      Hi Ben

      Thanks for your question.

      There are different ways to do it. The two robots are to be seen as two individual robots with each their own program – and then if nessecary send status to each other.

      I have not tried programming two arms that works together, but at these links is examples of controlling UR via script – and you can do that for two arms as well by sending script commands to two different IP adresses.

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

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

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

      Reply
      1. BEN

        Hello
        thanks for you quick reply
        so the idea that i control each arm different the other but i don’t know if that should work simultaneously because i want to use both of them for grasping a box and move it , so i think if i have a delay between the two arms i will have a problem for grasping.
        Thanks and Regards
        BEN

        Reply
        1. zacopressadmin Post author

          Hi Ben

          I think an electronic delay will be negligible compared to physics and maybe you can consider to use the force mode then it will be based on when a certain force is achieved which will be regardless of a delay.

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

          Reply
  40. Allan

    Hi Lars

    I have a question regarding controlling the UR-5 from a PC with a tcp/ip socket.
    The way I’m controlling the robot today, is like the way you described in the this article, but I would like, if it’s possible, to use the Force_mode(..) feature, but can’t find much about this, can you give me a small examlpe or some hints.

    The application I want to create is basically just moving an item from waypoint A to waypoint B and when the robot encounters a given force on it’s way to waypoint B, it stops. After a given time it moves back to waypoint A.

    Hope you can help me.

    Thanks in advance
    Allan

    Reply
    1. zacopressadmin Post author

      Hi Allan

      Thanks for your question.

      My experience is that when there is “iterations” and also when information’s from the robot is needed like an input – then it is better have the program on the robot – i.e. make a master program on the robot like the client/server example where it is possible to ask and to command by sending variable over such TCP socket connection.

      We have to remember that the robot and its controller is closely related especially when it is operations that need relative fast updates and commands which force mode does – so to have a control loop over a TCP connection is more challenging to establish – rather than to let the internal controller and GUI environment do the control where fast updates are necessary – and then exchange user data over the TCP connection.

      I think you can better achieve what you are looking for by having a master program on the robot GUI and then exchange user data over the TCP connection.

      Below is an example of using the force_mode script command from within GUI.

      movej([-0.1, -1.4, 1.64, -2.00, -1.57, 1.52], a=1.4, v=1.0)
      sync()
      force_mode(p[0.0,0.0,0.0,0.0,0.0,0.0], [0, 0, 1, 0, 0, 0], [0.0, 0.0, 30.0, 0.0, 0.0, 0.0], 1, [0.1, 0.1, 0.15, 0.35, 0.35, 0.35])
      sleep(3.0)
      end_force_mode()
      stopl(3.0)

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

      Reply
      1. Allan

        Hey Lars

        Thanks for your reply.

        Maybe I don’t understand the force_mode feature correct and what’s possible to control by a socket connetion to the robot, but is the following example not possible?

        Pseudo code:

        //move to first position
        socket.send(“movel(p[X1,Y1,Z1,RX1,RY1,RZ1],a=A1, v=V1)\n”);

        //sync
        socket.send(“sync()”);

        //enable force mode. Force = 30N and is “measured” on the Z-axis.
        socket.send(“force_mode(p[0.0,0.0,0.0,0.0,0.0,0.0], [0, 0, 1, 0, 0, 0], [0.0, 0.0, 30.0, 0.0, 0.0, 0.0], 1, [0.1, 0.1, 0.15, 0.35, 0.35, 0.35])\n”);

        //move to 2nd position, where force mode is activ. When the force of 30N is reached, the robot //stops at that point.
        socket.send(“movel(p[X2,Y2,Z2,RX2,RY2,RZ2],a=A2, v=V2)\n”);

        //waits for the robot to stop at the point where it reaches 30N of force in the Z -axis.
        Sleep(10);

        //disable force mode
        socket.send(“end_force_mode()”);

        //move back to the first position
        socket.send(“movel(p[X1,Y1,Z1,RX1,RY1,RZ1],a=A1, v=V1)\n”);

        Reply
        1. zacopressadmin Post author

          Hi Allan

          An example:

          s.send (“def myProg():”+ “\n”+”force_mode(p[0.0,0.0,0.0,0.0,0.0,0.0], [0, 0, 1, 0, 0, 0], [0.0, 0.0, 30.0, 0.0, 0.0, 0.0], 1, [0.1, 0.1, 0.15, 0.35, 0.35, 0.35])” +”\n” +”sleep(10)”+”\n” + “end”+”\n”)
          s.send (“end_force_mode()” + “\n”)

          I pseudo form the code is

          def myProg():
          force_mode(xxx)
          sleep(10)
          end_force_mode()
          end

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

          Reply
          1. Allan

            Hi again

            Thanks for the hint, it works now.
            There is only one issue when I use the force mode, the Robot moves very unstable along the Z-axis, even if I program it in the GUI or command it by the socket connection. The documentation describes that, when the robot is in force mode, the position of TCP is not accurate.
            But can it be true that while the robot moves along the z-axis, it moves uptil +- 1 cm along the x and y-axis as well?

            If I narrows the limits, in the force_mode function, the robot just stops, the a warning is displayed on the GUI, saying that the position is to big.

            /Allan

          2. zacopressadmin Post author

            Hi Allan

            A few things.

            1. My experience is that the force function works best when the robot has the force to work with i.e. that the robot meets the “obstruction” that creates the force. For example in polishing there is a surface that the robot approach and thereby a force is build up and thereby the robot can “find” the force. If the robot is standing out in thin air it will start moving in the direction according to your program, but if there is no force then the robot will search for the force.

            2. You might need to work a little on the parameters you give. Each robot is slightly different in mechanics and therefore the force measured can be a little different from robot to robot.

            3. When programming in script the programmer needs to control the communication flow and has to be more specific in the timing because now the controller is the programmer. Therefore the timing of commands becomes important – so small pauses in between commands might be necessary. This is why I think programming in the GUI is easier because then the controller is the robot itself.

            4. I just tried this on my UR 3 and it looks quite good. (There is a delay for the robot to perform the force command).

            s.send (“def myProg():”+ “\n”+”force_mode(p[0.0,0.0,0.0,0.0,0.0,0.0],[0, 0, 1, 0, 0, 0], [0.0, 0.0, 30.0, 0.0, 0.0, 0.0], 1, [0.1, 0.1, 0.15, 0.35, 0.35, 0.35])” +”\n” +”sleep(100)”+”\n” + “end”+”\n”)
            time.sleep(5)
            s.send (“end_force_mode()” + “\n”)

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

          3. Allan

            It doesn’t seems to work, the robot is still moving quite uneven.
            Is it possible to implement this functionality by using an if statement and the force() function like this:

            //moving to position 1
            socket.send(“movel(p[X1,Y1,Z1,RX1,RY1,RZ1],a=A1, v=V1)\n”);

            //if the robot measures a force above 30 N, it stops the movement //towards position 1
            socket.send (“def myProg():\n if force() > 30: stopl(1)\n end\n”);

            Sleep(10);

            If it’s possible what is the right syntax?

          4. zacopressadmin Post author

            Hi Allan

            1.
            Have you consider trying other values than 30 Newton e.g. 40 or 50 ?

            2.
            My experience is to use “If” in the GUI with force measurements – an example at this link.

            http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/force-feedback-function/

            3.
            When making iterations and conditional branch and reading inputs etc. a master program in GUI seems better and if data is necessary to send an external host then the client/server concept is a possibility.

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

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

  41. Gopi

    Hi,
    I would like control the UR10 robot from PC using UR Script program by Socket connection, I have successfully opened the client connection from PC. and I could able to send “move” command to move the robot arm by specifying joint angles.. But I want to read the current joint positions and TCP positions and DIO status etc…

    When I enabled the receive part of the client I am receiving some junk continuously .. I dont know what the junk means.. and How do we disable this … and How do we read the joint positions and TCP positions in this method..
    I am using port 30002.

    Also I have tested with port 30003 and getting the same issue..

    Kindly help me to solve this issue..

    Basically I want to run the UR10 from my PC with out the help of teach pendent..

    I have read about your sample programs and all shows how to send the command from PC, I would like to see it for receiving responses also.

    Thanks and Regards
    Gopi

    Reply
    1. zacopressadmin Post author

      Hi Gopi

      Thanks for your question.

      The data you see flowing from port 30002 and 30003 are not junk, but status information like Matlab data. This dataflow is normal – a little more information’s can be found at this link

      http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/remote-control-via-tcpip-16496/

      To receive a response from the robot you can consider either:

      1. Have a local program on the robot that reads and sends back automatically or by request to a server program you have on a host e.g. PC. This is how the client-server program on this forum works at this link

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

      2. Or you can connect to the MODBUS registers on the robot via port 502 and read from a PC with MODBUS protocol and commands. More information’s about the MODBUS registers in the UR robot can be found here.

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

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

      Reply
      1. Gopi

        Hi Thanks for your suggestion..

        I have one more question, When I am trying to move the robot using TCP , X,Y,Z positions, Most of the times I ma facing singularity issue, Could you please suggest me, why this issue is occurring and how do we get it solved.

        Thanks and Regards
        Gopi

        Reply
        1. zacopressadmin Post author

          Hi Gopi

          Can you explain how you try to move the robot ?
          Is it from within the GUI or script commands ?
          What is the robot type ?
          What are the coordinates of the from and to positions ?
          Are you using MoveJ or MoveL etc. ?

          Regards
          Lars

          Reply
          1. Gopi

            Hi Lars,
            These are the answers with respect to your following question you have asked.
            Ques:Can you explain how you try to move the robot ?Is it from within the GUI or script commands ?
            Ans: We tried with both the methods and both the method gives us the same singularity issue.
            Ques:What is the robot type ?
            Ans: UR10 CB3.
            Ques:What are the coordinates of the from and to positions ?
            Ans: we are trying to move both joint angles as well as TCP Positions from random positions.
            Ques:Are you using MoveJ or MoveL etc. ?
            Ans: We are using both the above script commands.

            Thanks & Regards
            Gopi

          2. zacopressadmin Post author

            Hi Gopi

            If it is from random positions to random positions then there can be singularity – you might consider having waypoints (positions) in between. As a programmer it might be necessary to consider and manage avoiding the singularities by having more positions.

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

      2. Shangke

        Hi

        I would like to get the system clock in the script program when using the UR 10. How can I achieve it? I have checked the manual and did not find the function to return the system clock.

        Thank you for your time.
        Regards
        Shangke

        Reply
  42. GANESH P

    Hi
    I am working on socket communication in UR10 robot, i made my UR10 as server and my PC as client after both gets connected, from my PC i tried to get status such as get (actual joint positions()) and digital IO but it is giving me some junk values, so help me to go froward from here…

    Reply
    1. zacopressadmin Post author

      Hi Ganesh

      Thanks for your question.

      To get a feedback from the robot you can consider either:

      1. Have a local program on the robot that reads and sends back automatically or by request to a server program you have on a host e.g. PC. This is how the client-server program on this forum works at this link

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

      2. Or you can connect to the MODBUS registers on the robot via port 502 and read from a PC with MODBUS protocol and commands. More informations about the MODBUS registers in the UR robot can be found here.

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

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

      Reply
  43. Christian Hahna

    Hello Lars,

    in our company we have the following problem(s):
    We have the UR5 / CB3.
    We try to operate the robot with the following code from a Laptop:

    import socket
    HOST = “192.168.1.56″
    PORT = 30002
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))
    s.send (“movel([-94.67,-36.74,196.62,3.2735,0.0192,-4.0174])” + “\n”)
    data = s.recv(1024)
    s.close()
    print (“Received”, repr(data))

    The code as such works and the robot arm moves but we always get
    Protective Stop Error Messages such as “C153A0 – Position deviates from path : Base”.
    We also had other Protective Stop Error Messages (e.g. 154, ….) depending how the
    arm was positioned before. But it never looked like that the starting position would
    be any weird. The arm always moves a few centimeters and then it stops because of
    one of the Protective Stops.

    Do you have any suggestion what we can do or how we approach this problem the
    best way!?

    Thanks and best regards

    Christian

    Reply
    1. zacopressadmin Post author

      Hi Chrisitan

      Thanks for your question.

      Can you check that it is a valid position you are asking the robot to go to ? The data seems unusual high because joint data in a script command can be in radians.

      You can make a waypoint for the position you intend to move the robot to in a normal GUI program – then you can see the joint data in the x.script file for that program and use the same data for testing the position you ask the robot to go to.

      Another reason can be if the position is very far away from where the robot is starting from and then it experiences a singularity – which means you might need to have more positions on route to the final position.

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

      Reply
      1. Christian Hahna

        Hello Lars,

        thanks for your quick reply to my last question. We could figure it and now it works.
        But now we are confronted with another problem:

        We want to receive the ‘actual TCP position’ of the robot arm and have it sent
        to a PC. See to following code which runs on the PC:

        import socket
        import time
        HOST = “192.168.1.11″
        PORT = 30002
        print “Starting Program”
        s = socket.socket()
        s.bind((HOST, PORT))
        s.listen(5)
        c, addr = s.accept()
        print c.recv(1024)
        c.close()
        print “Program finish”

        This is the code which runs on the robot. There we also have a pop-up-window to tell us
        the current TCP position:

        def sendDataToClient_FromRobot():
        set_standard_analog_input_domain(0, 1)
        set_standard_analog_input_domain(1, 1)
        set_tool_analog_input_domain(0, 1)
        set_tool_analog_input_domain(1, 1)
        set_analog_outputdomain(0, 0)
        set_analog_outputdomain(1, 0)
        set_tool_voltage(0)
        set_tcp(p[0.0,0.0,0.0,0.0,0.0,0.0])
        set_payload(0.0)
        set_gravity([0.0, 0.0, 9.82])
        $ 1 “Robot Program”
        $ 2 “MoveJ”
        $ 3 “Waypoint_1″
        movej([-0.9780608981942036, -0.7214399377484852, -1.8638256010495597, -0.589019797479601, -1.935071987309266, 0.7081922499350776], a=1.3962634015954636, v=1.0471975511965976)
        $ 4 “MoveJ”
        $ 5 “Waypoint_2″
        movej([-0.9780527317397407, -0.7214353191283882, -1.8638286835667701, -0.5890214248041321, -1.9350801460022922, 0.7081919935392023], a=1.3962634015954636, v=1.0471975511965976)
        $ 6 “socket_open(’192.168.1.11′, 30002)”
        socket_open(“192.168.1.11″, 30002)
        $ 7 “popup(get_actual_tcp_pose())”
        popup(get_actual_tcp_pose())
        $ 8 “socket_send_string(get_actual_tcp_pose())”
        socket_send_string(get_actual_tcp_pose())
        $ 9 “socket_close()”
        socket_close()
        end

        The result we get sent to the PC and on the pop-up window on the GUI are of
        course the same
        (p[-0.09985, 0.00477246, 0.675595, -1.54106, 0.391288, 0.749075])
        but when we check the TCP coordiantes of Waypoint_2 on the
        GUI (last position of the robot arm -> the data supposed to be sent) the coordiantes
        data here is different. Check it out:

        X = -99.88 mm
        Y = 4.81
        Z = 275.61
        RX = 3.9683
        RY = -1.0074
        RZ = -1.9288

        X and Y are quite ok when you move the comma 3 places to the right but
        then with Z, it seems to be completely wrong. RX, RY and RZ also don’t seem
        to be right (except for RX when you move to comma 1 place to the right …. but
        i am not sure because this should be the pose position of RY!?).

        I hope you can help us again.
        Thanks in advance!

        Christian

        Reply
        1. zacopressadmin Post author

          Hi Christian

          Thanks for your question.

          I looks like the 400mm difference in the Z value might be because the Move screen is set to show “View” instead of “Base”. The coordinate use in script is referenced to the Base. You might consider to try and set the drop down in the move screen to “Base” and check the value.

          The difference in the rotation vectors might be because – since the joints can rotate 720 degree (+/- 360 degree) then there are more results to the same pose because a joint can be rotated 360 degree which will still be the same pose.

          With the pose editor it is possible to set the robot in a desired pose base on the coordinate given in the pose editor and thereby verify the pose position with the data provided in the result.

          The rotation data given in script are in radians.

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

          Reply
          1. Christian Hahna

            Hello Lars,

            thanks for you quick reply again!

            We set it to ‘Base’, so the X, Y and Z coordinates are now ok.
            Problem is still the RX, RY and RZ coordinates.

            In the ‘Edit Pose’ screen the coordinates are as follows:

            Feature: Base
            Tool Position
            X: -204.81 mm
            Y: -164.14 mm
            Z: 746.11 mm

            Rotation Vector [rad] (–> we checked out all 4 possibilities in the drop down menue)
            RX: 0.1245
            RY: 2.3289
            RZ: -2.3119

            And this is what the function ‘get_actual_tcp_pose()’ returns to us:

            p[-0.204787, -0.164126, 0.746095, -0.113889, -2.12709, 2.11159]

            Why does the result of the function still differ from what we see on
            the GUI!? Any ideas how we can fix this!?

            Thanks,

            Christian

          2. zacopressadmin Post author

            Hi Chrisitan

            Did you try to insert the data in the pose editor with the data the get_actual_tcp_pose() provied – and then see where this position is ?

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

          3. Christian Hahna

            Hi Lars,

            thanks for you help.
            Yes, the get_actual_tcp_pose() data and the data on the GUI
            are actually the “same” …. as so far as the position of the arm
            is the same.

          4. Christian Hahna

            Hello Lars,

            now we know that the END-Position of the robot arm is the same.
            For example:
            p[0.10976, -0.15826, 1.00264, -0.58548, 1.87436, -1.87662]
            is the same END-Position like
            p[0.10976, -0.15826, 1.00264, 0.7688, -2.4612, 2.4643]
            (note how only RX, RY and RZ differ!) but the way the robot arm takes to get there is different.

            And this is our problem.
            Sometimes the pose given to us from get_actual_tcp_pose() is the same like on the GUI, sometimes it is different (but the END-Position is in both cases the same!). Same when we send commands via socket like
            –> s.send(“movej([X, Y, Z, RX, RY, RZ]” + “\n”).
            Sometimes the robot arm moves into the desired position without problems, sometimes the “Shoulder” wants to make a 360 degree turn first (which is not possilbe because there is the floor in the way).

            Do you have any suggesten how we can approach this problem!?
            When we can expect A (RX,RY, RZ) from get_actual_tcp_pose() and
            when B (RX, EY, RZ)?
            Or when do we have to send [a(RX,RY, RZ)] and when [b(RX, EY, RZ)],
            so that the robot arm doesn’t try to make a whole turn around himself
            first? (a, b: same end position, differnt ways / different data)

            Thanks very much!

            Christian

          5. zacopressadmin Post author

            Hello Chrisitan

            This is because of different rotation status of the joint at the time of get_actual_tcp_pose() because some joints can turn 720 deg (+/- 360 deg). I do not have the algorithm for the calculation. You might consider having more waypoints in between start and end positions to control the desired path – especially if you are using script and if there is a big distance between start and end positions.

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

    2. Christian Hahna

      Thanks for your reply Lars.
      I’d have one last question about this problem.

      This is what we send via socket connection:
      s.send(“movej([-0.4437614627869806, -2.066329861363151, 1.867615889800172, -1.355958638052253, -1.52020726598505, -0.2980780494440687], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)

      This is the data we get from get_actual_tcp_pose() and we see on the Waypoint on the GUI. In this case, with this waypoint, it is both the same ….. but there are other waypoints where GUI and get_actual_tcp_pose() differ, but the end position is the same (as you explained, +/- 360 degrees. etc. ).
      p[-0.298375, 0.0164997, 0.45658, 2.35501, 2.02907, -0.0562185]

      Why for Example X, Y, Z is different from movej(p) and get_actual_tcp()/GUI?
      In Edite Pose, i can’t find this data which made the robot move in his position.

      Thank you,

      Christian

      Reply
      1. zacopressadmin Post author

        Hi Christian

        It is because a joint can rotate 720 degrees (+/- 360 deg) and therefore the same pose can have different results because turning a joint 360 degrees will give the same position but the angle data and rotation vector is different for the same position and therefore different value for the same pose.

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

        Reply
        1. Christian Hahna

          Dear Lars,

          thanks again …. ok, we try a different approach now, but again we need you help.

          We gonna have a couple of waypoints on a file on the robot/GUI, run this file and
          want to have the waypoints accessed from a PC. We do not want to send the coordiantes, we
          just want to send the commands like this: s.send(“Waypoint_1″).

          So on the robot/GUI, the program knows, “Waypoint_1″ => movej([X, Y, Z, ax, ay, az]).
          You know, like we send from the PC an integer and this integer is read and checked on
          the robot/GUI. For example we send 1 for Waypoint_1 and if this assignment on the
          robot is true, movej[Waypoint_1] is activated. After completion, the program waits for the
          next integer we (might) send.

          We tried to programme this according to this example
          http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-client-server-example/
          and it works, but this is not exactly what we need.

          We need some programme/code on the robot/GUI that waits constantly for input from the outside (a PC)
          and only reacts when it receives input.

          Can you give us some easy code example for this!? GUI and PC script.

          Thanks,

          Christian

          PS: We can not find the ‘while’ on the ‘Program Structure Editor’ …. we see
          in ‘Advanced’ the ‘Loop’, but no ‘While’ …. the meaning is for my understanding
          the same but still i am not sure if this is correct in this UR5 context.

          Reply
          1. zacopressadmin Post author

            Hi Christian

            Thanks for your question.

            Maybe you can consider something like this on the robot.

            var_1≔socket_open(“192.168.0.102″,12345)
            Loop var_1≟ False
            var_1≔socket_open(“192.168.0.102″,12345)

            var_2≔socket_read_ascii_float(3)

            If the data type is different than this example the socket_read_………. needs to be adjusted to the data type to be received e.g. string or byte

            The While is because the example is from some time ago where the Loop was called While – it was changed some time ago.

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

  44. Thomas M

    Dear Zacrobria Team,

    we have successfully installed a UR5 and have been able to send python commands via socket connection to move the robot. This is working.
    Unfortunately we are not able to receive or display meaningful data received from the UR5. Please find below a simple example where we want to read the current tcp pose (could any other command).

    Many thanks in advance,

    Thomas

    # Echo client program
    import socket
    import time
    HOST = “192.168.1.56″ # The remote host
    PORT = 30002 # The same port as used by the server
    TEST = 0
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))

    s.send(“get_actual_tcp_pose()” +”\n”)

    data = s.recv(1024)
    s.close()
    print (“Received”, repr(data))

    Output:
    \\x00\\x00\\x004\\x14\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\x03\\tURControl\\x03\\x01\\x00\\x00B\\x14Feb 06 2015, 15:17:07′

    Reply
    1. zacopressadmin Post author

      Hi Thomas

      Thanks for your email.

      The data received from port 30002 is not related to your command, but is data that is automatically is streamed out and I think it is Matlab data.

      When you send data to port 30002 it is one way communication so you can make the robot move and also set output ports, but not read data in this way – more is described on this page.

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

      To receive data about the position of the robot it is possible to create a client server scenario where a program is running on the robot using the get_actual-tcp_pose and then send the result data back to the server (maybe a PC) over the TCP socket connection. An example is shown at this link.

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

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

      Reply
  45. Andi S

    Hallo,

    thank you for your response!
    I am still having my problems with the commands via socket connection…
    I have two different codes in Python. If I loaded a program on the robot and run the following, it works:
    import socket
    import time
    HOST = “192.168.1.10″ # The remote host
    PORT = 29999 # The same port as used by the server

    print “Creating Socket Connection…”
    sckt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sckt.connect((HOST, PORT))
    time.sleep(2)
    print “… created Socket Connection!”
    print “”

    sckt.send (“play” + “\n”)
    time.sleep(5)
    sckt.send(“stop” + “\n”)

    data = sckt.recv(1024)
    sckt.close()

    print (“Received”, repr(data))

    print “”
    print “Program finished”
    —————————
    The output in the console is the following:
    Creating Socket Connection…
    … created Socket Connection!

    (‘Received’, “‘Connected: Universal Robots Dashboard Server\\nStarting program\\n’”)

    Program finished
    ——————————

    If I run the following Python-Code, there is no reaction: (I tried it both in ‘Run Progam’ and ‘Program Robot’)
    import socket
    import time

    HOST = “192.168.1.10″ # The remote host
    PORT = 29999 # The same port as used by the server

    print “Creating Socket Connection…”
    sckt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sckt.connect((HOST, PORT))
    time.sleep(2)
    print “… created Socket Connection!”
    print “”

    print “Initializing Stuff…”
    sckt.send (“set_tool_voltage(0)” + “\n”)
    time.sleep(0.25)
    sckt.send (“set_tcp(p[0.0,0.0,0.0,0.0,0.0,0.0])” + “\n”)
    time.sleep(0.25)
    sckt.send (“set_payload(0.0)” + “\n”)
    time.sleep(0.25)
    sckt.send (“set_gravity([0.0, 0.0, 9.82])” + “\n”)
    time.sleep(0.25)
    sckt.send (“global Var_posInit=p[-0.250,0.750,0.4,3.14,0,0]” + “\n”)
    time.sleep(0.25)
    sckt.send (“global Var_posCur=get_actual_tcp_pose()” + “\n”)
    time.sleep(0.25)
    sckt.send (“global Var_posCorrZ=p[Var_posCur[0],Var_posCur[1],Var_posInit[2],Var_posCur[3],Var_posCur[4],Var_posCur[5]]” + “\n”)
    time.sleep(0.25)
    print “… initialized Stuff!”
    print “”

    print “Correct z Position…”
    sckt.send (“movej(Var_posCorrZ, a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
    time.sleep(3)
    print “… corrected z Position!”
    print “”

    print “Moving to Initial Position…”
    sckt.send (“movej(Var_posInit, a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
    time.sleep(5)
    print “… moved to Initial Position!”
    print “”

    sckt.send (“halt” + “\n”)
    time.sleep(0.5)

    data = sckt.recv(1024)
    sckt.close()
    print (“Received”, repr(data))
    print “”
    print “Program finished”
    ————————————-
    The output is the following:
    Creating Socket Connection…
    … created Socket Connection!

    Initializing Stuff…
    … initialized Stuff!

    Correct z Position…
    … corrected z Position!

    Moving to Initial Position…
    … moved to Initial Position!

    (‘Received’, ‘”Connected: Universal Robots Dashboard Server\\ncould not understand: \’set_tool_voltage(0)\’\\ncould not understand: \’set_tcp(p[0.0,0.0,0.0,0.0,0.0,0.0])\’\\ncould not understand: \’set_payload(0.0)\’\\ncould not understand: \’set_gravity([0.0, 0.0, 9.82])\’\\ncould not understand: \’global Var_posInit=p[-0.250,0.750,0.4,3.14,0,0]\’\\ncould not understand: \’global Var_posCur=get_actual_tcp_pose()\’\\ncould not understand: \’global Var_posCorrZ=p[Var_posCur[0],Var_posCur[1],Var_posInit[2],Var_posCur[3],Var_posCur[4],Var_posCur[5]]\’\\ncould not understand: \’movej(Var_posCorrZ, a=1.3962634015954636, v=1.0471975511965976)\’\\ncould not understand: \’movej(Var_posInit, a=1.3962634015954636, v=1.0471975511965976)\’\\ncould not understand: \’halt\’\\n”‘)

    Program finished
    —————————–
    Why are those commands not working and the robot is responding with “could not understand”?

    Thank you for your help and best regards,
    Andi S

    Reply
    1. zacopressadmin Post author

      Hi Andi

      Thanks for your question.

      I think it is because you are mixing the port purpose and commands.

      Port 29999 is the dash board server where you can “start” and “stop” a program that is already loaded.

      Port 30002 is a server port whereto you can send script commands.

      So in the second part you might consider to send to port 30002. Maybe send one command at a time so you know which one is received by the robot.

      But as mention in the forum page this is a sort of one way communication and for simple commands – for example it is not for reading back or variables etc..

      It is better and more user friendly to program in the polyscope GUI or establish a client server communication.

      Regards
      Lars

      Reply
      1. Andi S

        Hi Lars,

        thanks a lot, the hint with the wrong port was very helpful. Finally I am able to control the robot by sending the commands via socket connection.
        Initializing a variable works by sending the following:
        sckt.send (“global Var_posInit=p[-0.250,0.750,0.4,3.14,0,0]” + “\n”)
        But if I want to initialize a second one:
        sckt.send (“global Var_posInit=p[-0.250,0.750,0.4,3.14,0,0]” + “\n”)
        sckt.send (“global Var_posCur=get_actual_tcp_pose()” + “\n”)
        The first variable is overwritten, so I only have my Var_posCur…

        This problem only occurs if I use the Socket Connection. Initializing multiple variables with the polyscope GUI works fine. How can I prevent this overwriting?

        Best regards,

        Andi S

        Reply
        1. zacopressadmin Post author

          Hi Andi

          Thanks for your question.

          I am not sure if it is intended to assign variable in this way over the socket.

          In the GUI it works because it is within a program shell. You might consider to make a client/server scenario by having a small program on the robot that is written in GUI in a way so the robot program can receive data over the socket from a server – and then these data received on the robot are assigned to variables within the GUI program.

          Regards
          Lars

          Reply
  46. Andi S

    Hello,

    currently I am working on a task whose target is to pick up an item which could be located at any position p(x,y,z,rx,ry,rz). I want to transfer this position from the host PC. So far three questions/problems arised:

    1. Preferably I would simply send commands via Socket Connection like shown above:
    “s.send (“movej([-0.7203210737806529, -1.82796919039503, -1.8248107684866093, -1.3401161163439792, 3.214294414832996, -0.2722986670990757], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)
    time.sleep(2)”
    If I do this, the robot doesn’t move but sends a response “Could not understand” or something similar.

    2. I am interested in programming the robot in the URScript Programming Language on a PC as programming on the teaching pendant is rather time-consuming. Is there something like a programming environment to compile URScript-Code into a .urp-file?

    3. I programmed a test-code on the teaching pendant and wanted to “load” and “play” it by commands sent via a socket connection. (by s.send (“load” + “\n”) and s.send (“play” + “\n”) )
    If the program was already loaded, it was possible to play it with the command. But loading it via the command was not possible as the robot was searching in a “\root\” directory where the test.urp-file could not be found. Neither the path was correct. What is the correct directory of the programs stored on the robot?

    Í hope I could explain my concerns understandable. Thank you in advance!

    Best regards,

    Andi S

    Reply
    1. zacopressadmin Post author

      Hello Andi

      Thanks for your questions.

      1.
      Just to be sure – are you sending from a Python program ?

      If yes – Your command seems almost correct – only I can notice that you have “ at the front at end – and then the wait belongs to the Python.

      s.send (“movej([-0.7203210737806529, -1.82796919039503, -1.8248107684866093, -1.3401161163439792, 3.214294414832996, -0.2722986670990757], a=1.3962634015954636, v=1.0471975511965976)” + “\n”)

      time.sleep(2) #this wait is execute in Python – not on the robot. If you want it execute on the robot then you need to send it over and change it to sleep(2) i.e s.send(“sleep(2)” + “\n”)

      2.
      A the moment I am not aware of such compiler, but there is a Simulator so you can make GUI programs off line which creates .urp files. You robot provider might be able to help you with the simulator.

      My experience is that if the script file becomes big then it is difficult to troubleshoot – the GUI is better then.

      3.
      By default programs are stored in /programs

      And then you can organize directories below that.

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

      Reply
  47. Rick Norcross

    CanI, or how can I , execute a script file that is already resident on the robot’s controller?
    i.e., is there a way to load and execute a script file across the socket interface?

    Reply
    1. zacopressadmin Post author

      Hi Rick

      Thanks for your question.

      One way is to use the standard facility in the Polyscope GUI by making a polyscope program where the script file is imported and then configure in installation so this file is loaded upon start-up. Then you can start and stop the program through a socket interface.

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

      Reply
  48. Hayder

    I am connecting my laptop to both internet and robot via the gateway of the university
    The problem is: when I setup the robot default gateway to the university gateway and press apply then update, it reverts back to 0.0.0.0. As a result the only way I could communicate with the robot is by setting the laptop’s gateway as the robot IP Address but then I cannot access internet.

    I appreciate any help,
    Hayder

    Reply
    1. zacopressadmin Post author

      Hi Hayder

      Thanks for your question.

      Have you tried to use the DHCP option ? and see what ip adress the robot gets ? -and then use that to communicate.

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

      Reply
  49. Mohamed

    Hi Lars,
    Excuse me! I have another question about how to use the Port 502 in order to communicate the server Modbus TCP, I want to establish a HMI with the robot and I don’t know how the format of information packet. Any ideas please? thank you.
    regards

    Reply
    1. zacopressadmin Post author

      Hi Mohamed

      Yes it uses normal Modbus TCP protocol according to the Modbus TCP standard.

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

      Reply
  50. Mohamed

    Hi Lars,
    First of all, thank you very much for this effort, it is really so helpful.
    I have a question about the function used on script which allows us to free the drive and move the robot. So, I don’t find a kind of function like “tech_mode()” or “freedrive_mode()”, even when I use one of these I upload a script and I compile I get an error with “is not defined”. knowing that my robot is UR5 version 1.8.
    So how do I do to resolve this problem?
    Thank you in advance
    Best regards

    Reply
    1. zacopressadmin Post author

      Hi Mohamed

      Thanks for your question.

      I think the script command for free drive (or teach mode) was implemented after CB3 (Controller Box 3) – so you need a CB3 robot which is different as CB2 version 1.8

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

      Reply
  51. Allan

    Hi Lars Skovsgaard

    I have a question regarding controlling the UR-5 from a PC with a tcp/ip socket.
    The way I’m controlling the robot today, is like the way you described in the this article, but I would like, if it’s possible, to call waypoints or small waypoints sequences, programmed in the PolyScope software from my PC.
    What I mean is, using the Polyscope to program small waypoint sequences and waypoints, by the touch screen teaching pendant, and then call these sequences by the PC tcp/ip socket connection.
    By this way I don’t have to change/recompile my program, that runs on the PC, if I need to adjust the waypoint sequences or waypoints.
    Is this possible, and if so can you give me some hints on how to do this?

    Best Regards
    Allan

    Reply
    1. zacopressadmin Post author

      Hi Allan

      Thanks for your question.

      Yes that is possible and a good programming method.

      Maybe you can consider to send simple data variables from your PC like 1 or 2 or 3 – or A or B or C

      And then you Polyscope program has the waypoint sequence under an IF condition – so if you send 1 or A then perform sequence under that and so on.

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

      Reply
  52. Zoran

    Hi Lars,

    I was wondering if you could help me. For our project we are implementing UR5 control by sending a script file to the robot from an external PC over a network. We are running Polyscope version 1.8. Sending the script file and implementing basic commands works fine. We are also able to enable the freedrive mode over Port 30002 with the command “set robotmode freedrive”, however, we are unable to enable the freedrive mode from within the script that we send to the UR5. Is this a limitation with Polyscope version 1.8?
    The aim is to look at a digital input and enable the freedrive mode when this input is high. Based on your previous post, i cannot see how to link a digital input to trigger the freedrive mode. I am happy to try to update the firmware to v3.1, however, i am not sure if everything will continue to work. Is it possible to back-date the firmware if v3.1 doesn’t work with our current code?
    Thanks,
    Zok

    Reply
    1. zacopressadmin Post author

      Hi Zoran

      Thanks for your question.

      To set the robot in freedrive mode with a script command is supported in software version 3.1 – which only runs on a UR CB3 robot.

      If you are running software version 1.8 – it indicates that you have a CB2 UR robot and therefore you cannot upgrade to version 3.1.

      CB2 and CB3 are very different robots and controller box and they cannot be compared.

      If you have a CB3 robot then there was another person here on the forum who found that it is possible to set a CB3 in freedrive mode with a script command by setting an output and then hardwire that output to an input which is configured to set the robot in freedrive mode.

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

      Reply
  53. Frank Hoch

    Hello Lars,

    thanks in advance for every piece of information on this site and every answered question,
    it helped me a lot.
    One question i wasn’t able to get an answer for is the following:
    Is it possible to send only one command over the tcp_ip socket on port 30002 which puts the robot (UR5 CB3 3.1) in freedrive mode for as long as i don’t terminate that statement? I already tried it using
    1. “set robotmode freedrive”
    2. “teach_mode()”
    3. “freedrive_mode()”
    but none of that worked.
    I wrote a small skript on the robot which worked, therefore i know it’s possible to do that.
    freedrive_mode()
    sleep(10)
    end_freedrive_mode()
    But i could’t achieve to do that over the Socketconnection and using a defined timeframe isn’t dynamical or practical for my application.
    What i got so far is a c++ GUI on a mac with which i’m trying to clone the teachpanel. Therfore i want to get the freedrive button on my gui, which should keep the robot as long in freedrive mode as im pushing it or until i send another signal to the controller which terminates it.
    Can you please help me?

    Thank you.
    Best regards

    Frank

    Reply
    1. zacopressadmin Post author

      Hi Frank

      Thanks for your question.

      Can you consider to use a digital input ?

      Each digital input can be configured in the Installation I/O menu so it has “Freedrive” function when activated.

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

      Reply
      1. Frank Hoch

        Hi Lars,
        thanks for the reply.
        Since i don’t have any digitalOutputs on the other Pc yet i’m not able to do that, but i’ll consider it.
        I just wanted to make sure there’s absolutely no way to do that over the socket with just one command.
        Could i wire a digital output from the controller directly to a digital input? Because i can set the outputs via only one command and therefore that would make it possible.

        Thank you.
        Best regards

        Frank

        Reply
        1. zacopressadmin Post author

          Hi Frank

          You can wire output to input – but I think a program needs to be running before it reacts to a input change and set the robot in Freedrive. If you try then let me know the result.

          Regards
          Zacobria.

          Reply
          1. Frank Hoch

            Hey Lars,
            it worked!!!!

            Thanks again very much, this has been bothering me for weeks.
            Even the Universal Robots Support and my own reseller couldn’t help me with this.

            Frank

    2. markus

      Hello,

      “set robotmod freedrive” and “set robotmode run” worked for our CB2 robots when sent via Port 30002 but doesn’t work with a CB3. Does anybody know if that functionality can be activated on CB3 as well ?

      br

      Reply
      1. zacopressadmin Post author

        Hi Markus

        According to the latest Script manual the command is

        freedrive mode()

        There is also an option to set this via an input on CB3. In the Input menu an action can be associated to each input.

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

        Reply
  54. Leandro Guilherme

    Hello Lars,

    I made a C/C++ program to do this communication, and it work well to send information, so commands like movej and movel is working.
    But when I send “get_actual_tcp_pose()\n” from my client program didn’t receive any data. My code look like:

    char buffer[1024];
    int n = write(sockfd, msg.c_str(), strlen(msg.c_str()));
    bzero(buffer,1024);
    int r = read(sockfd, buffer, sizeof(buffer));

    Can you help my?
    Thank!

    Best regrads

    Reply
    1. zacopressadmin Post author

      Hi Leandro

      Thanks for your question.

      If you are using server ports 30001, 30002 or 30003 then you will not get any thing back for this command.

      You may consider using the command in a GUI program and then sending the data over to your host in a similar way as this example.

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

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

      Reply
  55. lmur

    Hello Lars,

    I’m trying to connect the robot (UR10) with my computer through and ethernet cable. I can ping it and execute scripts without ROS, but when I’m trying to execute some ROS scripts the UR10 log says “Not able to open Socket Socket 0 to host: “IP” at port: 50001: Connection timeout.

    Could you give us some advice?
    I am looking forward to hearing from you soon.

    Kind regards,
    Lmur.

    Reply
  56. chen

    Hi Lars,

    Thank you for the fast reply!

    Currently, we use the camera to guide the movement of UR5 accoring to a optical marker which could be recognized by the camera. If the marker moved, the robot will move correspondingly. For example the Marker is located in position A. Next step, the marker will move to position B very fast, and the robot should move to position B fast. But We have encounter the following problem:
    If the robot is on its way to position B, but the Marker has been moved to position C from B. It seems it is difficult for us to stop the MoveJ (B Position) command, which led to the result as follow: The robot move to the Postion B from A, and then moved to position C from B. However, we hope the robot will not move to position B, but directly to position C from the current position, because of the moving of Marker.

    Could you give us some advice?
    This problem has bothered our team for a long time.
    I would like to express my deep appreciation for your support!
    I am looking forward to hearing from you soon.

    Best regards,
    chen

    Reply
    1. zacopressadmin Post author

      Hi Chen

      Depending on how you have constructed the program, but maybe you can use an “IF” statement – and then Tick “Check expression continuously”.

      The if you have a different condition for Pos B and Pos C – then the program should be able to branch to the active condition right away.

      Regards
      Lars

      Reply
  57. chen

    Hi Lars,

    I am new to UR5 and I wonder if the universal robot can be controlled through visual servoing, such as grabbing the targrt in motion with stereoscopic vision tracker. I would be grateful if you could give me some directions or reference.

    Best Regards
    chen

    Reply
    1. zacopressadmin Post author

      Hi Chen

      Thanks for your question.

      There are different ways to track items.

      1.
      UR has a Conveyor tracking function when using an encoder signal.

      2.
      You can use a vision camera and make an application to move the robot based on the feedback from the camera.

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

      Reply
  58. Julia

    Hi Lars,

    thank you for the fast answer!

    I use Python 3.4, but I think the connection should be work. My problem is that the ur5 doesn’t allowed the connection.

    Thank’s for your help!
    Julia

    Reply
    1. zacopressadmin Post author

      Hi Julia

      I just tested the program using Python 2.7 and it works.

      I don’t know if using Python 3.4 it needs some changes – I know Python 3.4 is different from Python 2.7 and code cannot just be copied.

      I have seen that when copying and pasting then the quotation marks can change to one of these ‘ ’ “ ” ‘ ‘ ” ”

      This one ̎ is the one I use.

      The robot just receives the data and there is no need for enabling on the robot – port 30002 is listening. You need to set the IP address of the robot in the Python program.

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

      Reply
  59. Julia

    Hi Lars,

    thank’s for your answer. I can now ping the ur5, but when I tried your example I can’t connect to the robot with the error: “Target PC denied the connection.

    I hope you can help me also this time!

    Best Regards
    Julia

    Reply
  60. Julia

    Hi Lars,

    I have tried out your example to connect from my laptop to the robot with the small python script. But all the times I get an timeOut Error…..I have connect my laptop directly with the robot. I also can not ping the robot. I have’nt any idea why it didnt works and hope you can help me!

    Best Regards
    Julia

    Reply
    1. zacopressadmin Post author

      Hi Julia

      Thanks for your email.

      You need to be able to ping the robot from your PC.

      What is the IP address of the PC Ethernet port that you are using – and what is the IP address of the robot ?

      Make sure they are in the same network.

      A direct connection between the PC and robot can work, but make sure the PC and robot are not set for DHCP – and instead give them a fixed IP address.

      You can also try to connect through a hub if you are using a DHCP server on your network.

      If you are using a direct connection – and If you are using a RJ-45 ethernet port on your PC and at the same time have a Wireless connection on your PC – then make sure the PC is using the RJ-45 for the connection to the robot – maybe disable the Wi-Fi on the PC when you are testing this so the Wi-Fi is not confusing you for the IP address used for the test.

      If you are using Wi-Fi on your PC – then connect the robot to a hub or access point that is in the same subnet as the PC.

      Get the ping to work first.

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

      Reply
  61. M.Ebert

    Hi Lars,

    could you maybe show an example where the UR is the client and the PC the server. I am thinking of some kind of “position server” which is waiting for requests. Eg, in a Pick and Place application the UR “asks” the position server for the next position to pick and place. In this way it would not be necessary to program all the points to the UR but only a type of generic script and the actual pick and place position would be stored on the server ? This could run in a loop until the servers decides that all jobs are done.

    Thanx.

    Matt

    Reply
    1. zacopressadmin Post author

      Hi Matt

      Thanks for your question.

      The function you suggest is actually what the example on the Client-Server page show.

      On this page

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

      Scroll down to where it says

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

      This example shows the UR robot as the Client and a small program on a PC as the host. The robot asks for 3 waypoints from the host. The host send 3 waypoints and the robot move accordingly.

      Author:

      By Zacobria Lars Skovsgaard

      Reply
  62. Ollie

    Hi Lars,

    Thanks for your tutorials – they are very informative!

    I am having a problem connecting from my MacBook Pro to a UR10 via ethernet, as described on this page. The ethernet cable is plugged in to the UR10 controller (the CAT-5 input underneath the control box), and the IP addresses on the UR10 and my mac are exactly as in your tutorial. Whenever I run the python code (example 1 or 2), I get the error:

    File "001.py", line 6, in
    s.connect((HOST, PORT))
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
    socket.error: [Errno 60] Operation timed out

    I also seem to be unable to ping the UR10 either – I can only assume that I am doing something very simple wrong. Which screen should be up on the robot when I run the Python code on my MacBook (at the moment it is the pre-loading screen)?

    Kind regards

    Ollie

    Reply
    1. zacopressadmin Post author

      Hi Ollie

      Thanks for your question.

      You need to make sure you can ping the UR first – can you check the cabling and make sure the IP address on the UR and on the host (maybe your Mac) is different, but in the same subnet ?

      For the error I need to know exactly which code you are trying – can you list it all ?

      Maybe it is because my examples are made in Python 2.7 (not Python 3.0).

      Regards
      Zacobria

      Reply
    1. zacopressadmin Post author

      Hi Fred

      Thanks for your question.

      I have not seen a command that can do such conversion.

      Regards
      Zacobria

      Reply
      1. Fred

        Hi, Lars,
        Thanks for your reply.
        I have seen the rpy information in move robot page frame in ur controler,I also know no command in ur API can do that, I want to know how can I convert Rotation vector to rpy angle by myself ? I try to
        make it ,but it is different from the value in the ur controler .
        I really appreciate it.

        Reply
  63. SJ Teo

    Dear Lars,

    I am not able to read the data send from my UR 5 to my computer. I am trying to control the robot using Python 3. The code below is as follows
    HOST= "192.168.1.100"
    PORT = 30002
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST,PORT))

    and my program on the UR 5 is as follows:

    open socket
    socket_send_string("Waiting for Command")

    however, what i recieve in python is unreadable. the data i receive is this: “x00\x00\x020\x10\x00\x00\x00\x1d\x00\x00\x00\x00\x00\x00\x02%1\x01\x01\x01\x00\x00\x01\x00\x00?\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfb\x01\xbf\xee\xa0\x0f\xc5>\x83\xc8\xbf\xee\xa08\x8d\nL6\x00\x00\x00\x00\x00\x00\x00\x00\xbd\xea\’\x13B?\x99\x9aA\xf0\x00\x00BXfg\xfd\xbf\xfd\xcd9B4;\x04\xbf\xfd\xcd!\xd4\r*\xe6\x00\x00\x00\x00\x00\x00\x00\x00?\x11\xc5\x81B?\x99\x9aA\xed\x99\x9aBHfg\xfd?\xe7\xc0`s\x1eL\xa8?\xe7\xc0P\xac\\\xbd(\x00\x00\x00\x00\x00\x00\x00\x00\xbfPS\xb5B?\x99\x9aA\xd8\x00\x00BF\xcc\xcd\xfd\xc0\x01p\xee\xf3\xe6\xa4\xa8\xc0\x01p\xf4\x90\x98\xc6v\x00\x00\x00\x00\x00\x00\x00\x00>A\xa4\xc5B>fgB\x0c\xcc\xcdBM\x99\x9a\xfd\xc0\x08O\x9d\xf2^\xc8\xe0\xc0\x08O\xa4\x05!c\”

    This is part of the data recieved. How do i decode it?

    Regards,
    SJ Teo

    Reply
  64. SJ Teo

    I was wondering how would i be able to decode the text received from the robot. I have connected the robot to my computer using the Ethernet cable and have managed to control the digital inputs mentioned in this tutorial through python scripts. May i know what does data = s.recv(1024) do? When my computer prints out this, all i get is b'\x00\x00\x04\xe6\x10\x00\x00\x00\x1d\x00\x00\x00\x00\x00\x00\x089g\x01\x01\x01\x00\x00\x00\x00\x00?\xe2\x8f\\(\xf5\xc2\x8f\x00\x00\x00....... x99\x99\x99\x9a@9\x00\x00\x00\x00\x00\x00?\xf0\xc1R8-se?........ \x1f\xcd$\xe1a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

    How would I be able to decode this?

    Also, Would I be able to send commands such as get_actual_joint_positions()

    Reply
  65. Adam

    Hi,
    I am totally new to UR5 and when I connect my computer to the robot and open connection in SocketTest at robot_ip:30002 it starts sending lots of random data. What am I doing wrong? Previously I tried Modbus communication and it worked, but scripting via TCP at 30002 doesn’t.

    Cheers,
    Adam

    Reply
    1. zacopressadmin Post author

      Hi Adam

      Thanks for your question.

      It is normal that on port 30002 you will receive these data from the robot, but you can still send data out from an external device (e.g. PC) on port 30002 to the robot and the robot will understand – so you are maybe not necessarily doing something wrong.

      You can also use other port number by following the Client – Server example. This is a better two way communication method.

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

      Regards
      Lars

      Reply
      1. Adam

        Hi Lars,
        Thanks for your help!
        I am currently exploring the client-server strategy and it works quite nice!
        But going back to sending raw script commands to 30002 – can you get any feedback from the robot (e.g. current position), since there is so much rubbish on the bus?

        Regards,
        Adam

        Reply
        1. zacopressadmin Post author

          Hi Adam

          My pleasure.

          The method using port 30002 is mainly for one way communication – to get reply from the robot the client-server example is the way forward.

          Regards
          Lards

          Reply
  66. alberto

    Hi Lars,

    Thanks for all your help.

    For me the example was a litle confusing as it seems that the program continues with “MoveL(Move_To_Pos)” and the Move_To_Pos is “constructed” with the data received by the instruction “socket_read_ascii_float”.

    Have a nice day!!
    Alberto

    Reply
  67. alberto

    Hi Lars,

    I was looking at the link you send me. But I do not see(understand) what is the part of the code in which the program continues its execution after a short timeout when nothing is received.

    Thanks in advance. Best regards.
    Alberto

    Reply
    1. zacopressadmin Post author

      Hi Alberto

      At the highlighted programline

      socket_read_ascii_float

      the program continue after a short timeout.
      Zacobria Universal-Robots forum socket_read_ascii_float

      Regards
      Lars

      Reply
  68. alberto

    Hi Lars,

    My problem is that, as I understand, when you call the instruction ”socket_read_ascii_float” the execution of the program seems to get stuck at this point until it receives the data. I would like to call this function and if nothing is received, and therefore the function times out, do some other action instead.

    So I think that if you call this function the program (or the thread in which is being executed) gets stuck and this is kind of a problem. For instance, the robot would want to check if there is some new order coming from the PC from time to time, so it calls ”socket_read_ascii_float”, but if the PC has not sent any order to the robot, then it would want continue performing another tasks.

    I would want to do something like this (expressed in pseudocode):

    data = socket_read_ascii_float(4)
    if(socket_read_ascii_float(4) has timed out) :
    #do some other amazing stuff
    else:
    #perform some hard work with the data received
    end

    I would want to have the actual UR Script code in order to implement this functionality.

    Thanks in advance. Best regards.
    Alberto

    Reply
  69. alberto

    Hi Lars,

    I am calling the UR script function “socket_read_ascii_float” in a thread. As it seems , by checking the Log tab of the PolyScope interface, this function times out when nothing is received and then is called again and again until the array of floats is received.

    I would like to know how to change this behaviour, as I understand that the the thread gets stuck until it reads a valid sequence of floats. After the call to “socket_read_ascii_float” times out I would like to do other tasks, instead of beeing continuosly calling “socket_read_ascii_float” until the data arrives. How can I achieve this behaviour?

    Thanks in advance. Best regards.
    Alberto

    Reply
    1. zacopressadmin Post author

      Hi Alberto

      Thanks for your question.

      I am trying to understand the situation because you ask how to change the function that ”socket_read_ascii_float” is timing out – and at the same time you still want to do other tasks – which seems contradicting.

      The ”other tasks” is that in the same thread or just generally e.g. in the main program ? or in other Threads or Sub routines ?

      You can consider to take control over when things happens by setting variables at certain points in the program (for example in the main program) and then check on these variable other places in the program (for example in the threads) and thereby create a condition for when ”socket_read_ascii_float” starts.

      An example of using variables in main program and checking on then in a Thread can be seen here.

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

      Note:
      Previously the “Set” was called “Action” and that’s why you see that in this example.

      You can also insert wait instruction before a ”socket_read_ascii_float” starts again etc..

      I do not favour to have ”socket_read_ascii_float” in threads because a thread generally runs all the time.

      Regards
      Lars

      Reply
  70. Robbert

    Hey,

    First of all i want to say that your site and tips are very helpfull!!
    I have some trouble with writing stuff to the robot.
    I’m currently working on how to make an output go high and low on the robot through java.
    I just cant seem to get it to work.
    I made a connection with the robot in java. Im just not sure wich command i got to send because when i try the command u used in your example i get a couple of java errors.
    When i put those commands in a txt file and upload it to the robot through usb it works fine.
    i hope you can help me a bit.

    greetings Robbert

    Reply
    1. zacopressadmin Post author

      Hi Robbert

      Thanks for your question

      I am not familiar with Java, but never mind it should be possible to get to work anyway.

      It sounds like you have some kind of error in your Java program since you say you get a Java error.

      You just have to make sure you only send the UR script command over the TCP socket followed by a line feed.

      I python this looks like this

      s.send (“set_digital_out(2,True)” + “\n”)

      As shown on the page on our forum.

      Actually it is only the

      set_digital_out(2,True)

      that the robot need and followed by a line feed

      This will turn output 2 high on the robot

      So the rest like s.send and the parentheses and apostrophe and + sign is just Python commands and syntax which the robot never sees. But the line feed which in python is \n must also be send to the robot.

      So the robot only sees

      set_digital_out(2,True)

      and the line feed

      You need to make sure Java is only sending that over the TCP socket – nothing else.

      For this test you can send to TCP port 30002 which is always listening on the robot.

      And it is good to get this to work first.

      But for real programming it is better to follow the method mentioned in the Client – Server example.

      To be able to flip an output high and low in the way you try is a good starting point to know the communication is working and then move forward.

      Regards
      Lars

      Reply
  71. alberto

    I just wanted to know if more than one instrucction can be send to the robot without waiting (sleep).
    For me would be just fine if I were able to send serveral robot instructions at once and then wait in another part of the PC program for the robot completion.

    I would apreciate an example. Thanks!!

    Reply
    1. zacopressadmin Post author

      Hi Alberto

      Thanks for your question.

      Yes you can – you can almost get the robot to function as you can program it.

      In this case you can make a small receiver program on the robot side that receives your instructions and execute them in the sequence you want while the PC is waiting or doing something else.

      The main thing to understand is that you need to develop a small program that runs on the robot – and then you have your PC program that sends data-instructions-variables to the robot.

      An example of this is on the forum here at this link

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

      You need to modify the robot program a little so you can send several instructions to the robot before executing them and the PC do something else. For example make more variables on the robot side.

      (Note: You can send instructions or called script commands to the robot without having a program running on the robot side, but then the instructions has to be send one by one and the functionality is limited).

      So you need to develop two programs – one on the robot – and one on your PC as you intend to already. In this way you can make the robot to receive your commands as you wish and execute them as you wish).

      Regards
      Lars

      Reply
  72. pascal

    Hello

    Thanks again for explenation.

    Is there a way to just send a file with commands over the TCP port that will executed one by one? In the Client-Server example there is writin how to send a single command and give a feedback from the robot to the computer, but instead of sending single commands everytime send a list of data.

    Like what looks the most familiar is the “”pose_trans(p_from, p_from_to)”. Then It would be like from>toP1>fromP1>toP2>fromP2>toP3. Im going to try it out.

    Thanks again
    Kind regards
    Pascal

    Reply
    1. zacopressadmin Post author

      Hi Pascal

      Yes the example called ”script via socket connection – Host computer to UR robot #2.” Which is a one way sending a flow of commands.

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

      These commands still needs to follow the syntax mentioned in the script manual and note that this is one way flow i.e. you cannot read back from the robot in this way.

      For the example you mention I think you need to make a “receiver” program on the robot side that understands your commands and then execute them on the robot similar to the client server program.

      Regards
      Lars

      Reply
  73. pascal

    Hello

    The main problem is to terminated the shocking movement when sending like 50-100 commands (coordinates) every second for an unknown time (it can be one second or 3 minutes). Setting the blend radius parameter and recalculate the path before it should move is devious.

    The solution should be terminated the acceleration, deacceleration, stop and blend radius, so the robot only stops when it reaches his last command (coordinate). Is there not such an options to off set those parameters?

    If tried several possibilities put it doesnt seem to have any effect. Putting a PID controller or something like that between the robot and the pc would probably solve this problem, but isnt there any way to do it in the polyscope interface?

    Kind regards
    Pascal

    Reply
    1. zacopressadmin Post author

      Hi Pascal

      Thanks for your question.

      I think it is matter of finding a way to look ahead and not stop in each position and at the moment I am only aware of the “Blend” that can do that from the Polyscope as the speed is made of the speed of each 6 joints in combination calculated by Polyscope. I will let you know if I learn other methods.

      Regards
      Lars

      Reply
  74. pascal

    Hello

    Thank you for your reply. I do it on your way now.

    The robot seems te move very shocking when sending movement commando’s(coordinates) continuously(sending mouse coordinates as movement commando’s). I think it is becuase evry single commando, the robot has to accelerate, deaccelarate and stop at evry command.

    Is there a way to smooth the movement of the robot, so I can continuously send coordinates to the robot, but only the last coordinate will be executed even if the previous coordinate was not yet been reached? So basicly the next following command is always overlapping the previous command.

    Thanks again. Very good feedback, service and every question is taking serious!

    Kind regards
    Pascal Jacobs

    Reply
    1. zacopressadmin Post author

      Hi Pascal

      Thanks for your question.

      Yes that’s correct – it is because you have Acceleration – Cruise and declaration for every waypoint.

      Yes – you can smoothen the move by using the ”Blend” parameter – and then you need to recalculate your path according to how big you have set the “Blend radius”.

      Regards
      Lars

      Reply
  75. pascal

    Thank you for your time. I have the script manual and I will studie it carefully.

    Im doing it without a checksum from the robot now, just to prove my concept, it is enough without it. The robot does response and moves when a stream of commando’s are being sended.

    Is it possible to send coordinates that moves from a origin that is different then the “Base” feature? So instead of using the Base plane(feature), define another plane, use this plane and send commando’s that move from that origin.
    I already have made a different plane, but the robot does not seems to move from that origin. It is always moving from the “base” feature. Is there some command that tell the robot to move from this “feature” as I cannot find it back in the script manual,

    Thank you for your time.

    Kind regards
    Pascal

    Reply
    1. zacopressadmin Post author

      Hi Pascal

      Thanks for your question.

      I always use the Base as the reference point so I can calculate the pose from the base or use joint angles as the joints are physical constructed.
      I am not aware of a method to change this reference point when using coordinates in script mode.

      I think you can make a sub routine that changes your reference point by offsetting you coordinates with your new reference point. For example if you want the original Y = 400mm to be your new Y = 0 reference point then when you want to give a move command that involves to move to a new Y = 100 location then your program must have a converter behind that add the original Y to your new coordinate i.e. add 400 in this case so that move to Y = 100 becomes automatically go to Y = 100 + 400.

      Regards
      Lars

      Reply
  76. pascal

    Thanks for explaining.

    Now my program looks like this:

    init.variable
    robotprogram
    -input_pc;= false
    - commando;= commando
    // I think im reading the socket. Then say input is now true.
    if input_pc = false
    socket_read_ascii_float()
    input_pc;= true

    // Now the input is true, ask for it. Then format the data with get_forward_kin. Then I give the value to command. The movel performs the commando.
    if input_pc = true
    get_forward_kin() = socket_read_ascii_float()
    commando = get_forward_kin()

    movel([command0])

    This seems reasonable but it gives me SysntaxError: line 1 def unnamed(). In the init.variables are:
    - tool_var = tool
    - commando = commando
    -input_pc = false

    Its very hard to see what is wrong or how to structure the program as you cannot exactly see what is wrong.

    Thanks in advance
    pascal

    Reply
    1. zacopressadmin Post author

      Hi Pascal

      Thanks for your question. I see several things that can be an issue.

      Do you have the script manual ? You should be able to get it from the supplier of the robot and then consult that manual for detailed description of the commands.

      I don’t know if the code you are showing me is the entire program or just a part of it, but some of the issue I see are:

      1.
      Use := instead of ;= when appropriate

      2.
      I am not sure why you are setting this
      commando;= commando (aside from the ;= which should be := then it should not be necessary to set something that is the same).

      3.
      socket_read_ascii_float()
      Is a command and should not stand alone. Normally it should be together with a variable assignment e.g.

      var_1 = socket_read_ascii_float()

      4.
      get_forward_kin() = socket_read_ascii_float()
      Is both script commands and cannot be set equal – nor can a command name be a variable name.

      This is a correct command
      commando = get_forward_kin()

      5.
      get_forward_kin()
      Is not used to format data, but the command get_forward_kin() is a command that returns the pose of the robot.

      6.
      commando = get_forward_kin()
      movel([command0]) I assume that you mean movel([commando])

      This will not move the robot. You are asking the pose position with the get_forward_kin() command – and then moving the robot into the same position with the move command.

      7.
      I am not sure what is the intention of this asignment

      tool_var = tool

      There is no command named tool, but maybe you are setting one variable equal to another variable.

      8.
      I do not see where you open and close your TCP connection, but maybe you left that out in your question.

      9.
      There are many syntax errors in this program. If you do not know where the syntax error is then you are moving forward too fast.

      Instead you can write one line or a few lines at the time and try to run the program – and only move forward if you have no syntax errors. That will help to troubleshoot and easier find the syntax errors.

      9.
      Maybe study the second example under Client-Server some more and see how the commands and used in that example and use that as inspiration in your program. And read about the script command in the Script manual before using the command.

      Regards
      Lars

      Reply
  77. pascal

    Thanks for your reply.

    I have one last question. Programming this robot is still a bit new for me. I hope you could check if Im thinking in the right way.

    Can I just ask for the input from my laptop with: If socket_read_ascii_float()? Then get_forward_kin(socket_read_ascii_float()) and at last movel(get_forward_kin()). Or am I thinking in the wrong way?

    Do I still have to send a string(movel([xxxxx)]), wich is in X Y Z=millimeters, in order to use get_forward_kin that will translate this into radians? I would be very greatfull if there is any sample code for the polyscope interface to receive incoming(cartesians) data and format them into tcp positions.

    Thanks for your time explaining.

    pascal

    Reply
    1. zacopressadmin Post author

      Hi Pascal

      For reading the input or get position information’s back to your PC – then you need to make a program on the UR polyscope also.
      This is what I mean that a raw script command from your PC is a one way communication and therefore has limitations. You can send move commands this way because the robot will just execute a move command and not reply anything.

      For sending information’s from the robot back to your PC you need something like the Client-Server example i.e. you need to make a program on the UR polyscope side that reads the inputs and the position information’s and then for example stores these information’s in variables. Then when you need these information’s on your PC you need to make a TCP interface where you can ask for the value of these variables or make the program logic in the polyscope so you are asking the value at the time you are asking for it from the PC.

      In human text the logic on the Polyscope program side could be something like this.

      Read command from PC

      If pc_command = inp_1
      Read input 1
      Return the value of inp_1 to the PC.

      If pc_command = pose
      Pose = get_forward_kin
      Return the value of pose to the PC.

      Else
      Do nothing or continue program.

      For sending positions from the PC to the robot you can also use the Client – Server example.

      Form the PC you can send like you desire e.g. send (0,-1,0,1,3.14,1.57) and then on the robot side while receiving these data you put them into a variable maybe called Move_To_Pos_1.

      Or you can just from the PC send the text pos_1 and then on the robot side have a variable you already have defined before program start like pos_1 = (0,-1,0,1,3.14,1.57) which is your pose coordinates if you have very static positions and few waypoints to go to.

      Then on the robot side you will make a program line when you need the robot to go to the position

      movel(Move_To_Pos_1)
      Or
      movel(pos_1)

      Notice that a command like movel([xxxxx)]) then the x is joint angles in radians. If you want to specify coordinates (pose) the command is movel(p[xxxxx)]) then the x is coordinates in mm/1000 i.e. 0.4 = 400mm.

      So the programming is typical like this. You can program only on the UR Polyscope and execute the program locally – this is how most programs are made. Then you only have one program, but you are not receiving coordinates from the PC.

      If you want to communicate with a PC and for example send coordinates from the PC to the robot – then you need 2 programs i.e. one program on the UR Polyscope and one program on your host PC (e.g. Java).

      Regards
      Lars

      Reply
  78. pascal

    Thanks again.

    My next goal is to send a constant flow of coordinates X Y Z(100hz) in millimeters. So basicly I define the origin at a certain point and thats where to robot calculates his distance from. If I send x100 y100 z20 then it should move 100mm from the origin in X and Y direction and 20mm up in the Z direction.

    Is there any command where you can fill in these command without running a program on the polyscope interface?

    Thanks in advance
    Kind regards
    Pascal

    Reply
    1. zacopressadmin Post author

      Hi Pascal

      Thanks for your question

      I am not aware of there is such command. Your idea is good and I think you need to make a program on the UR that receives your coordinates and then translate them into position coordinates the robot knows about.

      Regards
      Lars

      Reply
  79. pascal

    Hello

    In the polyscope interface, do I have to run a program in order to send a command from my pc via TCP socket or can I just go to “program robot” and let the robot doing nothing?

    So basicly I have to start a client applications that connects to the host (polycope) and then I’m able to send command in scriptcode, right?

    Im doing an internship and I’m not very familiar with TCP connection:). The programlanguage I use is Java.

    Thanks in advance
    Kind regards
    Pascal

    Reply
    1. zacopressadmin Post author

      Hi Pascal

      Thanks for you enquiry.

      Yes you can do both. There is actually generally 3 ways to script programs.

      1.
      You can make script programs locally on the UR control inside the Polyscope using the teach pendant.

      2.
      You can send a raw script command from a remote host via the TCP port.

      An example of this is shown here.

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

      Note that is simple and kind of a one way method i.e. you just send commands from the host – and expects the UR robot to execute, but there is really no handshake and there are many limitations in this e.g. not possible to use flow controls. This is mainly use to just test that your TCP connection is working.

      3.
      You can make a kind on “Client – Server” setting where you have a local program running on the UR control that is asking a remote host for coordinates over the TCP connection.
      And then you have a host program running on your server e.g. your PC. You should be able to use Java although I have no experience on using Java, but I mean Java also for sure can use TCP port communication.

      An example using Python is shown here.

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

      This is a more elegant situation. The example show is still very simple and you can virtually make it as intelligent you want and with many communication exchange depending on how much you want to program.

      Regards
      Lars

      Reply
      1. pascal

        Hello

        Thanks for the quick response! It helped me alot.

        Controlling the robot via the SocketTest works great.

        I have not searched it yet, but why are the movej and movel in radians instead of degrees? Didn’t noticed that they where in radians, as I had to press the emergency stop because he moved the other way. Then I tried it radains and it worked great.

        The polyscope script to send the joint, pose positions and asking for waypoint 1-3 is not really working. Do I have to start the server/host on my computer first? The polyscope TCP program starts and waits for while on socket_open(“xxxx”, 30002) and then moves on. When it reaches movel(Move_To_Pos) it moves to a point where I have to press the emergency button before it hurts it self. The xxxx are replaced by my PC Ip adress. What could went wrong and is there anything definied in the init.variables?

        Thanks again for your time.
        Kind regards
        Pascal Jacobs

        Reply
        1. zacopressadmin Post author

          Hi Pascal

          Great to hear that you had some success. Why the commands are chosen to be specified in radians I don’t know.

          For the client server it sounds like the robot is trying to move to the position specified, but if this is far away from where the robot happens to be located when you start the program it might be the reason for the odd move.

          Before starting any programs then try and move the robot into near this position by hand.

          p[0, 0.4, 0.4, 0, 3.14, 0]

          Which is X = 0, Y = 400 mm, Z = 400 mm, RX = 0, RY = 3.14, RZ = 0

          Then the robot does not have long to move when the first point is received if you are using the same coordinates as in the example.

          Make sure the view is ”Base” in the move screen.

          And yes there is these Init variables

          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

          Yes start the host program first (the PC program) because the UR expects to be able to get a reply.

          As mention before this is just an example and can be improved a lot so for example it doesn’t matter which program to start first and better handshake etc.

          Yes you must specify your PC IP address and make sure the port you are using is not use for anything else on your PC. I notice you mention port 30002 – maybe try port 30000.

          Regards
          Lars

          Reply
  80. Khattak

    Hello Lars,

    I tried the simple echo client program both using c++ and python. When I check the tablet pad I know that the program worked because the digital output goes on and off (I did both the on and off, and I see the function running in the log), but I don’t receive valid information on the PC side. The output I receive on python is something like \\x0\\x1\\ etc… The output on c++ is a bunch of symbols such as the european pound currency symbol. I am having trouble receiving valid information. Do you have any suggestions on how to proceed? I really appreciate your help. Thanks!

    Reply
    1. zacopressadmin Post author

      Hello Khattak

      Thanks for your question. It sounds like you are using port 30002 which replies with the kind of data you describe. Have you tried to use another port e.g. 30000 as in the example ?

      Regards
      Lars

      Reply
      1. Khattak

        Hello Lars,

        Thanks for replying! I tried different port numbers using Socket Test (30000, 30001, 30002, 30003, 30004). 30000 and 30004 do not provide a connection. 30001 and 30002 continuously keep giving invalid information. 30003 gives invalid information once at the beginning then stops. 30003 gives nothing when I send command to it. The robot receives the command (I can see that in the log at the tablet) but I do not get any feedback. When I use Socket Test, my PC is the client and I test the server (the robot). If I try being a server on the PC side and listen to the robot (client), there is a bind connection error. I hope this information can help you point me in the right direction. Thanks for the help once again!

        Khattak

        Reply
        1. zacopressadmin Post author

          Hello Khatak

          What are you sending to the robot from the PC ?

          Do you have a program running on the robot ?

          Regards
          Lars

          Reply
          1. Khattak

            Hello Lars,

            I am sending instructions set_digital_out(2,True) joint_positions = get_joint_positions(), socket_send_string(joint_positions). No program is running prior to when I am sending this. I do not do the whole def, end thing and make it a complete program. I am just sending instructions. Thanks!

            Khattak

          2. zacopressadmin Post author

            Hello Khattak

            Thanks for your reply.

            When you send these commands like this – the only thing the robot will do is turn output 2 high and nothing else – not even any reply.
            You need to have a corresponding program running on the robot to receive your commands, do flow controls, loops and assignment of variables and also make the program on the robot so it reply with what you program it to reply with i.e. program the robot to send a reply back (e.g. variable values you have programmed in robot program) over a socket connection.
            The data you see on port 30002 is normal machine data and therefore try to use another port e.g. 30000 that does not send any data without you programming the robot to do so. Therefore you need two programs i.e. the program on your PC and a program on the robot in order to have a two way communication – Take a look at the example called “Script – Client-Server”.
            If you only send data one way from the PC to the robot you can only use those commands that can be executed without any logic e.g. like you have done with setting an output, but a move is also possible this way, but you will get no reply just the execution of the command in this way.

            Regards
            Lars

  81. Tom Svilans

    Hi Lars,

    We’ve been having a bit of trouble configuring the IP on the robot and communicating with it via Ethernet… Just to clarify, which network socket do we plug the cable into in the control box? There is the ‘Do not remove’ socket and the ‘Internet’ socket, I just want to make sure we’re connecting in the right place…

    Otherwise, I’ve mimicked the script in the above example but it’s giving me back a “A socket operation was attempted to an unreachable network” error when I run it.

    Anyway, thanks a lot for these examples, this is very helpful! If you’ve got a spare moment, I would love to hear from you regarding setting this up properly.

    Best,

    Tom

    Reply
    1. zacopressadmin Post author

      Hi Tom

      Thanks for your question.

      You must use the port ” Internet’ socket” – which is the one that is lead to the outside of the controller box.

      Based on the error messages ”A socket operation was attempted to an unreachable network” you get – it sounds like it is related to the IP address setting. Could be the Subnet address setting or that the IP address on the robot and your server is not on the same subnet. Make sure the IP addresses are on the same network and then try to ping the robot from your server and verify a reply – and then try communicating again.

      Regards
      Lars

      Reply

Leave a Reply to Mary Cancel 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>