Why are the first three rows and columns of the Jacobian matrix calculated using Pinocchio and MuJoCo inconsistent, while the others are consistent? #2047
Unanswered
LHTLiu
asked this question in
Asking for Help
Replies: 1 comment 3 replies
-
Hi @LHTLiu, MuJoCo computes a Jacobian in Here is some code to illustrate how to match forward kinematics in MuJoCo and Pinocchio: import mujoco
import numpy as np
import pinocchio as pin
from robot_descriptions.loaders.mujoco import (
load_robot_description as mj_load_description,
)
from robot_descriptions.loaders.pinocchio import (
load_robot_description as pin_load_description,
)
np.set_printoptions(precision=2, threshold=1e-5, suppress=True)
def skew(x):
wx, wy, wz = x
return np.array(
[
[0.0, -wz, wy],
[wz, 0.0, -wx],
[-wy, wx, 0.0],
]
)
def adjoint(R, t):
assert R.shape == (3, 3)
assert t.shape == (3,)
A = np.block(
[
[R, np.zeros((3, 3))],
[skew(t) @ R, R],
]
)
assert A.shape == (6, 6)
return A
def inverse(R, t):
assert R.shape == (3, 3)
assert t.shape == (3,)
R_inv = R.T
t_inv = -R_inv @ t
return R_inv, t_inv
# Sample a random joint configuration
q = 0.1 * np.pi * (2.0 * np.random.random((9,)) - 1.0)
print(q.shape) # (9 because 7 + 2 gripper).
# Pinocchio model and data.
robot = pin_load_description("panda_description")
model_pin = robot.model
data_pin = robot.data
# Run forward kinematics.
pin.computeJointJacobians(model_pin, data_pin, q)
pin.updateFramePlacements(model_pin, data_pin)
frame_id = model_pin.getFrameId("panda_link7")
# Mujoco model and data.
print("Loading mujoco model...")
model_mj = mj_load_description("panda_mj_description")
data_mj = mujoco.MjData(model_mj)
# Run forward kinematics.
data_mj.qpos = q
mujoco.mj_kinematics(model_mj, data_mj)
mujoco.mj_comPos(model_mj, data_mj)
# Forward kinematics: check frame transforms are identical.
# Pin.
T_sb_pin = data_pin.oMf[frame_id].copy()
t_sb_pin = T_sb_pin.np[:3, 3]
R_sb_pin = T_sb_pin.np[:3, :3]
# Mujoco.
t_sb = data_mj.body("link7").xpos.copy()
R_sb = data_mj.body("link7").xmat.copy().reshape(3, 3)
np.testing.assert_allclose(t_sb, t_sb_pin, atol=1e-7)
np.testing.assert_allclose(R_sb, R_sb_pin, atol=1e-7)
# Jacobian: check that mujoco's jac matches pinocchio's jac in frame: LOCAL_WORLD_ALIGNED.
jac_pin_local_world_aligned: np.ndarray = pin.getFrameJacobian(
model_pin, data_pin, frame_id, pin.ReferenceFrame.LOCAL_WORLD_ALIGNED
)
jac_muj = np.empty((6, model_mj.nv))
mujoco.mj_jacBody(model_mj, data_mj, jac_muj[:3], jac_muj[3:], model_mj.body("link7").id)
np.testing.assert_allclose(jac_pin_local_world_aligned, jac_muj, atol=1e-7)
# How to transform MuJoCo's jacobian so that it matches pinocchio's LOCAL frame.
jac_pin_local: np.ndarray = pin.getFrameJacobian(model_pin, data_pin, frame_id, pin.ReferenceFrame.LOCAL)
R_bs, t_bs = inverse(R_sb, t_sb)
A_bs = adjoint(R_bs, np.zeros(3))
jac_muj_local = A_bs @ jac_muj
np.testing.assert_allclose(jac_muj_local, jac_pin_local, atol=1e-7) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Intro
Hi!
I am a PhD student at Beihang University, I use MuJoCo for my research on forward kinematics and jacobian matrix of mobile manipulator.
My setup
Apple M1 Pro macOS Sonoma 14.6.1
PyCharm 2023.3.5 (Community Edition)
mujoco 3.2.2
My question
I used the same urdf file (xml file), used pinocchio and mujoco to calculate the forward kinematics and Jacobian matrix of the same position of robot (first the floating joint and then franka's robot with a total of 15 degrees of freedom (6+7+2fingers)), and found that the forward kinematics were consistent, but the first three rows and first three columns of the Jacobian matrix were inconsistent, and the remaining They are all consistent, what’s going on?
thanks
@yuvaltassa
Minimal model and/or code that explain my question
pinocchio
mujoco
Confirmations
Beta Was this translation helpful? Give feedback.
All reactions