Universal Robots Forum

Subroutine within subprogram

I’m running regular polyscope on a CB3 and I want to make a subroutine to do numerous things at frequent points throughout the main program. My original intent was a subprogram, but I am already running in a subprogram and it seems you can’t call subprograms from within subprograms.

The way it’s configured now is that there’s an event trigger based on a variable. Then the few lines of code runs and the code resets the variable. While this does work, it requires adding delays to the main program because the event runs simultaneous with the main program and can create conflicts if there aren’t extra delays added in.

Is there any way to do this?

I could be wrong but I believe you can still call subprograms within subprograms using a script block.

For example, if you have two subprograms subA and subB you can call subB in a script node as subB().

If I remember correctly, you may run into scoping issues with variables though.

In your method, you could also use a boolean flag to make sure your main program tests to see if your event code is completed yet before continuing on.

Hi,
As I know, you cannot call a sub program under another sub program. However, you could call custom defined function under another defined function by UR script.

Thanks

Just whipped up a quick example. for CB series calling a subprogram within a subprogram using a script block.

And remember, you may or may not need to pay attention to variables you might try to modify with this structure depending if they are global or local.