Universal Robots Forum

URCap Program Node Execution

Hello, I’m currently developing a URCap for an interface between two of our robots. I want the URCap program node when executed to call a function within the Program Node Contribution similar to how the Hello World URCap creates a popup on execution.

I know that the Hello World URCap is using the GenerateScript function and a script line to create the popup.
I can put my function into generateScript but its only called when the program is started. Just to be clear i’m trying to call a function (inside of the program node contribution script) when the program node is executed durning run time.

You can either use an Installation node to define the script code in the pre-amble, and call this later by a program node.

In this case the outputted code from your Installation Node should be:

def NameOfYourFunction():
   URScript to be executed...
end

And your Program Node should output:

NameOfYourFunction()

So the ScriptWriter would contain:

writer.appendLine("NameOfYourFunction()")

Alternatively simple have the Program Node simply paste and modify the code from the function every time you insert the ProgramNode.

Okay this works but not the way I want. Is there a way to call a function within the program node java script? This function sets up a socket connection and then sends a message to a connected computer running a python server. I know I can simiply

   writer.appendLine("socket_open("IP", port)" )
   writer.appendLine("socket_send_string( "test")")
   writer.appendLine("socket_close()")

but I would rather it call the java function and communicate that way.

It sounds like an XML-RPC call to connect from your running robot program, to an external function, e.g. running in a Python script.
Check out the XML-RPC Math sample found under the samples topic.

Could TCP/IP communication also be implemented directly in the URCap without using URScript? In other words, could the socket connection run through a Java function instead of having to use a ScriptWriter to build a URScript function?

Additionally, when the Robot Program reaches the Program Node during execution, what method(s) is executed in the URCap, besides generateScript()?

URCap contributions are not called during program execution. They are only supplying script code that is executed by real time controller thread. Basically they are called just once before program starts execution.
Only way to communicate from real time thread to URCap is to use network sockets.

1 Like

Exactly the answer I was looking for. Thank you for the quick response.

Is this still the case?
I’m trying to communicate from the real time thread to my URCap, seems like some needles extra actions.

So the only way is to use network sockets ?

I have a ProgramContrbution that uses functions from my ModBus communication protocol. So i should make a websocket to communicate from the real time thread to the programcontribution to call these functions ?

If you need to interact with the program executing at real-time, you should use a daemon process, and not the Java layer (Contributions, etc.)

Take a look at our software architecture.

I’m curious why though ? Is it speed or functionality ?

I’ve managed quite fine with just a simple socket in Java.
Doing this for testing on my internship assignment.
I have been making a URCap to control Festo Motors with the modbus protocol.

1 Like