Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions dm_control/mjcf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,7 @@
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference" reference_namespace="joint"/>
<attribute name="jointinparent" type="string"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
<attribute name="tendon" type="reference" reference_namespace="tendon"/>
<attribute name="slidersite" type="reference" reference_namespace="site"/>
<attribute name="cranksite" type="reference" reference_namespace="site"/>
Expand Down Expand Up @@ -2232,7 +2232,7 @@
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference" reference_namespace="joint"/>
<attribute name="jointinparent" type="string"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
<attribute name="tendon" type="reference" reference_namespace="tendon"/>
<attribute name="slidersite" type="reference" reference_namespace="site"/>
<attribute name="cranksite" type="reference" reference_namespace="site"/>
Expand Down Expand Up @@ -2260,7 +2260,7 @@
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference" reference_namespace="joint"/>
<attribute name="jointinparent" type="string"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
<attribute name="tendon" type="reference" reference_namespace="tendon"/>
<attribute name="slidersite" type="reference" reference_namespace="site"/>
<attribute name="cranksite" type="reference" reference_namespace="site"/>
Expand Down Expand Up @@ -2291,7 +2291,7 @@
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference" reference_namespace="joint"/>
<attribute name="jointinparent" type="string"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
<attribute name="tendon" type="reference" reference_namespace="tendon"/>
<attribute name="slidersite" type="reference" reference_namespace="site"/>
<attribute name="cranksite" type="reference" reference_namespace="site"/>
Expand Down Expand Up @@ -2322,7 +2322,7 @@
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference" reference_namespace="joint"/>
<attribute name="jointinparent" type="string"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
<attribute name="tendon" type="reference" reference_namespace="tendon"/>
<attribute name="slidersite" type="reference" reference_namespace="site"/>
<attribute name="cranksite" type="reference" reference_namespace="site"/>
Expand Down Expand Up @@ -2372,7 +2372,7 @@
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference" reference_namespace="joint"/>
<attribute name="jointinparent" type="string"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
<attribute name="tendon" type="reference" reference_namespace="tendon"/>
<attribute name="slidersite" type="reference" reference_namespace="site"/>
<attribute name="cranksite" type="reference" reference_namespace="site"/>
Expand Down Expand Up @@ -2400,7 +2400,7 @@
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference" reference_namespace="joint"/>
<attribute name="jointinparent" type="string"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
<attribute name="tendon" type="reference" reference_namespace="tendon"/>
<attribute name="slidersite" type="reference" reference_namespace="site"/>
<attribute name="cranksite" type="reference" reference_namespace="site"/>
Expand Down Expand Up @@ -2431,7 +2431,7 @@
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference" reference_namespace="joint"/>
<attribute name="jointinparent" type="string"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
<attribute name="tendon" type="reference" reference_namespace="tendon"/>
<attribute name="slidersite" type="reference" reference_namespace="site"/>
<attribute name="cranksite" type="reference" reference_namespace="site"/>
Expand Down Expand Up @@ -2486,7 +2486,7 @@
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference" reference_namespace="joint"/>
<attribute name="jointinparent" type="string"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
<attribute name="site" type="reference" reference_namespace="site"/>
<attribute name="actdim" type="int" default="-1"/>
<attribute name="dyntype" type="keyword" valid_values="none integrator filter filterexact muscle dcmotor pid user" default="none"/>
Expand Down Expand Up @@ -3128,6 +3128,28 @@
<attribute name="user" type="array" array_type="float"/>
</attributes>
</element>
<element name="contact" repeated="true" namespace="sensor">
<attributes>
<attribute name="name" type="identifier"/>
<attribute name="noise" type="float"/>
<attribute name="cutoff" type="float"/>
<attribute name="nsample" type="int"/>
<attribute name="interp" type="keyword" valid_values="zoh linear cubic"/>
<attribute name="delay" type="float"/>
<attribute name="interval" type="array" array_type="float" array_size="2"/>
<attribute name="user" type="array" array_type="float"/>
<attribute name="num" type="int"/>
<attribute name="data" type="string"/>
<attribute name="reduce" type="keyword" valid_values="none mindist maxforce netforce"/>
<attribute name="site" type="reference"/>
<attribute name="body1" type="reference" reference_namespace="body"/>
<attribute name="body2" type="reference" reference_namespace="body"/>
<attribute name="subtree1" type="reference" reference_namespace="body"/>
<attribute name="subtree2" type="reference" reference_namespace="body"/>
<attribute name="geom1" type="reference" reference_namespace="geom"/>
<attribute name="geom2" type="reference" reference_namespace="geom"/>
</attributes>
</element>
<element name="tactile" repeated="true" namespace="sensor">
<attributes>
<attribute name="name" type="identifier"/>
Expand Down Expand Up @@ -3182,7 +3204,7 @@
<attributes>
<attribute name="name" type="identifier" required="true"/>
<attribute name="size" type="int"/>
<attribute name="data" type="string"/>
<attribute name="data" type="array" array_type="float"/>
</attributes>
</element>
<element name="text" repeated="true">
Expand Down
41 changes: 41 additions & 0 deletions dm_control/mjcf/schema_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,46 @@ def constructible(spec_node, path):
+ '\n'.join(failures[:20]))


class SchemaRegressionTest(absltest.TestCase):
"""Declarations that MuJoCo accepts must stay representable in PyMJCF."""

def test_contact_sensor_parses_and_compiles(self):
xml_string = """
<mujoco>
<worldbody>
<body name="b">
<joint name="j" type="slide"/>
<geom name="g" size="0.1"/>
</body>
</worldbody>
<sensor>
<contact name="cs" geom1="g" num="1" data="found"
reduce="netforce"/>
</sensor>
</mujoco>"""
root = mjcf.from_xml_string(xml_string)
physics = mjcf.Physics.from_mjcf_model(root)
self.assertEqual(physics.model.nsensor, 1)
self.assertEqual(root.find('sensor', 'cs').geom1.name, 'g')

def test_jointinparent_is_scoped_on_attach(self):
child = mjcf.RootElement(model='child')
body = child.worldbody.add('body', name='b')
body.add('joint', name='j', type='hinge')
body.add('geom', name='g', size=[0.1])
child.actuator.add('general', name='a', jointinparent='j')
parent = mjcf.RootElement(model='parent')
parent.attach(child)
self.assertIn('jointinparent="child/j"', parent.to_xml_string())
physics = mjcf.Physics.from_mjcf_model(parent)
self.assertEqual(physics.model.nu, 1)

def test_custom_numeric_accepts_array_data(self):
root = mjcf.RootElement(model='m')
root.custom.add('numeric', name='x', data=[1, 2, 3])
physics = mjcf.Physics.from_mjcf_model(root)
self.assertEqual(physics.model.nnumericdata, 3)


if __name__ == '__main__':
absltest.main()