Universal Robots Forum

Issues with the generateScript method

With my URCap i need to add in the preamble of a program some customized functions that i’m going to recall in the main program.

I’ve already check the samples (i.e. ScriptFunction) and this is usually done by typing the code, line by line, in the script generation section of the Installation/ProgramNodeContribution.java file (using ScriptWriter methods).

  1. Is there a simpler way to quickly add a already written .script file as input within the generateScript method? I mean a method that allows to read a .script file (previusly loaded in the resources folder), something like the getResource method to load an image.
    I’m asking this because i’ve a couple of .script files (hundreds of rows), already tested within an urp program, and adding line by line all the code would be a bit annoying.

  2. I’ve notice that the script code added in the previous way (generateScript method) will appear in the .script file that is autogenerated whenever i save a new urp program with the related URCap package installed.
    Is it possible to hide to the user all the URCap-related functions which are going to appear in this file?

Thanks in advance.


If you already have the “complete” URScript code, you could use the appendRaw method to just paste the code as is.
They you would have to read the script code from the desired file in Java, and paste it.

All URScript necessary to execute the program should be contained in the script file generated, as this is the code sent as one single program for execution in by URControl.
PolyScope basically sends the same as is stored in the .script file to URControl for execution. If the script functions are not defined there, the URControl would not know what they mean.
If you are looking to protect your code, e.g. from an IP point of view, I would suggest generating your functions so they e.g. to an XML-RPC call to a daemon, which contains your core code.

XML-RPC is basically another way to create your “own” script codes, which are not covered by the generic URScript language.

Thank you @jbm for the reply.

I’ve solved the issues regarding the parsing of a .script file.

About the IP protection of the code, using the XML-RPC call to a daemon sounds interesting but i’m not sure if it will be my case.
Some functions that I’ve already defined in the script are sub-part of the main robot program and they contain direct commands to the robot (i.e. movej, movel, activation and deactivation of freedrive,…): is it possible to call such part of the program using the XML-RPC communication?

If not, is there any different way to protect a pre-defined part of the main robot program and hide the related code contained in the .script file?

All script that the robot should execute, should be contained in the script program.
An alternative, would be to send the script program directly over TCP to a client interface, however there is a risk that this might be intercepted by a LAN sniffer.

An option is to use an XML-RPC call to give the next instruction.
Something like:

runThisControlLoop = True
while( runThisControlLoop ):
   command = myRPC.get_cmd()
   if ( command = 0 ):
      # Could be some linear motion
   elif ( command = 1 ):
      # Could be some joint motion
   elif ( command = 2 ):
      # Could be some servoj
   elif ( command = 3 ):
      # Could be enter freedrive
   elif ( command = 4 ):
      # Could be exit freedrive
   elif ( command = x ):
      # Could be something else
      # Exit control loop and do the next thing in program
      runThisControlLoop = False

In this way, the way your code actually generates the next motion and all the clever logic behind this will not be undisclosed. And only the respective waypoints and commands could be intercepted.

1 Like