1. Home
  2. Knowledge Base
  3. Functions-1

UR Programming Functions:

Application Description:
This article shows how it is possible to make functions in script files that can be embedded into a UR program.

Example 1: Function for Control Outputs from a local script file.
Example 2: Function with parameter transfer.
Example 3: Function with parameter transfer and make calculation and return result.
Example 4: Function with move command and calculate new position for move.
Example 5: Function with If condition.
Example 6: Function that combine all of the above 5 examples.

Example 7: Function with 2 lists of poses – (Each list contain 6 poses i.e. a total of 12 poses).

A function is typically a small piece of code that performs a calculation routine or can be programs lines that are often used in the main program.

Some benefits of using the method of Functions is that such script files can be maintained offline, but needs to be transferred and loaded into the Polyscope program (compiled) to take effect.

Another benefit is that the main Polyscope program can be fewer lines.

However a disadvantage might be that the program is more difficult to troubleshoot because the UR will only show an error for the Script – not where in the script the error is. So some evaluation for Pros and Cons needs to be performed.

As describe in other articles on this forum Script commands and Script files can be used in various ways with a Universal-Robots – either send from an external device or used locally on the UR – or a combination of that.

Note: Variables will not work when sending as raw script commands because variables (and other programming technique like loop – If-Else etc) needs to be controlled either by the external host program (e.g. a Python program) – or within a Polyscope program. Such variable cannot be left in between a host program and a Polyscope program – there is no controller in between.

To send variables – make loops – use If-Else and to get informations back from the robot then the client-server method can be considered.

UR Script: Client-Server example.

A function might not be ideally transferred from an external device via port 30001 – 30002- 30002 and to expect return data back to the external device. Other approaches can be used if this is the goal – like Client-Server situation and use of the UR MODBUS server on Port 502.

Other articles on this forum describe how it is possible to send raw Script commands from an external device e.g. a PC to the robot on Port 30001 – 30002 and 30003 – and is considered as a kind of “One Way” commands – meaning it is not ideal to ask for data back with this method. The robot does automatically send data back from Port 30002 which is a kind of fixed Matlab data.

Instead a function is best and most ideally used locally on the UR and the function code will be embedded into the Polyscope program. The script file can be prepared on an external device for example if the robot is already in production and then when the robot is idle and available – then the script file can be transferred to the UR and then manually embedded into the Polyscope program.

Function description:
A function program typically looks like this

def myProgram()
 Some script code……..
 “
 “
end

Although it is possible to send code that looks like a function to Port 30001– 30002 – 30003, and the robot will execute this, Something like this below can be send to Port 30002 and it will be executed.

def Move():                                     followed by a \n (newline)
set_digital_out(1,True)                         followed by a \n (newline)
movel(p[0.0,0.3,0.3,0.0,3.14,0.0], a=1, v=1)    followed by a \n (newline)
set_digital_out(1,False)                        followed by a \n (newline)
end                                             followed by a \n (newline)

Turning Output 1 on then move the robot to position X=0, Y=300mm, Z=300mm, Rx=0, Ry = 3.14, Rz = 0 and the turn Output 1 off.

But with this method is not ideal to read Inputs or use flow controls likes “IF” or “While” or “sleep(x.x) with this method. For example a command like sleep(5.0) will not result in a 5 second delay. This is because every new line will be executed immediately. Therefore if the previous command is not finished – then this previous command will be terminated and the new command will be executed.

And flow controls like “If” and “While” also does not execute when they are send to port 30002 from an external device. And similar a “sleep(10) (wait 10 seconds) will not be executed if send through port 30002.

So – if the goal is to read data back from variables or inputs and use of flow controls (If and While statements) then another approach can be used like a UR Client-Server situation – or read data from the UR robot MODBUS registers via Port 502

Instead this article will show some example on how functions can be used locally on the UR robot and then be embedded into the Polyscope program.

It is important to notice that a function becomes an embedded part of the Polycope program (compiled together). So if the function file has been changed – this file needs to be loaded into the Polyscope program again (compiled together) in order for the changes in the function to take effect.

Program description:
The following 6 examples show the use of functions locally on the UR robot.

Program code:

Example 1:  Function for Control Outputs from a local script file.

A script file is create in Notepad on a PC. When the script file is embedded into the Polyscope and called from the main program the code in the script file will turn Output 1 On and OFF with a wait of 1 second interval in between.

This file is transferred to the robot or it can be loaded directly from a USB drive inserted into the UR robot.

universal-robots-zacobria-function-flash-script-0

def Flash_Out_1():
 sleep(0.1)
 set_digital_out(1,True)
 sleep(1.0)
 set_digital_out(1,False)
 sleep(1.0)
