mujoco icon indicating copy to clipboard operation
mujoco copied to clipboard

[Python] Can't create model using adhesion

Open hendrikE opened this issue 3 years ago • 2 comments

Hi,

I'm a trying to model a robot which uses adhesion in Python using the following code. To build the model I use PyMJCF, which works well and knows adhesion.

import mujoco
from dm_control import mjcf

class Leg(object):
    def __init__(self, length, rgba):
        self.model = mjcf.RootElement()

        # Defaults:
        self.model.default.joint.damping = 2
        self.model.default.joint.type = 'hinge'
        self.model.default.geom.type = 'capsule'
        self.model.default.geom.rgba = rgba

        # Thigh:
        self.thigh = self.model.worldbody.add('body')
        self.hip = self.thigh.add('joint', axis=[0, 0, 1])
        self.thigh.add('geom', fromto=[0, 0, 0, length, 0, 0], size=[length / 4])

        # Hip:
        self.shin = self.thigh.add('body', pos=[length, 0, 0])
        self.knee = self.shin.add('joint', axis=[0, 1, 0])
        self.shin.add('geom', fromto=[0, 0, 0, 0, 0, -length], size=[length / 5])

        # Position actuators:
        self.model.actuator.add('position', joint=self.hip, kp=10)
        self.model.actuator.add('position', joint=self.knee, kp=10)

        self.model.actuator.add('adhesion', body=self.shin)

def simulate():
    model = Leg(0.1, (255, 0, 0, 0)).model

Then I try to pass the model on to Mujoco with the following code:

physics = mjcf.Physics.from_mjcf_model(model)

This causes the following error:

ValueError: XML Error: Schema violation: unrecognized element

Element 'adhesion', line 21

I additionally also tried the following code:

model = model.to_xml_string()
model = mujoco.MjModel.from_xml_string(model)

This gives the same error, so I tried this with the active adhesion example found here: https://github.com/deepmind/mujoco/blob/main/model/adhesion/active_adhesion.xml

But this fails already without even reaching the adhesion at "" with the same type of error. I'm using Mujoco version 2.3.4, so adhesion should be included. Am I missing anything to make this work, or is this simply not yet accessible in the Python Wrapper?

Thanks!

hendrikE avatar Apr 24 '23 20:04 hendrikE

I reran your PyMJCF code and got no error, I also loaded the example model in the native bindings (using the public colab) with no errors. Could you please investigate further?

I suspect there is some issue with your installation.

yuvaltassa avatar Apr 25 '23 11:04 yuvaltassa

You're right, I set it up again on a different machine and it works there, seems to be something related to my virtual environments. Thanks for having a look!

hendrikE avatar Apr 25 '23 16:04 hendrikE