Variables

Also checkout the new CB3 forum

Init Variables

In the Program tree – Point on the “Init Variables” line and this screen appear.

universal_robots_zacobria_variables_1

In the centre screen the actual value of the variables are instantly shown and these variables used in the program can be set to an initial value desirable for the main program.

The value can also be set to an expression or to the Value from the last run of the program by ticking the “Preferred value from previous run”. This is especially useful when using the Pattern templates for picking or placing items in an array – and therefore continue from the point from where the robot left from the last program run.

In this case the program comprises of a Pallet Pattern which has variables for the number of transversal positions to keep track of the progress besides a user created variable called “var_1”.

universal_robots_zacobria_variables_2

Variables – Prefer to keep value from last run.

Here comes a beautiful function.

So far the robot program will start at position 1 (Waypoint_4_1) every time we start up the Robot program – also is this was after a safety stop.

But in the Init Variables screen there is a feature called ”Prefer value from previous run”. If this one is clicked for the intended variable then the robot can remember which position is next to be delivered to on the conveyor so we do not stack to work piece on top of each other or leaves any location unoccupied.

universal_robots_zacobria_variables_4

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 “Variables

  1. Osiris

    Hello,

    I have a program that uses a variable, the list type. the variable is initialized at the beginning of the program. I had a runtime problem because I took to much time processing data and the robot was doing nothing.
    I started to troubleshoot and I noticed in the “Variable Tab” that the list variable not only changed the values, which I did not modified during the execution but the size which is not allowed in the Polyscope coding.
    I spent a lot of time trying to figure it out without a logical explanation. I decided to put an if statement at the end of the program to popup a message if the variable was the same I defined at the beginning, every run the popup was true, the variable defined at the beginning was the same at the end of every execution of the program while the “Variable Tab” was showing different value as if it was changed.
    Is it a bug?
    Tha original problem I revolved it adding a wait statement inside the loop that was processing the data and that fixed the problem.
    Now I’m concerned whether this is a problem or not.
    Please advise.
    Thanks

    Reply
    1. zacopressadmin Post author

      Hello Osiris

      Thanks for the question.

      I have not heard about this before.

      How is the variable list assigned in the beginning ?

      What is the variable list assigned to at the beginning ?

      What is the variable showing in the variables tab during program run ?

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

      Also check out the CB3 forum



      Reply
      1. Osiris

        Hello,

        The variable was defined as a list at the beginning of the program like this:

        window=[0,0.0.0.0.0,0]

        Then, during the socket connection this var was changed to:

        window=[6,1,2,3,4,5,6]

        At the end of the execution the “variable tab”was showing:

        window=[3,0,0,0]

        How the variable defined at the beginning as a list and with 7 values got resized during the execution, this is wrong because we can not resize a list var once it is defined and I checked the value of the var using an if statement to popup if it was the initial value and always i had the true popup, in other word the “variables tab” showed a wrong value at the end of the execution of the program but the program showed it was using the right value. How this thing has sense?

        I can tell you that I use a lot of variables in my program. Is it posible that I ran out of memory and the system started to allocate the var in random places without warning?

        please advise.

        Thanks

        Reply
        1. zacopressadmin Post author

          Hello

          Maybe consider to use the “varmsg” function to insert the variable value for display in the variables tab. The “varmsg” is used in this example

          http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-tcp-socket-test/

          If there are many variables as you mention then maybe consider to reduce the amount of variables and keep the variable externally of the robot and transfer them to the robot when needed.

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

          Also check out the CB3 forum



          Reply
          1. Osiris

            Hello Lars,

            Before everything, thank you for your time and dedication.

            I did what you recommended, the result was as I described.I was hoping to paste an screenshot but unfortunately I don’t know how to do it.

            The result was like this:

            in the program:

            varmsg(“window value”, window)

            in the variable Tab:

            window : [3.00000, 0.00000, 0.00000, 0.00000]
            window value : [6,2,0,0,0,0,1],

            window value is the result expected from the socket connection.

            How is this posible? Same variable, two values?

            Please advice.

            the program is working but the variable tab has no sense.

          2. zacopressadmin Post author

            Hello Osiris

            Thanks for the informations.

            You mentioned you have many variables – Have you tried with less variables in the program ?

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

            Also check out the CB3 forum



  2. Rahul

    Hello Lars,

    I have a initialization variable (initial value is false)which should be set to true in a particular script 1(to check whether that script 1 is run or not) and then need to check whether that script 1 is run at later stage by comparing the value of that initialization variable from an another script 2.In teach pendent the robot is working fine with the scripts 1 and 2 (its detecting whether that script 1 is run or not from another script 2 ) but if i run that script from my computer all the initialization variables are reset in the beginning of that script 2 and that initialization variable is set to false again. So I cant detect whether the script 1 is run or not from the script 2. Is there any solution to do this from my computer?

    Reply
    1. zacopressadmin Post author

      Hello Rahul

      Thanks for the question.

      I assume that you are not using Polyscope GUI as part of the program when you send the script commands from the computer ? Because from the Polyscope GUIn the instalation variable is available.

      So if the scripts are run entirely from a computer then it can maybe be considered to save the variable on the computer and fetched on the computer.

      Another method that can be considered is to store the variable in a MODBUS register on the robot. At this link is among others an example on how to read and write to the robot MODBUS registeres from a computer.

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

      At this link are more general informations about the MODBUS registers where it can be seen that register 128-255 are for general purpose.

      https://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
  3. Osiris

    Hello,

    I have a program written in the teaching pendant, the program is growing up and for my convenience I would like to use Subprograms.
    The problem is that when I insert the Subprogram into the main program most of the variables in the Subprogram got renamed, creating a problem.
    What I’m doing is using folders to keep everything in the main program but with the inconvenience
    of having to modify all the folders in case of a change.
    That is why I would like to use subprograms but so far it has been impossible.
    Is there a way of avoiding the variables inside the subprogram getting renamed?

    Thanks in advance

    Reply
      1. Osiris

        Hello,

        This is the program used as a subprogram:

        Program
        Robot Program
        MoveL
        p2≔pose_add(start_pos,p[d3,d2,d1,0.0,0.0,0.0])
        p2
        p3≔pose_add(start_pos,p[d3,d2,d4,0.0,0.0,0.0])
        p3
        p4≔pose_add(start_pos,p[d3,d2,(d4+d5),0.0,0.0,0.0])
        p4
        p5≔pose_add(start_pos,p[(d3+d6),d2,(d4+d5),0.0,0.0,0.0])
        p5
        p6≔pose_add(start_pos,p[(d3+d6),d2,d4,0.0,0.0,0.0])
        p6
        p5
        p7≔pose_add(start_pos,p[(d3+d6+d6),d2,(d4+d5),0.0,0.0,0.0])
        p7
        p8≔pose_add(start_pos,p[(d3+d6+d6),d2,d4,0.0,0.0,0.0])
        p8
        p7
        p9≔pose_add(start_pos,p[(d3+d6+d6),(d2-d7),(d4+d5),0.0,0.0,0.0])
        p9
        p10≔pose_add(start_pos,p[(d3+d6+d6),(d2-d7),d4,0.0,0.0,0.0])
        p10
        p9
        p11≔pose_add(start_pos,p[(d3+d6),(d2-d7),(d4+d5),0.0,0.0,0.0])
        p11
        p12≔pose_add(start_pos,p[(d3+d6),(d2-d7),d4,0.0,0.0,0.0])
        p12
        p11
        p13≔pose_add(start_pos,p[d3,(d2-d7),(d4+d5),0.0,0.0,0.0])
        p13
        p14≔pose_add(start_pos,p[d3,(d2-d7),d4,0.0,0.0,0.0])
        p14
        p15≔pose_add(start_pos,p[d3,(d2-d7),d1,0.0,0.0,0.0])
        p15

        And this is how the same program looks when inserted as a subprogram in another program:

        SubP_Sweep
        MoveL
        p_5≔pose_add(start_pos,p[d3,d2,d1,0.0,0.0,0.0])
        p_5
        p_2≔pose_add(start_pos,p[d3,d2,d4,0.0,0.0,0.0])
        p_2
        p_3≔pose_add(start_pos,p[d3,d2,(d4+d5),0.0,0.0,0.0])
        p_3
        p_20≔pose_add(start_pos,p[(d3+d6),d2,(d4+d5),0.0,0.0,0.0])
        p_20
        p_19≔pose_add(start_pos,p[(d3+d6),d2,d4,0.0,0.0,0.0])
        p_19
        p_20
        p_21≔pose_add(start_pos,p[(d3+d6+d6),d2,(d4+d5),0.0,0.0,0.0])
        p_21
        p_4≔pose_add(start_pos,p[(d3+d6+d6),d2,d4,0.0,0.0,0.0])
        p_4
        p_21
        p_23≔pose_add(start_pos,p[(d3+d6+d6),(d2-d7),(d4+d5),0.0,0.0,0.0])
        p_23
        p_22≔pose_add(start_pos,p[(d3+d6+d6),(d2-d7),d4,0.0,0.0,0.0])
        p_22
        p_23
        p_25≔pose_add(start_pos,p[(d3+d6),(d2-d7),(d4+d5),0.0,0.0,0.0])
        p_25
        p_24≔pose_add(start_pos,p[(d3+d6),(d2-d7),d4,0.0,0.0,0.0])
        p_24
        p_25
        p_26≔pose_add(start_pos,p[d3,(d2-d7),(d4+d5),0.0,0.0,0.0])
        p_26
        p_27≔pose_add(start_pos,p[d3,(d2-d7),d4,0.0,0.0,0.0])
        p_27
        p_28≔pose_add(start_pos,p[d3,(d2-d7),d1,0.0,0.0,0.0])
        p_28

        Thanks

        Reply
        1. zacopressadmin Post author

          Hello

          Do I understand correct that you have first created the main robot program – and then save that program as an file ?

          And then created a new program where you load the main program in as a sub routine ?

          If the variables in what is now becoming the sub program already exist – then the GUI show a popup messages with a warning that the variables already exist – and an option to choose “Rename Automatically” or “Cancel”. If the Cancel is chosen then the variable names will remain and can be reused and shared with the same name in the new main program.

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

          Also check out the CB3 forum

          Reply
          1. Osiris

            Hello,

            I saw the popup window but I’m pretty sure I clicked on the cancel option. I’ll try again and see what happens.

            Thanks

  4. Toni

    Hello. Thanks for this spectacular forum about UR.

    I’m simulating the UR robot with URSim. I want to do a loop that repeats the script “x” times. But i want to ask to the user how many times. So my question is how i can fix the value of a variable using the keyboard/teach pendant…Asking this value to the user.

    Then the value is saved in the variable loop, and script executed the number of times of the variable. ..

    Thanks!!

    Reply
    1. zacopressadmin Post author

      Hello Toni

      Thanks for your question.

      It depends how you use the script.

      1. If you are using the script locally on the UR from within a Polyscope program – then you can make an Operator variable that can present a popup for the user where the user can enter a value which can be used as the loop counter.

      At this link there is an example on the operator variable part.

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

      2. If you are sending the script from an external device then you need to make the loop counter function in the application that is running on the external device.

      At this link there is an example on script send from an external device one time – so the example has to modified a little so there is a loop counter so the script can be send more times from the external device to the robot.

      http://www.zacobria.com/universal-robots-knowledge-base-tech-support-forum-hints-tips/knowledge-base/script-from-host-to-robot-via-socket-connection/

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

      Also check out the CB3 forum

      Reply
  5. Robotprogrammer

    Hi,

    I have a question related to variable for CB2 programming.
    Can you create a variable (S) which can control the speed of the robot and program it like the following.
    If Digital Input 1= high then S= 100mm/sec else S= 500mm/sec. In this way I can slowdown the robot if an input from a sensor becomes high.

    Looking forward for your comments.

    Thanks

    Reply
    1. zacopressadmin Post author

      Hi Faisal

      Thanks for your question.

      You might consider to take a look at the link below where there is an example of how to control the speed slider. Take note of the comments regarding CB2 – so if the time for Wait commands in the program should be the same regardless of the Digital input state then the Wait time has to be changed opposite of the speed when there is a change.

      http://www.universal-robots.com/how-tos-and-faqs/how-to/ur-how-tos/setting-the-speed-slider-from-a-program-15293/

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

      Also check out the CB3 forum

      Reply
  6. Rick Norcross

    I have a question. Probably not a very good one, but I haven’t found an answer in the manual and my guessing isn’t doing any better.

    I’m twisting a nut onto a bolt. If I give a pose that rotates the last joint 360 degrees, the UR10 doesn’t move. Instead I make several 90 degree steps. But this looks “funny” as the robot stops between motions (blending resulted in no motion). I seem to be able to command a joint motion to an array of values. But I need to know how to change the value of the array.

    Thanks

    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>