end

Polyscope program is created.

A BeforeStart sequence is inserted.

universal-robots-zacobria-function-flash-1

In the BeforeStart sequence a “Script entry” is selected from the Advances menu.

universal-robots-zacobria-function-flash-2

From the Command tab “File” is selected.

universal-robots-zacobria-function-flash-3

To enter the editor and to import the script file “Edit” is selected.

universal-robots-zacobria-function-flash-4

An editor opens up.

universal-robots-zacobria-function-flash-5

To import the script file “Open” is selected and the script file is pointed out.

universal-robots-zacobria-function-flash-6

The contents of the script file is now in the editor on the robot.

universal-robots-zacobria-function-flash-7

After selecting “Exit” in the editor – the script file is now inserted into the Polyscope program.

universal-robots-zacobria-function-flash-8

A small wait is inserted in order to prevent “infinite loop error”.

universal-robots-zacobria-function-flash-9

In order to call the script file from the main Polyscope program – a “Script entry” is selected from the Advanced menu.

universal-robots-zacobria-function-flash-10

This time the “Line” entry for a single line script command is selected.

universal-robots-zacobria-function-flash-11

The script file is called with the command “Flash_Out_1()” because this is the name that is defined in the script file for this function.

universal-robots-zacobria-function-flash-12

The call the the function “Flash_Out_1” In the Polyscope program.

universal-robots-zacobria-function-flash-13

The program file is saved.

universal-robots-zacobria-function-flash-14

Program run:
To run the program the “Play” is pressed.

universal-robots-zacobria-function-flash-15

Digital Output 1 is tuned On and Off according to the code in the script file.

universal-robots-zacobria-function-flash-16

universal-robots-zacobria-function-flash-17

The code in the script file only show as one line in the main program, but behind the code in the script file is being executed.

 

Example 2:  Function with parameter transfer.

A script file is create in Notepad on a PC. When the script file is embedded into the Polyscope and called from the main program the code in the script file will make a pause based on the value transferred into the function by the variable “counter”.

This file is transferred to the robot or it can be loaded directly from a USB drive inserted into the UR robot.

universal-robots-zacobria-function-pause-script-0

def Pause(counter):
 while 0 < counter:
 counter = counter - 1
 sleep(0.001)
 end
end

Polyscope program is created.

A BeforeStart sequence is inserted where the script file is loaded into the main Polyscope program.

In the main program Digital Output 1 is set to high. And the variable in this example is set to the value 1000.

The function “Pause” is called with the parameter value of variable var_1. The function provied a pause until var_1 is counted down from 1000 to 0.

Then the Digital Output is set to low and a new pause is inserted. So this program toggles Digital Output 1 on/off.

universal-robots-zacobria-function-pause-1

Program run:

Digital Output 1 is observed from the I/O menu and Digital Output toggles on/off.

universal-robots-zacobria-function-pause-2   universal-robots-zacobria-function-pause-3

 

Example 3:  Function with parameter transfer and make calculation and return result.

A script file is create in Notepad on a PC. When the script file is embedded into the Polyscope and called from the main program the code in the script file will calculate adding the local variable a and b – and also subtract a and b. The variable d is made global so it can be used directly in the main program. The variable c is local in the function and c is returned into the variable from where it was transferred as a parameter – now with a new value based on the calculation in the function.

This file is transferred to the robot or it can be loaded directly from a USB drive inserted into the UR robot.

universal-robots-zacobria-function-calculation-script-0

def Calc(a, b):
 c = a + b
 global d = a - b
 return c
end

Polyscope program is created.

A BeforeStart sequence is inserted where the script file is loaded into the main Polyscope program.

In the main program the variable var_1 is set to 1 and the variable var_2 is set to 2.

The variable “Result” is set to the result of the calculation in the function by calling “Calc” with the var_1 and var_2 as the two parameters which are transferred into the function and their value is used for the calculation.

var_3 is set to the value of the variable Result.

var_4 is set to the value of the global variable d.

In this example the program is Halted just to be able to verify the variable values before a new program run.

universal-robots-zacobria-function-calculation-1

Program run:

The variables are confirmed in the Variables tab window.

var_1 and var_2 has their original value.

var_3 is the result of a + b.

var_4 is the result of a – b.

universal-robots-zacobria-function-calculation-2

 

Example 4:  Function with move command and calculate new position for move.

A script file is create in Notepad on a PC. When the script file is embedded into the Polyscope and called from the main program the code in the script file will move to the position based on the transferred values from the main program. Then wait 1 second and calculate new values for x, y and z. And then move to the new calculated position.

