Universal Robots Forum

Let the program node continue when a machine is finished moving

Im currently working on a communication with a machine, and the program node needs to wait until the machine is finished positioning. after the machine is positioned, the UR can move again.


In the programnodecontribution, implementing a while loop (see below) in generatescript will freeze the screen and render it useless.

    // declaration:
    private String message_Done = "0";    //message from the machine ("0" & "0") where "1" is done


    //in generateScript(ScriptWriter writer) {
    // use this loop to keep the node busy until the machine is at its position.
    while(message_Done.equals("0")){
        updatePreview();
        writer.sleep(0.1);
    }
}

private void updatePreview() {
    String title = "";                        // used to set the ip adress in the preview
    
    try {
        // Provide a real-time preview of the daemon state
        title = getInstallation().getXmlRpcDaemonInterface().getTitle();   // get ip adress
        message_Done = getInstallation().getXmlRpcDaemonInterface().getDone();   // get machine status

    } catch (Exception e) {
        System.err.println("Could not retrieve essential data from the daemon process for the preview.");
        title = "<Daemon disconnected>";
    }
    titlePreviewLabel.setText(title); // set preview
}

The machine has variable positions, so it isn’t a fixed wait time. without the while loop implemented it will just jump over the program node immediately. And another wait node (using a guessed number of seconds) has to be used to stop the program in order for it to work.
After the movement of the machine is done the UR can move again.
Anybody an idea? Thanks in advance!

Well, you need to create a while loop, but in UR script, not in java.

generateScript is a function which is run when program starts. Polyscope first generates whole script and then starts it. If you never finish generating, program will never start.

I would try something like that:

writer.appendLine("machine = rpc_factory("xmlrpc", "http://yourmachine/")")
writer.appendLine("machine_finished = False")
writer.appendLine("while not machine_finished:")
writer.appendLine("    machine_finished = machine.isFinished()")
writer.appendLine("    sleep(0.1)")
writer.appendLine("end")

Actually, I think there is no timeout for xmlrpc, so if you call machine.Move() it will not return until you finish moving machine:

writer.appendLine("machine = rpc_factory("xmlrpc", "http://yourmachine/")")
writer.appendLine("machine_finished = machine.Move()")
writer.appendLine("if machine_finished:")
writer.appendLine("    textmsg("Machine is ok.", "")")
writer.appendLine("else:")
writer.appendLine("    textmsg("Machine is not ok", "")")
writer.appendLine("    halt")
writer.appendLine("end")
1 Like

you might want to try following UR Script:

while not is_steady() 
   wait 0.1

Thank you, dozminkowski & effendi
I will give that a try.