Skip to content

Commit

Permalink
--Test fixes to support semantic sensor updates (#1801)
Browse files Browse the repository at this point in the history
* --fix test_sim_utils
Hardcoded values referring to the stage needed to be changed.
* --remove magic numbers for test_robot_wrapper ids
* --modify reference to stage ID from magic number to habitat_sim.stage_id constant.
* --further references
  • Loading branch information
jturner65 authored Feb 27, 2024
1 parent a25a022 commit 9fb686c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def sample(
On failure, return None.
"""
ids_to_names = sutils.get_all_object_ids(sim)
ids_to_names[-1] = "_stage"
ids_to_names[habitat_sim.stage_id] = "_stage"
logger.info(ids_to_names)
# first collect all instances associated with requested samplers
aom = sim.get_articulated_object_manager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def sample_placement(
if isinstance(receptacle, OnTopOfReceptacle):
snap_down = False
if snap_down:
support_object_ids = [-1]
support_object_ids = [habitat_sim.stage_id]
# add support object ids for non-stage receptacles
if receptacle.is_parent_object_articulated:
ao_instance = sim.get_articulated_object_manager().get_object_by_handle(
Expand Down
9 changes: 5 additions & 4 deletions habitat-lab/habitat/sims/habitat_simulator/sim_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def bb_ray_prescreen(
"""
if support_obj_ids is None:
# set default support surface to stage/ground mesh
support_obj_ids = [-1]
# STAGE ID IS habitat_sim.stage_id
support_obj_ids = [habitat_sim.stage_id]
lowest_key_point: mn.Vector3 = None
lowest_key_point_height = None
highest_support_impact: Optional[mn.Vector3] = None
Expand Down Expand Up @@ -217,7 +218,7 @@ def bb_ray_prescreen(
margin_offset = 0
if highest_support_impact_id is None:
pass
elif highest_support_impact_id == -1:
elif highest_support_impact_id == habitat_sim.stage_id:
margin_offset = sim.get_stage_initialization_template().margin

surface_snap_point = (
Expand Down Expand Up @@ -246,7 +247,7 @@ def snap_down(
:param sim: The Simulator instance.
:param obj: The RigidObject instance.
:param support_obj_ids: A list of object ids designated as valid support surfaces for object placement. Contact with other objects is a criteria for placement rejection. If none provided, default support surface is the stage/ground mesh (-1).
:param support_obj_ids: A list of object ids designated as valid support surfaces for object placement. Contact with other objects is a criteria for placement rejection. If none provided, default support surface is the stage/ground mesh (0).
:param dbv: Optionally provide a DebugVisualizer (dbv) to render debug images of each object's computed snap position before collision culling.
Reject invalid placements by checking for penetration with other existing objects.
Expand All @@ -260,7 +261,7 @@ def snap_down(

if support_obj_ids is None:
# set default support surface to stage/ground mesh
support_obj_ids = [-1]
support_obj_ids = [habitat_sim.stage_id]

bb_ray_prescreen_results = bb_ray_prescreen(
sim, obj, support_obj_ids, check_all_corners=False
Expand Down
8 changes: 4 additions & 4 deletions test/test_robot_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def test_fetch_robot_wrapper(fixed_base):
)
fetch.reconfigure()
fetch.update()
assert fetch.get_robot_sim_id() == 1 # 0 is the ground plane
assert fetch.get_robot_sim_id() == ground_plane.object_id + 1
print(fetch.get_link_and_joint_names())
observations += simulate(sim, 1.0, produce_debug_video)

Expand Down Expand Up @@ -484,7 +484,7 @@ def test_franka_robot_wrapper():
franka = franka_robot.FrankaRobot(urdf_path=robot_path, sim=sim)
franka.reconfigure()
franka.update()
assert franka.get_robot_sim_id() == 1 # 0 is the ground plane
assert franka.get_robot_sim_id() == ground_plane.object_id + 1
print(franka.get_link_and_joint_names())
observations += simulate(sim, 1.0, produce_debug_video)

Expand Down Expand Up @@ -606,7 +606,7 @@ def test_spot_robot_wrapper(fixed_base):
spot = spot_robot.SpotRobot(agent_config, sim, fixed_base=fixed_base)
spot.reconfigure()
spot.update()
assert spot.get_robot_sim_id() == 1 # 0 is the ground plane
assert spot.get_robot_sim_id() == ground_plane.object_id + 1
print(spot.get_link_and_joint_names())

# set the motor angles
Expand Down Expand Up @@ -757,7 +757,7 @@ def test_stretch_robot_wrapper(fixed_base):
)
stretch.reconfigure()
stretch.update()
assert stretch.get_robot_sim_id() == 1 # 0 is the ground plane
assert stretch.get_robot_sim_id() == ground_plane.object_id + 1

# set base ground position using object transformation approach
target_base_pos = sim.pathfinder.snap_point(
Expand Down
5 changes: 3 additions & 2 deletions test/test_sim_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
snap_down,
within,
)
from habitat_sim import Simulator, built_with_bullet
from habitat_sim import Simulator, built_with_bullet, stage_id
from habitat_sim.metadata import MetadataMediator
from habitat_sim.physics import MotionType
from habitat_sim.utils.settings import default_sim_settings, make_cfg
Expand Down Expand Up @@ -104,7 +104,8 @@ def test_snap_down(support_margin, obj_margin, stage_support):

# add the cube objects
cube_stage_obj = None
support_obj_ids = [-1]
# stage defaults to ID specified as constant in habitat_sim.stage_id
support_obj_ids = [stage_id]
if not stage_support:
cube_stage_obj = rom.add_object_by_template_handle(
cube_stage_template_handle
Expand Down

0 comments on commit 9fb686c

Please sign in to comment.