Raise error if trying to bind with a spec with an empty name.
PiperOrigin-RevId: 731360983 Change-Id: I00365d158c1cae1cd912962ef453f43e93701080
This commit is contained in:
committed by
Copybara-Service
parent
ed16f2daf2
commit
1c240d8bad
@@ -295,7 +295,9 @@ class BindModel(object):
|
|||||||
self.prefix = ''
|
self.prefix = ''
|
||||||
ids = []
|
ids = []
|
||||||
for spec in specs:
|
for spec in specs:
|
||||||
if isinstance(spec, mujoco.MjsBody):
|
if not spec.name:
|
||||||
|
raise KeyError(f'cannot bind spec with empty name')
|
||||||
|
elif isinstance(spec, mujoco.MjsBody):
|
||||||
self.prefix = 'body_'
|
self.prefix = 'body_'
|
||||||
idx = name2id(model, mujoco.mjtObj.mjOBJ_BODY, spec.name)
|
idx = name2id(model, mujoco.mjtObj.mjOBJ_BODY, spec.name)
|
||||||
elif isinstance(spec, mujoco.MjsJoint):
|
elif isinstance(spec, mujoco.MjsJoint):
|
||||||
@@ -400,7 +402,9 @@ class BindData(object):
|
|||||||
self.prefix = ''
|
self.prefix = ''
|
||||||
ids = []
|
ids = []
|
||||||
for spec in specs:
|
for spec in specs:
|
||||||
if isinstance(spec, mujoco.MjsBody):
|
if not spec.name:
|
||||||
|
raise KeyError(f'cannot bind spec with empty name')
|
||||||
|
elif isinstance(spec, mujoco.MjsBody):
|
||||||
idx = name2id(model, mujoco.mjtObj.mjOBJ_BODY, spec.name)
|
idx = name2id(model, mujoco.mjtObj.mjOBJ_BODY, spec.name)
|
||||||
elif isinstance(spec, mujoco.MjsJoint):
|
elif isinstance(spec, mujoco.MjsJoint):
|
||||||
self.prefix = 'jnt_'
|
self.prefix = 'jnt_'
|
||||||
|
|||||||
@@ -333,6 +333,13 @@ class SupportTest(parameterized.TestCase):
|
|||||||
vdx.bind(mx, s.bodies[i]).xpos, [d.xpos[i, :]] * batch_size
|
vdx.bind(mx, s.bodies[i]).xpos, [d.xpos[i, :]] * batch_size
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# test emtpy name
|
||||||
|
s.worldbody.add_body()
|
||||||
|
m = s.compile()
|
||||||
|
mx = mjx.put_model(m)
|
||||||
|
with self.assertRaises(KeyError, msg='cannot bind spec with empty name'):
|
||||||
|
mx.bind(s.bodies)
|
||||||
|
|
||||||
_CONTACTS = """
|
_CONTACTS = """
|
||||||
<mujoco>
|
<mujoco>
|
||||||
<worldbody>
|
<worldbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user