Servo function in UR robots

I have been working with UR5e robot for sometime. I have done quite some explorations on how MoveJ, MoveL etc works. But I am still not sure on what is a servo function? and how it works?. I went through the docs from UR and a few topics on this forum but still I was not able to get a good understanding on its working. It would be great if any of you can explain the working of servo functions in simple terms and how the parameters like lookahead_time, gain, step_time influence it. And more importantly how different it is from Move functions(MoveJ ) and when to use what (MoveJ or ServoJ)?

The short answer is just use moveJ. It takes care of determining gain parameters for you and simplifies things immensely. ServoJ requires you to manage gain and update target positions along a path. The script manual is the definitive source of info on the parameters but here is a bit more :

The servo function servoj controls the joint positions. For each joint it calculates the desired position and the actual position (error) and adjusts the position accordingly. The magnitude of the error is modified with the parameter gain , which can range from 100 to 2000. Its effect is similar to the P gain of a PID controller. The higher this value is, the faster reaction the robot will have. However, it is more likely to produce oscillations and shakiness. The default value is 300. The parameter lookahead_time plays a role in the error calculation by predicting the future position of the joint some time in advance. It can range from 0.03 to 0.2 seconds. The higher this value is, the slower the reaction will be. Nevertheless, the movement will become smoother and with fewer sharp movements / oscillations. The default value is 0.1.

So with servoJ you are able to mess with proportional and integral gains. However, you can easily break the arms joints if you are not careful about how you do this.

Thanks a Lot @bba. This helped us a lot