google-deepmind / mujoco

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

Question about the way of calculating forward kinematics in Mujoco #1836

Closed Yingfan99327 closed 1 month ago

Yingfan99327 commented 1 month ago

Hi,

I'm a student and I'm trying to use MuJoCo for robotic simulation.

I'm looking for some help with fprward kinematics of robotic arms in mujoco.

I am curious about how mujoco caclulate the forward kinematics of a robotic arm. Right now, I am using Franka Panda Robot to do some simulation in Mujoco.

I compared the cartesian posture results of the flange site of the Franka robot obtained by calling the data.xpos function and the results calculated by the KDL chain I built based on the xml files of the Franka robot. I guess I built the robot chain in a right way and I just choose the joint positions as [0, 0, 0, 0, 0, 0, 0], however, there are some discrepancies between them.

Thus, I am curious that whether it's due to difference between the original internal way of calculating forward kinematics in Mujoco and the way of using the classic KDL library to build the chain on my own and then calculating the forward kinematics. If so, does it mean that I cannot get the same cartesian posture of the site at the robot by using KDL method? If not, I will double check my KDL chain first and if I cannot find problems on my own, I will then post them later for further help.

Thanks very much for your time and wishing you all the best.

quagla commented 1 month ago

Hi, the forward kinematics computation is here https://github.com/google-deepmind/mujoco/blob/main/src/engine/engine_core_smooth.c#L37 there shouldn't be any reason why the result is different.