Skip to content
Closed
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
24 changes: 24 additions & 0 deletions dm_control/mjcf/element_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,30 @@ def testDictLikeInterface(self):
with self.assertRaisesRegex(TypeError, 'does not support item deletion'):
del elem['foo']

@parameterized.parameters('general', 'motor', 'position', 'velocity',
'intvelocity', 'damper', 'cylinder', 'muscle')
def testActuatorArmatureAndDamping(self, actuator_type):
# MuJoCo accepts `armature` and `damping` on these actuators, and the
# <default> section of the schema already allowed both, but the <actuator>
# elements themselves did not list them.
xml_string = """
<mujoco model="test">
<worldbody>
<body>
<joint name="j" type="hinge"/>
<geom type="sphere" size="0.1"/>
</body>
</worldbody>
<actuator>
<{} name="a" joint="j" armature="0.7" damping="2.5"/>
</actuator>
</mujoco>
""".format(actuator_type)
mujoco = parser.from_xml_string(xml_string)
actuator = mujoco.find('actuator', 'a')
self.assertEqual(actuator.armature, 0.7)
np.testing.assert_array_equal(actuator.damping, [2.5])

def testSetAndGetAttributes(self):
mujoco = element.RootElement(model='test')

Expand Down
16 changes: 16 additions & 0 deletions dm_control/mjcf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,8 @@
<attribute name="actrange" type="array" array_type="float" array_size="2"/>
<attribute name="lengthrange" type="array" array_type="float" array_size="2"/>
<attribute name="gear" type="array" array_type="float" array_size="6"/>
<attribute name="damping" type="array" array_type="float" array_size="3"/>
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
Expand Down Expand Up @@ -2135,6 +2137,8 @@
<attribute name="forcerange" type="array" array_type="float" array_size="2"/>
<attribute name="lengthrange" type="array" array_type="float" array_size="2"/>
<attribute name="gear" type="array" array_type="float" array_size="6"/>
<attribute name="damping" type="array" array_type="float" array_size="3"/>
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
Expand All @@ -2160,6 +2164,8 @@
<attribute name="forcerange" type="array" array_type="float" array_size="2"/>
<attribute name="lengthrange" type="array" array_type="float" array_size="2"/>
<attribute name="gear" type="array" array_type="float" array_size="6"/>
<attribute name="damping" type="array" array_type="float" array_size="3"/>
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
Expand Down Expand Up @@ -2190,6 +2196,8 @@
<attribute name="forcerange" type="array" array_type="float" array_size="2"/>
<attribute name="lengthrange" type="array" array_type="float" array_size="2"/>
<attribute name="gear" type="array" array_type="float" array_size="6"/>
<attribute name="damping" type="array" array_type="float" array_size="3"/>
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
Expand Down Expand Up @@ -2218,6 +2226,8 @@
<attribute name="actrange" type="array" array_type="float" array_size="2"/>
<attribute name="lengthrange" type="array" array_type="float" array_size="2"/>
<attribute name="gear" type="array" array_type="float" array_size="6"/>
<attribute name="damping" type="array" array_type="float" array_size="3"/>
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
Expand Down Expand Up @@ -2267,6 +2277,8 @@
<attribute name="forcerange" type="array" array_type="float" array_size="2"/>
<attribute name="lengthrange" type="array" array_type="float" array_size="2"/>
<attribute name="gear" type="array" array_type="float" array_size="6"/>
<attribute name="damping" type="array" array_type="float" array_size="3"/>
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
Expand All @@ -2293,6 +2305,8 @@
<attribute name="forcerange" type="array" array_type="float" array_size="2"/>
<attribute name="lengthrange" type="array" array_type="float" array_size="2"/>
<attribute name="gear" type="array" array_type="float" array_size="6"/>
<attribute name="damping" type="array" array_type="float" array_size="3"/>
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
Expand Down Expand Up @@ -2322,6 +2336,8 @@
<attribute name="forcerange" type="array" array_type="float" array_size="2"/>
<attribute name="lengthrange" type="array" array_type="float" array_size="2"/>
<attribute name="gear" type="array" array_type="float" array_size="6"/>
<attribute name="damping" type="array" array_type="float" array_size="3"/>
<attribute name="armature" type="float"/>
<attribute name="cranklength" type="float"/>
<attribute name="joint" type="reference"/>
<attribute name="jointinparent" type="reference" reference_namespace="joint"/>
Expand Down
19 changes: 19 additions & 0 deletions dm_control/mjcf/xml_validation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ def testXmlFromZip(self):
model = parser.from_zip(_ZIPPED_MODEL)
validate(model.to_xml_string(), model.get_assets())

def testActuatorArmatureAndDampingRoundTrip(self):
model = parser.from_xml_string("""
<mujoco model="test">
<worldbody>
<body>
<joint name="j" type="hinge"/>
<geom type="sphere" size="0.1"/>
</body>
</worldbody>
<actuator>
<position name="a" joint="j" armature="0.7" damping="2.5"/>
</actuator>
</mujoco>
""")
validate(model.to_xml_string())
mjmodel = wrapper.MjModel.from_xml_string(model.to_xml_string())
self.assertEqual(mjmodel.actuator_armature[0], 0.7)
self.assertEqual(mjmodel.actuator_damping[0], 2.5)


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