Universal Robots+

Trigger Digital Output from Installation node

Hello,

I am trying to create a URCaps that can toggle I/O states depending on the robot status while a program is not running.

For example, if the robot E-Stop is triggered, toggle an output to True, even if the robot is idle.

Does anyone know the easiest way to get this done? I tried using URscript through the ScriptWriter, however this script is only generated when the program runs.

Thanks,
Tyler

It is possible to toggle an output to True by accessing to port 30003.

void sendCommand() {
    try {

        Socket socket = new Socket("127.0.0.1", 30003);
        socket.setSoTimeout(1000);

        PrintWriter writer = new PrintWriter(socket.getOutputStream(), true);

        String command = "write_output_boolean_register(0, True)";

        if (socket.isConnected()) {

            writer.println(command);
            writer.flush();

        }

        socket.close();
        writer.close();

    } catch (Exception e) {
        System.out.println(MESSAGE_HEADER + e.getMessage());
    }
}

@fujikit,

Thank you for your reply! I tried your code and was able to get it to work.

Is there a way to run this in the background while this installation page is not open? Or would I have to accomplish this with the use of a Daemon?

It need not use daemon to run in the background.

Is can be realized by the thread running on constructor of installation contribution.

Thank you for your help so far. I’m sure I understand how to run a thread inside the constructor? Could you provide a short snippet of code to help me understand?

Thank you so much for your help!

The class of thread is created and started from constructor of contribution.
Please see here.

https://www.tutorialspoint.com/java/lang/thread_start.htm

Awesome! Thanks, was able to get the thread running in the constructor of contribution.

I am having trouble using the writer.println(command); to toggle multiple outputs one after another. Is there a specific sequence that I should be using to accomplish this?

You should read up more on URScipt functions in the manual here: https://www.universal-robots.com/download/
And more on secondary functions to execute things in parrallel here: https://www.universal-robots.com/articles/ur-articles/secondary-program/

1 Like

Chris,

That’s exactly what I was looking for! Thanks very much for leading me in the right direction!

1 Like