### Run Example Pick Task Script Source: https://github.com/facebookresearch/habitat-lab/blob/main/README.md Execute the example script to test the Pick task. This script uses a configuration file for task and agent setup. ```bash python examples/example.py ``` -------------------------------- ### Install OpenCV Source: https://github.com/facebookresearch/habitat-lab/blob/main/docs/pages/quickstart.rst Install the OpenCV library for image processing. This is a prerequisite for running the example. ```sh pip install opencv-python ``` -------------------------------- ### Setup and Imports for Habitat Lab Visualization Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/Habitat_Lab_TopdownMap_Visualization.ipynb This code block handles the initial setup, including importing necessary libraries, setting up paths, and creating output directories. It's essential for running any Habitat Lab visualization examples. ```python # [setup] import os from typing import TYPE_CHECKING, Union, cast import git import matplotlib.pyplot as plt import numpy as np import habitat from habitat.config.default_structured_configs import ( CollisionsMeasurementConfig, FogOfWarConfig, TopDownMapMeasurementConfig, ) from habitat.core.agent import Agent from habitat.tasks.nav.nav import NavigationEpisode, NavigationGoal from habitat.tasks.nav.shortest_path_follower import ShortestPathFollower from habitat.utils.visualizations import maps from habitat.utils.visualizations.utils import ( images_to_video, observations_to_image, overlay_frame, ) from habitat_sim.utils import viz_utils as vut # Quiet the Habitat simulator logging os.environ["MAGNUM_LOG"] = "quiet" os.environ["HABITAT_SIM_LOG"] = "quiet" if TYPE_CHECKING: from habitat.core.simulator import Observations from habitat.sims.habitat_simulator.habitat_simulator import HabitatSim repo = git.Repo(".", search_parent_directories=True) dir_path = repo.working_tree_dir data_path = os.path.join(dir_path, "data") output_path = os.path.join( dir_path, "examples/tutorials/habitat_lab_visualization/" ) os.makedirs(output_path, exist_ok=True) os.chdir(dir_path) # [/setup] ``` -------------------------------- ### Habitat Lab Colab Setup and Imports Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/Habitat_Lab.ipynb Sets up the Colab environment by installing necessary packages and importing core libraries for Habitat Lab. Ensures the correct directory is set and data paths are configured. ```python # Copyright (c) Meta Platforms, Inc. and affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import random import git import numpy as np from gym import spaces %matplotlib inline from matplotlib import pyplot as plt repo = git.Repo(".", search_parent_directories=True) dir_path = repo.working_tree_dir data_path = os.path.join(dir_path, "data") os.chdir(dir_path) from PIL import Image import habitat from habitat.core.logging import logger from habitat.core.registry import registry from habitat.sims.habitat_simulator.actions import HabitatSimActions from habitat.tasks.nav.nav import NavigationTask from habitat_baselines.common.baseline_registry import baseline_registry from habitat_baselines.config.default import get_config as get_baselines_config ``` -------------------------------- ### PointNav Task Example Source: https://github.com/facebookresearch/habitat-lab/blob/main/docs/pages/quickstart.rst Sets up and runs a PointNav task where the agent navigates to a target location. User controls agent movement using keyboard inputs. Requires Habitat-Sim and Habitat Lab to be installed, along with scene data. ```python import habitat from habitat.sims.habitat_simulator.actions import HabitatSimActions import cv2 FORWARD_KEY="w" LEFT_KEY="a" RIGHT_KEY="d" FINISH="f" def transform_rgb_bgr(image): return image[:, :, [2, 1, 0]] def example(): env = habitat.Env( config=habitat.get_config("benchmark/nav/pointnav/pointnav_habitat_test.yaml") ) print("Environment creation successful") observations = env.reset() print("Destination, distance: {:3f}, theta(radians): {:.2f}".format( observations["pointgoal_with_gps_compass"][0], observations["pointgoal_with_gps_compass"][1])) cv2.imshow("RGB", transform_rgb_bgr(observations["rgb"])) print("Agent stepping around inside environment.") count_steps = 0 while not env.episode_over: keystroke = cv2.waitKey(0) if keystroke == ord(FORWARD_KEY): action = HabitatSimActions.move_forward print("action: FORWARD") elif keystroke == ord(LEFT_KEY): action = HabitatSimActions.turn_left print("action: LEFT") elif keystroke == ord(RIGHT_KEY): action = HabitatSimActions.turn_right print("action: RIGHT") elif keystroke == ord(FINISH): action = HabitatSimActions.stop print("action: FINISH") else: print("INVALID KEY") continue observations = env.step(action) count_steps += 1 print("Destination, distance: {:3f}, theta(radians): {:.2f}".format( observations["pointgoal_with_gps_compass"][0], observations["pointgoal_with_gps_compass"][1])) cv2.imshow("RGB", transform_rgb_bgr(observations["rgb"])) print("Episode finished after {} steps.".format(count_steps)) if ( action == HabitatSimActions.stop and observations["pointgoal_with_gps_compass"][0] < 0.2 ): print("you successfully navigated to destination point") else: print("your navigation was unsuccessful") if __name__ == "__main__": example() ``` -------------------------------- ### Download Example Datasets Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/Habitat_Lab.ipynb Downloads example datasets required for Habitat simulations, specifically the 'mp3d_example_scene'. Ensure the data path is correctly set. ```python !python -m habitat_sim.utils.datasets_download --uids mp3d_example_scene --data-path {data_path} --no-replace ``` -------------------------------- ### Install Habitat-Baselines Source: https://github.com/facebookresearch/habitat-lab/blob/main/README.md Installs habitat-baselines along with all its additional requirements. This command should be run after installing habitat-lab. ```bash pip install -e habitat-baselines # install habitat_baselines ``` -------------------------------- ### Setup Habitat Lab Environment Source: https://github.com/facebookresearch/habitat-lab/blob/main/docs/pages/habitat-lab-tdmap-viz.rst Imports necessary modules for Habitat Lab visualization. ```python import habitat from habitat.utils.visualizations import maps from habitat.utils.visualizations.utils import ObservationsToVideo import numpy as np import cv2 # Define the path to the test scene SCENE_PATH = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb" # Define the configuration for the environment config = habitat.get_config( "test/habitat_testing/habitat_sim/test_habitat_sim.yaml" ) config.defrost() config.SIMULATION.SCENE = SCENE_PATH config.freeze() # Initialize the environment env = habitat.Env(config=config) # Initialize the agent agent = habitat.Agent(config.ENVIRONMENT.AGENT) # Initialize the shortest path follower agent shortest_path_follower = ShortestPathFollowerAgent(env.habitat_config.simulator) # Initialize the observation to video converter obs_video_res = ObservationsToVideo(env.habitat_config.simulator.max_episode_steps, $( "output/videos/shortest_path_follower.mp4" )) # Get the first episode episode = env.reset() # Set the agent's start state agent.reset() # Set the goal location goal_position = episode.goals[0].position # Compute the shortest path to the goal sim_shortest_path = shortest_path_follower.get_shortest_path(agent.current_position, goal_position) # Initialize the top-down map measure top_down_map = env.get_measure("top_down_map") # Initialize the shortest path measure shortest_path_measure = env.get_measure("shortest_path") # Set the shortest path for the top-down map top_down_map.shortest_path = sim_shortest_path # Set the shortest path for the shortest path measure shortest_path_measure.shortest_path = sim_shortest_path # Initialize the agent's position on the top-down map top_down_map.agent_position = agent.current_position # Initialize the goal position on the top-down map top_down_map.goal_position = goal_position # Get the initial top-down map initial_top_down_map = top_down_map.get_topdown_map() # Get the initial shortest path map initial_shortest_path_map = shortest_path_measure.get_shortest_path() # Add the initial top-down map to the video obs_video_res.add_observation(initial_top_down_map) # Add the initial shortest path map to the video obs_video_res.add_observation(initial_shortest_path_map) # Simulate the agent's movement along the shortest path for _ in range(env.habitat_config.simulator.max_episode_steps): # Get the next action from the shortest path follower agent action = shortest_path_follower.get_next_action(agent.current_position) # If no action is available, break the loop if action is None: break # Perform the action in the environment obs, _, done, _ = env.step(action) # Update the agent's position agent.current_position = obs["agent_position"] # Update the top-down map with the agent's new position top_down_map.agent_position = agent.current_position # Get the updated top-down map current_top_down_map = top_down_map.get_topdown_map() # Get the updated shortest path map current_shortest_path_map = shortest_path_measure.get_shortest_path() # Add the updated top-down map to the video obs_video_res.add_observation(current_top_down_map) # Add the updated shortest path map to the video obs_video_res.add_observation(current_shortest_path_map) # If the episode is done, break the loop if done: break # Close the environment env.close() ``` -------------------------------- ### Install Habitat-Lab Stable Version Source: https://github.com/facebookresearch/habitat-lab/blob/main/README.md Clones the stable branch of habitat-lab and installs it in editable mode. This installs the core library. ```bash git clone --branch stable https://github.com/facebookresearch/habitat-lab.git cd habitat-lab pip install -e habitat-lab # install habitat_lab ``` -------------------------------- ### Main Execution Block Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/Habitat_Lab_TopdownMap_Visualization.ipynb Entry point for running various Habitat Lab examples. Calls specific example functions based on the script's execution context. ```python if __name__ == "__main__": example_pointnav_draw_target_birdseye_view() example_pointnav_draw_target_birdseye_view_agent_on_border() example_get_topdown_map() example_top_down_map_measure() ``` -------------------------------- ### Install Habitat-Baselines Source: https://github.com/facebookresearch/habitat-lab/blob/main/habitat-baselines/README.md Install the habitat-baselines sub-package and its additional requirements. This command installs the package in editable mode. ```bash pip install -e habitat-lab pip install -e habitat-baselines ``` -------------------------------- ### Top-Down Map Measurement Example Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/Habitat_Lab_TopdownMap_Visualization.ipynb Demonstrates how to add and use TopDownMap and Collisions measurements in a Habitat environment. This example configures the environment, creates a ShortestPathFollowerAgent, and generates a video of the agent's navigation. ```python def example_top_down_map_measure(): # Create habitat config config = habitat.get_config( config_path=os.path.join( dir_path, "habitat-lab/habitat/config/benchmark/nav/pointnav/pointnav_habitat_test.yaml", ) ) # Add habitat.tasks.nav.nav.TopDownMap and habitat.tasks.nav.nav.Collisions measures with habitat.config.read_write(config): config.habitat.task.measurements.update( { "top_down_map": TopDownMapMeasurementConfig( map_padding=3, map_resolution=1024, draw_source=True, draw_border=True, draw_shortest_path=True, draw_view_points=True, draw_goal_positions=True, draw_goal_aabbs=True, fog_of_war=FogOfWarConfig( draw=True, visibility_dist=5.0, fov=90, ), ), "collisions": CollisionsMeasurementConfig(), } ) # Create dataset dataset = habitat.make_dataset( id_dataset=config.habitat.dataset.type, config=config.habitat.dataset ) # Create simulation environment with habitat.Env(config=config, dataset=dataset) as env: # Create ShortestPathFollowerAgent agent agent = ShortestPathFollowerAgent( env=env, goal_radius=config.habitat.task.measurements.success.success_distance, ) # Create video of agent navigating in the first episode num_episodes = 1 for _ in range(num_episodes): # Load the first episode and reset agent observations = env.reset() agent.reset() # Get metrics info = env.get_metrics() # Concatenate RGB-D observation and topdowm map into one image frame = observations_to_image(observations, info) # Remove top_down_map from metrics info.pop("top_down_map") # Overlay numeric metrics onto frame frame = overlay_frame(frame, info) # Add fame to vis_frames vis_frames = [frame] # Repeat the steps above while agent doesn't reach the goal while not env.episode_over: # Get the next best action action = agent.act(observations) if action is None: break # Step in the environment observations = env.step(action) info = env.get_metrics() frame = observations_to_image(observations, info) info.pop("top_down_map") frame = overlay_frame(frame, info) vis_frames.append(frame) current_episode = env.current_episode video_name = f"{os.path.basename(current_episode.scene_id)}_{current_episode.episode_id}" # Create video from images and save to disk images_to_video( vis_frames, output_path, video_name, fps=6, quality=9 ) vis_frames.clear() # Display video vut.display_video(f"{output_path}/{video_name}.mp4") ``` -------------------------------- ### Create Habitat Environment from Configuration Source: https://github.com/facebookresearch/habitat-lab/blob/main/README.md Python code demonstrating how to create a Habitat environment using a configuration file and overrides. This allows for customized environment setup. ```python config = habitat.get_config( "benchmark/rearrange/skills/pick.yaml", overrides=["habitat.environment.max_episode_steps=20"] ) env = habitat.gym.make_gym_from_config(config) ``` -------------------------------- ### TensorBoard Visualization Example Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/Habitat_Lab.ipynb Placeholder comment indicating an example for TensorBoard visualization. This section would typically contain code to launch or connect to a TensorBoard instance for monitoring training progress. ```python # @markdown (double click to see the code) # example tensorboard visualization ``` -------------------------------- ### Start HITL Tool Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/hitl/pick_throw_vr/README.md Launch the Human-in-the-Loop (HITL) tool from the root habitat-lab directory. This command initiates the server for the Unity client to connect to. ```bash # Launch command ``` -------------------------------- ### Run Habitat Viewer with Test Scene (Source) Source: https://github.com/facebookresearch/habitat-lab/blob/main/TROUBLESHOOTING.md Verify issues on a minimal setup using habitat-sim built from source and the base viewer. Ensure MAGNUM_LOG is set to verbose and MAGNUM_GPU_VALIDATION is ON. ```bash MAGNUM_LOG=verbose MAGNUM_GPU_VALIDATION=ON {habitat-sim}/build/viewer data/scene_datasets/habitat-test-scenes/skokloster-castle.glb ``` -------------------------------- ### Example Evaluation Results Source: https://github.com/facebookresearch/habitat-lab/blob/main/habitat-baselines/README.md These are example average episode metrics obtained from evaluating the social navigation task. They provide insights into agent performance. ```bash Average episode social_nav_reward: 1.8821 Average episode social_nav_stats.has_found_human: 0.9020 Average episode social_nav_stats.found_human_rate_after_encounter_over_epi: 0.6423 Average episode social_nav_stats.found_human_rate_over_epi: 0.4275 Average episode social_nav_stats.first_encounter_steps: 376.0420 Average episode social_nav_stats.follow_human_steps_after_first_encounter: 398.6340 Average episode social_nav_stats.avg_robot_to_human_after_encounter_dis_over_epi: 1.4969 Average episode social_nav_stats.avg_robot_to_human_dis_over_epi: 3.6885 Average episode social_nav_stats.backup_ratio: 0.1889 Average episode social_nav_stats.yield_ratio: 0.0192 Average episode num_agents_collide: 0.7020 ``` -------------------------------- ### Start Interactive Docker Session Source: https://github.com/facebookresearch/habitat-lab/blob/main/README.md Run a Docker container with NVIDIA runtime support and start an interactive bash session within it. ```bash docker run --runtime=nvidia -it fairembodied/habitat-challenge:testing_2022_habitat_base_docker ``` -------------------------------- ### Configure Environment with Override Options Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/habitat2_gym_tutorial.ipynb Shows how to customize environment configurations using the `override_options` argument in `gym.make`. This example changes the gripper controller to 'SuctionGraspAction' for the Pick Task. ```python env = gym.make( "HabitatPick-v0", override_options=[ "habitat.task.actions.arm_action.grip_controller=SuctionGraspAction", ], ) print("Action space with suction grip", env.action_space) env.close() ``` -------------------------------- ### Launch Experimental Headless Server Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/hitl/pick_throw_vr/README.md Starts an experimental headless server for the Pick_throw_vr application. This is useful for server-only operations without a graphical interface. ```bash python examples/hitl/pick_throw_vr/pick_throw_vr.py \ +experiment=headless_server ``` -------------------------------- ### Install and Use Pre-commit Hooks Source: https://github.com/facebookresearch/habitat-lab/blob/main/CONTRIBUTING.md Install pre-commit hooks to automate linting and style enforcement before committing code. This ensures code quality and consistency. ```python pip install pre-commit && pre-commit install ``` -------------------------------- ### Check if libglvnd is Installed (Debian-based) Source: https://github.com/facebookresearch/habitat-lab/blob/main/TROUBLESHOOTING.md Verify the installation of `libglvnd` on Debian-based systems using `apt`. ```bash apt list --installed | grep libglvnd ``` -------------------------------- ### Basic Habitat Environment Interaction Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/habitat2_gym_tutorial.ipynb Sets up a 'HabitatRenderPick-v0' environment, performs a series of random actions, and records the interaction as a video. This example demonstrates a basic loop of environment reset, stepping with random actions, rendering, and saving the video. ```python env = gym.make("HabitatRenderPick-v0") video_file_path = os.path.join(output_path, "example_interact.mp4") video_writer = imageio.get_writer(video_file_path, fps=30) done = False env.reset() while not done: obs, reward, done, info = env.step(env.action_space.sample()) video_writer.append_data(env.render("rgb_array")) video_writer.close() if vut.is_notebook(): vut.display_video(video_file_path) env.close() ``` -------------------------------- ### Start RL Training for Pick Skill Source: https://github.com/facebookresearch/habitat-lab/blob/main/docs/pages/habitat2.rst Initiate training for a pick skill policy using Habitat Baselines. This command starts the default pick skill training. ```sh python -u -m habitat_baselines.run \ --config-name=rearrange/rl_skill.yaml ``` -------------------------------- ### Setup Habitat Base Path and Imports Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/habitat2_gym_tutorial.ipynb Sets up the Habitat base path for Colab environments and imports necessary libraries including git, PIL, imageio, and Habitat simulator utilities. It also configures environment variables to quiet simulator logging and initializes the repository path for output. ```python import os import git if "COLAB_GPU" in os.environ: print("Setting Habitat base path") # # %env HABLAB_BASE_CFG_PATH=/content/habitat-lab import importlib import PIL importlib.reload(PIL.TiffTags) # type: ignore[attr-defined] import imageio # Video rendering utility. from habitat_sim.utils import viz_utils as vut # Quiet the Habitat simulator logging os.environ["MAGNUM_LOG"] = "quiet" os.environ["HABITAT_SIM_LOG"] = "quiet" repo = git.Repo(".", search_parent_directories=True) dir_path = repo.working_tree_dir output_path = os.path.join( dir_path, "examples/tutorials/habitat_lab_visualization/" ) os.makedirs(output_path, exist_ok=True) os.chdir(dir_path) # If the import block below fails due to an error like "'PIL.TiffTags' has no attribute # 'IFD'", then restart the Colab runtime instance and rerun this cell and the previous cell. ``` -------------------------------- ### Download Benchmark Assets with habitat-sim Source: https://github.com/facebookresearch/habitat-lab/blob/main/scripts/hab3_bench/README.md Use this command to download benchmark assets when habitat-sim is installed via conda. Ensure you have habitat-sim and habitat-lab installed with Bullet physics support. ```bash python -m habitat_sim.utils.datasets_download --uids hab3_bench_assets ``` -------------------------------- ### Launch HITL Rearrangement App Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/hitl/rearrange/README.md Use this command to start the human-in-the-loop rearrangement application. Ensure you are in the correct directory. ```bash python examples/hitl/rearrange/rearrange.py ``` -------------------------------- ### SLURM Integration with Submitit Launcher Source: https://github.com/facebookresearch/habitat-lab/blob/main/habitat-lab/habitat/config/README.md Explains how to enable and use the Submitit Launcher for seamless SLURM integration, requiring installation of the hydra-submitit-launcher package. ```bash python -u -m habitat_baselines.run --config-name=config.yaml \ hydra/launcher=submitit_slurm --multirun ``` -------------------------------- ### Create and Activate Conda Environment Source: https://github.com/facebookresearch/habitat-lab/blob/main/README.md Prepares a conda environment with specific Python and CMake versions. Requires conda to be installed. ```bash # We require python>=3.9 and cmake>=3.14 conda create -n habitat python=3.9 cmake=3.14.0 conda activate habitat ``` -------------------------------- ### Run Habitat Viewer with Test Scene (Conda) Source: https://github.com/facebookresearch/habitat-lab/blob/main/TROUBLESHOOTING.md Verify issues on a minimal setup using the habitat-sim Conda package and the base viewer. Ensure MAGNUM_LOG is set to verbose and MAGNUM_GPU_VALIDATION is ON. ```bash MAGNUM_LOG=verbose MAGNUM_GPU_VALIDATION=ON habitat-viewer data/scene_datasets/habitat-test-scenes/skokloster-castle.glb ``` -------------------------------- ### Run Single Agent Training Source: https://github.com/facebookresearch/habitat-lab/blob/main/habitat-baselines/README.md Command to start single-agent training for the social rearrangement task using a specified configuration file. ```python python habitat_baselines/run.py --config-name=social_rearrange/pop_play.yaml ``` -------------------------------- ### Run Testing Script Inside Docker Source: https://github.com/facebookresearch/habitat-lab/blob/main/README.md Navigate to the habitat-lab directory and run the example testing script within the activated Docker environment. ```bash cd habitat-lab; python examples/example.py ``` -------------------------------- ### Define Environment Configuration Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/articulated_agents_tutorial.ipynb Defines the simulator and habitat configurations, including scene, dataset, and agent actions. This setup is necessary for initializing the environment. ```python from habitat.config.default_structured_configs import TaskConfig, EnvironmentConfig, DatasetConfig, HabitatConfig from habitat.config.default_structured_configs import ArmActionConfig, BaseVelocityActionConfig, OracleNavActionConfig, ActionConfig from habitat.core.env import Env def make_sim_cfg(agent_dict): # Start the scene config sim_cfg = SimulatorConfig(type="RearrangeSim-v0") # Enable Horizon Based Ambient Occlusion (HBAO) to approximate shadows. sim_cfg.habitat_sim_v0.enable_hbao = True sim_cfg.habitat_sim_v0.enable_physics = True # Set up an example scene sim_cfg.scene = os.path.join(data_path, "hab3_bench_assets/hab3-hssd/scenes/103997919_171031233.scene_instance.json") sim_cfg.scene_dataset = os.path.join(data_path, "hab3_bench_assets/hab3-hssd/hab3-hssd.scene_dataset_config.json") sim_cfg.additional_object_paths = [os.path.join(data_path, 'objects/ycb/configs/')] cfg = OmegaConf.create(sim_cfg) # Set the scene agents cfg.agents = agent_dict cfg.agents_order = list(cfg.agents.keys()) return cfg def make_hab_cfg(agent_dict, action_dict): sim_cfg = make_sim_cfg(agent_dict) task_cfg = TaskConfig(type="RearrangeEmptyTask-v0") task_cfg.actions = action_dict env_cfg = EnvironmentConfig() dataset_cfg = DatasetConfig(type="RearrangeDataset-v0", data_path="data/hab3_bench_assets/episode_datasets/small_large.json.gz") hab_cfg = HabitatConfig() hab_cfg.environment = env_cfg hab_cfg.task = task_cfg hab_cfg.dataset = dataset_cfg hab_cfg.simulator = sim_cfg hab_cfg.simulator.seed = hab_cfg.seed return hab_cfg def init_rearrange_env(agent_dict, action_dict): hab_cfg = make_hab_cfg(agent_dict, action_dict) res_cfg = OmegaConf.create(hab_cfg) return Env(res_cfg) ``` -------------------------------- ### Download Required Assets Source: https://github.com/facebookresearch/habitat-lab/blob/main/habitat-hitl/README.md Use this command to download necessary assets for example HITL applications. Ensure you run this from the habitat-lab root directory and specify the data path. ```bash python -m habitat_sim.utils.datasets_download \ --uids hab3-episodes habitat_humanoids hab_spot_arm ycb hssd-hab \ --data-path data/ ``` -------------------------------- ### Launch XR Reader Application Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/hitl/experimental/xr_reader/README.md Run this command from the root habitat-lab directory to launch the XR reader application. Ensure your Quest headset and server are on the same network and the client application is installed. ```bash python examples/hitl/experimental/xr_reader/xr_reader.py ``` -------------------------------- ### Load Episode and Configure Scene Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/articulated_agents_tutorial.ipynb Loads a specific episode from a gzipped JSON file and configures the simulator with it. This is useful for setting up a scene with pre-defined objects and agent starting positions. Ensure necessary imports like `RearrangeEpisode`, `gzip`, `json`, and `os` are present. ```python from habitat.datasets.rearrange.rearrange_dataset import RearrangeEpisode import gzip import json # Define the agent configuration episode_file = os.path.join(data_path, "hab3_bench_assets/episode_datasets/small_large.json.gz") sim = init_rearrange_sim(agent_dict) # Load the dataset with gzip.open(episode_file, "rt") as f: episode_files = json.loads(f.read()) # Get the first episode episode = episode_files["episodes"][0] rearrange_episode = RearrangeEpisode(**episode) art_agent = sim.articulated_agent art_agent._fixed_base = True sim.agents_mgr.on_new_scene() sim.reconfigure(sim.habitat_config, ep_info=rearrange_episode) sim.reset() art_agent.sim_obj.motion_type = MotionType.KINEMATIC sim.articulated_agent.base_pos = init_pos _ = sim.step({}) ``` -------------------------------- ### Navigate to Object Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/humanoids_tutorial.ipynb Navigates the humanoid agent towards a specified object in the scene. This example demonstrates how to get an object's ID and its transformation for navigation. ```python env.reset() rom = env.sim.get_rigid_object_manager() # env.sim.articulated_agent.base_pos = init_pos # As before, we get a navigation point next to an object id obj_id = env.sim.scene_obj_ids[0] first_object = rom.get_object_by_id(obj_id) object_trans = first_object.translation print(first_object.handle, "is in", object_trans) # TODO: unoccluded object did not work # print(sample) observations = [] delta = 2.0 object_agent_vec = env.sim.articulated_agent.base_pos - object_trans object_agent_vec.y = 0 dist_agent_object = object_agent_vec.length() ``` -------------------------------- ### Define a Custom Rearrange Task Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/Habitat2_Quickstart.ipynb Implement a custom task by inheriting from RearrangeTask and defining the reset function for episode initialization. This example sets a random target object and a random starting position for the agent. ```python import habitat import habitat.tasks.rearrange.rearrange_task from habitat.tasks.rearrange.rearrange_task import RearrangeTask from habitat.core.registry import registry import numpy as np @registry.register_task(name="RearrangeDemoNavPickTask-v0") class NavPickTaskV1(RearrangeTask): """ Primarily this is used to implement the episode reset functionality. Can also implement custom episode step functionality. """ def reset(self, episode): self.target_object_index = np.random.randint( 0, self._sim.get_n_targets() ) start_pos = self._sim.pathfinder.get_random_navigable_point() self._sim.articulated_agent.base_pos = start_pos # Put any reset logic here. return super().reset(episode) ``` -------------------------------- ### Initialize Habitat Environment and Sensors Source: https://github.com/facebookresearch/habitat-lab/blob/main/docs/pages/view-transform-warp.rst Sets up the Habitat environment, configures sensors (like depth sensor), and retrieves initial camera state including position and rotation. ```python import os import numpy as np import quaternion import matplotlib.pyplot as plt import habitat from habitat.config import read_write from habitat.config.default import get_agent_config import torch.nn.functional as F import torch from torchvision.transforms import ToTensor # Set up the environment for testing config = habitat.get_config(config_paths="benchmark/nav/pointnav/pointnav_habitat_test.yaml") with read_write(config): config.habitat.dataset.split = "val" agent_config = get_agent_config(sim_config=config.habitat.simulator) agent_config.sim_sensors.depth_sensor.normalize_depth = False # Intrinsic parameters, assuming width matches height. Requires a simple refactor otherwise W = agent_config.sim_sensors.depth_sensor.width H = agent_config.sim_sensors.depth_sensor.height assert(W == H) hfov = float(agent_config.sim_sensors.depth_sensor.hfov) * np.pi / 180. env = habitat.Env(config=config) obs = env.reset() initial_state = env._sim.get_agent_state(0) init_translation = initial_state.position init_rotation = initial_state.rotation ``` -------------------------------- ### Configure and Initialize Environment Source: https://github.com/facebookresearch/habitat-lab/blob/main/docs/pages/habitat-lab-demo.rst Loads a configuration, modifies dataset split, and initializes a Habitat environment. Ensure to close the environment before creating a new one if needed. ```python config = habitat.get_config(config_paths="benchmark/nav/pointnav/pointnav_mp3d.yaml") with read_write(config): config.habitat.dataset.split = "val" env = habitat.Env(config=config) ``` ```shell-session 2019-06-06 16:11:35,200 initializing sim Sim-v0 2019-06-06 16:11:46,171 initializing task Nav-v0 ``` -------------------------------- ### Test Magnum Installation (Mac) Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/hitl/pick_throw_vr/README.md Verify Magnum installation on macOS by running a Python command. Note that Homebrew might install packages to a separate Python location. ```python python -c "from magnum import math, meshtools, scenetools, trade" ``` -------------------------------- ### Check if libglvnd is Installed (RPM-based) Source: https://github.com/facebookresearch/habitat-lab/blob/main/TROUBLESHOOTING.md Verify the installation of `libglvnd` on RPM-based systems using `dnf`. ```bash dnf list installed | grep libglvnd ``` -------------------------------- ### Download Benchmark Assets from Source Source: https://github.com/facebookresearch/habitat-lab/blob/main/scripts/hab3_bench/README.md Use this command to download benchmark assets if you are running habitat-sim from source. Provide the correct path to the habitat_sim source directory. ```bash python /path/to/habitat_sim/src_python/habitat_sim/utils/datasets_download.py --uids hab3_bench_assets ``` -------------------------------- ### Install and Uninstall PyOpenSSL Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/Habitat_Lab.ipynb Installs and uninstalls the pyopenssl package. This is often a prerequisite for certain network-related functionalities. ```python !pip uninstall --yes pyopenssl !pip install pyopenssl ``` -------------------------------- ### Test Magnum Python Bindings Installation Source: https://github.com/facebookresearch/habitat-lab/blob/main/scripts/habitat_dataset_processing/README.md Verifies the installation of Magnum Python bindings by importing core modules. Note that Homebrew might install packages to its own Python location, potentially requiring 'python3' and manual path configuration. ```python from magnum import math, meshtools, scenetools, trade ``` -------------------------------- ### Install Dependencies for Interactive Play Source: https://github.com/facebookresearch/habitat-lab/blob/main/README.md Install Pygame and PyBullet, which are required for interactive visualization and inverse kinematics in the interactive play script. ```bash # Pygame for interactive visualization, pybullet for inverse kinematics pip install pygame==2.0.1 pybullet==3.0.4 ``` -------------------------------- ### Configure and Run Habitat Environment Source: https://github.com/facebookresearch/habitat-lab/blob/main/docs/pages/habitat-lab-demo.rst Initializes a Habitat environment with custom configurations, including sensor settings and turn angles. The script then samples episodes, resets the environment, and performs random actions for a fixed number of steps, displaying observations after each step. ```python config = habitat.get_config(config_paths="benchmark/nav/pointnav/pointnav_mp3d.yaml") with read_write(config): config.habitat.dataset.split = "val" agent_config = get_agent_config(sim_config=config.habitat.simulator) agent_config.sim_sensors.update( {"semantic_sensor": HabitatSimSemanticSensorConfig(height=256, width=256)} ) config.habitat.simulator.turn_angle = 30 env = habitat.Env(config=config) env.episodes = random.sample(env.episodes, 2) max_steps = 4 action_mapping = { 0: 'stop', 1: 'move_forward', 2: 'turn left', 3: 'turn right' } for i in range(len(env.episodes)): observations = env.reset() display_sample(observations['rgb'], observations['semantic'], np.squeeze(observations['depth'])) count_steps = 0 while count_steps < max_steps: action = random.choice(list(action_mapping.keys())) print(action_mapping[action]) observations = env.step(action) display_sample(observations['rgb'], observations['semantic'], np.squeeze(observations['depth'])) count_steps += 1 if env.episode_over: break env.close() ``` -------------------------------- ### Install Habitat Dataset Processing Package Source: https://github.com/facebookresearch/habitat-lab/blob/main/scripts/habitat_dataset_processing/README.md Installs the Habitat dataset processing package in editable mode within the activated conda environment. ```bash cd scripts/habitat_dataset_processing pip install -e . ``` -------------------------------- ### Install Habitat-Sim with Bullet Physics Source: https://github.com/facebookresearch/habitat-lab/blob/main/README.md Installs habitat-sim using conda, including bullet physics support. For the latest features, consider nightly builds. ```bash conda install habitat-sim withbullet -c conda-forge -c aihabitat ``` -------------------------------- ### Install Dependencies for Interactive Stretch Play Source: https://github.com/facebookresearch/habitat-lab/blob/main/habitat-lab/habitat/articulated_agents/robots/README.md Installs Pygame and Pybullet for interactive visualization and inverse kinematics. Ensure you use the specified versions for compatibility. ```bash pip install pygame==2.0.1 pybullet==3.0.4 ``` -------------------------------- ### Initialize Robot Interface and Run Policy Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/polymetis_example.ipynb Initialize the `RobotInterface` with the robot's IP address, reset the robot to its home position, create an instance of the custom `MySinePolicy`, and then execute the policy using `send_torch_policy`. ```python # Initialize robot interface robot = RobotInterface( ip_address="localhost", ) # Reset robot.go_home() # Create policy instance hz = robot.metadata.hz default_kq = torch.Tensor(robot.metadata.default_Kq) default_kqd = torch.Tensor(robot.metadata.default_Kqd) policy = MySinePolicy( time_horizon=5 * hz, hz=hz, magnitude=0.5, period=2.0, kq=default_kq, kqd=default_kqd, ) # Run policy print("\nRunning custom sine policy ...\n") state_log = robot.send_torch_policy(policy) ``` -------------------------------- ### Install and Use Black for Code Formatting Source: https://github.com/facebookresearch/habitat-lab/blob/main/CONTRIBUTING.md Install the 'black' code formatter using pip. This tool enforces PEP8 compliant styling and linting. ```python pip install black ``` -------------------------------- ### List Available Objects and Scenes Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/Habitat2_Quickstart.ipynb Use this command to list all available objects, receptacles, and scenes that can be used in dataset generation. This is helpful for understanding the available assets in Habitat Lab. ```bash python -m habitat.datasets.rearrange.run_episode_generator --list ``` -------------------------------- ### Launch Training with Batch Renderer Enabled Source: https://github.com/facebookresearch/habitat-lab/blob/main/habitat-lab/habitat/core/batch_rendering/README.md Initiate training with batch rendering enabled. Ensure to set the composite file path and disable individual renderer creation and concurrent rendering. ```bash habitat-baselines/habitat_baselines/run.py --config-name=rearrange/rl_skill.yaml habitat_baselines.trainer_name="ppo" habitat.simulator.renderer.enable_batch_renderer=True habitat.simulator.habitat_sim_v0.enable_gfx_replay_save=True habitat.simulator.create_renderer=False habitat.simulator.concur_render=False habitat.simulator.renderer.composite_files=[path/to/composite_file.gltf] ``` -------------------------------- ### Download Point-Goal Navigation Episodes Source: https://github.com/facebookresearch/habitat-lab/blob/main/README.md Download episodes for point-goal navigation tasks for the test scenes. ```bash python -m habitat_sim.utils.datasets_download --uids habitat_test_pointnav_dataset --data-path data/ ``` -------------------------------- ### Launch Basic Viewer HITL App Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/hitl/basic_viewer/README.md Run this command from the root habitat-lab directory to launch the basic viewer application. It allows filtering episodes for inspection. ```bash python examples/hitl/basic_viewer/basic_viewer.py habitat_hitl.episodes_filter='0 2 4 10:15 1000:4000:500' ``` -------------------------------- ### Create Simulator Configuration Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/articulated_agents_tutorial.ipynb Defines the simulator configuration, including scene path, dataset, and agent settings. Use this to set up the simulation environment. ```python def make_sim_cfg(agent_dict): # Start the scene config sim_cfg = SimulatorConfig(type="RearrangeSim-v0") # This is for better graphics sim_cfg.habitat_sim_v0.enable_hbao = True sim_cfg.habitat_sim_sim_cfg.enable_physics = True # Set up an example scene sim_cfg.scene = os.path.join(data_path, "hab3_bench_assets/hab3-hssd/scenes/103997919_171031233.scene_instance.json") sim_cfg.scene_dataset = os.path.join(data_path, "hab3_bench_assets/hab3-hssd/hab3-hssd.scene_dataset_config.json") sim_cfg.additional_object_paths = [os.path.join(data_path, 'objects/ycb/configs/')] cfg = OmegaConf.create(sim_cfg) # Set the scene agents cfg.agents = agent_dict cfg.agents_order = list(cfg.agents.keys()) return cfg ``` -------------------------------- ### Launch Sim Viewer HITL Application Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/hitl/sim_viewer/README.md Run this command from the root habitat-lab directory to launch the basic viewer application. ```bash python examples/hitl/sim_viewer/sim_viewer.py ``` -------------------------------- ### Launch Minimal HITL Application Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/hitl/minimal/README.md Run this command from the root habitat-lab directory to launch the minimal HITL application. ```bash python examples/hitl/minimal/minimal.py ``` -------------------------------- ### Get Top-Down Map from Simulator Source: https://github.com/facebookresearch/habitat-lab/blob/main/docs/pages/habitat-lab-tdmap-viz.rst Retrieves a top-down map from a HabitatSim instance. Requires habitat. ```python import habitat from habitat.sims.habitat_simulator.habitat_simulator import HabitatSim # Assuming 'env' is an initialized Habitat environment with a HabitatSim instance # config = habitat.get_config("path/to/your/config.yaml") # env = habitat.Env(config=config) # Get the simulator instance sim = env.habitat_config.simulator # Get the top-down map top_down_map = sim.get_topdown_map() ``` -------------------------------- ### Create and Configure a New Navigation Task Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/Habitat_Lab.ipynb This code demonstrates how to create a new navigation task by loading a configuration, overriding specific parameters, and registering the task with a custom type. It also shows how to close and re-initialize the environment with the new configuration. ```python if __name__ == "__main__": config = habitat.get_config( config_path=os.path.join( dir_path, "habitat-lab/habitat/config/benchmark/nav/pointnav/pointnav_habitat_test.yaml", ), overrides=[ "habitat.environment.max_episode_steps=10", "habitat.environment.iterator_options.shuffle=False", ], ) @registry.register_task(name="TestNav-v0") class NewNavigationTask(NavigationTask): def __init__(self, config, sim, dataset): logger.info("Creating a new type of task") super().__init__(config=config, sim=sim, dataset=dataset) def _check_episode_is_active(self, *args, **kwargs): logger.info( "Current agent position: {}".format(self._sim.get_agent_state()) ) collision = self._sim.previous_step_collided stop_called = not getattr(self, "is_stop_called", False) return collision or stop_called if __name__ == "__main__": with habitat.config.read_write(config): config.habitat.task.type = "TestNav-v0" try: env.close() except NameError: pass env = habitat.Env(config=config) ``` -------------------------------- ### Launch Robot with Habitat Client Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/polymetis_example.ipynb Use this command to launch the robot client with Habitat integration. Ensure `habitat_scene_path` is an absolute path to your scene file. ```bash launch_robot.py robot_client=habitat_sim habitat_scene_path=/PATH/TO/scene use_real_time=false gui=true ``` -------------------------------- ### Interact with Habitat Environment and Save Video Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/Habitat2_Quickstart.ipynb Sets up a Habitat environment using a specified configuration, then interacts with it by taking random actions and saving the rendered observations to a video file. This snippet demonstrates a basic environment interaction loop. ```python with habitat.Env( config=insert_render_options( habitat.get_config( os.path.join( dir_path, "habitat-lab/habitat/config/benchmark/rearrange/skills/pick.yaml", ), ) ) ) as env: observations = env.reset() # noqa: F841 print("Agent acting inside environment.") count_steps = 0 # To save the video video_file_path = os.path.join(output_path, "example_interact.mp4") video_writer = imageio.get_writer(video_file_path, fps=30) while not env.episode_over: observations = env.step(env.action_space.sample()) # noqa: F841 info = env.get_metrics() render_obs = observations_to_image(observations, info) render_obs = overlay_frame(render_obs, info) video_writer.append_data(render_obs) count_steps += 1 print("Episode finished after {} steps.".format(count_steps)) video_writer.close() if vut.is_notebook(): vut.display_video(video_file_path) ``` -------------------------------- ### Display GIF in IPython Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/Habitat_Lab.ipynb This snippet displays a GIF image within an IPython environment. It requires the IPython library to be installed. ```python try: from IPython import display with open("./res/img/tensorboard_video_demo.gif", "rb") as f: display.display(display.Image(data=f.read(), format="png")) except ImportError: pass ``` -------------------------------- ### Execute Base Velocity Actions and Record Video Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/articulated_agents_tutorial.ipynb This snippet demonstrates how to sample and execute base velocity actions in a loop and then generate a video from the collected observations. Ensure the environment and video utility are properly initialized. ```python observations = [] num_iter = 40 for _ in range(num_iter): params = env.action_space["base_velocity_action"].sample() action_dict = { "action": "base_velocity_action", "action_args": params } observations.append(env.step(action_dict)) vut.make_video( observations, "third_rgb", "color", "robot_tutorial_video", open_vid=True, ) ``` -------------------------------- ### Take Observation from Environment Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/articulated_agents_tutorial.ipynb Resets the environment and takes a step to get an observation. Displays the 'third_rgb' observation using matplotlib. ```python # Let's get an observation as before: env.reset() obs = env.step({"action": (), "action_args": {}}) plt.imshow(obs["third_rgb"]) ``` -------------------------------- ### Get Environment Metrics Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/notebooks/Habitat_Lab.ipynb Prints the metrics obtained from the Habitat environment after an episode has concluded. This is useful for evaluating agent performance. ```python print(env.get_metrics()) ``` -------------------------------- ### Launch Pick_throw_vr App (Mouse/Keyboard) Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/hitl/pick_throw_vr/README.md Use this command to launch the Pick_throw_vr application for interaction with mouse and keyboard controls. ```bash python examples/hitl/pick_throw_vr/pick_throw_vr.py ``` -------------------------------- ### Extend Point Navigation Configuration for Gibson Dataset Source: https://github.com/facebookresearch/habitat-lab/blob/main/habitat-lab/habitat/config/README.md Configuration to extend the base point navigation setup to use the Gibson dataset. ```yaml # @package _global_ defaults: - pointnav_base - /habitat/dataset/pointnav: gibson ``` -------------------------------- ### Configure Agent Sensors and Actions Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/humanoids_tutorial.ipynb Set up sensor configurations for the agent and define action dictionaries for environment interaction. This is typically done before initializing the environment. ```python main_agent_config.sim_sensors = { "third_rgb": ThirdRGBSensorConfig(), "head_rgb": HeadRGBSensorConfig(), } agent_dict = {"main_agent": main_agent_config} action_dict = { "humanoid_joint_action": HumanoidJointActionConfig() } env = init_rearrange_env(agent_dict, action_dict) ``` -------------------------------- ### Get Sensor Observations Source: https://github.com/facebookresearch/habitat-lab/blob/main/examples/tutorials/articulated_agents_tutorial.ipynb Retrieves observations from all sensors in the simulation environment. The keys of the returned dictionary indicate the names of the available sensors. ```python observations = sim.get_sensor_observations() print(observations.keys()) ``` -------------------------------- ### Download Habitat Test Assets Source: https://github.com/facebookresearch/habitat-lab/blob/main/TROUBLESHOOTING.md Run this command from the root of your habitat-lab or habitat-sim repository to download necessary test scene assets. ```bash python -m habitat_sim.utils.datasets_download --uids habitat_test_scenes --data-path data/ ``` -------------------------------- ### Initialize and Step Through Habitat Environment Source: https://github.com/facebookresearch/habitat-lab/blob/main/README.md Python code to load the Habitat-Lab environment and step through it using random actions. This demonstrates basic interaction with the embodied AI task. ```python import gym import habitat.gym # Load embodied AI task (RearrangePick) and a pre-specified virtual robot env = gym.make("HabitatRenderPick-v0") observations = env.reset() terminal = False # Step through environment with random actions while not terminal: observations, reward, terminal, info = env.step(env.action_space.sample()) ```