Skip to content

Commit c4e0f44

Browse files
yuvaltassaalimuldal
authored andcommitted
Raise error if _find_non_contacting_height() does not terminate. This should never happen for this task but is added to safeguard in case of future modifications.
PiperOrigin-RevId: 258642433
1 parent eca8e57 commit c4e0f44

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

dm_control/suite/quadruped.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,13 @@ def _find_non_contacting_height(physics, orientation, x_pos=0.0, y_pos=0.0):
258258
orientation: A quaternion.
259259
x_pos: A float. Position along global x-axis.
260260
y_pos: A float. Position along global y-axis.
261+
Raises:
262+
RuntimeError: If a non-contacting configuration has not been found after
263+
10,000 attempts.
261264
"""
262265
z_pos = 0.0 # Start embedded in the floor.
263266
num_contacts = 1
267+
num_attempts = 0
264268
# Move up in 1cm increments until no contacts.
265269
while num_contacts > 0:
266270
try:
@@ -273,6 +277,9 @@ def _find_non_contacting_height(physics, orientation, x_pos=0.0, y_pos=0.0):
273277
pass
274278
num_contacts = physics.data.ncon
275279
z_pos += 0.01
280+
num_attempts += 1
281+
if num_attempts > 10000:
282+
raise RuntimeError('Failed to find a non-contacting configuration.')
276283

277284

278285
def _common_observations(physics):

0 commit comments

Comments
 (0)