This file is transferred to the robot or it can be loaded directly from a USB drive inserted into the UR robot.

universal-robots-zacobria-function-move-script-0

def Move(x, y, z, rx, ry, rz):
 movel(p[x, y, z, rx, ry, rz], a=1, v=1)
 sleep(1.0)
 x = x + 0.01
 y = y + 0.01
 z = z + 0.01
 movel(p[x, y, z, rx, ry, rz], a=1, v=1)
 sleep(1.0)
end

Polyscope program is created.

A BeforeStart sequence is inserted where the script file is loaded into the main Polyscope program.

In the main program the variable x is set to 0.0, variable y is set to 0.3, variable z is set to 0.3, variable Rx is set to 0.0, variable Ry is set to 3.14 and variable Rz is set to 0.0.

The function “Move” is called with the 6 variables above as paremetrs which are therefore transferred into the function.

In the function the robot first moves to the position of x, y, z, Rx, Ry, Rz.

The the function wait 1 second.

The variables x, y and z are added by the value 0.01 (1 cm).

The the robot moves to the new calculated position.

universal-robots-zacobria-function-move-1

Program run:

The robot position is observed as it moves between the two positions.

universal-robots-zacobria-function-move-2

universal-robots-zacobria-function-move-3

 

Example 5: Function with If condition.

A script file is create in Notepad on a PC. When the script file is embedded into the Polyscope and called from the main program the code in the script file will make a check on the status of Digital Input 0. If the input is True the robot will move to one position and if the input is False the robot will move to another position.

Notice; the value of x is 0.2 or -0.2 based on the status of input 0.

This file is transferred to the robot or it can be loaded directly from a USB drive inserted into the UR robot.

universal-robots-zacobria-function-if-check-script-0

def If_Check():
 if (get_standard_digital_in(0) == True):
 movel(p[0.2,0.4,0.3,0.0,3.14,0.0], a=1, v=1)
 end
 if (get_standard_digital_in(0) == False):
 movel(p[-0.2,0.4,0.3,0.0,3.14,0.0], a=1, v=1)
 end
end

Polyscope program is created.

A BeforeStart sequence is inserted where the script file is loaded into the main Polyscope program.

A small wait is inserted in order to avoid “infinite loop” error messages.

The function “If_Check” is called which moves the robot between two position based on the status of the Digital Input 0.

universal-robots-zacobria-function-if-check-1

Program run:

Digital input is set to True.

universal-robots-zacobria-function-if-check-true-2

Robot moves to one side.

universal-robots-zacobria-function-if-check-true-3

Digital input is set to False.

universal-robots-zacobria-function-if-check-false-4

Robot moves to the other side.

universal-robots-zacobria-function-if-check-false-5

 

Example 6: Function that combine all of the above 5 examples.

A script file is create in Notepad on a PC. When the script file is embedded into the Polyscope and called from the main program the code in the script file will turn Output 1 On and OFF with a wait of 1 second interval in between.

Then make a pause based on the value transferred into the function by the variable “counter”.

Then calculate adding the local variable a and b – and also subtract a and b. The variable d is made global so it can be used directly in the main program. The variable c is local in the function and c is returned into the variable from where it was transferred as a parameter – now with a new value based on the calculation in the function.

Then move to the position based on the transferred values from the main program. Then wait 1 second and calculate new values for x, y and z. And then move to the new calculated position.

Then make a check on the status of Digital Input 0. If the input is True the robot will move to one position and if the input is False the robot will move to another position.

Notice; the value of x is 0.2 or -0.2 based on the status of input 0.

This file is transferred to the robot or it can be loaded directly from a USB drive inserted into the UR robot.

universal-robots-zacobria-function-combined-script-0auniversal-robots-zacobria-function-combined-script-0b

def Flash_Out_1():
 sleep(0.1)
 set_digital_out(1,True)
 sleep(1.0)
 set_digital_out(1,False)
 sleep(1.0)
end
def Pause(counter):
 while 0 < counter:
 counter = counter - 1
 sleep(0.001)
 end
end
def Calc(a, b):
 c = a + b
 global d = a - b
 return c
end
def Move(x, y, z, rx, ry, rz):
 movel(p[x, y, z, rx, ry, rz], a=1, v=1)
 sleep(1.0)
 x = x + 0.01
 y = y + 0.01
 z = z + 0.01
 movel(p[x, y, z, rx, ry, rz], a=1, v=1)
 sleep(1.0)
