From 9fb686cfc32e82b1272fc45a92184644a78c7855 Mon Sep 17 00:00:00 2001 From: John Turner <7strbass@gmail.com> Date: Mon, 26 Feb 2024 22:15:34 -0500 Subject: [PATCH] --Test fixes to support semantic sensor updates (#1801) * --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 --- .../habitat/datasets/rearrange/samplers/art_sampler.py | 2 +- .../datasets/rearrange/samplers/object_sampler.py | 2 +- .../habitat/sims/habitat_simulator/sim_utilities.py | 9 +++++---- test/test_robot_wrapper.py | 8 ++++---- test/test_sim_utils.py | 5 +++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/habitat-lab/habitat/datasets/rearrange/samplers/art_sampler.py b/habitat-lab/habitat/datasets/rearrange/samplers/art_sampler.py index d419788fdf..ee5bef639d 100644 --- a/habitat-lab/habitat/datasets/rearrange/samplers/art_sampler.py +++ b/habitat-lab/habitat/datasets/rearrange/samplers/art_sampler.py @@ -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() diff --git a/habitat-lab/habitat/datasets/rearrange/samplers/object_sampler.py b/habitat-lab/habitat/datasets/rearrange/samplers/object_sampler.py index 4f853b9681..cab786e471 100644 --- a/habitat-lab/habitat/datasets/rearrange/samplers/object_sampler.py +++ b/habitat-lab/habitat/datasets/rearrange/samplers/object_sampler.py @@ -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( diff --git a/habitat-lab/habitat/sims/habitat_simulator/sim_utilities.py b/habitat-lab/habitat/sims/habitat_simulator/sim_utilities.py index 5fa0229abf..fc3087822e 100644 --- a/habitat-lab/habitat/sims/habitat_simulator/sim_utilities.py +++ b/habitat-lab/habitat/sims/habitat_simulator/sim_utilities.py @@ -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 @@ -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 = ( @@ -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. @@ -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 diff --git a/test/test_robot_wrapper.py b/test/test_robot_wrapper.py index 1e8ff9be01..eeeaad1cd2 100644 --- a/test/test_robot_wrapper.py +++ b/test/test_robot_wrapper.py @@ -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) @@ -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) @@ -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 @@ -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( diff --git a/test/test_sim_utils.py b/test/test_sim_utils.py index 9e6fdc3710..e74d896930 100644 --- a/test/test_sim_utils.py +++ b/test/test_sim_utils.py @@ -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 @@ -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