# How to decrease error value of Servoj

**URL:** <https://forum.universal-robots.com/t/how-to-decrease-error-value-of-servoj/6112>\
**Category:** URScript\
**Created:** [January 21, 2020, 8:32am UTC](https://forum.universal-robots.com/t/how-to-decrease-error-value-of-servoj/6112 "2020-01-21T08:32:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon77302081](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@anon77302081](https://forum.universal-robots.com/u/anon77302081)\
**Post date:** [January 21, 2020, 8:32am UTC](https://forum.universal-robots.com/t/how-to-decrease-error-value-of-servoj/6112/1 "2020-01-21T08:32:58Z")

</div>

Hi. I’m Onur

I’m trying to control robot joint from URCap after my inverse kinematics solutions and trajectory planning. I’m keeping calculations results in the robot position, speed, acceleration limits. Even so trajectory tracking is not so good. error is around 3 mm in the tool space. I’m working on UR5 CB real robot.

The following jointposition is result of calculation code.  
I’m sending this script code every 8 millisecond by 3003 port.  
“servoj(”+ jointposition +",0,0,0.008,0.03,2000)"

lookahead\_time=0.03  
gain=2000  
How do I adjust these parameter values?  
Can I reduce the error by 0.5 mm?

---

<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:** [January 21, 2020, 3:15pm UTC](https://forum.universal-robots.com/t/how-to-decrease-error-value-of-servoj/6112/2 "2020-01-21T15:15:45Z")

</div>

Hi Onur,

Many things can influence to the error. The robot will always be chasing the last given target. If the target i moving fast and the robot is limited be strict safety configuration, the error will be bigger.  
In theory you can increase the gain and reduce the look ahead time to reduce the error. But it will also result in much bigger joint torques/acceleration.

---

<div class="post-metadata">

**Author:** ![anon77302081](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@anon77302081](https://forum.universal-robots.com/u/anon77302081)\
**Post date:** [January 23, 2020, 1:57pm UTC](https://forum.universal-robots.com/t/how-to-decrease-error-value-of-servoj/6112/3 "2020-01-23T13:57:18Z")

</div>

Thanks.

Sometime there is excessive vibration , some time there is no vibration for the same trajectory planning. i think its because sometime controller finishes servoj() over 8 millisecond.

can i get “servoj() done” feedback from controller to URCap quickly

---

<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:** [January 23, 2020, 2:20pm UTC](https://forum.universal-robots.com/t/how-to-decrease-error-value-of-servoj/6112/4 "2020-01-23T14:20:28Z")

</div>

How do you handle the timing. The Java is far from real time, so you should make sure to feed the controller with a new target each time slot.  
If you make a script run the loop of servoj() i would not expect this behavior, if the target is moving continuously and not too fast.

---

<div class="post-metadata">

**Author:** ![anon77302081](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@anon77302081](https://forum.universal-robots.com/u/anon77302081)\
**Post date:** [January 24, 2020, 7:42am UTC](https://forum.universal-robots.com/t/how-to-decrease-error-value-of-servoj/6112/6 "2020-01-24T07:42:01Z")

</div>

I’m handling the timing this way in java

```
	long start_time=System.currentTimeMillis();
	for (int i = 0; i <transformation_matrix_list.size(); i++) {
		long elapsed_time=System.currentTimeMillis()-start_time ;
        int delay_millisecond=(int) (i*8-elapsed_time); //delay_millisecond is arround 6-7 millisecond

        if(delay_millisecond>0) {
	        try {
	        	Thread.sleep(delay_millisecond);
        	}catch (InterruptedException e) {
        			e.printStackTrace();
        	}
        }

        float[][] transformation_matrix=transformation_matrix_list.get(i);
        float[] joint_positions=robot.getInverseKinematics(transformation_matrix,robot.getLastRobotJointPositions());
        sendServoj(joint_positions);
	}

```

Isn’t it real time?  
Can i do it real time in java in URCap
