Skip to content

Commit

Permalink
Fixes #1668
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 634483090
Change-Id: I30b55bbf419e57a7b2966dfca4da6bb57d5879ad
  • Loading branch information
btaba authored and Copybara-Service committed May 16, 2024
1 parent e885a3d commit 86e6fc6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions mjx/mujoco/mjx/_src/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def _kbi(
k = 1 / (dmax * dmax * timeconst * timeconst * dampratio * dampratio)
b = 2 / (dmax * timeconst)
# TODO(robotics-simulation): check various solparam settings in model gen test
k = jp.where(dampratio <= 0, -dampratio / (dmax * dmax), k)
b = jp.where(timeconst <= 0, -timeconst / dmax, b)
k = jp.where(dampratio <= 0, -solref[0] / (dmax * dmax), k)
b = jp.where(timeconst <= 0, -solref[1] / dmax, b)

imp_x = jp.abs(pos) / width
imp_a = (1.0 / jp.power(mid, power - 1)) * jp.power(imp_x, power)
Expand Down
8 changes: 4 additions & 4 deletions mjx/mujoco/mjx/_src/constraint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,21 @@ def test_disable_equality(self):
ne, nf, nl, nc = constraint.counts(constraint.make_efc_type(m))
self.assertEqual(ne, 0)
self.assertEqual(nf, 0)
self.assertEqual(nl, 2)
self.assertEqual(nl, 3)
self.assertEqual(nc, 148)
dx = constraint.make_constraint(mjx.put_model(m), mjx.make_data(m))
self.assertEqual(dx.efc_J.shape[0], 150) # only joint range, contact
self.assertEqual(dx.efc_J.shape[0], 151) # only joint range, contact

def test_disable_contact(self):
m = test_util.load_test_file('constraints.xml')
m.opt.disableflags = m.opt.disableflags | mjx.DisableBit.CONTACT
ne, nf, nl, nc = constraint.counts(constraint.make_efc_type(m))
self.assertEqual(ne, 10)
self.assertEqual(nf, 0)
self.assertEqual(nl, 2)
self.assertEqual(nl, 3)
self.assertEqual(nc, 0)
dx = constraint.make_constraint(mjx.put_model(m), mjx.make_data(m))
self.assertEqual(dx.efc_J.shape[0], 12) # only joint range, limit
self.assertEqual(dx.efc_J.shape[0], 13) # only joint range, limit


if __name__ == '__main__':
Expand Down
5 changes: 5 additions & 0 deletions mjx/mujoco/mjx/test_data/constraints.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<geom class="box"/>
</body>

<body name="beam5" pos="-2 0 0" euler="45 45 0">
<joint name="joint5" type="ball" range="0 45" solreflimit="-100 -1"/> <!-- test negative solref -->
<geom class="box" contype="0" conaffinity="0"/>
</body>

<body name="box_condim1" pos="4 0 0">
<freejoint/>
<geom class="box" condim="1"/>
Expand Down

0 comments on commit 86e6fc6

Please sign in to comment.