# Prevent move command from reaching joint limits

**URL:** <https://forum.universal-robots.com/t/prevent-move-command-from-reaching-joint-limits/23739>\
**Category:** URScript\
**Created:** [September 9, 2022, 6:13am UTC](https://forum.universal-robots.com/t/prevent-move-command-from-reaching-joint-limits/23739 "2022-09-09T06:13:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon27607866](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@anon27607866](https://forum.universal-robots.com/u/anon27607866)\
**Post date:** [September 9, 2022, 6:13am UTC](https://forum.universal-robots.com/t/prevent-move-command-from-reaching-joint-limits/23739/1 "2022-09-09T06:13:25Z")

</div>

Hi,  
The `wrist-3` **joint** of my ur5 can rotate from `-360` to `+360°`

When calling a **move command** (e.g. `moveL`), it sometimes happens that the **`wrist-3` tries to go outside of this range**. This of course causes an error.

- **My question: how can I avoid that?**

- My temporary solution: check before each new move command, that `wrist-3` is not to close to its limits. If it is, then rotate by `+/-360°` to get it closer to the center of the permitted range. This reduces the errors, but do not prevent them all.

- I saw that old topic but it does not answer my question: [Movej runs into joint limit](https://forum.universal-robots.com/t/movej-runs-into-joint-limit/2095)

---

<div class="post-metadata">

**Author:** ![giorgigedaminski](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@giorgigedaminski](https://forum.universal-robots.com/u/giorgigedaminski)\
**Post date:** [September 9, 2022, 6:52am UTC](https://forum.universal-robots.com/t/prevent-move-command-from-reaching-joint-limits/23739/2 "2022-09-09T06:52:18Z")

</div>

Hi Simon,  
If you aren’t limited in the working area, the best way to solve this problem is using MoveJ with joint angles. MoveJ makes a curve when executing so, be aware that there isn’t standing anything close robot.

---

<div class="post-metadata">

**Author:** ![anon27607866](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@anon27607866](https://forum.universal-robots.com/u/anon27607866)\
**Post date:** [September 9, 2022, 7:07am UTC](https://forum.universal-robots.com/t/prevent-move-command-from-reaching-joint-limits/23739/3 "2022-09-09T07:07:02Z")

</div>

thank you giorgigedaminski,  
Indeed I am very limited in the working area, so `moveJ` is unfortunately not an option.

To be honest, **I would have expected the controller to take care of that**.

- Compute the target `joint-angles` from the taget `pose`.
- Then check if any of them is out of range.
- If so, apply some modulo or so to make sure they all remain safe.

---

<div class="post-metadata">

**Author:** ![giorgigedaminski](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@giorgigedaminski](https://forum.universal-robots.com/u/giorgigedaminski)\
**Post date:** [September 9, 2022, 7:52am UTC](https://forum.universal-robots.com/t/prevent-move-command-from-reaching-joint-limits/23739/4 "2022-09-09T07:52:16Z")

</div>

It would be good, but this has to be counted by developer.  
I would suggest to

1. Change waypoints in your program and try joint positions to be close to 0 degree. This way joint safety limit problem will be very very low.  
Second option is to:
2. Define additional waypoint somewhere in the safe area with movej(use joint angles), and then send a waypoint where robot goes out of limit. Additional waypoint will Recorrect joint values and at the waypoint, where robot goes out of limit.

---

<div class="post-metadata">

**Author:** ![anon27607866](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@anon27607866](https://forum.universal-robots.com/u/anon27607866)\
**Post date:** [September 9, 2022, 9:53am UTC](https://forum.universal-robots.com/t/prevent-move-command-from-reaching-joint-limits/23739/5 "2022-09-09T09:53:49Z")

</div>

thank you giorgigedaminski for the answer