end
def If_Check():
 if (get_standard_digital_in(0) == True):
 movel(p[0.2,0.4,0.3,0.0,3.14,0.0], a=1, v=1)
 end
 if (get_standard_digital_in(0) == False):
 movel(p[-0.2,0.4,0.3,0.0,3.14,0.0], a=1, v=1)
 end
end

Polyscope program is created.

A BeforeStart sequence is inserted where the script file is loaded into the main Polyscope program.

The function Flash_Out_1 is called which toggles Digital Output 1.

Then the function “Pause” is called with a parameter the determine the length of the pause.

Then the function “Calc” is called as a part of the variable “Result” assignment – which will insert the result from the returned variable in the function back into the variable “Result”.

Then the function “Move” is called that moves the robot to a position based on the parameters given in the function call – and the function calculate a new position value and the robot moves to this new position.

Then the function “If_Check” is called that moves the robot between two different position based on the status of the Digital Input 0.

universal-robots-zacobria-function-combined-1

  universal-robots-zacobria-function-combined-2

Program run:

Notice: var_1 change between 1000 and 1.

universal-robots-zacobria-function-combined-3

 

universal-robots-zacobria-function-combined-4

 

Example 7: Function with 2 lists of poses (Each list contain 6 poses i.e. a total of 12 poses).

A script file is create in Notepad on a PC. When the script file is embedded into the Polyscope and called from the main program the code in the script file will move the robot to 12 positions loaded into the script via the parameter transfer variables pose_x0 and pose_x1.

The pose_x0 variable contain 6 poses – (see polyscope program below).

The pose_x1 variable contain 6 poses – (see polyscope program below).

The while loop pick runs 6 times in order to pick each of the 6 poses in both variables. The first movel pick element number 0 from the variable pose_x0 and the robot moves there. A wait (sleep) makes sure the robot reaches the position before next command. The second movel pick element number 0 from the variable pose_x1 and the robot moves there. As the while loop runs 6 times all the 6 poses in both variables are picked one by one and therefore the robot moves to 12 positions.

The name of the function is “MoveLinear” and in this case it has an option of importing 2 variables as parameteres (pose_x0 and pose_x1).

universal-robots-zacobria-function-pose-list-4

 

def MoveLinear(pose_x0, pose_x1):
 i = 0
 while i < 6:
 movel(pose_x0[i], accel_mss, speed_ms, blend_radius_m)
 sleep (0.5)
 movel(pose_x1[i], accel_mss, speed_ms, blend_radius_m)
 sleep (0.5)
 i = i + 1
 end
end

The script code can be entered directly into the polyscope script editor as shown below – or imported from the file created externally in notepad.

universal-robots-zacobria-function-pose-list-5

Polyscope program is created.

In the BeforeStart routine the script is entered into the polyscope environment.

In the main program the acceleration, speed and blend variables are created and given values. Also 12 poses are created which are the positions the robot needs to go to.

The 12 poses are inserted into two variables pose_x0_list and pose_x1_list which each contain a list on 6 poses.

As the name of the function in the script file is named “MoveLinear” the the script is called from the polyscope program with the command “MoveLinear(pose_x0_list, pose_x1_list)” which means the 2 variables pose_x0_list and pose_x1_list are transferred into the script routine.

universal-robots-zacobria-function-pose-list-1

 

universal-robots-zacobria-function-pose-list-2universal-robots-zacobria-function-pose-list-3

Program run:

The robot runs through the 12 positions.

 

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

 

 


Was this article helpful?

