# Error: Another thread is already controlling the robot

**URL:** <https://forum.universal-robots.com/t/error-another-thread-is-already-controlling-the-robot/21263>\
**Category:** Technical Questions\
**Created:** [May 12, 2022, 8:01am UTC](https://forum.universal-robots.com/t/error-another-thread-is-already-controlling-the-robot/21263 "2022-05-12T08:01:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon70625529](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@anon70625529](https://forum.universal-robots.com/u/anon70625529)\
**Post date:** [May 12, 2022, 8:01am UTC](https://forum.universal-robots.com/t/error-another-thread-is-already-controlling-the-robot/21263/1 "2022-05-12T08:01:11Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/1/123a49bc81e1b68b9ded7e319bab8bedbb2d638f.png)  
Hi guys,

I’m trying to set a waypoint just for inspection  
Condition  
When switch is on - halt on whichever step and goes to the inspection waypoint  
When switch is off - resume where the program is before it goes to the inspection waypoint.

But i keep getting an error where it says “another thread is already controlling the robot” when i flip my digital\_in0 to true. Any easy way to solve this?

---

<div class="post-metadata">

**Author:** ![eikefranke](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@eikefranke](https://forum.universal-robots.com/u/eikefranke)\
**Post date:** [May 12, 2022, 9:07am UTC](https://forum.universal-robots.com/t/error-another-thread-is-already-controlling-the-robot/21263/2 "2022-05-12T09:07:16Z")

</div>

maybe juse not a thread.  
is it important to go instand from the moveing situation to another position? if not, maybe make it like an funktion that will be asked after reaching every single Waypoint.

Like  
move WP\_1  
if var\_inspec =? true than…  
set var\_inspec = false  
move WP\_2  
if var\_inspec =? true than…

in the thread you can handle the input:  
Thread:  
wait if digital\_in[0] =? true  
set var\_inspec = true

---

<div class="post-metadata">

**Author:** ![cags](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/cags/32/6304_2.png) [@cags](https://forum.universal-robots.com/u/cags)\
**Post date:** [May 12, 2022, 10:01am UTC](https://forum.universal-robots.com/t/error-another-thread-is-already-controlling-the-robot/21263/3 "2022-05-12T10:01:39Z")

</div>

You could change it to a subprogram. So whenever the robot is a start position or waiting for something to happen, you can call the subprogram.  
Something like:

```auto
# Robot Program
MoveJ
	Start_Position
	Waypoint_1
	Waypoint_2
	Waypoint_3
	# Now the robot is avaliable for doing something else
	Call SubProgram_1

# SubProgram_1
if get_standard_digital_input(0):
	MoveJ
		inspection

```

---

<div class="post-metadata">

**Author:** ![anon70625529](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@anon70625529](https://forum.universal-robots.com/u/anon70625529)\
**Post date:** [May 13, 2022, 4:50am UTC](https://forum.universal-robots.com/t/error-another-thread-is-already-controlling-the-robot/21263/4 "2022-05-13T04:50:44Z")

</div>

Thanks for your suggestion but I have around 12 waypoints in my actual program so it will be a hassle to add it in after every single one of them. Will use this if I cant find any other ways!

---

<div class="post-metadata">

**Author:** ![anon70625529](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@anon70625529](https://forum.universal-robots.com/u/anon70625529)\
**Post date:** [May 13, 2022, 4:54am UTC](https://forum.universal-robots.com/t/error-another-thread-is-already-controlling-the-robot/21263/5 "2022-05-13T04:54:26Z")

</div>

Hi thanks for your suggestion! but I would like the robot to go to inspection whenever digital input0 is true wherever the program is being executed instead of it only being executed after the robot moves to waypoint 1,2,3.

---

<div class="post-metadata">

**Author:** ![anon43334322](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@anon43334322](https://forum.universal-robots.com/u/anon43334322)\
**Post date:** [May 13, 2022, 9:55am UTC](https://forum.universal-robots.com/t/error-another-thread-is-already-controlling-the-robot/21263/6 "2022-05-13T09:55:19Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/1/176a064aaefe1d79f13219f808271cd13dd81d5a.png)  
This solution may be right for you.  
Use the loop with the check expression continuously, as long as the expression is false, you will get out of this loop.  
Be careful to use a STOPJ or STOPL to have a smooth change of direction.
