On the sample movie above, How can I set the joint to have the correct position value?

I tried to change type, damping & stiffness in various values, It doesn’t help so much.

Please give me some tips for proper PID gain tuning

maybe it’s related with some mass or inertia matrix, but I have no idea how can I set PID gain or some options for the simulated joint (i.e., ideal joint).

Yes - The Inertia does have an impact on the joint drive, regardless of whether it’s a position control, or a velocity control.

The Joint drive is defined as a mass-srping-damping system, where Stiffness is the spring component, and Damping is the Derivative gain. You can see it as in a Vehichle’s suspension system - increasing the stiffness will make the joint react more rapidly, but it may overshoot if it’s too large. The damping factor is how much the system reacts to changes in velocity. The caveat here is that different from a car’s suspension you can also set a target velocity - If the target velocity is different from zero, the drive will try to stabilize your system to reach that desired velocity instead, which will be countered by the joint stiffness to reach a specific joint position, because maintaining a specific joint position requires the joint to be at velocity = 0.

Therefore, if you want a position control, first make sure you have a stiffness greater than zero, and not required but good to have damping greater than zero, but smaller than stiffness to avoid instability on the system (High damping mean you are adding stress to your controller and it may not be able to reach the target pose).

If you want a velocity controlled joint, make sure stiffness is zero or close to zero so it doesn’t fight your target velocity, and a high damping so it follows the target velocity more precisely.

The drive type indicates if the joint will be driven with a direct force or a target acceleration.

Now Tuning this system it all depends on the response curve you are trying to achieve. For that I’d suggest you create an extension that records the joint value at every time step and plot this response curve for you to analyze.

Here’s some source reading that you may find interesting to understand the problem