Skip to content

Commit

Permalink
Add missing plugin sections in dm_control schema. Fixes #434.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 577848939
Change-Id: I4d444a82344f728c752b4ce2348f5bd1adcf3622
  • Loading branch information
DeepMind authored and copybara-github committed Oct 30, 2023
1 parent 6fdcda2 commit f2f0e23
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 16 deletions.
26 changes: 26 additions & 0 deletions dm_control/mjcf/physics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,5 +579,31 @@ def test_error_when_pickling_synchronizing_array_wrapper(self):
mjcf_physics._PICKLING_NOT_SUPPORTED.format(type=type(xpos_view))):
pickle.dumps(xpos_view)

def test_plugins(self):
root = mjcf.RootElement()
root.extension.add('plugin', plugin='mujoco.elasticity.cable')

# Replicate example in mujoco/model/plugin/elasticity/cable.xml
composite = root.worldbody.add(
'composite',
type='cable',
curve='s',
count=[41, 1, 1],
size=[1, 0, 0],
offset=[-0.3, 0, 0.6],
initial='none',
)
plugin = composite.add('plugin', plugin='mujoco.elasticity.cable')
plugin.add('config', key='twist', value='1e7')
plugin.add('config', key='bend', value='4e6')
plugin.add('config', key='vmax', value='0.05')
composite.add('joint', kind='main', damping=0.015)
composite.geom.type = 'capsule'
composite.geom.size = [0.005, 0, 0]
composite.geom.rgba = [0.8, 0.2, 0.1, 1]
composite.geom.condim = 1

mjcf.Physics.from_mjcf_model(root)

