Universal Robots Forum

Starting and Stopping URScript Function

I am working with a UR10e robot. I am having some trouble starting and stopping a function with external buttons.

The main program is basically an If statment that is waiting on the PLC start button to be pushed, as shown.

Robot Program
    If(    PLC_Start_Button_Is_Pushed   ):
        Script(   Trim()   )
    Wait(0.05 Seconds)

While this function is running, if the PLC Stop Button is pressed the code will eventually reach this line in the Trim() function-

If( PLC_Stop_Button_Pressed):
    return 0
end

This causes the function to return 0 and exit, essentially stopping the function and returning to the main loop where it will wait for the start button to be pressed.

The function starts and stops fine, however if start is pressed again, the Trim function will pick up where it was stopped last (the section of code with the If statement) instead of starting at the beginning.

For clarification, I am starting and stopping the function rather than the program because there are event listeners that will allow for manual robot control that need to always be on.

Could someone help me figure out how to get this function to start at the beginning rather than the middle?

Hi,

the re-called function should generally start again from its beginning.

Could you provide a sample script for replicating the issue?
I was not able to reproduce the described behavior directly.

Thank you!

sko