UR Script: Script programming from the teaching pendant.

Also checkout the new CB3 forum

Using the UR teaching pendant for Script programming.

In this method of script programming you still need the teaching pendant, but this function is very helpful and makes it possible to edit part or entire program on another computer while the robot is running production.

This function can be used extensive script programming, but also just as a method to manipulate variables, input/output states and especially timers. This makes the programming very elegant i.e. the program tree is the overall pattern and flow of the program whereas things that can change such as variables I/O and timers are kept in separate blocks. In this way the commissioning and adjustment can be done in these blocks without touching the program flow.

universal_robots_zacobria_script_1

In the Advanced program menu under Structure section the Script Code object is located. This object will insert at “Script:” entry into the program. Note it is still yellow which means we have to define it.

To define the Script entry in the program – point on the Script line to define and choose “Command” on top of the menus.

However before we proceed with the programming we need to prepare our Script file – otherwise there is nothing to load so let’s step a little back to the point where we have no Script entries in the program tree and just two simple Waypoints.

universal_robots_zacobria_script_2

I am planning to change 2 outputs in between the two Waypoints and after the last Waypoint before the program goes back to Waypoint 1. And I need a delay in between the change of the 2 outputs – note the second delay is 2 seconds whereas the first is 1 second.

This could also be done by using the traditional teaching pendant method and it would look like below program.

universal_robots_zacobria_script_3

But in this case we want to use the Script method so we have a separate Script file with our variables for later adjustment opportunity while the robot is running production.

So before we go any further we only have a small program with 2 waypoints.

Now we need to prepare the separate Script file. The format of the Script statements can be studied in the Script manual, but a very useful method to learn about the format of a Script language is to open a Script file the robot already have provided from previous created program. Remember the robot creates three files every time a program file is saved – a x.urp file which is the robots main program file – a x.txt file which is a very simple text file to illustrate the program flow and a x.script file which is the actual program in script format. Try and open such an x.script file in a simple editor e.g. a Notepad and study the contents.

For example our first program looked like this in script format:

My_first_program.script
def My_first_program():
set_analog_inputrange(0, 0)
set_analog_inputrange(1, 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])
while True:
$ 0 “Robot Program”
$ 1 “MoveJ”
$ 2 “Waypoint_1″
movej([-0.7601482324296471, -1.9284112483400442, 2.4200850009312065, -2.13148960204731, -1.562351390833685, -0.9523963238633675], a=1.3962634015954636, v=1.0471975511965976)
$ 3 “Waypoint_2″
movej([-0.7601145807261123, -1.925313457229536, 1.4271208291636501, -1.1406326407517442, -1.5621569587688118, -0.9518539657810257], a=1.3962634015954636, v=1.0471975511965976)
end
end

 

Don’t dwell too much into the details at this stage of this script file and may just study a single line statement e.g. the “set_tool_voltage(24)” which sets the Voltage on the tool to 24 Volt and compare to the explanation in the scriptmanual_enx.xdocument.

universal_robots_zacobria_script_4

Note that in this case the robot has wrapped the Script code around with some initial definitions that you do not see in the tree structure, but that’s default robot settings and also comments like “$ 2 “Waypoint_1″” – this you might or might not need in your Script file depending on your complexity of your Script program and also because we are inserting Script code into a part of a already existing robot program and therefore some of these wrappings will be duplicated and cause program errors – so in this first simple case we do not need it.

Study also the long “movej(xx, xx, xx, …………, v= xx) which is actual positions of the waypoints. The meaning of the values will be explained later section.

In our case we just need two script files because we need to insert Script code at to different locations in the program i.e. in between the Waypoints and after the last Waypoint – and we need two files because they need different contents because we swap the status of the outputs.

Some we will now prepare the Script files on a PC computer and we just use a simple editor such as Notepad to create these two files.

universal_robots_zacobria_script_5

