Skip to content

Commit

Permalink
update the default_link code to align with new lab util
Browse files Browse the repository at this point in the history
  • Loading branch information
aclegg3 authored and jturner65 committed Sep 18, 2024
1 parent 4a19f16 commit 5f111d7
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src_python/habitat_sim/utils/namespace/hsim_physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,18 @@ def get_ao_default_link(
"""
Get the "default" link index for a ManagedArticulatedObject.
The "default" link is the one link which should be used if only one joint can be actuated. For example, the largest or most accessible drawer or door.
:param ao: The ManagedArticulatedObject instance.
:param compute_if_not_found: If true, try to compute the default link if it isn't found.
:return: The default link index or None if not found. Cannot be base link (-1).
The default link is determined by:
- must be "prismatic" or "revolute" joint type
- first look in the metadata Configuration for an annotated link.
- (if compute_if_not_found) - if not annotated, it is programmatically computed from a heuristic.
Default link heuristic: the link with the lowest Y value in the bounding box with appropriate joint type.
:param compute_if_not_found: If true, try to compute the default link if it isn't found.
:return: The default link index or None if not found. Cannot be base link (-1).
"""

# first look in metadata
Expand All @@ -218,7 +220,7 @@ def get_ao_default_link(
habitat_sim.physics.JointType.Revolute,
habitat_sim.physics.JointType.Prismatic,
]
lowest_link = None
lowest_links: List[int] = None
lowest_y: int = None
# compute the default link
for link_id in ao.get_link_ids():
Expand All @@ -228,11 +230,21 @@ def get_ao_default_link(
get_articulated_link_global_keypoints(ao, link_id),
key=lambda x: x[1],
)[1]
if lowest_y is None or link_lowest_y < lowest_y:
if (
lowest_y is None
or link_lowest_y < lowest_y
or abs(lowest_y - link_lowest_y) < 0.01
):
if lowest_y is not None and abs(lowest_y - link_lowest_y) < 0.01:
# 1 cm or less difference
lowest_links.append(link_id)
else:
lowest_links = [link_id]
lowest_y = link_lowest_y
lowest_link = link_id
if lowest_link is not None:
default_link = lowest_link

if lowest_links is not None:
# if multiple links could be confused as the default, use the lowest link index of the set
default_link = min(lowest_links)
# if found, set in metadata for next time
ao.user_attributes.set("default_link", default_link)

Expand Down

0 comments on commit 5f111d7

Please sign in to comment.