Hi, I'm trying to implement a robot manipulator and gripper in Mujoco. I used torque actuator and wrote a pid controller myself but I had a lot of trouble making the simulation stable mainly due to gravity. My initial thoughts on compensating the gravity are as follows: get the gravity bias on each joint and then add control term calculated from error. I searched previous post and found that mjData->qfrc_bias gives the gravitational bias and all internal forces. At each time step I calculate the ctrl term from errors my pid gains and then add qfrc_bias. But it didn't work well. The joint angles have large steady state errors. Is "mjData->qfrc_bias" the correct way to access ONLY the gravity bias on each joint at each time step? What exactly is the definition of internal forces? Do contact forces count as internal forces or external forces? I want to work on manipulation tasks so I definitely don't want to compensate for contact and frictions.... Thanks!

What you are suggesting is correct! There shouldn't be a steady state error. I don't know what went wrong (large joint friction, destabilizing derivative feedback) .. but the general approach of gravity compensation with PD / PID control provably converges to the desired configuration in the steady state.

Hi florianw, Sorry for the late reply. I tried but method but the manipulator couldn't stabilize itself in the initial configuration. I set ctrl the same as qfrc_bias at every step. Any idea where went wrong? Thanks a lot! Here's a video of the manipulator behaviour.