UR Script: Thread-in-script-file-example

Also checkout the new CB3 forum

This example shows how to make a Thread in a script file.

Prepare the script file – (here using Notepad)

This thread will turn digital output 1 on and off in 1 second interval. The file is saved with the name “blink.txt” in the same directory as were the GUI program where the script file is to be used.

universal-robots-zacobria-thread-in-script-file-example

universal-robots-zacobria-thread-in-script-file-example

Make a program in GUI.

Insert (import) the script file at top level. Use the “File” function for importing the script file into GUI.

Call the script file with a single line script command using format thrd = run myThread()

Use the “Line” function for writing a single line script command.

universal-robots-zacobria-thread-in-script-file-example

universal-robots-zacobria-thread-in-script-file-example

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



23 thoughts on “UR Script: Thread-in-script-file-example

    1. zacopressadmin Post author

      Hello Harsh

      Thanks for the question.

      Maybe if you program a FTP transfer in Python, but I have not seen such function.

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

      Also check out the CB3 forum



      Reply
  1. Sascha

    Hi there!

    I try to create a thread, with which i can save analog_in values (from a sensor) every 0.5 seconds.
    The analog_in values shall all be saved in a vector or something similar.

    My Progress so far is as following:

    thread myThread():
    i=1
    z=[] #here i need a kind of “empty vector”
    while True:
    z[i] = analog_in(0)
    i = i+1
    sleep(0.5)
    end
    end

    Do you know how to solve this Problem, or create a vector/table … something else for saving all the values?

    Thanks a lot!

    Best Regards
    Sascha

    Reply
    1. zacopressadmin Post author

      Hi Sascha

      Thanks for the question.

      It is possible to make a list. At this link there is an example of variables as lists. (In this example the list contains poses – so the “p” might not be neccesary if the list is not made of poses).

      The number of elements might also need to be predefined e.g. making a variable var_1 := [0,0,0,0,0,0]

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/planes-and-position-variables-2/

      And then insert values into a element as

      var_1[0] := analog_in(0)
      var_1[1] := analog_in(1)

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

      Also check out the CB3 forum



      Reply
  2. Frieder

    Hi

    I thing I’m a little bit off topic but maybe you can help me

    I want to concat 2 strings in UR Script but I can’t find anything for the right syntax

    i have
    var1=”hello ”
    var2=”world”

    and i want to have
    var3=”hello world”

    can you help me with that?

    Thanks a lot
    Frieder

    Reply
    1. zacopressadmin Post author

      Hi Frieder

      Thanks for the question.

      To my knowledge this is not possible on the robot. Maybe it can be considered to do that on an external device and then send the sum string back to the robot.

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

      Also check out the CB3 forum



      Reply
  3. ziceva

    Hi,

    Is it still possible to have top level scripts in the latest version of Polyscope (3.3)?

    I have some sample programs that do show the a Script: statement at the top level, but I cannot add one in my own projects .. It is very convenient to have a Script file at the top level and define functions that can then be called inside all the program sections (threads, RobotProgram, BeforeStart etc)

    Thanks,
    John

    Reply
    1. zacopressadmin Post author

      Hi Ziceva

      Thanks for the question.

      It is possible to insert a Script file with functions in the BeforeStart sequence – and then call these functions from various places in the program – which also can be used to initialize settings and variables.

      Below is three functions that are made in a “.txt” file on a PC. In this example the script file is named “top_level_script_1.txt” and stored on a USB drive.

      top_level_script_1

      Then on the robot in Polyscope program the above script file is imported (as a file) in the BeforeStart sequence by using the “Script Code” (File) from the Advanced menu under the structure tab.

      In this example the “init” function from the Script file is called in the BeforeStart sceuence in order to initialize some settings and a variable. The payload setting can be observed and verified from the “initialize” menu – and the tool voltage can be observed and verified from the I/O tab.

      In the main part of the Polyscope program the function “pause_1″ from the Script file is used as an adjustable delay for toggling the output 2 by calling the function with a parameter.

      The main program also sets output 4 and 5 to a high state – but every 5 second the Thread is resetting the output 4 and 5 back to low state.

      The change in “variable_1″ can be observed and verified from the “Variables” tab. At the start of the program the variable_1 is set to 10 because the “init” function is called – and later in the main program the variable_1 is set to 1 and will remain at 1.

      top_level_script_2

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

      Also check out the CB3 forum

      Reply
  4. Christian

    Hello
    I have some problem to read data from UR10 on port 30002. I first receiv the right data comparing to robot data. But the following packet from robots seems to be wrong.
    Do you have any ideas why.
    Thanks a lot for your answer.
    Christian

    Reply
  5. Pedro

    Hello! I was wondering if there is a way to create a variable and change it through script code and then use it in another script code and if there is a way how can you do it? Thanks in advance and keep up the good job, your other tutorials have helped me a lot!

    Reply
    1. zacopressadmin Post author

      Hi Pedro

      Thanks for your email.

      Depending on whether you use script programming from a remote host (PC) or you use script programming locally on the robot – you might consider to use the MODBUS server at port 502.
      The MODBUS has general purpose registers at address 128 to 255 and they can be reached on port 502 where data variables can be stored and fetched.

      A similar example to use these registers is shown at this link

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

      And more information about the MODBUS server on Universal-Robots can be found at this link

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

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

      Also check out the CB3 forum

      Reply
  6. Christian

    Hello I want to know if it possible to plug a joystick on the UR10 and which interface can we use to write a script.

    Reply
        1. zacopressadmin Post author

          Hi Christian

          As long it is the UR script code the UR recognize that is send to the UR you can use many different programming methods.

          Regards
          Lars

          Reply
      1. Christian

        Hello

        Where can I find Package URx for java? I have seen these package for python. Does it exist for Java?

        thanks

        Reply
          1. Christian

            Hello Lars

            When you wrote the code for joystick did you need to write a specific code to the side of robot?
            thanks

  7. Giorgos

    Hello,
    I try to use thread to move specified joints of the robot so I can perform a complicated motion.
    The message that I get when I try to run the program is that “An other program is controlling the robot”.
    How can I over come this problem? How can I do parallel programing on the robot?

    Thanks a lot,
    Best Regards

    Reply
    1. zacopressadmin Post author

      Hi Giorgos

      Thanks for your question.

      A thread is parallel programming – however not for moves because it is a robot – and the robot can only be at one locations at a time – so if one thread say the robot should be at one location and another thread or main program say the robot should be at another location – then there is a conflict and therefore thread is not for moves.

      Instead you can control variables and monitor inputs and set outputs in threads in parallel with the main program. Maybe you can consider to control variables in threads and then use the values of these variables to decide where the robot should move in the main program.

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

      Also check out the CB3 forum

      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>