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:
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.
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
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’