0

I wanted to call the function : emptymatrix=np.zeros((sim.data.nv,sim.data.nv))
mjp.cymj._mj_fullM(model, emptymatrix, sim.data.qM) in mujoco so that I can Convert sparse inertia matrix M into full matrix so that I can calclulate the torque but I have this error:raceback (most recent call last): File "kuka.py", line 58, in mjp.cymj._mj_fullM(sim.model,emptymatrix ,sim.data.qM) File ".local/lib/python3.8/site-packages/mujoco_py/generated/wrappers.pxi", line 5061, in mujoco_py.cymj._mj_fullM
ValueError: Buffer has wrong number of dimensions (expected 1, got 2)
If someone could help me I ll be so grateful.

ayman
  • 1
  • 2
    Can you provide some code samples as well as what you have already tried to rectify the issue? – cp-stack Apr 19 '22 at 15:04
  • 1
    Your question is unreadable! – hpaulj Apr 19 '22 at 15:21
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 20 '22 at 05:09

1 Answers1

0

mujoco_py's implementation of mj_fullM expects your emptymatrix to be a vector of length nv*nv, rather than a square matrix.

See these lines from robosuite:

mass_matrix = np.ndarray(shape=(len(self.sim.data.qvel) ** 2,), dtype=np.float64, order="C")
mujoco_py.cymj._mj_fullM(self.sim.model, mass_matrix, self.sim.data.qM)
mass_matrix = np.reshape(mass_matrix, (len(self.sim.data.qvel), len(self.sim.data.qvel)))
self.mass_matrix = mass_matrix[self.qvel_index, :][:, self.qvel_index]

If you make use of the new MuJoCo python bindings (pip install mujoco), mujoco.mj_fullM takes the square matrix as you'd expect.

Nimrod Gileadi
  • 410
  • 1
  • 3
  • 12