Home Programming


Left ArrowBack to discussions page
MarvinWMarvinW Posts: 3 Apprentice
Hi Everyone,

since the last time it was so helpfull (big thanks to matthewd92!) to ask here a question a have another one.

We have the UR10 and in our applikation the robot have to execute different tasks depending on which state the machine is he has to serve. So, there is a Client which tests something the Robot has to put in. There is a Server connecting this Client to the Robot, sending for the Moment simple commands via the socket Connection. Now we maybe have a bunch of scripts of possible movements of the Robot an there is a objectrecognition function also with a camera. The big question is how to Control everything depending on the different states of the Client. An idea was to have a scriptbib and depending on the state we just send the Robot a whole Script but we did not find out how to do this via the sockets, is this even possible?

Again, thanks a lot and have a good day!


  • louis_bergeronlouis_bergeron Posts: 94 Handy

    You can send a whole script to the UR with a socket connection to the client at the port 30001 - 30002 - 30003. Your script file must start with a def() end finish with an end to work correctly.  This is an example I have done last year in Python to send a file and execute it:

    def rq_set_zero():
      		socket_send_string("SET ZRO","acc")
    </code># Echo client program
    import socket
    HOST = "" # The UR IP address
    PORT = 30003 # UR secondary client
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))
    f = open ("setzero.script", "rb")  #Robotiq FT sensor
    l = f.read(1024)
    while (l):
        l = f.read(1024)
    </pre><div><br>The script file setzero.script is:<br><br><pre class="CodeBlock"><code>

    You can find information about this connection on the UR website: 


    Louis Bergeron
    Integration Coach
    [email protected]
  • MarvinWMarvinW Posts: 3 Apprentice
    Thank you very much for your quick Response!
    I tried it exactly the way you wrote it here but i didn't manage it. 
    I took the python Code for the Client as it is and then modified the script Code, you can see it below. 
    In this line you give your port as a fix integere but from where do you know it? It's something that does your OS for you i thougt. 
    The modified Code, with an additional line so that i can see if the Robot is moving (in URSim) and that i could see in the response the message with the multiple \xff ' s. 
    def rq_set_zero():<br>   if(socket_open("",63350,"acc")):<br>      socket_send_string("SET ZRO","acc")<br>      sleep(0.1)<br>      movej(p[0.603, 0.729, -0.309, 3.539, -1.146, 0.186], a=1.200, v=0.50, r=0)<br>      sleep(2)<br>      socket_send_string("\xff\xff\xff\xff\xff\xff","acc")<br>      socket_close("acc")<br>   end<br>end
    But neither i get the message back(a lot of Bytes but not the \xff's)( i print it in the while-loop) nor i can see the Robot moving. 
    I deleted the if condition to try if that would change the behavior but nothing happens. 
    Do you have any suggestions? Anything would help :) 
  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,266 Handy
    edited November 2018
    The one thing that I notice is you are sending robot commands to the FT Sensor.  The robot commands need to be sent to either port 30001, 30002 or 30003.  In the file that you are sending to the robot you are sending the set_zero command to the FT sensor and then trying to move which is perfectly fine.  Just change the port that you are sending the whole file to back to 30003.

    Or I may be misunderstanding what you are asking.  Do you have a FT sensor installed on the robot?  If not, the port is never opening and therefore you are not getting into the if statement.

    Try modifying the script you are sending to the following

    def rq_set_zero():<br>   if(socket_open("",63350,"acc")):<br>      socket_send_string("SET ZRO","acc")<br>      sleep(0.1)
          socket_close("acc")<br>   end
       movej(p[0.603, 0.729, -0.309, 3.539, -1.146, 0.186], a=1.200, v=0.50, r=0)
Sign In or Register to comment.
Left ArrowBack to discussions page