### Install pre-commit Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Install the pre-commit tool, which is used for automatically formatting your code. This command uses pip for installation. ```bash pip install pre-commit ``` -------------------------------- ### Verify Extension Installation Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Run this command to verify that the extension has been correctly installed and is recognized by the system. ```bash python scripts/rsl_rl/train.py --task=Template-Isaac-Velocity-Rough-Anymal-D-v0 ``` -------------------------------- ### Install Extension Library Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Install the extension library using pip within a Python environment that has Isaac Lab installed. ```bash python -m pip install -e source/ext_template ``` -------------------------------- ### Setup Python Environment for IDE Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Run this VSCode task to set up your Python environment, which helps with code indexing and intelligent suggestions. ```bash Ctrl+Shift+P, Tasks: Run Task, setup_python_env ``` -------------------------------- ### Build and Deploy Isaac Lab Extension with Docker Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Commands for building and deploying an Isaac Lab extension using Docker. Includes starting the base image, building the extension image, starting the container, executing commands inside, and shutting down. ```bash # Build Isaac Lab base image first (required) cd /path/to/IsaacLab ./docker/container.py start # Build template extension image cd IsaacLabExtensionTemplate/docker docker compose --env-file .env.base --file docker-compose.yaml build isaac-lab-template # Start container docker compose --env-file .env.base --file docker-compose.yaml up -d # Execute commands in running container docker exec --interactive --tty -e DISPLAY=${DISPLAY} isaac-lab-template /bin/bash # Inside container, run training python scripts/rsl_rl/train.py --task=Template-Isaac-Velocity-Rough-Anymal-D-v0 # Shutdown container docker compose --env-file .env.base --file docker-compose.yaml down ``` -------------------------------- ### Create Omniverse UI Extension Example Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Example of an Omniverse extension that creates a basic UI window with a label and buttons. The buttons allow incrementing and resetting a counter displayed on the label. ```python import omni.ext import omni.ui def some_public_function(x: int): """Public API function accessible from other extensions.""" print("[ext_template] some_public_function was called with x:", x) return x ** x class ExampleExtension(omni.ext.IExt): """Example Omniverse extension with basic UI.""" def on_startup(self, ext_id): """Called when extension is enabled.""" print("[ext_template] startup") self._count = 0 # Create UI window self._window = omni.ui.Window("My Window", width=300, height=300) with self._window.frame: with omni.ui.VStack(): label = omni.ui.Label("") def on_click(): self._count += 1 label.text = f"count: {self._count}" def on_reset(): self._count = 0 label.text = "empty" on_reset() with omni.ui.HStack(): omni.ui.Button("Add", clicked_fn=on_click) omni.ui.Button("Reset", clicked_fn=on_reset) def on_shutdown(self): """Called when extension is disabled.""" print("[ext_template] shutdown") ``` -------------------------------- ### Register Custom Gym Environment Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Register a new Gymnasium environment by creating configuration classes and using `gym.register`. This example shows how to register a rough terrain environment for the Anymal-D robot. ```python import gymnasium as gym from . import agents, flat_env_cfg, rough_env_cfg # Register training environment gym.register( id="Template-Isaac-Velocity-Rough-Anymal-D-v0", entry_point="isaaclab.envs:ManagerBasedRLEnv", disable_env_checker=True, kwargs={ "env_cfg_entry_point": rough_env_cfg.AnymalDRoughEnvCfg, "rsl_rl_cfg_entry_point": f"{agents.__name__}.rsl_rl_ppo_cfg:AnymalDRoughPPORunnerCfg", }, ) ``` -------------------------------- ### Run Isaac Lab Container Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Start the Docker containers defined in your 'docker-compose.yaml' file. This command brings up all associated services. ```bash docker compose --env-file .env.base --file docker-compose.yaml up ``` -------------------------------- ### Configure Anymal-D Rough Environment Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Defines environment configurations by extending the base LocomotionVelocityRoughEnvCfg class for the Anymal-D robot. Includes robot articulation setup and scene parameters. ```python # In source/ext_template/ext_template/tasks/locomotion/velocity/config/anymal_d/rough_env_cfg.py from isaaclab.utils import configclass from ext_template.tasks.locomotion.velocity.velocity_env_cfg import LocomotionVelocityRoughEnvCfg from isaaclab_assets.robots.anymal import ANYMAL_D_CFG @configclass class AnymalDRoughEnvCfg(LocomotionVelocityRoughEnvCfg): def __post_init__(self): super().__post_init__() # Configure robot articulation self.scene.robot = ANYMAL_D_CFG.replace(prim_path="{ENV_REGEX_NS}/Robot") @configclass class AnymalDRoughEnvCfg_PLAY(AnymalDRoughEnvCfg): def __post_init__(self): super().__post_init__() # Reduced environment for visualization self.scene.num_envs = 50 self.scene.env_spacing = 2.5 self.scene.terrain.max_init_terrain_level = None # Reduce terrain complexity if self.scene.terrain.terrain_generator is not None: self.scene.terrain.terrain_generator.num_rows = 5 self.scene.terrain.terrain_generator.num_cols = 5 self.scene.terrain.terrain_generator.curriculum = False # Disable randomization for deterministic playback self.observations.policy.enable_corruption = False self.events.base_external_force_torque = None self.events.push_robot = None ``` -------------------------------- ### Clone Isaac Lab Extension Template Repository Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Clone this repository to start developing your Isaac Lab project. Choose between HTTPS or SSH protocols. ```bash git clone https://github.com/isaac-sim/IsaacLabExtensionTemplate.git ``` ```bash git clone git@github.com:isaac-sim/IsaacLabExtensionTemplate.git ``` -------------------------------- ### Run Isaac Lab Container in Detached Mode Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Start the Docker containers in the background. Use the '-d' flag for detached mode to keep your terminal free. ```bash docker compose --env-file .env.base --file docker-compose.yaml up -d ``` -------------------------------- ### Configure Anymal-D Flat PPO Runner Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Simplified configuration class for Anymal-D robot training on flat terrain, enabling faster training. Overrides base configuration for max iterations, experiment name, and policy hidden dimensions. ```python @configclass class AnymalDFlatPPORunnerCfg(AnymalDRoughPPORunnerCfg): """Simplified configuration for flat terrain (faster training).""" def __post_init__(self): super().__post_init__() self.max_iterations = 300 self.experiment_name = "anymal_d_flat" self.policy.actor_hidden_dims = [128, 128, 128] self.policy.critic_hidden_dims = [128, 128, 128] ``` -------------------------------- ### Build Isaac Lab Template Image Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Build the Docker container for the Isaac Lab template project. Ensure you are in the 'docker' directory and have the necessary environment file. ```bash cd docker docker compose --env-file .env.base --file docker-compose.yaml build isaac-lab-template ``` -------------------------------- ### Configure Anymal-D Rough PPO Runner Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Configuration class for Anymal-D robot training on rough terrain using PPO. Sets training parameters like number of steps, save interval, and experiment name. Defines actor-critic and algorithm configurations. ```python from isaaclab.utils import configclass from isaaclab_rl.rsl_rl import RslRlOnPolicyRunnerCfg, RslRlPpoActorCriticCfg, RslRlPpoAlgorithmCfg @configclass class AnymalDRoughPPORunnerCfg(RslRlOnPolicyRunnerCfg): num_steps_per_env = 24 max_iterations = 1500 save_interval = 50 experiment_name = "anymal_d_rough" empirical_normalization = False policy = RslRlPpoActorCriticCfg( init_noise_std=1.0, actor_hidden_dims=[512, 256, 128], critic_hidden_dims=[512, 256, 128], activation="elu", ) algorithm = RslRlPpoAlgorithmCfg( value_loss_coef=1.0, use_clipped_value_loss=True, clip_param=0.2, entropy_coef=0.005, num_learning_epochs=5, num_mini_batches=4, learning_rate=1.0e-3, schedule="adaptive", gamma=0.99, lam=0.95, desired_kl=0.01, max_grad_norm=1.0, ) ``` -------------------------------- ### Run pre-commit on All Files Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Execute pre-commit to format all files in the repository. This ensures consistent code style across the project. ```bash pre-commit run --all-files ``` -------------------------------- ### Play Trained Policy and Record Video Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Execute a trained policy and record a video of the playback. Specify the task, video recording options, and the run identifier. ```bash python scripts/rsl_rl/play.py \ --task=Template-Isaac-Velocity-Rough-Anymal-D-Play-v0 \ --video \ --video_length=500 ``` -------------------------------- ### Register Playback Environment Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Registers a Gym environment for playback with reduced complexity. This is useful for visualization and testing. ```python gym.register( id="Template-Isaac-Velocity-Rough-Anymal-D-Play-v0", entry_point="isaaclab.envs:ManagerBasedRLEnv", disable_env_checker=True, kwargs={ "env_cfg_entry_point": rough_env_cfg.AnymalDRoughEnvCfg_PLAY, "rsl_rl_cfg_entry_point": f"{agents.__name__}.rsl_rl_ppo_cfg:AnymalDRoughPPORunnerCfg", }, ) ``` -------------------------------- ### List Available Gym Environments Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Query and list all registered Gymnasium environments within the Isaac Lab Template Extension. This helps in identifying available tasks for training and playback. ```bash python scripts/list_envs.py ``` -------------------------------- ### Configure Pylance Extra Paths Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Add the path to your extension repository in '.vscode/settings.json' under 'python.analysis.extraPaths' to help Pylance index extensions. Replace '' with the actual path. ```json { "python.analysis.extraPaths": [ "/source/ext_template" ] } ``` -------------------------------- ### Train RL Agent with Weights & Biases Logging Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Train an RL agent and configure logging with Weights & Biases. Specify the project name for organizing training runs. ```bash python scripts/rsl_rl/train.py \ --task=Template-Isaac-Velocity-Rough-Anymal-D-v0 \ --logger=wandb \ --log_project_name=my_locomotion_project ``` -------------------------------- ### Play Trained Policy with Visualization Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Load and execute a trained policy for evaluation and visualization. Specify the task and the run identifier for the trained model. ```bash python scripts/rsl_rl/play.py \ --task=Template-Isaac-Velocity-Rough-Anymal-D-Play-v0 \ --load_run=2024-01-15_10-30-00 ``` -------------------------------- ### Resume RL Training from Checkpoint Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Resume training an RL agent from a specific checkpoint. Provide the run identifier and the checkpoint file name. ```bash python scripts/rsl_rl/train.py \ --task=Template-Isaac-Velocity-Rough-Anymal-D-v0 \ --resume=True \ --load_run=2024-01-15_10-30-00 \ --checkpoint=model_1000.pt ``` -------------------------------- ### Play Trained Policy with Custom Environment Count Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Execute a trained policy with a custom number of environments for evaluation. Use 'latest' to load the most recent trained model. ```bash python scripts/rsl_rl/play.py \ --task=Template-Isaac-Velocity-Flat-Anymal-D-Play-v0 \ --num_envs=16 \ --load_run=latest ``` -------------------------------- ### Train RL Agent with Video Recording Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Train an RL agent and enable video recording during training. Specify the video length and interval for recording segments. ```bash python scripts/rsl_rl/train.py \ --task=Template-Isaac-Velocity-Rough-Anymal-D-v0 \ --video \ --video_length=200 \ --video_interval=2000 ``` -------------------------------- ### Clone and Rename Isaac Lab Extension Template Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Clone the repository and use the rename script to customize the template for your project by replacing all instances of 'ext_template' with your chosen name. ```bash git clone https://github.com/isaac-sim/IsaacLabExtensionTemplate.git cd IsaacLabExtensionTemplate python scripts/rename_template.py my_robot_extension # Enter 'y' when prompted to confirm python -m pip install -e source/my_robot_extension ``` -------------------------------- ### List Docker Images Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Check if the Isaac Lab base image exists after building it locally. This command lists all Docker images on your system. ```bash docker images ``` -------------------------------- ### Train RL Agent with Custom Parameters Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Train an RL agent with custom parameters, including the number of environments, maximum iterations, and a specific seed for reproducibility. ```bash python scripts/rsl_rl/train.py \ --task=Template-Isaac-Velocity-Flat-Anymal-D-v0 \ --num_envs=2048 \ --max_iterations=1000 \ --seed=42 ``` -------------------------------- ### Implement Velocity-Based Terrain Curriculum Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Creates a curriculum that adjusts terrain difficulty based on robot's distance walked relative to commanded velocity. Use this to progressively challenge the robot. ```python from __future__ import annotations import torch from collections.abc import Sequence from typing import TYPE_CHECKING from isaaclab.assets import Articulation from isaaclab.managers import SceneEntityCfg from isaaclab.terrains import TerrainImporter if TYPE_CHECKING: from isaaclab.envs import RLTaskEnv def terrain_levels_vel( env: RLTaskEnv, env_ids: Sequence[int], asset_cfg: SceneEntityCfg = SceneEntityCfg("robot") ) -> torch.Tensor: """Curriculum based on distance walked vs commanded velocity. Increases terrain difficulty when robot walks far enough, decreases when robot fails to achieve half the commanded distance. Args: env: The RL task environment env_ids: Environment indices to update asset_cfg: Robot asset configuration Returns: Mean terrain level across environments """ asset: Articulation = env.scene[asset_cfg.name] terrain: TerrainImporter = env.scene.terrain command = env.command_manager.get_command("base_velocity") # Compute walked distance distance = torch.norm( asset.data.root_pos_w[env_ids, :2] - env.scene.env_origins[env_ids, :2], dim=1 ) # Progress to harder terrain if walked far enough move_up = distance > terrain.cfg.terrain_generator.size[0] / 2 # Regress to easier terrain if walked less than half expected expected_distance = torch.norm(command[env_ids, :2], dim=1) * env.max_episode_length_s * 0.5 move_down = distance < expected_distance move_down *= ~move_up # Update terrain levels terrain.update_env_origins(env_ids, move_up, move_down) return torch.mean(terrain.terrain_levels.float()) ``` -------------------------------- ### Implement Feet Air Time Reward Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Calculates reward based on feet air time, rewarding longer steps. It uses a contact sensor and command manager to determine movement. ```python # In source/ext_template/ext_template/tasks/locomotion/velocity/mdp/rewards.py from __future__ import annotations import torch from typing import TYPE_CHECKING from isaaclab.managers import SceneEntityCfg from isaaclab.sensors import ContactSensor if TYPE_CHECKING: from isaaclab.envs import ManagerBasedRLEnv def feet_air_time( env: ManagerBasedRLEnv, command_name: str, sensor_cfg: SceneEntityCfg, threshold: float ) -> torch.Tensor: """Reward long steps taken by the feet using L2-kernel. Args: env: The RL environment instance command_name: Name of the velocity command ("base_velocity") sensor_cfg: Contact sensor configuration threshold: Minimum air time threshold for reward Returns: Reward tensor of shape (num_envs,) """ contact_sensor: ContactSensor = env.scene.sensors[sensor_cfg.name] first_contact = contact_sensor.compute_first_contact(env.step_dt)[:, sensor_cfg.body_ids] last_air_time = contact_sensor.data.last_air_time[:, sensor_cfg.body_ids] reward = torch.sum((last_air_time - threshold) * first_contact, dim=1) # Zero reward when no movement commanded reward *= torch.norm(env.command_manager.get_command(command_name)[:, :2], dim=1) > 0.1 return reward ``` -------------------------------- ### Exclude Pylance Indexing Paths Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Comment out unused Omniverse packages in '.vscode/settings.json' under 'python.analysis.extraPaths' to resolve Pylance crashes due to excessive file indexing. Replace '' with the actual path. ```json "/extscache/omni.anim.*" // Animation packages "/extscache/omni.kit.*" // Kit UI tools "/extscache/omni.graph.*" // Graph UI tools "/extscache/omni.services.*" // Services tools ... ``` -------------------------------- ### Execute Command in Running Container Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Run commands inside a running Isaac Lab container. The '-e DISPLAY=${DISPLAY}' flag is often necessary for GUI applications. ```bash docker exec --interactive --tty -e DISPLAY=${DISPLAY} isaac-lab-template /bin/bash ``` -------------------------------- ### Implement Positive Biped Feet Air Time Reward Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Rewards biped robots for ensuring single-leg stance phases. It calculates reward based on air time and contact time, with a specified threshold. ```python def feet_air_time_positive_biped( env: ManagerBasedRLEnv, command_name: str, threshold: float, sensor_cfg: SceneEntityCfg ) -> torch.Tensor: """Reward for biped robots ensuring single-leg stance phases.""" contact_sensor: ContactSensor = env.scene.sensors[sensor_cfg.name] air_time = contact_sensor.data.current_air_time[:, sensor_cfg.body_ids] contact_time = contact_sensor.data.current_contact_time[:, sensor_cfg.body_ids] in_contact = contact_time > 0.0 in_mode_time = torch.where(in_contact, contact_time, air_time) single_stance = torch.sum(in_contact.int(), dim=1) == 1 reward = torch.min(torch.where(single_stance.unsqueeze(-1), in_mode_time, 0.0), dim=1)[0] reward = torch.clamp(reward, max=threshold) reward *= torch.norm(env.command_manager.get_command(command_name)[:, :2], dim=1) > 0.1 return reward ``` -------------------------------- ### Rename Template References Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md After cloning, use this script to rename all occurrences of 'ext_template' to your desired extension name. ```bash cd IsaacLabExtensionTemplate python scripts/rename_template.py your_fancy_extension_name ``` -------------------------------- ### Configure Locomotion Task Rewards Source: https://context7.com/isaac-sim/isaaclabextensiontemplate/llms.txt Defines reward terms for locomotion tasks, including velocity tracking, penalties for undesirable behavior, gait rewards, and contact penalties. Use this to tune robot behavior. ```python from isaaclab.managers import RewardTermCfg as RewTerm from isaaclab.managers import SceneEntityCfg import ext_template.tasks.locomotion.velocity.mdp as mdp import math @configclass class RewardsCfg: """Reward terms for the locomotion MDP.""" # Task rewards - encourage velocity tracking track_lin_vel_xy_exp = RewTerm( func=mdp.track_lin_vel_xy_exp, weight=1.0, params={"command_name": "base_velocity", "std": math.sqrt(0.25)} ) track_ang_vel_z_exp = RewTerm( func=mdp.track_ang_vel_z_exp, weight=0.5, params={"command_name": "base_velocity", "std": math.sqrt(0.25)} ) # Penalty terms - discourage undesirable behavior lin_vel_z_l2 = RewTerm(func=mdp.lin_vel_z_l2, weight=-2.0) ang_vel_xy_l2 = RewTerm(func=mdp.ang_vel_xy_l2, weight=-0.05) dof_torques_l2 = RewTerm(func=mdp.joint_torques_l2, weight=-1.0e-5) dof_acc_l2 = RewTerm(func=mdp.joint_acc_l2, weight=-2.5e-7) action_rate_l2 = RewTerm(func=mdp.action_rate_l2, weight=-0.01) # Gait rewards - encourage proper foot timing feet_air_time = RewTerm( func=mdp.feet_air_time, weight=0.125, params={ "sensor_cfg": SceneEntityCfg("contact_forces", body_names=".*FOOT"), "command_name": "base_velocity", "threshold": 0.5, }, ) # Contact penalties undesired_contacts = RewTerm( func=mdp.undesired_contacts, weight=-1.0, params={ "sensor_cfg": SceneEntityCfg("contact_forces", body_names=".*THIGH"), "threshold": 1.0 }, ) ``` -------------------------------- ### Shut Down Isaac Lab Containers Source: https://github.com/isaac-sim/isaaclabextensiontemplate/blob/main/README.md Stop and remove the running Docker containers. This command cleans up the service containers but leaves the images intact. ```bash docker compose --env-file .env.base --file docker-compose.yaml down ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.