45 comments

  1. Hello,

    i have a problem with programming an UR10.
    i want to call a subroutine in a subroutine, but that isnt possible because there is an popup that i cant call subprogramms there.
    Is there a way to make that possible? Maybe by calling the subroutine “subroutine” in a scripcall “subroutine()” or something like that ?

    Thank you for your answer,

    speedy

    1. Hello Danilo

      Thanks for the question.

      I have not seen a method to do such nesting of subroutines – and I also think that such nesting of Subroutines and also for IF statements should be avoided on a robot – because a robots main task is a machine.

      Maybe it can be consider to do such programming technique on a seperate external device instead of on the robot.

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

      Also check out the CB3 forum



  2. Hi,

    I would like to get an opinion regarding UR10 changeover.
    It would be great to get some input on this.

    Let’s consider that we work on a palletizing process. We just need to get boxes and move it to a specific area.

    Definitions:
    a) We do have different size of boxes: small, medium and large.
    b) We do have 2 UR10 firmware files for small and medium boxes (not for large box yet).

    1) What is the proper way of working with the UR10 when the process have more than 1 product? Should we have specific firmware for each product and apply it during changeover?

    2) Considering that the firmware among products are the same except by the waypoints (which has a slight change in positions). Should we still have a different firmware for each product?

    3) Is there a way to use the same firmware all the time and only load a different map points for different products? In this case, for my process, I would use the same firmware file and only load the specific waypoints for each box (small, medium and large).

    4) Now, consider we want to add the product for large box. I could create a new firmware for large box OR I could use the default one and only load the large box waypoints. Does that make sense then?

    Thanks for your advise on this.

    Regards,
    Sylvio

    1. Hi Sylvio

      Thanks for the questions.

      I am not sure if you mean “firmware” or “program” ?

      If assuming you mean “program” then are my comments as below.

      1.
      Maybe it can be considered to use oprator variables and then ask the user fo the size of boxes and then have a sub program for each box size. More informations at this link for “operator variables”.

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/operator-input-variables/

      2.
      Same as in item 1.

      3.
      Yes same as item 1 with different sub programs for each box size.

      4.
      Maybe it can be considered to have sub program for each box size that is loaded based on a operator input.

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

      Also check out the CB3 forum



  3. Quick question:
    I want to create a list of length x with poses. I want to manipulate those poses afterwards, my problem right now is the creating of such a list and to fill it with random pose variables.

    Would be great if anyone could come up with an idea.

    1. Hi Dominik

      Thanks for the question.

      The script manual mention a function called “random()” – maybe that can be used to make a random number – and then use the random number to create a list element and insert this element into a list of 6 elements that makes up a pose.

      I have not used the “random()” function, but at this link there are some more informations on using variables as lists.

      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



      1. Hello again.
        i could solve the Problem with the flexible list length but now comes another problem.
        I want to manipulate those pose-variables in the list.
        Therefore i wanted to write a script-code where i can write the actual TCP-Position in one of the given variables inside the list.

        it´s like this:

        def write_to_pose(act_pose,Position_list,i):
        global Position_list[i]=act_pose
        end

        act_pose= TCP pose from get_actual_tcp_pose
        Position_list= list filled with all the needed poses
        i= count-variable. each time i is increased i need the counting variable inside the script to increase.
        so first run of the script should write the actual tcp Position to the first variable inside the list, the second should write the actual tcp Position to the second variable in the script and so on.
        But nothing works. Everytime a nameless variable is created.

        Hope someone can help me with this one

        1. Hello Dominik

          Thanks for the question.

          How does the rest of the program look like ?

          How is the counter “i” counted up or down ?

          Maybe it can be considerd to write the program step by step – and for each step check that the variables is as expected using the “Variables” tab.

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

          Also check out the CB3 forum



  4. Hi,

    I have a UR10/Polyscope software architecture issue.

    Let’s consider we have an operation that consists in 3 stages:
    1) movej + movej
    2) movej + movej
    3) movej + movej

    If I desired to make the Robot arm to have a flow/soft move between all stages and moves, I must consider adding the “Blend” radius on every move, right?

    Now, let’s consider I have to check a input or flag in-between every stage like this:

    1) movej + movej + check
    2) movej + movej + check
    3) movej + movej + check

    In this situation, the arm soft flow between the stages won’t happen as there will be a movej stop operation at the check function, right? In this case, I would have to remove the “Blend” radius from the second movej of every stage..

    So, what should be the proper system architecture to let the flow soft/continuously and also keep track of current arm stage/position?

    The answer could be using Threads. However, how could I keep track of the current “robot stage (1 or 2 or 3)” to evaluate the proper “check” within the this thread call WITHOUT causing the movements to stop in-between then?

    I hope to be clear in my explanation. Let me know..

    Thanks!

    1. Hi sylvioalves.

      Thanks for the question.

      The robot does not have to stop when checking an input.

      In this program below the robot moves through the waypoints without stopping – and when it reaches waypoint 2 the robot checks on Input 1 and perform the action depending on the state of input 1 – without stopping the robot.

      Program
      Robot Program
      MoveJ
      Waypoint_1
      Waypoint_2
      If digital_in[1]≟ True
      Set DO[1]=On
      Waypoint_3
      Waypoint_4
      Set DO[1]=Off

      It is also possible to use a Thread as you mention and then set a flag when the robot has reach a waypoint – and then use this flag in the Thread. This program below does the same as above and the robot does not stop.

      Program
      Init Variables
      Robot Program
      MoveJ
      Waypoint_1
      Waypoint_2
      var_1≔ True
      Waypoint_3
      Waypoint_4
      var_1≔ False
      Thread_1
      Wait: 0.01
      If var_1≟ True
      If digital_in[1]≟ True
      Set DO[1]=On
      If var_1≟ False
      Set DO[1]=Off

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

      Also check out the CB3 forum



  5. Hello. I would like to know if it is possible to simulate the directional buttons (tool X/Y/Z +- and joints +-) in the teach panel with a script. The thing is that the customer doesn’t always have access to the teach panel (some security things) or at least it’s not easy using it while working with the robot. But there is always a software running that is connected to the robot.
    I can send movej commands to the robot with poses, but either the robot can’t move far and I have to send the command again, which makes the robot move like this: “go stop go stop go stop” so it’s not a smooth movement. Or I send it a command to move to a larger relative position, but then it can happen that the robot is not able to move there at all or moves in a strange way.

    Is there a command to tell the robot to move in one direction and continue moving or something like that to simulate the smooth movement of the buttons in the teach panel?

    1. Hello rmain

      Thanks for the question.

      maybe the “speedl” command can be considered.

      speedl([X, Y, Z Rx, Ry, Rz], accl, time)

      Move the tool head straight up (Z axis) at 25 m/s with acceleration 1.2 for 1 second.

      speedl([0.0,0.0,0.025,0.0,0.0,0.0], 1.2, 1.0)

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

      Also check out the CB3 forum



  6. Hi,

    How can I pause an ongoing operation like Move from another thread?

    Currently, the only way I found was by calling a popup and select the option to halt the program. However, once the popup is dismissed, the execution continues.

    I would like to be able to have the SW running but to pause any ongoing movement during some private conditions..

    1. I mean, I do want the operation to be paused and the return to its current operation withou having to restart from beginning. The popup with halt partially helps but it is not enough.

      1. Hi sylvioalves

        Thanks for your question.

        From the Dashboard server on port 29999 it is possible to send a “pause” – more information 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



        1. Hi,

          I did not mean by using the dashboard.
          I would like to have a “Pause” command from within the code where I could pause any “Move” operation. And “Un-paused” it by command line as well.

          1. Hi sylvioalves

            The dashboard server can also be called from a Thread to make a pause.

            Program
            Robot Program
            MoveJ
            Waypoint_2
            Waypoint_3
            Thread_1
            Wait: 2.0
            var_1≔ False
            Loop var_1≟ False
            var_1≔socket_open(“127.0.0.1”,29999)
            Wait: 0.5
            socket_send_string(“pause”)
            socket_send_byte(10)
            var_1≔ False
            socket_close()

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

            Also check out the CB3 forum



          2. Hi again,

            Indeed it works with socket_send_line(“pause”) instead of socket_send_string(“pause”).

            However, the Thread dies once the robot is Paused, right?
            The only way to restart it is to press the Play button OR use some configurable input to start it.
            I wish I could also restart it by command line.

            Thanks,

          3. Hi sylvioalves.

            The thread does not die, but it pause ofcause because that is the request.

            What is the trigger to resume you wish ? – is it a human action ? or some other action that should resume the program ?

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

            Also check out the CB3 forum



  7. Hi,

    What is the proper way of importing a project (urp file and .scripts files) from the VMWare environment to the real Robot environment?

    I usually copy the VMWare files to a flash drive and load it into the Robot. However, I have to re-save all .script files and urp files manually in its local drive otherwise it won`t work after unplugging the flash drive.

    Thanks.

    1. Hi Sylvio

      My experience is that VMWare or Virtual Machine behaves differently on different machines and on different networks – and also the type of USB flash drive behave differently – so the method depends on that.

      But the method you describe seems correct in some cases. At the moment I use a 16GB USB formatted FAT32 and it works ok to run programs from.

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

      Also check out the CB3 forum



  8. Hi,

    I am trying to calculate time of movement of Robot from position A to B using Threads.
    Kindly let me know how to do it .

    1. Hi Prinzal

      Thanks for the question.

      I have not seen a timer counter in the robot or any examples of this. But maybe it s possible to design one by counting in between small wait statement. For example loop wait 0.01 and then count a variable one up. And then have a flag variable that is set at point A and the reset the flag at point B and count how many loop has passed in between and multiply by 0.01.

      Some test might need to be made because the robot will give priority to the robot movements and safety system – it is a robot not a timer.

      Another method that might be more accurate is to st an output at point A and the reset the output at point B and the have an external component that counts the time in between.

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

      Also check out the CB3 forum


      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?’http’:’https’;if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+’://platform.twitter.com/widgets.js’;fjs.parentNode.insertBefore(js,fjs);}}(document, ‘script’, ‘twitter-wjs’);


      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?’http’:’https’;if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+’://platform.twitter.com/widgets.js’;fjs.parentNode.insertBefore(js,fjs);}}(document, ‘script’, ‘twitter-wjs’);

  9. Hi,

    I’m wondering if its possible to use the readings in the log tab (Picture: http://imgur.com/a/xM9b9 )

    For example, we want to set the payload depending on values in the log tab.
    e.g
    If io_curret < 2
    set_payload(1.2[1,1,1])

    Is this possible?

    I only found that you can export the log file to a usb stick but not how to actually use the readings during the program.

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

    were you can see this values in the output. But can you just use those variable names in the program?

    Best Regards
    Fredrik Tallroth

    1. Hi Fredrik

      Thanks for the question.

      I have not seen how to read values from the log tab, but some values for current consumption are in the MODBUS registers.

      A list of the contents in the MODBUS registers can be found at this link

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

      For example register 290-295 has value for joint currents. And register 450-451 and 770 also have some values for current I/O .

      And an example of readin MODBUS registers can be found at this link

      https://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



      1. Cheers for the fast reply!

        So in the robot programmer i use the script and write:

        var_io_current:=read_port_register(290)
        If (var_io_current < 4 )
        ….. set …
        ?

        Best Regards
        Fredrik Tallroth

        1. Hi Fredrik

          There is another example of reading the registers from an external device at this link

          https://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



          1. Ah ok,

            So you can’t use the MODBUS register directly when programming the robot with the pendant?

          2. Hi Fredrik

            It is also possible to use the MODBUS registers directly as shown in the example at this link

            https://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



  10. Hi,
    Thank you very much for your help.
    I hope you can help me with my next question as well:)
    I sent a program to ur3, and I’m trying to debug it.
    I reduced it to send two commands: popup and textmsg.
    While sending each one separately works, sending the following program-
    popup(“starting”)
    textmsg(“starting”)
    results with only the text message showing- the popup doesn’t work.
    sending-
    popup(“starting”)
    sleep(1)
    msg = “skdps”
    sleep(1)
    textmsg(msg)
    doesn’t show any message, only set sleep.
    What am I doing wrong?

    Best regards,
    Tali

    1. Hi Tali

      Thanks for the question.

      Are you sending the “program” via a socket connection to the robot ?

      If yes then the variable msg = “skdps” will not work because variables (and other programming technique like loop – If-Else etc) needs to be controlled either by the external host program (e.g. a Python program) – or within a Polyscope program. Such variable cannot be left in between a host program and a Polyscope program – there is no controller in between.

      Maybe consider sending textmsg(“starting”).

      And yes – it is nessecary to have some wait in between when sending commands in this way because if the previous command is not finish – it will be overwritten by next command.

      To send variables and the get informations back from the robot then the client-server method can be considered.

      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



  11. Hi

    I would like to now how make the palette ….if the format of pallet change time …. i what to ask user to enter the informations of pallet . thanks

    1. Hi sdow

      I assume the “palette” is a typo error – because after that you refer to “pallet”.

      Maybe consider to make different “pallet” routines in SubRoutines – and then you a operator input to choose which pallet routine to execute.

      An example of operator inputs can be found at this link.

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/operator-input-variables/

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


        1. Hi sdow
          Random picking and placing often needs some external intelligent system to handle to different scenarios -there are bin picking and vision systems on the market that might be help full.

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

          Also check out the CB3 forum


  12. Hi,
    Thank you for your site, I find it very helpful.
    I’m new to UR3 and URScript,
    I’m trying to write a program that reads states from port 30001,
    but I can’t find the state message definition. i.e. how the message is build, how I can parse it.
    Perhaps you could guide me with that?
    Best regards,
    Tali.

    1. Hi Tali

      Thanks for the question.

      Some more informations can be fund at this link.

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

      The messages definition can be found in the Client_Interfaces.xls document on the UR support page.

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


  13. Hello
    I’m new to URScript via TCP
    i have written a program: tower.urp which i load and play via dashboard server using tcp ip. At the begin of this program i defined a variable “finished” which is set to “false”. When the program is completely runned the variable is set to “true”.
    Now i would like the read this variable in my c# program. It seems like it is not possible to read the variable via the dashboard server. How can i achieve this using other ports. Thank u in advance for xyour support.
    Ariane F

    1. Hello Ariane

      Thanks for the question.

      A variable can not be read in this way because it is not know outside the Polyscope.

      One way to consider is to store this variable in a MODBUS register from inside the Polyscope program.

      And then from the outside – in this case the C program then access the same MODBUS register from the outside and read the value.

      An example of a similar situation can be seen at this link below. Scroll down to where the Polyscope program set MODBUS register 129 – and then the same MODBUS register 129 is read from the Python program on a PC – can properly be made i C also.

      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


      1. Ok thank you for your reply.
        Here at work we do not want to use the modbus way.
        Probably another solution will be to send the value of the variable from the robot to our c# program via a socket…

        Does requesting the value of a specific variable is possible when sending commands directly to the robots via port 30002? If yes what command should we use?
        Thank you.
        Ariane

        1. The MODBUS method is straight forward and does not need any addtional equipment

          If the variable is not known outside the Polyscope program – then it cannot be fetched via port 30002.

          Yes to send the variabe via a socket from inside the Polyscope program is another method – that can be seen in part of the Client-Server 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


  14. Hi

    I would like to know how to make this function ( verify expression continuously )

    Your comment is awaiting moderation.
    Hi i would like to use a commend script code .

    If some body can help me what is my error in this script :

    def GoDownLiToForce(forceZ ,z):

    while ( force() < forceZ): ( how make expression continuously )

    local pose1=pose_sub(get_actual_tcp_pose(),p[0,0,z,0,0,0])

    movel (pose1,1,0.25,0,0)

    end
    end

    1. Hi Miljan

      Thanks for the question.

      One trick to learn how the robot handle script code is to make a program in Polyscope with similar function as the required function made in script code.

      For example from your program above – a Polyscope program can be considered with a Loop that has “Check expression continiously” checked and then save that as a program. And then Open with a editor (e.g. notepad) the program_name.script file that the robot has created by itself to study the underlaying script code. This could look like something below

      BeforeStart
      Script: miljan_cec_script.txt
      forceZ:=100
      z:= 0.2

      RobotProgram
      Movej
      Waypoint_1
      Loop force() < forceZ (“Check expression continiously” checked)
      cec()

      Where the miljan_cec_script.txt contains these lines

      def cec():
      local pose1=pose_sub(get_actual_tcp_pose(),p[0,0,z,0,0,0])
      movel (pose1,1,0.25,0,0)
      end

      This runs in Polyscope.

      Now the Polyscope program can be analyzed in program_name.script file and can look something like this below – and notice how the robot create a “Thread” and a “IF” to handle the “Check expression continiously”. Also check the labels numbering.

      $ 1 “BeforeStart”
      $ 2 “Script: miljan_cec_script.txt”
      def cec():
      local pose1=pose_sub(get_actual_tcp_pose(),p[0,0,z,0,0,0])
      movel (pose1,1,0.25,0,0)
      end
      $ 3 “forceZ≔100”
      global forceZ=100
      $ 4 “z≔0.2”
      global z=0.2
      while (True):
      $ 5 “Robot Program”
      $ 6 “MoveJ”
      $ 7 “Waypoint_1”
      movej([-1.8899853865252894, -1.467895809804098, 1.2303557395935059, -1.3209670225726526, -1.546408478413717, 2.8901078701019287], a=1.3962634015954636, v=1.0471975511965976)
      $ 8 “Loop force() < forceZ”
      thread Thread_while_8():
      while (True):
      $ 9 “cec()”
      cec()
      end
      end
      if (force() < forceZ):
      global thread_handler_8=run Thread_while_8()
      while (force() < forceZ):
      sync()
      end
      kill thread_handler_8
      end
      end
      end

      So this can be used in making a self created script file with the function “Check expression continiously”, but make sure the labels numbering are not dublicated – in this example the labels are renamed to a higher number in the self created script file – because Polyscope wil start labeling from low number. In this case the created script file is called cec.txt and contains the following lines.

      def cec():
      while (True):
      $ 15 “Robot Program”
      $ 16 “MoveJ”
      $ 17 “Waypoint_1”
      movej([-1.8899853865252894, -1.467895809804098, 1.2303557395935059, -1.3209670225726526, -1.546408478413717, 2.8901078701019287], a=1.3962634015954636, v=1.0471975511965976)
      $ 18 “Loop force() < forceZ”
      thread Thread_while_18():
      while (True):
      $ 19 “Script: miljan_cec_script.txt”
      local pose1=pose_sub(get_actual_tcp_pose(),p[0,0,z,0,0,0])
      movel (pose1,1,0.25,0,0)
      end
      end
      if (force() < forceZ):
      global thread_handler_18=run Thread_while_18()
      while (force() < forceZ):
      sync()
      end
      kill thread_handler_18
      end
      end
      end

      Now this script file is used as basis for import and the main program looks like this

      BeforeStart
      Script: cec.txt
      forceZ:=100
      z:= 0.2

      Robot Program
      Movej
      Waypoint_1
      cec()

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

      Also check out the CB3 forum


Leave a Reply to Prinzal Cancel reply

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