Closed hartikainen closed 1 week ago
I can't reproduce it in C so this looks like a binding issue (likely not even related to mjSpec). I'm having a deeper look. My MRE is
def test_solref(self):
spec = mujoco.MjSpec.from_string("""
<mujoco>
<worldbody>
<body>
<geom size=".1"/>
<joint axis="0 0 1"/>
<body>
<geom size=".1"/>
<joint axis="0 0 1"/>
</body>
</body>
</worldbody>
</mujoco>
""")
model = spec.compile()
for joint in range(model.njnt):
solref = model.joint(joint).solref
solimp = model.joint(joint).solimp
np.testing.assert_array_equal(solref, [[0.02, 1]])
np.testing.assert_array_equal(solimp, [[0.9, 0.95, 0.001, 0.5, 2.0]])
In the meantime, could you please see if extracting the values with
solref = model.jnt_solref[i]
solimp = model.jnt_solimp[i]
fixes your issue?
Indeed, extracting the values directly with integers works as expected. Here's a bit simpler test case that passes:
import mujoco
import numpy as np
from robot_descriptions import fr3_mj_description
from robot_descriptions import shadow_dexee_mj_description
def main():
hand_spec = mujoco.MjSpec.from_file(shadow_dexee_mj_description.MJCF_PATH)
hand_model = hand_spec.compile()
arm_spec = mujoco.MjSpec.from_file(fr3_mj_description.MJCF_PATH)
arm_model = arm_spec.compile()
combined_spec = arm_spec.copy()
attachment_site = next(s for s in combined_spec.sites if s.name == "attachment_site")
attachment_site.attach(hand_spec.worldbody, "hand_base:", "")
combined_model = combined_spec.compile()
np.testing.assert_equal(
hand_model.jnt_solref,
combined_model.jnt_solref[None:hand_model.njnt, ...],
)
np.testing.assert_equal(
arm_model.jnt_solref,
combined_model.jnt_solref[hand_model.njnt:None, ...],
)
np.testing.assert_equal(
hand_model.jnt_solimp,
combined_model.jnt_solimp[None:hand_model.njnt, ...],
)
np.testing.assert_equal(
arm_model.jnt_solimp,
combined_model.jnt_solimp[hand_model.njnt:None, ...],
)
if __name__ == "__main__":
main()
Intro
Hi!
I am a MuJoCo user working on manipulation.
My setup
MuJoCo:
What's happening? What did you expect?
When I attach a model to another using
MjsSite.attach
, the joints'sol{ref,imp}
values seem to change. I'm not sure if this is a bug or not, but it feels a little suspicious to me. The following code demonstrates what's happening. (The code is a bit verbose, although still relatively simple.)Output:
I was expecting the
sol{imp,ref}
values to match between each attached joint and its corresponding joint in the non-attached model, but for some reason they seem to get mixed.It's also a bit surprising to me that even for the non-attached model, some joints have
solref == [1, 0.02]
and othersolref == [0.02, 1]
even though none of these parameters are set in the model xml.Edit: The results of these are so surprising to me that I feel like this has to be expected and I just misunderstand something. I spent a bit of time crawling through the documentation but couldn't find anything that would've explain this.
Steps for reproduction
See above.
Minimal model for reproduction
See above.
Code required for reproduction
See above.
Confirmations