UR Script output for a URP program that does NOT loop forever in 5.6

In my project we’re using the following workflow.

We develop motions by using Polyscope and the urp format.
But once the motions are complete we use the *.script file, to store our scripts under version control and later on upload them via the TCP script interface.

In version 5.6 I’ve noticed that if I disabled the Program Loops Forever I get the following code added into my script.

  step_count_19991243_4749_4c97_893d_10539f4cd390 = 0
  thread Step_Counter_Thread_dab11f0e_2e45_442f_b6d8_42ddfd80cdf0():
    while (True):
      step_count_19991243_4749_4c97_893d_10539f4cd390 = step_count_19991243_4749_4c97_893d_10539f4cd390 + 1
      sync()
    end
  end

This does not seem to happen in ver 5.5. Is this a bug? If there any purpose of the program having a step counter added to it?

Thanks

The section of program you have highlighted is a thread that constantly runs in the background whenever a program is playing, what the purpose of this thread is I don’t know.

You will see further down in the programs script file where the program actually begins, that the program is still wrapped in a while(true) loop as expected, dependant on the state of the “Program Loops Forever” checkbox. Below is 2 extracts from a simple program which contained only a 1 second wait and a moveJ. The first is with “Program Looped Forever” ticked", and the second with it un-ticked.

Program Loops Forever:

while (True):
    $ 1 "Robot Program"
    $ 2 "Wait: 1.0"
    sleep(1.0)
    $ 3 "MoveJ"
    $ 4 "Waypoint_1" "breakAfter"
    movej(get_inverse_kin(Waypoint_1_p, qnear=Waypoint_1_q), a=1.3962634015954636, v=1.0471975511965976)
  end

Program Doesn’t Loop Forever:

  $ 1 "Robot Program"
  $ 2 "Wait: 1.0"
  sleep(1.0)
  $ 3 "MoveJ"
  $ 4 "Waypoint_1" "breakAfter"
  movej(get_inverse_kin(Waypoint_1_p, qnear=Waypoint_1_q), a=1.3962634015954636, v=1.0471975511965976)

Hi Sam,

Thanks for the reply. I understand what the code does, but it seems to be of no relevance to the main program, and in my use case it actually is causing me issues.

What version of UR Software did you use to generate your example? Was it 5.6 or earlier.
Maybe it’s one of the steps I’m using in URP format that is causing this mysterious thread to be added to my generated code.

Thanks,
Maciej

The above script files were generated from URSim 5.6, and I have a similar step_count while(true) loop at the top of both script files, so I wouldn’t have thought that that is what is causing the problem. I suspect that its just something that the back end of Polyscope needs to add to a programs script file for whatever reason, and it shouldn’t end up intruding, whats the problem exactly?

OK in my case the step counting while(true) loop only appeared in the script where the program was set not to loop forever. And I did not see that loop added in 5.5 version of the software.

Here is my Exact problem I have a top level script attached below.

The <<*.urscript>> tags are used by me to programatically copy and paste the contents scripts created in URP converted to URScript scripts and than I upload them over TCP.

Each <<*.urscript>> there is supposed to represent a single motion of the robot. So I have an issue of having a while loop added for me “as a bonus” in those scripts as I want to treat them as a single function with a defined start and end. I have a 2nd developer who is more comfortable in developing URP motions 1 at a time, and than we convert them into urscripts and use them so that we can invoke them as needed though an XMLRPC call.

Now if I remove that automagically added while loop step counting code I have expected, but I’m trying to understand the reasoning behind adding this step counting thread in the first place, as I did not see that happen when I tried on 5.5 version of the software.

This way of assembling a top level script seemed to work well, but I’m seeing a little bit of an issue here and the solution begins to feel a little wobbly with the mysterious while (true) counter thread that supposedly does nothing.

Here is my top level script so you can get the idea of what I’m trying to do:

def Program():
    # Define UR number
    robotNumber = 1
    # set up the service object
    robotService = rpc_factory("xmlrpc","http://<<IP>>:5678/robotservice")
    #initialize thread shared variable
    motionType = "Idle"

    #motion definitions
    <<UR1\destack.urscript>>
    <<UR1\Home.urscript>>
    <<UR1\Reject.urscript>>

        #signal motion end
    def MotionEnd():
        robotService.SignalMotionComplete(robotNumber)
        motionType = "Idle"
    end

    #Listens to requests for motion from using XMLRPC
    thread XmlrpcThread():
        while (True):
            motionType = robotService.CheckIfMotionRequested(robotNumber)
            sleep(0.5)
        end
    end

    #run listener for xml rpc external motion requests
    thrd = run XmlrpcThread()
    
    #main program

    while (True):
        if motionType == "Idle":
            sleep(0.5)
        elif motionType == "Destack":
            destack()
            MotionEnd()
        elif motionType == "Home":
            Home()
            MotionEnd()
        elif motionType == "Reject":
            Reject()
            MotionEnd()
        else:
            popup("Error Motion Value not valid", "Error", False, True, blocking=True)
            halt
        end
    end
end