# How to stop Cobot from colliding with itself?

**URL:** <https://forum.universal-robots.com/t/how-to-stop-cobot-from-colliding-with-itself/37664>\
**Category:** General Application Help: How do I?\
**Created:** [December 13, 2024, 4:49pm UTC](https://forum.universal-robots.com/t/how-to-stop-cobot-from-colliding-with-itself/37664 "2024-12-13T16:49:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivory](https://avatars.discourse-cdn.com/v4/letter/i/b487fb/32.png) [@Ivory](https://forum.universal-robots.com/u/Ivory)\
**Post date:** [December 13, 2024, 4:49pm UTC](https://forum.universal-robots.com/t/how-to-stop-cobot-from-colliding-with-itself/37664/1 "2024-12-13T16:49:47Z")

</div>

We have a program where we often halt at random positions and need to jog it back to home position. I recently learned how to create a safe position by modifying the current pose Z axis. Here is how it looks:

**Before Start**  
Activate Gripper  
Gripper Open (50%)  
(Folder) Safe Position  
currpose := get\_actual\_tcp\_pose()  
safeZpose := p[currpose[0], currpose[1], .27513, currpose[3], currpose[4], currpose[5]]  
MoveL  
safeZpose

**Robot Program**  
Home\_Position  
…  
…

It works well with waypoints closest to Home\_Position but as I test waypoints farther away, the robot wants to collide into itself, triggering a stop. And if it’s halted at a far distance from Home\_Position, it goes back to it too fast. How to avoid these issues?

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [December 13, 2024, 6:25pm UTC](https://forum.universal-robots.com/t/how-to-stop-cobot-from-colliding-with-itself/37664/2 "2024-12-13T18:25:32Z")

</div>

If you change the MoveL to a MoveJ it should stop colliding with itself. (Assuming you’re telling it to go somewhere it can physically reach) As for moving too fast if it’s stopped far away, just drop the speed of the MoveJ. Personally, I would just set it to the slowest speed that I was comfortable with and just let it move that fast for the recovery move no matter where it’s at. If you really need DIFFERENT speeds depending on how far away it is, use multiple MoveJ commands with different speeds and use an If statement to run one or the other depending on the TCP location.

---

<div class="post-metadata">

**Author:** ![Ivory](https://avatars.discourse-cdn.com/v4/letter/i/b487fb/32.png) [@Ivory](https://forum.universal-robots.com/u/Ivory)\
**Post date:** [December 17, 2024, 4:52pm UTC](https://forum.universal-robots.com/t/how-to-stop-cobot-from-colliding-with-itself/37664/3 "2024-12-17T16:52:16Z")

</div>

I changed MoveL to MoveJ and it was going to collide with the ceiling. I then made a new program:

**BeforeStart**  
_(Folder)_ Z Clearance  
currpose:= get\_actual\_tcp\_pose()  
adjust\_z:= p[currpose[0], currpose[1], .27513, currpose[3], currpose[4], currpose[5]]  
MoveL  
adjust\_z

_(Folder)_ Get to Home  
safeheight:= get\_actual\_tcp\_pose()  
MoveJ  
safeheight  
current\_x:= safeheight[0]  
current\_y:= safeheight[1]  
current\_z:= safeheight[2]  
if (current\_x \<= -.380) or (current\_y\>= .296)  
MoveJ  
Half\_2  
Home\_Position  
Else  
MoveJ  
Home\_Position

**Robot Program**  
…  
Home\_Position  
…

This one works way better. However, when I tested it where the TCP was really far from the base, the Z Clearance routine makes it go into singularity. I will need to revise my program to make up for this case. Anyways, changing MoveL to MoveJ made a significant improvement, thank you.

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [December 17, 2024, 11:20pm UTC](https://forum.universal-robots.com/t/how-to-stop-cobot-from-colliding-with-itself/37664/4 "2024-12-17T23:20:46Z")

</div>

You’re hardcoding your Z coordinate. I could believe that if you’re sufficiently far away from the robot base, that Z height could produce a singularity. You should check the X and Y values and determine if they are “significantly” far from the base. If they are, alter the X and Y values of adjust\_z accordingly.