if __name__ == '__main__':
absltest.main()
91 changes: 75 additions & 16 deletions dm_control/mjcf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
</element>
<element name="geom">
<attributes>
<attribute name="type" type="keyword" valid_values="plane hfield sphere capsule ellipsoid cylinder box mesh"/>
<attribute name="type" type="keyword" valid_values="plane hfield sphere capsule ellipsoid cylinder box mesh sdf"/>
<attribute name="contype" type="int"/>
<attribute name="conaffinity" type="int"/>
<attribute name="condim" type="int"/>
Expand Down Expand Up @@ -577,7 +577,7 @@
</element>
<element name="geom">
<attributes>
<attribute name="type" type="keyword" valid_values="plane hfield sphere capsule ellipsoid cylinder box mesh"/>
<attribute name="type" type="keyword" valid_values="plane hfield sphere capsule ellipsoid cylinder box mesh sdf"/>
<attribute name="contype" type="int"/>
<attribute name="conaffinity" type="int"/>
<attribute name="condim" type="int"/>
Expand Down Expand Up @@ -811,7 +811,7 @@
</element>
<element name="extension">
<children>
<element name="plugin" repeated="true" namespace="plugin">
<element name="plugin" repeated="true">
<attributes>
<attribute name="plugin" type="string" required="true"/>
</attributes>
Expand Down Expand Up @@ -914,6 +914,23 @@
<attribute name="refpos" type="array" array_type="float" array_size="3"/>
<attribute name="refquat" type="array" array_type="float" array_size="4"/>
</attributes>
<children>
<element name="plugin" repeated="true" namespace="mesh">
<attributes>
<attribute name="name" type="identifier"/>
<attribute name="plugin" type="string"/>
<attribute name="instance" type="reference" reference_namespace="plugin"/>
</attributes>
<children>
<element name="config" repeated="true">
<attributes>
<attribute name="key" type="string"/>
<attribute name="value" type="string"/>
</attributes>
</element>
</children>
</element>
</children>
</element>
<element name="skin" repeated="true">
<attributes>
Expand Down Expand Up @@ -961,7 +978,7 @@
<attributes>
<attribute name="name" type="identifier"/>
<attribute name="class" type="reference" reference_namespace="default"/>
<attribute name="type" type="keyword" valid_values="plane hfield sphere capsule ellipsoid cylinder box mesh"/>
<attribute name="type" type="keyword" valid_values="plane hfield sphere capsule ellipsoid cylinder box mesh sdf"/>
<attribute name="contype" type="int"/>
<attribute name="conaffinity" type="int"/>
<attribute name="condim" type="int"/>
Expand Down Expand Up @@ -1058,19 +1075,24 @@
<element name="composite" repeated="true">
<attributes>
<attribute name="prefix" type="identifier"/>
<attribute name="type" type="keyword" valid_values="particle grid rope loop cloth box cylinder ellipsoid" required="true"/>
<attribute name="type" type="keyword" valid_values="particle grid cable rope loop cloth box cylinder ellipsoid" required="true"/>
<attribute name="count" type="array" array_type="int" array_size="3" required="true"/>
<attribute name="spacing" type="float" required="true"/>
<attribute name="spacing" type="float" required="false"/>
<attribute name="offset" type="array" array_type="float" array_size="3"/>
<attribute name="flatinertia" type="float"/>
<attribute name="solrefsmooth" type="array" array_type="float" array_size="2"/>
<attribute name="solimpsmooth" type="array" array_type="float" array_size="5"/>
<attribute name="vertex" type="string"/>
<attribute name="face" type="string"/>
<attribute name="initial" type="string"/>
<attribute name="curve" type="string"/>
<attribute name="size" type="array" array_type="float" array_size="3"/>
</attributes>
<children>
<element name="plugin" repeated="true" namespace="composite">
<attributes>
<attribute name="name" type="identifier"/>
<attribute name="plugin" type="string" reference_namespace="plugin"/>
<attribute name="name" type="string"/>
<attribute name="plugin" type="string"/>
<attribute name="instance" type="reference" reference_namespace="plugin"/>
</attributes>
<children>
Expand Down Expand Up @@ -1124,7 +1146,7 @@
</element>
<element name="geom">
<attributes>
<attribute name="type" type="keyword" valid_values="plane hfield sphere capsule ellipsoid cylinder box mesh"/>
<attribute name="type" type="keyword" valid_values="plane hfield sphere capsule ellipsoid cylinder box mesh sdf"/>
<attribute name="contype" type="int"/>
<attribute name="conaffinity" type="int"/>
<attribute name="condim" type="int"/>
Expand Down Expand Up @@ -1187,7 +1209,7 @@
<element name="plugin" repeated="true" namespace="body">
<attributes>
<attribute name="name" type="identifier"/>
<attribute name="plugin" type="string" reference_namespace="plugin"/>
<attribute name="plugin" type="string"/>
<attribute name="instance" type="reference" reference_namespace="plugin"/>
</attributes>
<children>
Expand Down Expand Up @@ -1247,7 +1269,7 @@
<attributes>
<attribute name="name" type="identifier"/>
<attribute name="class" type="reference" reference_namespace="default"/>
<attribute name="type" type="keyword" valid_values="plane hfield sphere capsule ellipsoid cylinder box mesh"/>
<attribute name="type" type="keyword" valid_values="plane hfield sphere capsule ellipsoid cylinder box mesh sdf"/>
<attribute name="contype" type="int"/>
<attribute name="conaffinity" type="int"/>
<attribute name="condim" type="int"/>
Expand Down Expand Up @@ -1279,6 +1301,23 @@
<attribute name="fluidcoef" type="array" array_type="float" array_size="5"/>
<attribute name="user" type="array" array_type="float"/>
</attributes>
<children>
<element name="plugin" repeated="true" namespace="geom">
<attributes>
<attribute name="name" type="identifier"/>
<attribute name="plugin" type="string"/>
<attribute name="instance" type="reference" reference_namespace="plugin"/>
</attributes>
<children>
<element name="config" repeated="true">
<attributes>
<attribute name="key" type="string"/>
<attribute name="value" type="string"/>
</attributes>
</element>
</children>
</element>
</children>
</element>
<element name="site" repeated="true">
<attributes>
Expand Down Expand Up @@ -1344,15 +1383,35 @@
<element name="composite" repeated="true">
<attributes>
<attribute name="prefix" type="identifier"/>
<attribute name="type" type="keyword" valid_values="particle grid rope loop cloth box cylinder ellipsoid" required="true"/>
<attribute name="type" type="keyword" valid_values="particle grid cable rope loop cloth box cylinder ellipsoid" required="true"/>
<attribute name="count" type="array" array_type="int" array_size="3" required="true"/>
<attribute name="spacing" type="float" required="true"/>
<attribute name="spacing" type="float" required="false"/>
<attribute name="offset" type="array" array_type="float" array_size="3"/>
<attribute name="flatinertia" type="float"/>
<attribute name="solrefsmooth" type="array" array_type="float" array_size="2"/>
<attribute name="solimpsmooth" type="array" array_type="float" array_size="5"/>
<attribute name="vertex" type="string"/>
<attribute name="face" type="string"/>
<attribute name="initial" type="string"/>
<attribute name="curve" type="string"/>
<attribute name="size" type="array" array_type="float" array_size="3"/>
</attributes>
<children>
<element name="plugin" repeated="true" namespace="composite">
<attributes>
<attribute name="name" type="string"/>
<attribute name="plugin" type="string"/>
<attribute name="instance" type="reference" reference_namespace="plugin"/>
</attributes>
<children>
<element name="config" repeated="true">
<attributes>
<attribute name="key" type="string"/>
<attribute name="value" type="string"/>
</attributes>
</element>
</children>
</element>
<element name="joint" repeated="true">
<attributes>
<attribute name="kind" type="keyword" valid_values="main twist stretch" required="true"/>
Expand Down Expand Up @@ -1395,7 +1454,7 @@
</element>
<element name="geom">
<attributes>
<attribute name="type" type="keyword" valid_values="plane hfield sphere capsule ellipsoid cylinder box mesh"/>
<attribute name="type" type="keyword" valid_values="plane hfield sphere capsule ellipsoid cylinder box mesh sdf"/>
<attribute name="contype" type="int"/>
<attribute name="conaffinity" type="int"/>
<attribute name="condim" type="int"/>
Expand Down Expand Up @@ -1830,7 +1889,7 @@
<attributes>
<attribute name="name" type="identifier"/>
<attribute name="class" type="reference" reference_namespace="default"/>
<attribute name="plugin" type="string" reference_namespace="plugin"/>
<attribute name="plugin" type="string"/>
<attribute name="instance" type="reference" reference_namespace="plugin"/>
<attribute name="group" type="int"/>
<attribute name="ctrllimited" type="keyword" valid_values="false true auto"/>
Expand Down Expand Up @@ -2224,7 +2283,7 @@
<element name="plugin" repeated="true" namespace="sensor">
<attributes>
<attribute name="name" type="identifier"/>
<attribute name="plugin" type="string" reference_namespace="plugin"/>
<attribute name="plugin" type="string"/>
<attribute name="instance" type="reference" reference_namespace="plugin"/>
<attribute name="cutoff" type="float"/>
<attribute name="objtype" type="keyword" valid_values="body joint geom site camera light mesh skin hfield texture material equality tendon actuator sensor numeric text tuple contact keyframe"/>
Expand Down

0 comments on commit f2f0e23

Please sign in to comment.