Note that the two outputs have swooped states and the delay has increased from 1 to 2 seconds. Also note the two files has different names i.e. sc1.script and sc2.script.

Also note how the “Wait 1.0” functions is now called “Sleep(1.0)” which is in line with standard Script language.

So now instead of programming these functions in the program tree we want to import these files instead.

Now we can proceed to insert a Script: statement into the program tree by picking it from the advanced program object menu and it comes into the program as yellow because so far it is undefined.

universal_robots_zacobria_script_6

Point on the “Script:” statement and choose “Command” screen. In this screen the Script function is defined. On the right hand side the amount of script commands are chosen i.e. only one line of script code or from a separate file containing maybe several script commands.

universal_robots_zacobria_script_7

In this case we choose file because understand file will also explain a single line – and the right screen appears.

So far no file has been chosen – hence there are no script statements. Choose “Edit”.

universal_robots_zacobria_script_8

Then choose “Select File” which will bring you to the file menu where you can navigate to your file destination of your prepared Script program block. Then choose your intended Script file and choose Open – in this case the sc1.script file we have prepared and choose “Open”.

This will open your Script file. Choose “Save & Exit” which will complete you’re “Script:” statement in the program tree and therefore turn green.

universal_robots_zacobria_script_9

Note how the contents of the Script file now have entered into our program under the Script: statement.

Now follow the exact way to insert a second “Script” statement under Waypoint_2, but this time import the script file “sc2.script” instead.

Then your program should look like this.

universal_robots_zacobria_script_10

Now try to test run your program which behave exactly like if the outputs and wait has been made in the tree structure.

Save the file which of cause will create three new files x.urp, x.txt and x.script which now has the entire program inside including the Script files interpreted by the Robot.

def Import_script_after():
set_analog_inputrange(0, 0)
set_analog_inputrange(1, 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])
while True:
$ 0 “Robot Program”
$ 1 “MoveJ”
$ 2 “Waypoint_1″
movej([-0.5263706597088378, -1.8182878349727298, -1.8120234982472114, -1.3619128328552264, 3.214885380931556, -0.27251695975573664], a=1.3962634015954636, v=1.0471975511965976)
set_digital_out(8,False)
sleep(1.0)
set_digital_out(9,True)

$ 4 “Waypoint_2″
movej([-0.8560998108900053, -1.7976119215251396, -1.7847397963745542, -1.410065160905723, 3.2146832909469674, -0.27251695975573664], a=1.3962634015954636, v=1.0471975511965976)
set_digital_out(8,True)
sleep(2.0)
set_digital_out(9,False)

end
end

 

Note how the content of our two script files has been inserted to the program (marked with yellow). The big advantage now is that we still have our two script files we can edit with an editor on another computer and make adjustments to our variables e.g. if we want to change output or change timer values it can be done while the robot is running production and then when there is a break be loaded into the robot program which can immediately be started.

It is possible to have the entire program as a script file and import in this way – so the tree structure will only have one statement – a Script: statement where the entire program is in a script file and thereby loaded into the robot. But in such case some of the wrappings and comments has to be removed from the script file format the robot create by itself in order to avoid double definitions.

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



