How do I set an overall condition for this application?

I need a condition that will popup message and pause the robot.

I have a thread which contains if sensor is low, pop up message and halt.

My issue is:

When I have if sensor is low, popup message and halt, I cannot resume the program. If I set to only popup message, a message will popup, but the robot does not pause and just continues with its program.

Any suggestions?

I’ve also tried incorporating a loop and If condition to popup message before resuming but then the issue is this:

loop and if condition for when sensor is low, popup message and dismiss to resume. However, the sensor is still low so when I dismiss popup message, it is stuck due to sensor still being low.

Hi @drakenguyen65 ,
if what you want to achieve is a safety behavior then you should use a safety function as a protective stop.

Otherwise have a look at this workaround that let you pause and resume the program using just UR script commands:

Untitled video - Made with Clipchamp (1)

# change runtime velocity
def set_vel(speed):
    socket_open("127.0.0.1", 30002)
    command = str_cat("set speed ", speed)
    socket_send_line(command)
    socket_close()
end

# check global condition
thread check_cond():
    while True:
        if get_standard_digital_out(1):
            set_vel(0.00001)
	        popup("Stopped", "Program paused", blocking=True)
	        set_vel(1.0)
        end
    end
end

run check_cond()

# main program
set_vel(1.0)
while True:
	movej([-1.60, -1.73, -2.20, -0.81, 1.60, -0.03])
	movej([1.60, -1.73, -2.20, -0.81, 1.60, -0.03])
end

In the example I am using a digital out, instead of digital in for manual testing purpose.

I have a completed polyscope program that I am trying to incorporate this to, am I be able to add this script code to my existing program on the teach pendant?

Thanks in advance.

Yes, you just need to put the code inside a script node of polyscope program :wink:

Another workaround (that doesn’t use undocumented control commands :slight_smile: ) is to use “pause” keyword:

# check global condition
thread check_cond():
  while True:
    if get_standard_digital_out(1):
      popup("Stopped", "Program paused", blocking=False)
      pause
    end
  end
end

Clicking “Continue” on popup will resume program.

1 Like

Also, my I ask, what program are you using to simulate the UR?

I’ve tried to “offline simulator e-series UR sim for non Linux” but had a bad experience. Looks like the page was even taken down from the UR site.

Will a thread be able to pause/resume program?

On another similar topic, I was recommended by user @efn that, “ You won’t be able to pause the program and resume it from a thread.

If I were you, I would connect the sensor to the Safeguard inputs and make it Normally Closed. Sounds like you want the entire program to be paused/started.”

Entire program will be paused (all threads). In this case program will be resumed by confirming popup. Safeguard input trick can also be used if restart from external input is needed.

The software you see in the screenshot is our platform Robpod Studio, you can find more info here: https://www.robpod.cloud/

I added the script code but It is not responding.

Any suggestions?

you missed the command to start the thread:

run check_cond()

My mistake. Got the script working but I get thrown a protective stop when I try to resume program.

Any suggestions?

Try to add a sync() to the thread cycle:

# check global condition
thread check_cond():
  while True:
    if get_standard_digital_out(1):
      popup("Stopped", "Program paused", blocking=False)
      pause
    end
    sync()
  end
end