# Servoj function

**URL:** <https://forum.universal-robots.com/t/servoj-function/7176>\
**Category:** URScript\
**Created:** [April 30, 2020, 11:10am UTC](https://forum.universal-robots.com/t/servoj-function/7176 "2020-04-30T11:10:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon29981536](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@anon29981536](https://forum.universal-robots.com/u/anon29981536)\
**Post date:** [April 30, 2020, 11:10am UTC](https://forum.universal-robots.com/t/servoj-function/7176/1 "2020-04-30T11:10:01Z")

</div>

Hello,  
I’m using _servoj_ for online real-time control of joints position, but I can’t reach the desired result.

With Matlab I have generated a path at frequency **F** in order to reproduce a normal _movej_ path (  
trapezoidal speed profile with the time for acceleration and deceleration equal to 1/3 of the time of the entire move) .  
When I pass the points at the _servoj_ function,I obtain a different patch, whit different speed and acceleration profile. The last one, in particular, have a lots of peaks.  
The result gets better if change the 3 parameters of _servoj_:  
1 t=1/ **F** ,  
2 lookahead\_time in the range: [0.03,0.2],  
3 gain in the range: [100,2000];  
as it’s written in the “scriptManual”; but the profiles is still very far from the profiles generated by _movej_ function, and the robot does’t reach the final position.

Are there more documentations about _servoj_ ?  
For example, can I know the best combination of the 3 parameters in order to have good profiles without execute dozens and dozens of test?

Thank you.

---

<div class="post-metadata">

**Author:** ![Ebbe](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/ebbe/32/1413_2.png) [@Ebbe](https://forum.universal-robots.com/u/Ebbe)\
**Post date:** [April 30, 2020, 2:44pm UTC](https://forum.universal-robots.com/t/servoj-function/7176/2 "2020-04-30T14:44:24Z")

</div>

hi @anon29981536,

servoj is targeting to be as close to the joint positions as possible, so the error is only considered at the discrete points in time. In the theory higher _frequency_, lower _lookahead\_time_ and higher _gain_ will reduce that error. But will result in huge acceleration peaks.  
In your case it sounds like servoc is a better choice because it will be easier to predict the speed and acceleration. So please take a look at that function. There is a little more description of the functionality [here](https://forum.universal-robots.com/t/understanding-servoc-command/1219)

---

<div class="post-metadata">

**Author:** ![anon29981536](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@anon29981536](https://forum.universal-robots.com/u/anon29981536)\
**Post date:** [May 5, 2020, 9:06am UTC](https://forum.universal-robots.com/t/servoj-function/7176/3 "2020-05-05T09:06:04Z")

</div>

hi @Ebbe,  
_servoc_ doesn’t seem to work well with many nearly points.  
The movement starts only after seconds and acceleration has peaks near 40 rad/s^2, so the robot with high frequency points goes to emergency stop.  
Could you suggest me something else to try?  
Thank you.

---

<div class="post-metadata">

**Author:** ![m.birkholz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/m.birkholz/32/7084_2.png) [@m.birkholz](https://forum.universal-robots.com/u/m.birkholz)\
**Post date:** [May 5, 2020, 11:53am UTC](https://forum.universal-robots.com/t/servoj-function/7176/4 "2020-05-05T11:53:11Z")

</div>

Hi @anon29981536,

to “reconstruct” a movej, you need to slice your path in time windows, calculated with the desired joint speed, e.g. 60 deg/s on the fastest joint. as you generate the path with a fixed frequency other than using the robot controller clock (2ms on e-Series) i would suggest to keep the lookahead\_time high to smoothen the path. The higher your frequency, the closer the servoj path gets to the movej path, but without using the controller frequency it would never be the same 😉

---

<div class="post-metadata">

**Author:** ![anon15176874](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@anon15176874](https://forum.universal-robots.com/u/anon15176874)\
**Post date:** [February 11, 2021, 11:29am UTC](https://forum.universal-robots.com/t/servoj-function/7176/5 "2021-02-11T11:29:42Z")

</div>

Hi @m.birkholz,

did I understand correctly that the lookahead\_time is the parameter that “slices” my path in these time windows? So if I turn the lookahead\_time up I´m giving the robot more “path” to move until I give it the next bit. Is that the reason why a high lookahead\_time smoothens the path?

---

<div class="post-metadata">

**Author:** ![anon15176874](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@anon15176874](https://forum.universal-robots.com/u/anon15176874)\
**Post date:** [February 11, 2021, 12:03pm UTC](https://forum.universal-robots.com/t/servoj-function/7176/6 "2021-02-11T12:03:05Z")

</div>

Or is the lookahead\_time more like a time where the robot waits for incoming joint angles and after the lookahead, it starts its movement to the desired joint angles? 🤔

That would explain why my robot is more lacking behind the desired pose with a higher lookahead\_time.

---

<div class="post-metadata">

**Author:** ![anon52592067](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@anon52592067](https://forum.universal-robots.com/u/anon52592067)\
**Post date:** [November 24, 2021, 2:24am UTC](https://forum.universal-robots.com/t/servoj-function/7176/7 "2021-11-24T02:24:03Z")

</div>

Hi  
Have you solved the problem? I am also interested in this, can you share your experience.

Looking forward to your reply!  
Thanks.

---

<div class="post-metadata">

**Author:** ![robert.kristof](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@robert.kristof](https://forum.universal-robots.com/u/robert.kristof)\
**Post date:** [May 20, 2023, 7:46pm UTC](https://forum.universal-robots.com/t/servoj-function/7176/8 "2023-05-20T19:46:02Z")

</div>

@Ebbe I used maxim values but still have the movement jagged

I am using the standard code provided by UR

> **[GitHub - UniversalRobots/RTDE\_Python\_Client\_Library: RTDE client library and...](https://github.com/UniversalRobots/RTDE_Python_Client_Library)**
>
> RTDE client library and examples. Contribute to UniversalRobots/RTDE\_Python\_Client\_Library development by creating an account on GitHub.

I want to move the robot in real time based on the mouse position, so I modified the python script to send just setp1 like this:\>

> x, y = pyautogui.position()  
> # Setpoints to move the robot to  
> setp1 = [-x_0.5/2000, -0.74822, y_0.5/2000, -0.02607, -3.14017, 0.01985]

I send that data at 500Hz from Python.

on the UR instead of MoveL → setp1 I used  
servoj(get\_inverse\_kin(setp1]), 0,0,0.002,0.2,2000)  
stopj(2)

The movement is jagged.

Can you help ? How can I make the movement smooth?
