### Prepare ROS Environment for Running Examples Source: https://stanfordvl.github.io/iGibson/ros_integration.html Source the ROS environment and your catkin workspace's setup file to make ROS packages and your custom workspace available. ```bash source /opt/ros/kinetic/setup.bash source ~/catkin_ws/devel/setup.bash ``` -------------------------------- ### Install Miniconda and Setup Environment Source: https://stanfordvl.github.io/iGibson/_sources/installation.md.txt Installs Miniconda, adds it to the PATH, updates conda, and creates a dedicated virtual environment for iGibson with Python 3.8. ```bash curl -LO http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh bash Miniconda-latest-Linux-x86_64.sh rm Miniconda-latest-Linux-x86_64.sh echo "export PATH=$HOME/.miniconda/bin:$PATH" >> .bashrc conda update -y conda conda create -y -n igibson python=3.8 conda activate igibson ``` -------------------------------- ### Run Non-GUI Docker Example Source: https://stanfordvl.github.io/iGibson/_sources/quickstart.md.txt Launches a Docker container to run a non-GUI iGibson example. Ensure Docker is installed and the --gpus flag is used if GPU acceleration is needed. ```bash docker run --gpus all -ti --rm igibson/igibson:latest /bin/bash python -m tests.benchmark.benchmark_static_scene ``` -------------------------------- ### Run Interactive Environment Example Source: https://stanfordvl.github.io/iGibson/viewer.html Execute this command to launch an interactive example of the iGibson Viewer. Ensure you have downloaded the Rs_int scene. ```bash python -m igibson.examples.environments.env_int_example ``` -------------------------------- ### Launch iGibson-ROS Examples Source: https://stanfordvl.github.io/iGibson/_sources/ros_integration.md.txt Launch various iGibson-ROS integration examples using roslaunch, including basic bringup, gmapping, and navigation. ```bash roslaunch igibson-ros turtlebot_rgbd.launch # Bare minimal bringup example roslaunch igibson-ros turtlebot_gmapping.launch # Run gmapping roslaunch igibson-ros turtlebot_navigation.launch # Run the navigation stack, we have provided the map ``` -------------------------------- ### Install Miniconda and Setup iGibson Environment on Linux Source: https://stanfordvl.github.io/iGibson/installation.html Installs Miniconda, updates conda, and creates a new virtual environment named 'igibson' with Python 3.8. This is recommended for managing iGibson dependencies. ```bash # Install miniconda curl -LO http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh bash Miniconda-latest-Linux-x86_64.sh rm Miniconda-latest-Linux-x86_64.sh # Add conda to your PATH echo "export PATH=$HOME/.miniconda/bin:$PATH" >> .bashrc # Update conda and create a virtual environment for iGibson conda update -y conda conda create -y -n igibson python=3.8 conda activate igibson ``` -------------------------------- ### Run Interactive Environment Example Source: https://stanfordvl.github.io/iGibson/_sources/viewer.md.txt Execute this command to launch an interactive environment example using the Viewer. Ensure you have downloaded the Rs_int scene. ```bash python -m igibson.examples.environments.env_int_example ``` -------------------------------- ### Install iGibson Simulator using Pip Source: https://stanfordvl.github.io/iGibson/_sources/installation.md.txt Installs the iGibson simulator as a Python package using pip. This is a quick method for users who do not need to modify the simulator's source code. It also includes a command to run a basic environment example. ```bash pip install igibson # This step takes about 4 minutes # run the demo python -m igibson.examples.environments.env_nonint_example ``` -------------------------------- ### Run iGibson Robot Navigation Demo Source: https://stanfordvl.github.io/iGibson/installation.html Execute a simple robot navigation demo after installing the code and downloading demo data. This script provides a basic example of iGibson's capabilities. ```bash python -m igibson.examples.environments.env_nonint_example ``` -------------------------------- ### ROS Environment Setup Source: https://stanfordvl.github.io/iGibson/_sources/ros_integration.md.txt Source the necessary ROS setup files to configure your current shell environment for ROS communication. ```bash source /opt/ros/kinetic/setup.bash source ~/catkin_ws/devel/setup.bash ``` -------------------------------- ### EGL Example Repository Source: https://stanfordvl.github.io/iGibson/_sources/issues.md.txt Refer to Erwin Coumans' egl_example repository for information on setting up OpenGL libraries and EGL. ```bash git clone https://github.com/erwincoumans/egl_example.git ``` -------------------------------- ### Visualize All Robots Source: https://stanfordvl.github.io/iGibson/_sources/robots.md.txt Run this example to quickly see all supported robots in iGibson. ```python python -m igibson.examples.robots.all_robots_visualizer ``` -------------------------------- ### Run Interactive Mesh Renderer Example Source: https://stanfordvl.github.io/iGibson/renderer.html Launches an interactive demo of the MeshRenderer. Use WASD to translate and mouse to rotate the camera. Press Q to exit. ```bash python -m igibson.examples.renderer.mesh_renderer_example ``` -------------------------------- ### Run GUI Docker Example (X11) Source: https://stanfordvl.github.io/iGibson/_sources/quickstart.md.txt Launches a Docker container with GUI access for X11 environments. This requires setting the DISPLAY environment variable and mounting the X11 socket. ```bash docker run --env="DISPLAY" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" --env="QT_X11_NO_MITSHM=1" --gpus all -ti --rm igibson/igibson python -m igibson.examples.environments.env_nonint_example ``` -------------------------------- ### Run Robot Control Example Source: https://stanfordvl.github.io/iGibson/robots.html Execute the example script to test robot control functionalities, including selecting robots, controllers, and input methods. ```python python -m igibson.examples.robots.robot_control_example ``` -------------------------------- ### Run Robot Control Example Script Source: https://stanfordvl.github.io/iGibson/_sources/robots.md.txt Execute the robot control example script to test different robots, controllers, and input methods. ```python python -m igibson.examples.robots.robot_control_example ``` -------------------------------- ### Install iGibson-ROS Dependencies Source: https://stanfordvl.github.io/iGibson/ros_integration.html Install the dependencies required for the iGibson-ROS package using rosdep. ```bash cd ~/catkin_ws rosdep install --from-paths src --ignore-src -r -y ``` -------------------------------- ### Install iGibson from Source Source: https://stanfordvl.github.io/iGibson/_sources/ros_integration.md.txt Clone the iGibson repository and install it from source using pip. Ensure you are using Python 3.8 and have a conda environment activated. ```bash git clone https://github.com/StanfordVL/iGibson --recursive cd iGibson # if you didn't create the conda environment before: conda create -y -n igibson python=3.8 conda activate igibson pip install -e . ``` -------------------------------- ### Run Non-Interactive Environment Example Source: https://stanfordvl.github.io/iGibson/_sources/quickstart.md.txt Executes a non-interactive iGibson environment example. Reduce texture scaling in the config file if you encounter segfaults. ```bash python -m igibson.examples.environments.env_nonint_example ``` -------------------------------- ### Create and Populate Catkin Workspace Source: https://stanfordvl.github.io/iGibson/_sources/ros_integration.md.txt Set up a ROS catkin workspace, create the 'src' directory, and soft-link the 'igibson-ros' package into it. Then, build the workspace and install ROS dependencies. ```bash mkdir -p ~/catkin_ws/src cd ~/catkin_ws/src ln -s $/igibson/examples/ros/igibson-ros/ . source /opt/ros/noetic/setup.bash # to setup ros environment cd ~/catkin_ws && catkin_make cd ~/catkin_ws rosdep install --from-paths src --ignore-src -r -y ``` -------------------------------- ### Launch iGibson-ROS Turtlebot Examples Source: https://stanfordvl.github.io/iGibson/ros_integration.html Launch various iGibson-ROS configurations for the Turtlebot, including a minimal bringup, gmapping, and navigation stack. ```bash roslaunch igibson-ros turtlebot_rgbd.launch # Bare minimal bringup example roslaunch igibson-ros turtlebot_gmapping.launch # Run gmapping roslaunch igibson-ros turtlebot_navigation.launch # Run the navigation stack, we have provided the map ``` -------------------------------- ### Run GUI Docker Example (VNC) Source: https://stanfordvl.github.io/iGibson/_sources/quickstart.md.txt Launches a Docker container with VNC support for headless environments. Access the GUI via a VNC client at :5900. ```bash docker run --gpus all -ti --rm igibson/igibson-vnc:latest /bin/bash python -m igibson.examples.environments.env_nonint_example ``` -------------------------------- ### Run PBR Mesh Renderer Example Source: https://stanfordvl.github.io/iGibson/renderer.html Tests the physically based renderer with a PBR demo. Requires a path to an object's visual folder in the iG dataset. ```bash python -m igibson.examples.renderer.mesh_renderer_example_pbr /objects/sink/sink_1/shape/visual ``` -------------------------------- ### Simple Mesh Rendering Example Source: https://stanfordvl.github.io/iGibson/renderer.html Demonstrates basic usage of MeshRenderer to load a scene, set up the camera, and render RGB, normal, and 3D images. Requires a scene model file. ```python import logging import os import sys import cv2 import numpy as np from igibson.render.mesh_renderer.mesh_renderer_cpu import MeshRenderer from igibson.utils.assets_utils import get_scene_path def main(selection="user", headless=False, short_exec=False): """ Minimal example of use of the renderer. Loads Rs (non interactive), renders one set of images (RGB, normals, 3D points (as depth)), shows them. """ print("*" * 80 + "\nDescription:" + main.__doc__ + "*" * 80) # If a model is given, we load it, otherwise we load Rs mesh (non interactive) if len(sys.argv) > 1: model_path = sys.argv[1] else: model_path = os.path.join(get_scene_path("Rs"), "mesh_z_up.obj") renderer = MeshRenderer(width=512, height=512) renderer.load_object(model_path) renderer.add_instance_group([0]) camera_pose = np.array([0, 0, 1.2]) view_direction = np.array([1, 0, 0]) renderer.set_camera(camera_pose, camera_pose + view_direction, [0, 0, 1]) renderer.set_fov(90) frames = renderer.render(modes=("rgb", "normal", "3d")) # Render 3d points as depth map depth = np.linalg.norm(frames[2][:, :, :3], axis=2) depth /= depth.max() frames[2][:, :, :3] = depth[..., None] if not headless: frames = cv2.cvtColor(np.concatenate(frames, axis=1), cv2.COLOR_RGB2BGR) cv2.imshow("image", frames) cv2.waitKey(0) if __name__ == "__main__": logging.basicConfig(level=logging.INFO) main() ``` -------------------------------- ### Compile iGibson from Source Source: https://stanfordvl.github.io/iGibson/installation.html Installs iGibson by cloning the GitHub repository and compiling from source. This method is recommended for developers who plan to modify the iGibson codebase. ```bash git clone https://github.com/StanfordVL/iGibson --recursive cd iGibson # if you didn't create the conda environment before: conda create -y -n igibson python=3.8 conda activate igibson pip install -e . # This step takes about 4 minutes ``` -------------------------------- ### Install iGibson from Source using Pip Source: https://stanfordvl.github.io/iGibson/_sources/installation.md.txt Installs iGibson in editable mode after cloning the repository and setting up the environment. This allows for direct modifications to the source code to be reflected immediately. ```bash pip install -e . # This step takes about 4 minutes ``` -------------------------------- ### Main Execution Block Source: https://stanfordvl.github.io/iGibson/simulators.html Configures logging and calls the main function to run the simulator examples. ```python if __name__ == "__main__": logging.basicConfig(level=logging.INFO) main() ``` -------------------------------- ### Install Dependencies for On-Screen Nvidia on Ubuntu 20.04 Source: https://stanfordvl.github.io/iGibson/_sources/installation.md.txt Installs required Nvidia drivers and CUDA libraries for on-screen rendering on Ubuntu 20.04, suitable for desktop computers. This includes setting up Nvidia repositories and installing specific driver and CUDA versions. ```bash # Add the nvidia ubuntu repositories apt-get update && apt-get install -y --no-install-recommends \ gnupg2 curl ca-certificates && \ curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub | apt-key add - && \ echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \ echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list # The following cuda libraries are required to compile igibson apt-get update && apt-get update && apt-get install -y --no-install-recommends \ xserver-xorg-video-nvidia-470 \ cuda-cudart-11-1=11.1.74-1 \ cuda-compat-11-1 \ cuda-command-line-tools-11-1=11.1.1-1 \ cuda-libraries-dev-11-1=11.1.1-1 \ ``` -------------------------------- ### Test iGibson Installation Source: https://stanfordvl.github.io/iGibson/_sources/installation.md.txt Verify your iGibson installation by importing the library in a Python interpreter. This is a basic check to ensure the package is accessible. ```python import igibson ``` -------------------------------- ### Load Objects into iGibson Environment Source: https://stanfordvl.github.io/iGibson/objects.html This example demonstrates importing objects into different types of iGibson scenes (empty, iG, static). It shows how to initialize the simulator, scene, and robot, and then load objects with specified positions and orientations. Use this to set up a scene with specific objects and a robot for interaction. ```python import logging import os from sys import platform import numpy as np import yaml import igibson from igibson.envs.igibson_env import iGibsonEnv from igibson.external.pybullet_tools.utils import quat_from_euler from igibson.objects.articulated_object import URDFObject from igibson.objects.ycb_object import YCBObject from igibson.render.mesh_renderer.mesh_renderer_cpu import MeshRendererSettings from igibson.render.profiler import Profiler from igibson.robots.turtlebot import Turtlebot from igibson.scenes.empty_scene import EmptyScene from igibson.scenes.gibson_indoor_scene import StaticIndoorScene from igibson.simulator import Simulator from igibson.utils.assets_utils import get_ig_avg_category_specs, get_ig_category_path, get_ig_model_path from igibson.utils.utils import let_user_pick, parse_config def main(selection="user", headless=False, short_exec=False): """ This demo shows how to load scaled objects from the iG object model dataset and additional objects from the YCB dataset in predefined locations Loads a concrete object model of a table, and a random one of the same category, and 10 cracker boxes The objects can be loaded into an empty scene, an interactive scene (iG) or a static scene (Gibson) The example also shows how to use the Environment API or directly the Simulator API, loading objects and robots and executing actions """ print("*" * 80 + "\nDescription:" + main.__doc__ + "*" * 80) scene_options = get_first_options() type_of_scene = let_user_pick(scene_options, selection=selection) - 1 if type_of_scene == 0: # Empty config = parse_config(os.path.join(igibson.configs_path, "turtlebot_static_nav.yaml")) settings = MeshRendererSettings(enable_shadow=False, msaa=False, texture_scale=0.5) s = Simulator( mode="gui_interactive" if not headless else "headless", image_width=512, image_height=512, rendering_settings=settings, ) scene = EmptyScene(floor_plane_rgba=[0.6, 0.6, 0.6, 1]) # scene.load_object_categories(benchmark_names) s.import_scene(scene) robot_config = config["robot"] robot_config.pop("name") turtlebot = Turtlebot(**robot_config) s.import_object(turtlebot) elif type_of_scene == 1: # iG config_filename = os.path.join(igibson.configs_path, "turtlebot_nav.yaml") config_data = yaml.load(open(config_filename, "r"), Loader=yaml.FullLoader) config_data["load_object_categories"] = [] # Uncomment this line to accelerate loading with only the building config_data["visible_target"] = False config_data["visible_path"] = False # Reduce texture scale for Mac. if platform == "darwin": config_data["texture_scale"] = 0.5 env = iGibsonEnv(config_file=config_data, mode="gui_interactive" if not headless else "headless") s = env.simulator elif type_of_scene == 2: # Gibson config = parse_config(os.path.join(igibson.configs_path, "turtlebot_static_nav.yaml")) settings = MeshRendererSettings(enable_shadow=False, msaa=False) # Reduce texture scale for Mac. if platform == "darwin": settings.texture_scale = 0.5 s = Simulator( mode="gui_interactive" if not headless else "headless", image_width=512, image_height=512, rendering_settings=settings, ) scene = StaticIndoorScene("Rs", build_graph=True, pybullet_load_texture=False) s.import_scene(scene) robot_config = config["robot"] robot_config.pop("name") turtlebot = Turtlebot(**robot_config) s.import_object(turtlebot) if not headless: # Set a better viewing direction s.viewer.initial_pos = [-2, 1.4, 1.2] s.viewer.initial_view_direction = [0.6, -0.8, 0.1] s.viewer.reset_viewer() # Objects to load: two tables, the first one is predefined model, the second, random for the same category table_objects_to_load = { "table_1": { "category": "breakfast_table", "model": "1b4e6f9dd22a8c628ef9d976af675b86", "pos": (0.0, -0.2, 1.01), "orn": (0, 0, 90), }, "table_2": { "category": "breakfast_table", "pos": (0.5, -2.0, 1.01), "orn": (0, 0, 45), }, } # Load the specs of the object categories, e.g., common scaling factor avg_category_spec = get_ig_avg_category_specs() scene_objects = {} try: for obj in table_objects_to_load.values(): category = obj["category"] if category in scene_objects: scene_objects[category] += 1 else: scene_objects[category] = 1 ``` -------------------------------- ### Install System Dependencies for iGibson Source: https://stanfordvl.github.io/iGibson/_sources/installation.md.txt Installs essential system packages required for building iGibson. Ensure CMake, Git, G++, and EGL development libraries are present. ```bash apt-get update && apt-get install -y --no-install-recommends \ cmake \ git \ g++ \ libegl-dev ``` -------------------------------- ### Install Linux Dependencies for Headless iGibson (e.g., Cluster) Source: https://stanfordvl.github.io/iGibson/installation.html Installs necessary system dependencies for iGibson on Ubuntu 20.04, including Nvidia drivers and CUDA libraries for headless operation. Run as root/superuser. ```bash # Add the nvidia ubuntu repositories apt-get update && apt-get install -y --no-install-recommends \ gnupg2 curl ca-certificates && \ curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub | apt-key add - && \ echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \ echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list # The following cuda libraries are required to compile igibson apt-get update && apt-get update && apt-get install -y --no-install-recommends \ nvidia-headless-470 \ cuda-cudart-11-1=11.1.74-1 \ cuda-compat-11-1 \ cuda-command-line-tools-11-1=11.1.1-1 \ cuda-libraries-dev-11-1=11.1.1-1 \ # For building and running igibson apt-get update && apt-get install -y --no-install-recommends \ cmake \ git \ g++ \ libegl-dev ``` -------------------------------- ### Instantiate and Step iGibsonEnv with Static Scene Source: https://stanfordvl.github.io/iGibson/_sources/environments.md.txt Use this snippet to create an iGibsonEnv with a static scene and step through episodes. Remember to call env.reset() at the start of each episode and env.step(action) to advance. ```python import pybullet import pybullet_data import igibson from igibson.envs import iGibsonEnv # Define the config file config_file = "igibson/configs/turtlebot_static_nav.yaml" # Create the environment env = iGibsonEnv(config_file=config_file) # Reset the environment at the beginning of each episode state, _ = env.reset() # Step through the environment for _ in range(1000): # Sample a random action action = env.action_space.sample() # Step the environment state, reward, done, info = env.step(action) # Check if the episode is done if done: print("Episode finished.") state, _ = env.reset() env.close() ``` -------------------------------- ### Load and Interact with iGibson Indoor Scenes Source: https://stanfordvl.github.io/iGibson/scenes.html Imports an interactive scene and demonstrates sampling points by room type and computing shortest paths. Useful for tasks requiring robots to spawn in specific room types. Requires iGibson dataset and simulator setup. ```python import logging from sys import platform import numpy as np from igibson.render.mesh_renderer.mesh_renderer_settings import MeshRendererSettings from igibson.render.profiler import Profiler from igibson.scenes.igibson_indoor_scene import InteractiveIndoorScene from igibson.simulator import Simulator from igibson.utils.assets_utils import get_available_ig_scenes from igibson.utils.utils import let_user_pick def main(selection="user", headless=False, short_exec=False): """ Prompts the user to select any available interactive scene and loads it. Shows how to load directly scenes without the Environment interface Shows how to sample points in the scene by room type and how to compute geodesic distance and the shortest path """ print("*" * 80 + "\nDescription:" + main.__doc__ + "*" * 80) available_ig_scenes = get_first_options() scene_id = available_ig_scenes[let_user_pick(available_ig_scenes, selection=selection) - 1] settings = MeshRendererSettings(enable_shadow=True, msaa=False) if platform == "darwin": settings.texture_scale = 0.5 s = Simulator( mode="gui_interactive" if not headless else "headless", image_width=512, image_height=512, rendering_settings=settings, ) scene = InteractiveIndoorScene( scene_id, # load_object_categories=[], # To load only the building. Fast build_graph=True, ) s.import_scene(scene) # Shows how to sample points in the scene np.random.seed(0) for _ in range(10): pt = scene.get_random_point_by_room_type("living_room")[1] print("Random point in living_room: {}".format(pt)) for _ in range(10): random_floor = scene.get_random_floor() p1 = scene.get_random_point(random_floor)[1] p2 = scene.get_random_point(random_floor)[1] shortest_path, geodesic_distance = scene.get_shortest_path(random_floor, p1[:2], p2[:2], entire_path=True) print("Random point 1: {}".format(p1)) print("Random point 2: {}".format(p2)) print("Geodesic distance between p1 and p2: {}".format(geodesic_distance)) print("Shortest path from p1 to p2: {}".format(shortest_path)) if not headless: input("Press enter") max_steps = -1 if not short_exec else 1000 step = 0 while step != max_steps: with Profiler("Simulator step"): s.step() step += 1 s.disconnect() def get_first_options(): return get_available_ig_scenes() if __name__ == "__main__": logging.basicConfig(level=logging.INFO) main() ``` -------------------------------- ### Install iGibson via Pip Source: https://stanfordvl.github.io/iGibson/installation.html Installs the iGibson simulator as a Python package using pip. This is a quick method for users who do not plan to modify the simulator's source code. ```bash pip install igibson # This step takes about 4 minutes ``` ```python python -m igibson.examples.environments.env_nonint_example ``` -------------------------------- ### Import Objects into iGibson Source: https://stanfordvl.github.io/iGibson/_sources/objects.md.txt This example demonstrates how to import various objects into the iGibson simulator. Ensure that the necessary object assets are available in the specified paths. ```python import pybullet as p import igibson from igibson.objects.ycb import YCBObject from igibson.objects.rbo import RBOObject from igibson.objects.shape import ShapeNetObject from igibson.objects.articulated_object import URDFObject from igibson.objects.visual_marker import VisualMarker from igibson.simulator import Simulator from igibson.utils.utils import parse_config def main(): # Initialize the simulator config = parse_config(os.path.join(igibson.root_path, 'configs', 'config.yaml')) env = Simulator(config=config) # Load YCB objects ycb_obj_path = os.path.join(igibson.assets_path, 'models', 'ycb') obj_name = '003_cracker_box' ycb_obj = YCBObject(os.path.join(ycb_obj_path, obj_name), name=obj_name) env.import_object(ycb_obj, use_aabb_center=True) # Load RBO objects rbo_obj_path = os.path.join(igibson.assets_path, 'models', 'rbo') obj_name = '0001_sugar_box' rbo_obj = RBOObject(os.path.join(rbo_obj_path, obj_name), name=obj_name) env.import_object(rbo_obj, use_aabb_center=True) # Load ShapeNet objects shapenet_obj_path = os.path.join(igibson.assets_path, 'models', 'shapenet') obj_name = '037_monitor' shapenet_obj = ShapeNetObject(os.path.join(shapenet_obj_path, obj_name), name=obj_name) env.import_object(shapenet_obj, use_aabb_center=True) # Load URDF objects urdf_obj_path = os.path.join(igibson.assets_path, 'models', 'urdf') obj_name = '0001_sugar_box' urdf_obj = URDFObject(os.path.join(urdf_obj_path, obj_name), name=obj_name) env.import_object(urdf_obj, use_aabb_center=True) # Load Visual Marker marker_path = os.path.join(igibson.assets_path, 'models', 'marker') marker_obj = VisualMarker(os.path.join(marker_path, 'marker.urdf'), name='marker') env.import_object(marker_obj, use_aabb_center=True) # Run simulation for a few steps for _ in range(1000): env.step() env.disconnect() if __name__ == "__main__": main() ``` -------------------------------- ### Simple Mesh Rendering Example Source: https://stanfordvl.github.io/iGibson/_sources/renderer.md.txt Renders an iGibson scene using the MeshRenderer. Ensure the scene and renderer are properly initialized before calling render. ```python import os import numpy as np import pybullet as p import igibson from igibson.scenes import Scene from igibson.objects.ycb.ycb_object import YCBObject from igibson.utils.utils import quat2rotmat, xyzw2wxyz from igibson.render.mesh_renderer import MeshRenderer def mesh_renderer_simple_example(): # Initialize the renderer # You can specify the image width, height, and vertical field of view renderer = MeshRenderer(width=960, height=720, vertical_fov=90) # Load a scene scene_name = "Rs" scene = Scene(os.path.join(igibson.ig_dataset_path, "scenes", scene_name)) env = igibson.simulator.Simulator(scene) # Add the scene to the renderer renderer.add_scene(scene) # Set the camera pose # The camera pose is defined by position and orientation (quaternion) # Here, we set the camera to look at the center of the scene camera_pose = env.get_camera_pose() renderer.set_camera(camera_pose[0], camera_pose[1]) # Render the scene in different modes # Supported modes: 'rgb', 'normal', 'seg', '3d', 'optical_flow', 'scene_flow' # The output is a dictionary of numpy arrays, where keys are the modes rendering_output = renderer.render(modes=("rgb", "normal", "seg", "3d", "optical_flow", "scene_flow")) # You can access the rendered images like this: # rgb_image = rendering_output["rgb"] # normal_image = rendering_output["normal"] # seg_image = rendering_output["seg"] # depth_image = rendering_output["3d"][:, :, 2] # optical_flow_image = rendering_output["optical_flow"] # scene_flow_image = rendering_output["scene_flow"] # Clean up the renderer and environment renderer.delete() env.disconnect() if __name__ == "__main__": mesh_renderer_simple_example() ``` -------------------------------- ### Load Objects into Simulator - Python Source: https://stanfordvl.github.io/iGibson/_sources/simulators.md.txt This example demonstrates how to import a scene, a Turtlebot, and multiple YCBObjects into the simulator. Ensure the necessary scene and object types are available. ```python import pybullet as p import numpy as np from igibson.envs.env_base import BaseEnv from igibson.scenes import InteractiveIndoorScene from igibson.objects.ycb import YCBObject from igibson.robots import Turtlebot from igibson.utils.utils import random_string class LoadObjectsEnv(BaseEnv): def __init__(self, config): super(LoadObjectsEnv, self).__init__(config) def _load_scene(self): scene_type = self.config.get("scene_type", "Rs") if scene_type == "Rs": scene = InteractiveIndoorScene(scene_id=scene_type) else: raise NotImplementedError return scene def _load_object(self, obj_name, placement): obj = YCBObject(obj_name) self.simulator.import_object(obj, placement=placement) return obj def _load_articulated_object(self, ao_name, placement): ao = YCBObject(ao_name) self.simulator.import_articulated_object(ao, placement=placement) return ao def _load_robot(self, robot_name, placement): if robot_name == "turtlebot": robot = Turtlebot(self.config) self.simulator.import_robot(robot, placement=placement) return robot else: raise NotImplementedError def reset(self): self.simulator.reload() self.scene = self._load_scene() self.simulator.import_scene(self.scene) # Load objects obj_name = "coffee_mug" obj_placement = np.array([0.5, 0.5, 0.8]) self.obj = self._load_object(obj_name, obj_placement) # Load articulated objects ao_name = "cheezit_box" ao_placement = np.array([0.6, 0.5, 0.8]) self.ao = self._load_articulated_object(ao_name, ao_placement) # Load robot robot_name = "turtlebot" robot_placement = np.array([0.7, 0.5, 0.8]) self.robot = self._load_robot(robot_name, robot_placement) # Load multiple YCB objects for i in range(10): obj_name = np.random.choice(YCBObject.get_all_object_names()) obj_scale = np.random.uniform(0.5, 1.0) obj_orientation = p.getQuaternionFromEuler(np.random.uniform(0, np.pi, 3)) obj_pose = np.array([np.random.uniform(-0.5, 0.5), np.random.uniform(-0.5, 0.5), 0.8]) obj = YCBObject(obj_name, scale=obj_scale) self.simulator.import_object(obj, pose=obj_pose, orientation=obj_orientation) return self.get_observation() def get_observation(self): return np.array([]) def step(self, action): # No-op for this example return self.get_observation(), 0.0, False, {} def close(self): self.simulator.disconnect() def main(): config = { "scene_type": "Rs", "render_options": { "viewer_kwargs": { "image_width": 512, "image_height": 512 } } } env = LoadObjectsEnv(config) env.reset() # Simulate for a few steps for _ in range(100): action = env.action_space.sample() # Replace with actual actions obs, reward, done, info = env.step(action) if done: break env.close() if __name__ == "__main__": main() ``` -------------------------------- ### Check NVIDIA Driver and EGL Installation Source: https://stanfordvl.github.io/iGibson/_sources/issues.md.txt Verify NVIDIA driver version and libegl1 installation. Ensure OpenGL libraries are visible and EGL is linked to Nvidia's implementation, not Mesa. ```bash nvidia-smi ``` ```bash apt list --installed | grep libegl1 ``` ```bash export LD_LIBRARY_PATH=/usr/lib/nvidia-:$LD_LIBRARY_PATH ``` ```bash ldconfig -p | grep EGL ``` -------------------------------- ### Docker Environment Setup for iGibson-ROS Source: https://stanfordvl.github.io/iGibson/_sources/ros_integration.md.txt Clone the iGibson repository and use the provided scripts to build and run the ROS environment within a Docker container. ```bash git clone https://github.com/StanfordVL/iGibson --recursive cd iGibson/docker/igibson-ros ./build.sh ./run_gui.sh ``` -------------------------------- ### Build and Run iGibson-ROS Docker Image Source: https://stanfordvl.github.io/iGibson/ros_integration.html Clone the iGibson repository and use the provided Dockerfile to build and run the iGibson-ROS environment. This simplifies setup by containerizing dependencies. ```bash git clone https://github.com/StanfordVL/iGibson --recursive cd iGibson/docker/igibson-ros ./build.sh ./run_gui.sh ``` -------------------------------- ### Get Scene Options Source: https://stanfordvl.github.io/iGibson/objects.html Returns a list of available scene types for selection. ```python return ["Empty scene", "Interactive scene (iG)", "Static scene (Gibson)"] ``` -------------------------------- ### Example EGL Library Linking Output Source: https://stanfordvl.github.io/iGibson/issues.html This output shows typical EGL library links. Verify that libEGL_nvidia is present and correctly linked, and avoid links to mesa-egl. ```text libEGL_nvidia.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libEGL_nvidia.so.0 libEGL_nvidia.so.0 (libc6) => /usr/lib/i386-linux-gnu/libEGL_nvidia.so.0 libEGL_mesa.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libEGL_mesa.so.0 libEGL.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libEGL.so.1 libEGL.so.1 (libc6) => /usr/lib/i386-linux-gnu/libEGL.so.1 libEGL.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libEGL.so libEGL.so (libc6) => /usr/lib/i386-linux-gnu/libEGL.so ``` -------------------------------- ### Load Static Scene and Compute Shortest Path Source: https://stanfordvl.github.io/iGibson/_sources/scenes.md.txt Loads a static indoor scene, samples random start and end locations, and computes the shortest path between them using the scene's traversability graph. Requires `igibson.g_dataset_path` to be set. ```python import igibson # Define the scene ID for a static indoor scene scene_id = 'Rs_train' # Load the static indoor scene scene = igibson.scenes.StaticIndoorScene(scene_id=scene_id) # Load the scene into the simulator simulator.import_scene(scene) # Sample a random start location start_pos = scene.get_random_point(nav_mesh_path=scene.get_nav_mesh_path(0)) # Sample a random end location end_pos = scene.get_random_point(nav_mesh_path=scene.get_nav_mesh_path(0)) # Compute the shortest path between the start and end locations path = scene.get_shortest_path(start_pos, end_pos, scene.get_nav_mesh_path(0)) # Print the computed path (list of waypoints) print(path) ``` -------------------------------- ### run_setup Source: https://stanfordvl.github.io/iGibson/apidoc/igibson.examples.web_ui.html Sets up the environment for sampling. Can specify a list of scenes to load. ```APIDOC ## run_setup ### Description Sets up the environment for sampling. ### Parameters - **scenes** (list, optional) - A list of scenes to load. ``` -------------------------------- ### Clone iGibson and Setup Conda Environment Source: https://stanfordvl.github.io/iGibson/ros_integration.html Clone the iGibson repository and set up a dedicated Conda environment for Python 3.8. This is a prerequisite for installing iGibson from source. ```bash git clone https://github.com/StanfordVL/iGibson --recursive cd iGibson # if you didn't create the conda environment before: conda create -y -n igibson python=3.8 conda activate igibson pip install -e . # This step takes about 4 minutes ``` -------------------------------- ### Install CMake on MacOS Source: https://stanfordvl.github.io/iGibson/_sources/issues.md.txt Use Homebrew to install CMake system-wide to resolve 'ModuleNotFoundError: No module named 'cmake''. Avoid using pip or conda installations for CMake. ```bash brew install cmake ``` -------------------------------- ### Install SVL PyBullet Fork Source: https://stanfordvl.github.io/iGibson/_sources/installation.md.txt Uninstalls the standard PyBullet package and installs the custom SVL fork required by iGibson. This is crucial for compatibility and performance, especially if you have a pre-existing PyBullet installation. ```bash pip uninstall pybullet pip install pybullet-svl ``` -------------------------------- ### Install freetype on arm64 MacOS Source: https://stanfordvl.github.io/iGibson/_sources/issues.md.txt Address 'RuntimeError: Freetype library not found' on arm64 MacOS by installing freetype using conda, as the pip package may install incorrect binaries. ```bash conda install freetype ``` -------------------------------- ### Check Installed libegl1 Source: https://stanfordvl.github.io/iGibson/issues.html Use this command to verify if the libegl1 package is installed on your system. This is a prerequisite for EGL functionality. ```bash apt list --installed | grep libegl1 ``` -------------------------------- ### Install Dependencies for Headless Nvidia on Ubuntu 20.04 Source: https://stanfordvl.github.io/iGibson/_sources/installation.md.txt Installs required Nvidia drivers and CUDA libraries for headless operation on Ubuntu 20.04, suitable for cluster environments. This includes setting up Nvidia repositories and installing specific driver and CUDA versions. ```bash # Add the nvidia ubuntu repositories apt-get update && apt-get install -y --no-install-recommends \ gnupg2 curl ca-certificates && \ curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub | apt-key add - && \ echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \ echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list # The following cuda libraries are required to compile igibson apt-get update && apt-get update && apt-get install -y --no-install-recommends \ nvidia-headless-470 \ cuda-cudart-11-1=11.1.74-1 \ cuda-compat-11-1 \ cuda-command-line-tools-11-1=11.1.1-1 \ cuda-libraries-dev-11-1=11.1.1-1 \ # For building and running igibson apt-get update && apt-get install -y --no-install-recommends \ cmake \ git \ g++ \ libegl-dev ``` -------------------------------- ### Run Interactive Mesh Renderer Demo Source: https://stanfordvl.github.io/iGibson/_sources/renderer.md.txt Launches an interactive demo of the MeshRenderer. Use WASD to translate the camera and mouse to rotate. Press Q to exit. ```bash python -m igibson.examples.renderer.mesh_renderer_example ``` -------------------------------- ### Install h5py on arm64 MacOS Source: https://stanfordvl.github.io/iGibson/_sources/issues.md.txt Resolve 'ERROR: Could not build wheels for h5py' on arm64 MacOS by installing h5py using conda. ```bash conda install h5py ``` -------------------------------- ### Instantiate and Step iGibsonEnv with Static Scene Source: https://stanfordvl.github.io/iGibson/environments.html Instantiates an iGibsonEnv with a static Gibson model and demonstrates stepping through the environment with random actions. Requires downloading assets and demo data. Note: Mac users may need to reduce texture scaling to avoid memory errors. ```python import logging import os from sys import platform import yaml import igibson from igibson.envs.igibson_env import iGibsonEnv from igibson.render.profiler import Profiler from igibson.utils.assets_utils import download_assets, download_demo_data def main(selection="user", headless=False, short_exec=False): """ Creates an iGibson environment from a config file with a turtlebot in Rs (not interactive). It steps the environment 100 times with random actions sampled from the action space, using the Gym interface, resetting it 10 times. """ print("*" * 80 + "\nDescription:" + main.__doc__ + "*" * 80) # If they have not been downloaded before, download assets and Rs Gibson (non-interactive) models download_assets() download_demo_data() config_filename = os.path.join(igibson.configs_path, "turtlebot_static_nav.yaml") config_data = yaml.load(open(config_filename, "r"), Loader=yaml.FullLoader) # Reduce texture scale for Mac. if platform == "darwin": config_data["texture_scale"] = 0.5 # Shadows and PBR do not make much sense for a Gibson static mesh config_data["enable_shadow"] = False config_data["enable_pbr"] = False env = iGibsonEnv(config_file=config_data, mode="gui_interactive" if not headless else "headless") max_iterations = 10 if not short_exec else 1 for j in range(max_iterations): print("Resetting environment") env.reset() for i in range(100): with Profiler("Environment action step"): action = env.action_space.sample() state, reward, done, info = env.step(action) if done: print("Episode finished after {} timesteps".format(i + 1)) break env.close() if __name__ == "__main__": logging.basicConfig(level=logging.INFO) main() ``` -------------------------------- ### Verify CUDA Compiler (nvcc) Installation Source: https://stanfordvl.github.io/iGibson/_sources/installation.md.txt Checks if the NVIDIA CUDA compiler (nvcc) is accessible and displays its version. This confirms that your CUDA installation and PATH configuration are correct. ```bash $ nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2020 NVIDIA Corporation Built on Mon_Oct_12_20:09:46_PDT_2020 Cuda compilation tools, release 11.1, V11.1.105 Build cuda_11.1.TC455_06.29190527_0 ``` -------------------------------- ### Download Dataset using URL Source: https://stanfordvl.github.io/iGibson/_sources/dataset.md.txt Use this command to download, decompress, and place the dataset in the correct folder. Replace URL with the provided download link after filling out the license agreement. ```bash python -m igibson.utils.assets_utils --download_dataset URL ``` -------------------------------- ### Run PBR Renderer Demo Source: https://stanfordvl.github.io/iGibson/_sources/renderer.md.txt Tests the physically based renderer (PBR) with a specified object folder. Ensure the path points to a directory containing .obj files. ```bash python -m igibson.examples.renderer.mesh_renderer_example_pbr /objects/sink/sink_1/shape/visual ``` -------------------------------- ### Identity Matrix Source: https://stanfordvl.github.io/iGibson/apidoc/igibson.external.pybullet_tools.html Returns a 4x4 identity matrix. Useful as a starting point for transformations or for verification. ```python >>> I = identity_matrix() >>> numpy.allclose(I, numpy.dot(I, I)) True >>> numpy.sum(I), numpy.trace(I) (4.0, 4.0) >>> numpy.allclose(I, numpy.identity(4, dtype=numpy.float64)) True ``` -------------------------------- ### Render to PyTorch Tensors Source: https://stanfordvl.github.io/iGibson/renderer.html Shows how MeshRenderer can directly render into PyTorch tensors for increased efficiency. Requires PyTorch installation. ```python # Code for rendering to PyTorch Tensors is not provided in the source text. # The description indicates it's in igibson/examples/renderer/mesh_renderer_gpu_example.py ```