google-deepmind / mujoco

Multi-Joint dynamics with Contact. A general purpose physics simulator.
https://mujoco.org
Apache License 2.0
7.81k stars 778 forks source link

Discrepancy between Optimized Joint Angles and Actual Positions in MuJoCo #1854

Closed abigsure closed 1 week ago

abigsure commented 1 month ago

I am working on an optimization task involving a robotic hand. The process involves providing a set of joint angles and using mj_forward() to obtain the joint positions. I then compute the difference between these positions and the target positions, propagate the position gradient back to the joint angle space through the Jacobian (mj_jac()). This approach has been effective in my optimization process.

However, I have encountered an issue when controlling the robotic hand using the optimized joint angles. When I apply these optimized joint angles to data.ctrl and use mj_step(), I observe a discrepancy between the actual joint positions and the target positions.The blue and red dots represent the target positions.

I suspect that this discrepancy arises because ,during the optimization process, I only consider the kinematics of the robot to obtain the joint angles. When these joint angles are applied via data.ctrl, the system dynamics, including factors such as gravity and inertia, come into play, which leads to the observed discrepancy.

I am looking for suggestions on how to bridge the gap between kinematic optimization and dynamic execution in MuJoCo. Any advice or recommendations would be greatly appreciated.

Thank you! QQ图片20240725112140

quagla commented 1 month ago

It's hard to give a suggestion without knowing the actuators you are using. You can also use a mocap with equality constraints if you need to track the target positions to possibly unphysical positions.