Universal Robots Forum

Adding Subprogram node in Java

Hi,

I would like to know if there’s a way to add a SubProgram node to the program tree (I know it would just add it belo in polyscope and make a call to it) programatically in Java by pressing a button or searching for an already present program in the robot. I have not found a solution to this yet, but it would be tremendous help to the end operator not having to do the same task for every unique program, that uses my URCap.
The main idea would be that the robot needs to open for example a door, but there are 5 different doors, and 3 different grippers, each gripper requiring a different approach to be able to open the doors. Currently, if there’s a program, that opens 3 doors with a gripper, you would need to teach the robot about the same waypoints to open the doors wwith the same gripper if you want to make an other program. To facilitate work, I want to be able to call a subprogram specific to the gripper and doors, so you just have to program what the robot does after the openings instead of programming opening the doors and what to do after.
I hope this little explanation makes sense. It would be absolutely great if this was possible.

Thanks,
Viktor

Whilst I am not sure if there if a solution to add the subprogram node to the tree directly, I think theres are some workarounds for your problem. The 2 that I have though of are to either have the URCap open a file explorer and read in a script file, or to have the costom functionality programmed as children nodes of the URCap node.

For the first idea, loading a script file, each .urp file (robot program) also saves a .script file of the same program. So whilst you may not be able to call a subprogram directly, you could read in this script file and have that be contributed as part of generate script. My other idea would be to have the custom programming be defined as a children of the URCap. You could then use writeChildren() in generate script to generate the routine defined by the children nodes and have it be called whenevr necessary. You also have the URCap generate its own custom URCap childern nodes to be used as “subprogram” parents, in a strucure similar to the tree below:

> Main URCap node
    > subroutine 1
        *soubtourine 1 inserted here*
    > subroutine 2
        *soubtourine 2 inserted here*
    > subroutine 3
        *soubtourine 3 inserted here*

Others may have more suggestions, but i hope this helps.
Sam

Hi Sam,

Thank you for the ideas. I’m already using the second one, currently there’s a main node that can generate children nodes with the required functionality by the push of a button. My main problem is that using this method, every time you create a new program that only differs in the material used, you have to do some really tedious programming even though you have already programmed almost all of it.
I will look into using a file explorer, hopefully I can make use of it to have my desired functionality. One more question: if I load a .script file, do I have to read it and feed it line by line to the generateScript() method, or can I just pop it in there and it just works?

Thanks,
Viktor

Regarding reading in a script file, you will need to feed it in line by line rather than parsing the whole thing in one go. Fortunately Jacob from UR has made a sample which does exactly this, just pinch what you need from the following sample.