UR Script: Client Server Test

Also checkout the new CB3 forum

Script: Client Server Test for Universal-Robots via TCP Socket Connection.

UR Script programming – Test for Receiving coordinates from Host.

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

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

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

Client program running on UR Robot.

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

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

 

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

From the PC this telegram is send over the Socket connection

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

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

universal-robots-zacobria-script-client-server

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



19 thoughts on “UR Script: Client Server Test

  1. tali

    Hello Lars,
    I have a client-server program working with universal ur3.
    I changed the connection: instead of connecting the robot to the network, and connecting the computer to
    the network, I am now connected directly to the robot via an internet cable. Should I be using a special cable for this? Re-configure the robot’s ip address?
    Thanks, Tali.

    Reply
  2. sun qiang

    hi,
    I got problem when comparing the string when I send a string from pc(server side) to ur(client side).
    Here is how UR read and compare in a scrpit:
    recv = socket_read_string()
    if( recv == “home\r\n”):
    global switch = 1
    end
    ///////////////////////////////////////
    UR received message as such “home\r\n”
    but when compare the two string it does go true

    Reply
    1. zacopressadmin Post author

      Hi sun qiang

      Thanks for the question.

      Maybe consider to receive as byte instead “socket_read_byte()” and then make the compare on byte level.

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

      Also check out the CB3 forum



      Reply
        1. zacopressadmin Post author

          Hi

          Maybe consider to try socket_read_byte_list()

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

          Also check out the CB3 forum



          Reply
  3. Andrei

    Hi Lars,
    I would appreciate if you could help with 2 questions
    1. Can I set up a similar communication but where the UR is not the client, but the server? (i.e. UR just opens a socket, and another device tries connecting to it via UR’s IP adress)
    2.Can I change the values of a predefined TCP? I would like to test a part connection’s compliance, by modifying the connection point with a certain value (+-1.5 mm, 2 deg, etc). Therefore I wanted to have a random value that would offset the TCP data on a certain axis before moving in for the connection, and having the original TCP back afterwards. Since I want as many different positions, switching between different TCP sith the SET function would not really do.
    Many thanks!
    Andrei

    Reply
    1. zacopressadmin Post author

      Hi Andrei

      Thanks for your questions.

      For your first question I think I need to give a similar answer like last time.

      1.
      There is no command to make a polyscope program a server – and rightly so because the robot is already busy controlling a 6 axis robot arm and many inputs and outputs and monitoring many safety functions. So to use a specific machine such as a robot also to be a server is not ideal. Maybe the prossecor load a server generate – can be considdered to be on a external device that communicate with the robot client.

      There are some static server ports such as port 30001, 30002, 30003 as described here

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

      And then there is the MODBUS port 502 described here.

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

      2.
      I am not sure I understand your question correct, but maybe you can consider to use planes – and the do pose_trans with the desired plane as reference.

      Some example here.
      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/working-with-planes-and-variables-2/

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

      Also check out the CB3 forum

      Reply
  4. Andrei

    Dear sir,
    I am successfully running an application on an UR5 that has the robot act like a client within the robot-PC communication. The question is: is it possible somehow to have the client as the server? The only possibility I’ve found so far in “socket_open” instruction was to specify the IP adress as well, therefore acting only as a client. Many thanks

    Reply
    1. zacopressadmin Post author

      Hi Andrei

      There is no command to make a polyscope program a server – and rightly so because the robot is already busy controlling a 6 axis robot arm and many inputs and outputs and monitoring many safety functions. So to use a specific machine such as a robot also to be a server is not ideal. Maybe the prossecor load a server generate – can be considdered to be on a external device that communicate with the robot client.

      There are some static server ports such as port 30001, 30002, 30003 as described here

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

      And then there is the MODBUS port 502 described here.

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

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

      Also check out the CB3 forum

      Reply
  5. Udo Bock

    Hi Lazlo.

    I have here a problem to sending files from the UR Robot to an Ubuntu Unit.

    Reason is, that i want control an Robothand from righthand-robots that works with Ubuntu and python-orders.
    My thoughts are now, that i write .txt commandfiles with the script order of the UR10 techingpendant an send it vi socket to the ubuntu unit.
    My problem is, that i cannot find the saved textfiles on the flashdisk of the ur10

    On interface i can see, that the txt. files are saved in /programs. But when i look over a terminal to search them on the flashdrive i cannot find them.

    I´m a complete Newby in programming with the UR10. Next problem is, that the hand is no plag&play. Runs only over a separaty Ubuntu-Unit with python orders.

    I hope you can help me.

    Thanks Udo Bock

    Reply
    1. zacopressadmin Post author

      Hi Udo

      Thanks for your question

      When a program is made in Polyscope GUI then the program is sored as a x.urp file along with a x.script and x.txt file. All three of these files are stored in the same directory as the program has been stored from the /programs directory and downwards if there has been created directories.

      If the program was stored on a USB drive the files are stored in /programs/usbdisk/ and downwards.

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

      Reply
  6. Laszlo Setela

    Hi Lars,
    I’m newbie with UR, maybe this is a wrong section for my question, but here I can explain my problem.
    I’d like to import sample script code from your site into teaching pendant environment. I already read your article “UR Script: Script programming from the teaching pendant.” But I’d like to import script into the main part of code. In other word how can I create this:

    from this?

    def P040413_sockettest_receive_3_coordinates():
    set_analog_inputrange(0, 0)
    set_analog_inputrange(1, 0)
    set_analog_inputrange(2, 0)
    set_analog_inputrange(3, 0)
    set_analog_outputdomain(0, 0)
    set_analog_outputdomain(1, 0)
    set_tool_voltage(24)
    set_runstate_outputs([])
    set_payload(0.0)
    set_gravity([0.0, 0.0, 9.82])
    Move_To_Pos=p[0, 0.4, 0.4, 0, 3.14, 0]
    Pointer=0
    Receive_Data=[0, 0, 0, 0, 0, 0, 0]
    Socket_Closed=True
    .
    .
    .

    Reply
    1. zacopressadmin Post author

      Hi Laszlo

      Thanks for your question.

      The code you list is from a .script file that the robot create automatically when making programs in the Polyscope GUI. Therefore it is wrapped in code from the GUI enviorment especially the “set_….” shown before $0 and also the comments shown in the lines with $.

      This wrapped code should therefore not be included if you want to reinseret into the GUI enviorment because then it will be double entry of some of the code. The .script file is shown there because it is very informative and a good place to look for how script commands look like for learning purpose.

      Also the “while True:” is already there behind when programming from the GUI because the GUI enviorment is for making programs and in this example the “Program loops forever” is ticked inside the GUI and therefore it will be double and incorrect to insert “While true:” one more time.

      When inserting the script code into the GUI enviorment it is therfore only the script commands that should be inserted like the example of setting an output shown at this link

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

      The code you show is from a program written in GUI and therefore it cannot directly be inserted in the GUI again.

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

      Reply
      1. Laszlo

        Hi Lars,
        This is really bad news for me, because my partner wants from me a very complex program (running 24/7), with a hundreds of positions and routes and I have not weeks but few days to be ready. I thought somehow possible write program using text editor.

        Reply
        1. zacopressadmin Post author

          Hi Laszlo

          What do mean by a complex program and running 24/7 ?

          There are programs made in GUI or made by text editor that can run 24/7. Yes you can make programs in text editor – did you click on the link ?

          What is your idea of having hundreds of positions and routes made in a text editor ?

          You can have a long list of positions and routes in a text file.

          However I find it easier and faster to make programs in GUI which are also more friendly to maintain and modify.

          What kind of application are you working on and how are the hundreds of positions and routes ?

          Reply
          1. Laszlo

            Hi Lars,
            Much appreciate for your quick answer.
            We preparing a project for car industry in enterprise environment where production is 24/7.
            I cannot shortly explain whole concept of our project, but you can imagine how easy reuse (copy/paste) earlier defined codes (of course positions easy define in UI)

          2. zacopressadmin Post author

            Hi Laszlo

            OK noted – yes in the GUI enviorment you can also very fast and easy copy and paste waypoints or whole sections of program with many waypoints inside.

            And in the GUI when you program execute the program pointer is shown which makes it friendly to maintain.

            If you program with a text editor there is no program pointer for the line of codes in the text file – so any error there will just to point to one line which is the text file that might have many lines of code – then it becomes difficult to maintain and also difficult to understand for others.

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

  7. Matthew Bush

    We are using socket_send_string to send data off the robot to a cloud storage. This is working very well fo us but we are having an issue. In our case we are monitoring the current being consumed by the device we are operating with the robot. If the current goes above or below certain limits we want to send an additional set of data out of the robot. We have placed these additional socket_send_string commands inside of an if control statement. We never get these bits of data. If I put the whole socket series of commands inside of an if statement we also never make the connection. Any ideas what we are doing wrong?

    Thanks,
    Matt

    Reply

Leave a Reply

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

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