Skip to content

Commit a793a34

Browse files
thowellcopybara-github
authored andcommitted
Raise error in mjx.rne_postconstraint for currently unsupported connect and weld constraints and raise error in mjx.put_model for unsupported sensor and equality constraint combinations.
PiperOrigin-RevId: 702119449 Change-Id: I034363db41629f19ef98bea79ec89140052a7a3c
1 parent c90a63a commit a793a34

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

doc/mjx.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,10 @@ The following features are **fully supported** in MJX:
244244
- ``MAGNETOMETER``, ``CAMPROJECTION``, ``RANGEFINDER``, ``JOINTPOS``, ``TENDONPOS``, ``ACTUATORPOS``, ``BALLQUAT``,
245245
``FRAMEPOS``, ``FRAMEXAXIS``, ``FRAMEYAXIS``, ``FRAMEZAXIS``, ``FRAMEQUAT``, ``SUBTREECOM``, ``CLOCK``,
246246
``VELOCIMETER``, ``GYRO``, ``JOINTVEL``, ``TENDONVEL``, ``ACTUATORVEL``, ``BALLANGVEL``, ``FRAMELINVEL``,
247-
``FRAMEANGVEL``, ``SUBTREELINVEL``, ``SUBTREEANGMOM``, ``TOUCH``, ``ACCELEROMETER``, ``FORCE``, ``TORQUE``,
248-
``ACTUATORFRC``, ``JOINTACTFRC``, ``FRAMELINACC``, ``FRAMEANGACC``.
247+
``FRAMEANGVEL``, ``SUBTREELINVEL``, ``SUBTREEANGMOM``, ``TOUCH``, ``ACTUATORFRC``, ``JOINTACTFRC``,
248+
``FRAMELINACC``, ``FRAMEANGACC``
249+
- ``ACCELEROMETER``, ``FORCE``, and ``TORQUE`` are supported if the model does not include connect or weld equality
250+
constraints.
249251

250252
The following features are **in development** and coming soon:
251253

@@ -274,6 +276,9 @@ The following features are **in development** and coming soon:
274276
- All except ``PLUGIN``, ``USER``
275277
* - Lights
276278
- Positions and directions of lights
279+
* - :ref:`Sensors <mjtSensor>`
280+
- ``ACCELEROMETER``, ``FORCE``, and ``TORQUE`` for models that include connect or weld equality
281+
constraints.
277282

278283
The following features are **unsupported**:
279284

mjx/mujoco/mjx/_src/io.py

+15
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,21 @@ def put_model(
142142
' implemented for spatial tendons.'
143143
)
144144

145+
# check for unsupported sensor and equality constraint combinations
146+
sensor_rne_postconstraint = (
147+
np.any(m.sensor_type == types.SensorType.ACCELEROMETER)
148+
| np.any(m.sensor_type == types.SensorType.FORCE)
149+
| np.any(m.sensor_type == types.SensorType.TORQUE)
150+
)
151+
eq_connect_weld = np.any(m.eq_type == types.EqType.CONNECT) | np.any(
152+
m.eq_type == types.EqType.WELD
153+
)
154+
if sensor_rne_postconstraint and eq_connect_weld:
155+
raise NotImplementedError(
156+
'rne_postconstraint not implemented with equality constraints:'
157+
' connect, weld.'
158+
)
159+
145160
for enum_field, enum_type, mj_type in (
146161
(m.actuator_biastype, types.BiasType, mujoco.mjtBias),
147162
(m.actuator_dyntype, types.DynType, mujoco.mjtDyn),

mjx/mujoco/mjx/_src/io_test.py

+32
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,38 @@ def test_contact_elliptic_condim1(self):
513513
with self.assertRaises(NotImplementedError):
514514
mjx.make_data(m)
515515

516+
@parameterized.product(
517+
sensor=['accelerometer', 'force', 'torque'], equality=['connect', 'weld']
518+
)
519+
def test_sensor_constraint_compatibility(self, sensor, equality):
520+
"""Test unsupported sensor and equality constraint combinations."""
521+
equality_constraint = f'{equality} body1="body1" body2="body2"'
522+
if equality == 'connect':
523+
equality_constraint += ' anchor="0 0 0"'
524+
m = mujoco.MjModel.from_xml_string(f"""
525+
<mujoco>
526+
<worldbody>
527+
<body name="body1">
528+
<freejoint/>
529+
<geom size="0.1"/>
530+
<site name="site1"/>
531+
</body>
532+
<body name="body2">
533+
<freejoint/>
534+
<geom size="0.1"/>
535+
</body>
536+
</worldbody>
537+
<equality>
538+
<{equality_constraint}/>
539+
</equality>
540+
<sensor>
541+
<{sensor} site="site1"/>
542+
</sensor>
543+
</mujoco>
544+
""")
545+
with self.assertRaises(NotImplementedError):
546+
mjx.put_model(m)
547+
516548

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

mjx/mujoco/mjx/_src/smooth.py

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from mujoco.mjx._src.types import CamLightType
2525
from mujoco.mjx._src.types import Data
2626
from mujoco.mjx._src.types import DisableBit
27+
from mujoco.mjx._src.types import EqType
2728
from mujoco.mjx._src.types import JointType
2829
from mujoco.mjx._src.types import Model
2930
from mujoco.mjx._src.types import TrnType
@@ -635,6 +636,10 @@ def _contact_force_to_cfrc_ext(force, pos, frame, id1, id2, com1, com2):
635636
)
636637

637638
# TODO(taylorhowell): connect and weld constraints
639+
if np.any(m.eq_type == EqType.CONNECT):
640+
raise NotImplementedError('Connect constraints are not implemented.')
641+
if np.any(m.eq_type == EqType.WELD):
642+
raise NotImplementedError('Weld constraints are not implemented.')
638643

639644
# forward pass over bodies: compute cacc, cfrc_int
640645
def _forward(carry, cfrc_ext, cinert, cvel, body_dofadr, body_dofnum):

0 commit comments

Comments
 (0)