importhabitat_simimportrandom%matplotlibinlineimportmatplotlib.pyplotaspltimportnumpyasnptest_scene="../data/scene_datasets/mp3d/17DRP5sb8fy/17DRP5sb8fy.glb"sim_settings={"width":256,# Spatial resolution of the observations"height":256,"scene":test_scene,# Scene path"default_agent":0,"sensor_height":1.5,# Height of sensors in meters"color_sensor":True,# RGB sensor"semantic_sensor":True,# Semantic sensor"depth_sensor":True,# Depth sensor"seed":1,}
defmake_cfg(settings):sim_cfg=habitat_sim.SimulatorConfiguration()sim_cfg.gpu_device_id=0sim_cfg.scene_id=settings["scene"]# Note: all sensors must have the same resolutionsensor_specs=[]color_sensor_spec=habitat_sim.CameraSensorSpec()color_sensor_spec.uuid="color_sensor"color_sensor_spec.sensor_type=habitat_sim.SensorType.COLORcolor_sensor_spec.resolution=[settings["height"],settings["width"]]color_sensor_spec.position=[0.0,settings["sensor_height"],0.0]color_sensor_spec.sensor_subtype=habitat_sim.SensorSubType.PINHOLEsensor_specs.append(color_sensor_spec)depth_sensor_spec=habitat_sim.CameraSensorSpec()depth_sensor_spec.uuid="depth_sensor"depth_sensor_spec.sensor_type=habitat_sim.SensorType.DEPTHdepth_sensor_spec.resolution=[settings["height"],settings["width"]]depth_sensor_spec.position=[0.0,settings["sensor_height"],0.0]depth_sensor_spec.sensor_subtype=habitat_sim.SensorSubType.PINHOLEsensor_specs.append(depth_sensor_spec)semantic_sensor_spec=habitat_sim.CameraSensorSpec()semantic_sensor_spec.uuid="semantic_sensor"semantic_sensor_spec.sensor_type=habitat_sim.SensorType.SEMANTICsemantic_sensor_spec.resolution=[settings["height"],settings["width"]]semantic_sensor_spec.position=[0.0,settings["sensor_height"],0.0]semantic_sensor_spec.sensor_subtype=habitat_sim.SensorSubType.PINHOLEsensor_specs.append(semantic_sensor_spec)# Here you can specify the amount of displacement in a forward action and the turn angleagent_cfg=habitat_sim.agent.AgentConfiguration()agent_cfg.sensor_specifications=sensor_specsagent_cfg.action_space={"move_forward":habitat_sim.agent.ActionSpec("move_forward",habitat_sim.agent.ActuationSpec(amount=0.25)),"turn_left":habitat_sim.agent.ActionSpec("turn_left",habitat_sim.agent.ActuationSpec(amount=30.0)),"turn_right":habitat_sim.agent.ActionSpec("turn_right",habitat_sim.agent.ActuationSpec(amount=30.0)),}returnhabitat_sim.Configuration(sim_cfg,[agent_cfg])cfg=make_cfg(sim_settings)sim=habitat_sim.Simulator(cfg)
defprint_scene_recur(scene,limit_output=10):print(f"House has {len(scene.levels)} levels, {len(scene.regions)} regions and {len(scene.objects)} objects")print(f"House center:{scene.aabb.center} dims:{scene.aabb.sizes}")count=0forlevelinscene.levels:print(f"Level id:{level.id}, center:{level.aabb.center},"f" dims:{level.aabb.sizes}")forregioninlevel.regions:print(f"Region id:{region.id}, category:{region.category.name()},"f" center:{region.aabb.center}, dims:{region.aabb.sizes}")forobjinregion.objects:print(f"Object id:{obj.id}, category:{obj.category.name()},"f" center:{obj.aabb.center}, dims:{obj.aabb.sizes}")count+=1ifcount>=limit_output:returnNone# Print semantic annotation information (id, category, bounding box details)# about levels, regions and objects in a hierarchical fashionscene=sim.semantic_sceneprint_scene_recur(scene)
random.seed(sim_settings["seed"])sim.seed(sim_settings["seed"])# Set agent stateagent=sim.initialize_agent(sim_settings["default_agent"])agent_state=habitat_sim.AgentState()agent_state.position=np.array([0.0,0.072447,0.0])agent.set_state(agent_state)# Get agent stateagent_state=agent.get_state()print("agent_state: position",agent_state.position,"rotation",agent_state.rotation)
Search for modules, classes, functions and other
symbols. You can omit any prefix from the symbol path; adding a .
suffix lists all members of given symbol.
Use ↓
/ ↑ to navigate through the list,
Enter to go.
Tab autocompletes common prefix, you can
copy a link to the result using ⌘L while ⌘M produces a Markdown link.