# How do I set an overall condition for this application?

**URL:** <https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668>\
**Category:** General Application Help: How do I?\
**Created:** [February 9, 2024, 8:38pm UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668 "2024-02-09T20:38:51Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![drakenguyen65](https://avatars.discourse-cdn.com/v4/letter/d/22d042/32.png) [@drakenguyen65](https://forum.universal-robots.com/u/drakenguyen65)\
**Post date:** [February 9, 2024, 8:38pm UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/1 "2024-02-09T20:38:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![drakenguyen65](https://avatars.discourse-cdn.com/v4/letter/d/22d042/32.png) [@drakenguyen65](https://forum.universal-robots.com/u/drakenguyen65)\
**Post date:** [February 9, 2024, 9:03pm UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/2 "2024-02-09T21:03:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Robpod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/robpod/32/5837_2.png) [@Robpod](https://forum.universal-robots.com/u/Robpod)\
**Post date:** [February 11, 2024, 8:25am UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/3 "2024-02-11T08:25:01Z")

</div>

Hi @drakenguyen65 ,  
if what you want to achieve is a safety behavior then you should use a safety function as a [protective stop](https://www.universal-robots.com/articles/ur/application-installation/connecting-an-emergency-stop-device-vs-a-safeguard-protective-device/).

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)](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/7/724a0e6e084e7f1e7bf2b41d5438e47bc384722d.gif)

```auto
# 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.

---

<div class="post-metadata">

**Author:** ![drakenguyen65](https://avatars.discourse-cdn.com/v4/letter/d/22d042/32.png) [@drakenguyen65](https://forum.universal-robots.com/u/drakenguyen65)\
**Post date:** [February 11, 2024, 9:30am UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/4 "2024-02-11T09:30:59Z")

</div>

> [@Robpod](#):
>
> ```auto
> # 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
> 
> ```

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.

---

<div class="post-metadata">

**Author:** ![Robpod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/robpod/32/5837_2.png) [@Robpod](https://forum.universal-robots.com/u/Robpod)\
**Post date:** [February 11, 2024, 12:05pm UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/6 "2024-02-11T12:05:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mmi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/mmi/32/691_2.png) [@mmi](https://forum.universal-robots.com/u/mmi)\
**Post date:** [February 12, 2024, 10:59am UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/7 "2024-02-12T10:59:22Z")

</div>

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

```auto
# 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.

---

<div class="post-metadata">

**Author:** ![drakenguyen65](https://avatars.discourse-cdn.com/v4/letter/d/22d042/32.png) [@drakenguyen65](https://forum.universal-robots.com/u/drakenguyen65)\
**Post date:** [February 12, 2024, 9:14pm UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/9 "2024-02-12T21:14:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![drakenguyen65](https://avatars.discourse-cdn.com/v4/letter/d/22d042/32.png) [@drakenguyen65](https://forum.universal-robots.com/u/drakenguyen65)\
**Post date:** [February 12, 2024, 9:15pm UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/10 "2024-02-12T21:15:16Z")

</div>

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.”

---

<div class="post-metadata">

**Author:** ![mmi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/mmi/32/691_2.png) [@mmi](https://forum.universal-robots.com/u/mmi)\
**Post date:** [February 13, 2024, 7:19am UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/11 "2024-02-13T07:19:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Robpod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/robpod/32/5837_2.png) [@Robpod](https://forum.universal-robots.com/u/Robpod)\
**Post date:** [February 13, 2024, 4:03pm UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/12 "2024-02-13T16:03:00Z")

</div>

> [@drakenguyen65](#):
>
> Also, my I ask, what program are you using to simulate the UR?

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

---

<div class="post-metadata">

**Author:** ![drakenguyen65](https://avatars.discourse-cdn.com/v4/letter/d/22d042/32.png) [@drakenguyen65](https://forum.universal-robots.com/u/drakenguyen65)\
**Post date:** [February 13, 2024, 8:22pm UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/13 "2024-02-13T20:22:20Z")

</div>

![UR](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/0/06b3cf53dfef9b2cabf8dc83b8e7bcef323be62e.jpeg)

I added the script code but It is not responding.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![Robpod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/robpod/32/5837_2.png) [@Robpod](https://forum.universal-robots.com/u/Robpod)\
**Post date:** [February 14, 2024, 6:42am UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/14 "2024-02-14T06:42:53Z")

</div>

you missed the command to start the thread:

```auto
run check_cond()

```

---

<div class="post-metadata">

**Author:** ![drakenguyen65](https://avatars.discourse-cdn.com/v4/letter/d/22d042/32.png) [@drakenguyen65](https://forum.universal-robots.com/u/drakenguyen65)\
**Post date:** [February 16, 2024, 6:11pm UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/15 "2024-02-16T18:11:29Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/9/900a2d6788cb6cb0c554517f2f042a6fc2ff1afe.jpeg)

Any suggestions?

---

<div class="post-metadata">

**Author:** ![Robpod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/robpod/32/5837_2.png) [@Robpod](https://forum.universal-robots.com/u/Robpod)\
**Post date:** [February 17, 2024, 7:41am UTC](https://forum.universal-robots.com/t/how-do-i-set-an-overall-condition-for-this-application/32668/16 "2024-02-17T07:41:11Z")

</div>

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

```auto
# 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

```
