Program execution for actions performed outside of the script writer

Hey everyone,
I am putting together a URCap with a couple of program nodes and in a number of them I would like to perform a scheduled action (to be executed in the compiled robot code) outside of the script writer. Here is an example of what I mean:

public void generateScript(ScriptWriter writer) {
writer.appendLine(“Var1 = True”);
DoSomething();
writer.appendLine(“Var1 = False”);
}

The problem I have is that DoSomething() is executed immediately when the program starts and not as a step in the program. Is there a way to fix this?

Thanks,
Eli

yes, that is the expected behavior.

there are always exceptions but in broad, general, strokes - everything in the generateScript() function should be in native urscript and wrapped in writer...(...) funcs.

check out the urscript xmlrpc client. you can find examples of xmlrpc servers written in java.

https://www.universal-robots.com/articles/ur/interface-communication/xml-rpc-communication/

in this case, you would construct an xmlrpc server in java and initialize it. then construct xmlrpc client in urscript with myXmlrpcHandle = rpc_factory("xmlrpc","http://127.0.0.1:1234") in your installation contribution’s own generateScript() (so that it is constructed in the “before start” of the robot program).

then replace your DoSomething() line with myXmlrpcHandle.DoSomething() (written in urscript)

…now… the urscript that gets executed when the program runs will call out to the xmlrpc server when it runs that line, and the xmlrpc server will execute the relevant code

1 Like

Thanks for the help! I have done some testing and this looks like it will solve my problem.

If anyone else is looking for a good example of a XMLRPC server set up in java, the project here has one: URCap Sample: Ethernet/IP monitor can be launched from toolbar

the interaction between the java of the urcaps and the urscript actually running on the robot in a program takes some getting used to.

at a high level , what happens when a user writes a program and hits play, all of the program nodes (read: polyscope program lines) ‘contribute’ their respective urscript snippets. This is compiled and sent to the robot for ‘near real-time’ execution. Once the robot starts running a program, it is isolated and silo’d away from polyscope/java. once a program is running, the robot has absolutely no awareness of java at all, and therefore no access to any java method.

it comes down to a scoping issue - the java methods (incl. DoSomething()) are out of scope of the robot program

…and that is where xmlrpc comes in… as a mechanism to reach ‘out of scope’