25 thoughts on “UR Script: Script programming from the teaching pendant.

  1. Manuchehr

    Hi!
    Do I need to use Ethernet connection to upload the script or USB flash drive?
    I’m just curious about overall connection with PC. Do I need to install a software on computer?

    Reply
    1. zacopressadmin Post author

      Hi Manuchehr

      Thanks for the question

      I find it the easiest to use a USb drive to transport a script file. No need for any software on the computer.

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

      Also check out the CB3 forum



      Reply
  2. Mark

    Another question, I have downloaded the script manual of the official website. It seems to be incomplete.
    For example, the commands rotvec2rpy([3.14,1.57,0]) or rpy2rotvec([3.14,1.57,0]) are not listed in that manual, i’ve found the commands somewhere else (sadly enough, don’t know where anymore)

    For me, those commands are quite important.
    Is there somewhere a complete list of ALL possible commands?

    An option I’m still looking for, is to create a new plane out of three poses.
    At the moment, I can only create these with Installation -> Features -> New plane. The result of this teaching is a pose when I export a program which uses this plane.
    However, I want to be able to define the three points myself and convert it to a plane.
    If I can do this, I can give my operators so much freedom to put products on new places with very little effort.

    Reply
    1. Mark


      popup ("
      A new plane will be defined by the following three points:
      1. Origin, 2 Y-direction, 3 X-direction
      ")
      freedrive_mode()
      var_1=request_boolean_from_primary_client("Go to first position and press Yes")
      while (not(var_1 == True )):
      sync()
      end
      end_freedrive_mode()
      Point_19 = get_actual_tcp_pose()
      sleep(2.0)
      freedrive_mode()
      var_2=request_boolean_from_primary_client("Go to second position and press Yes")
      while (not(var_2 == True )):
      sync()
      end
      end_freedrive_mode()
      Point_20 = get_actual_tcp_pose()
      sleep(2.0)
      freedrive_mode()
      var_3=request_boolean_from_primary_client("Go to third position and press Yes")
      while (not(var_3 == True )):
      sync()
      end
      end_freedrive_mode()
      Point_21 = get_actual_tcp_pose()
      sleep(2.0)
      end_freedrive_mode()
      global PP=Prod7

      At the moment I tried to change the three points (19, 20 and 21) which are related to Plane7, called Prod7 in this case.
      This doesnt work either.
      So i want:
      1. Modify the existing features
      2. Create new planes by a converting command. (my preference)

      The reason the second has my preference is that you can create own planes in global poses and use it for specific parts of programs. I already tried to use pose_trans with my own created poses (which were an offset of existing planes) and it worked.
      But in reality you can’t just use offset so i need to be able to make a real transfrom out of 3 poses.

      Thanks in advancce

      Reply
      1. zacopressadmin Post author

        Hi Mark

        Some examples of using plane variables at these links.

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

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

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

        Also check out the CB3 forum



        Reply
    2. zacopressadmin Post author

      Hi Mark

      Thanks for the question.

      These commands does not seem familiar and not seen before. The official UR script manual is the best source of script commands for the UR robot.

      At these links are some more informations about using plane variables.

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

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

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

      Also check out the CB3 forum



      Reply
  3. Mark

    I made a script with some calculations for positions. The operator has 5 decimal inputs, with the 5 decimal inputs, 24 calculations are made before the first movement instruction. 4 of the 5 inputs are in the before-start sequence.
    When I want to run it, the following message appears:
    “Runtime error: The program used too much time without instructing the robot what to do. Consider using a wait or sync() to split long program sequences that do not move the robot”

    Could someone give me an example of what to do?

    Reply
    1. zacopressadmin Post author

      Hi Mark

      Thanks for the question.

      Depending on the code – it could be because the robot program is looping without much to do – maybe it can be considered to insert a small “wait”. Also more informations at this link.

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

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

      Also check out the CB3 forum



      Reply
      1. Mark

        Thanks, with the Wait instruction i found out my script didn’t do anything while I had a counter in the script with a global variable.

        My problem was that i programmed the script as a program and not as a function.
        “def move.script()” and “end” had to be removed. Now the script works fine, thanks a lot! :)

        Reply
  4. Collin Roy

    I programmed a lot with FANUC and there a function called MOD to divide a number and only keep the whole number from it. I would like to know if this function exist with the UR10 version 3.3.

    Thanks, Collin Roy

    Reply
    1. zacopressadmin Post author

      Hi Collin

      Thanks for the question.

      Maybe consider to use the script commands floor or ceil.

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

      Also check out the CB3 forum



      Reply
      1. Collin Roy

        Thanks a lot
        I would also like to know I to formulate my script to use those functions on the teach pendant. Can you give me an example of a script using a ceil or a floor.

        Thanks Collin

        Reply
        1. zacopressadmin Post author

          var_1 := 3.1415
          var_1_floor=floor(var_1)

          This will result in that
          var-1_floor gets the value 3

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

          Also check out the CB3 forum



          Reply
  5. AliG

    Hi!

    I want to use a Matlab program as a server and the UR10 as a client. How can i combine these 2 components? Is there a example program or something? I think i have to work with socket_open and socket_send_string but i am not 100% sure. Is there any example or does anyone heard anything about a project like this?

    Kind regards AliG

    Reply
    1. zacopressadmin Post author

      Hi Alex

      Thanks for the question.

      If the Matlab can use TCP socket then it might be possible to use a Client-Server method.

      I have not seen an example directly with Matlab, but at this link is an example of Client-Server

      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
  6. Charlotte

    Hi!

    I’ve been using URScript language to get data from the UR10. However, I cannot seem to get a good understanding what the difference is between the target data and the actual data. For instance with get_target_joint_positions() and get_actual_joint_positions(), does one of these correct for the payload and the other one not? Or is it that one is the current position and the other the one where it is moving towards?

    Kind regards,
    Charlotte.

    Reply
    1. zacopressadmin Post author

      Hi Charlotte

      Thanks for the question.

      The “actual” is the actual position of the joints.

      The “target” is the desired position – which might differ from the actual because of heavy load or acceleration.

      So the robot has calculated the target position – but where the robot actual are might differ – for example if heavy load is causing the joints to be pushed.

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

      Also check out the CB3 forum



      Reply
  7. Senthil

    Hi,
    I am a new learner for Script Code. The above content is really good for the beginners. I just need a small clarification in the above content. Using notepad, I have prepared a small script file like stated above. And I don’t know in which format I have to save it to proceed further. “.txt” is enough to proceed further? It is not stated in the content.

    Reply
    1. zacopressadmin Post author

      Hi Senthil

      Thanks for the question.

      In a number of the images (e.g. open in notepad and when inserting into program) it is possible to see that the files in this example are called sc1.script and sc2.script.
      They can also be called .txt or something else as long they dont have any hidden control character in the file.

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

      Also check out the CB3 forum



      Reply
  8. Ben

    Hi Lars,

    Is it possible to use the teach pendant GUI program on a Windows machine via socket connection? I assume this isn’t possible but just wanted to make sure. I need to be able to control the UR5 arm wirelessly through a Windows machine while it’s mounted on a mobile platform in a dynamic environment. I have successfully created a simple program that sends commands through a WAP and parses the return packet to provide real time data. However, as I proceed with the project I find myself having to write a program that’s already on the teach pendant…

    I would like to utilize the teach pendant as much as possible. I’m considering transferring my UR5 state machine code to the pendant (instead of attempting to bypass it altogether) and feed it position variables when it comes time to react to the environment it’s in. Is this my best option or even possible?

    Also, I will still need real time feedback on the Windows machine. Can I request this data from the Modbus TCP server (port 502)?

    Reply
    1. zacopressadmin Post author

      Hi Ben

      There might be some safety concerns if the robot can be controlled remotely and from two different controllers. There is a URSim (Simulator) that can run on a Windows machine (without a real robot) – which makes it possible to edit and test Polyscope programs on a windows machine (without a real robot). The USim can be downloaded from UR webpage. http://www.universal-robots.com/support/

      The real time port is 30003 and 30004 – some more informations at the links below.

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

      http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/overview-of-client-interfaces-21744/

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

      Many data can also be fetched form the MODBUS server at port 502, but they might not be real time.

      A list of the content of the MODBUS registers 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
  9. dreamzoor

    Hello!

    Is it possible, to connect URSim Polyscope offline simulator (downloaded from original UR site) with real robot, and then sending programs, scripts… ?

    Reply

Leave a Reply to Manuchehr 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>