Implementation:Isaac sim IsaacGymEnvs HumanoidAMPBase
| Knowledge Sources | |
|---|---|
| Domains | Character_Animation, Motion_Imitation |
| Last Updated | 2026-02-15 11:00 GMT |
Overview
HumanoidAMPBase is the base simulation environment for Adversarial Motion Priors humanoid tasks, providing the physics setup, state management, and AMP observation buffer infrastructure for training natural humanoid motion policies.
Description
The HumanoidAMPBase class in isaacgymenvs/tasks/amp/humanoid_amp_base.py extends VecTask to create the foundational simulation layer for AMP-based humanoid control. It loads a humanoid character from an MJCF asset file with 28 actuated degrees of freedom distributed across 12 body segments (DOF_BODY_IDS), producing observations of size 105 (root height + root rotation + root velocity + root angular velocity + DOF positions + DOF velocities + key body positions for hands and feet).
The class manages GPU-accelerated state tensors acquired from Isaac Gym: actor root states, DOF states, rigid body states, and contact forces. The post_physics_step() method updates these tensors, computes observations, detects termination conditions (e.g., root height below terminationHeight), and handles environment resets. It supports both PD control and direct torque control modes via the pdControl configuration flag.
The AMP-specific infrastructure includes methods for computing AMP observations (_compute_amp_observations()), building demonstration observation buffers (_build_amp_obs_demo()), and initializing reference motion data (_init_amp_obs_ref()). AMP observations encode the character's pose in a format suitable for the discriminator network, capturing root state relative to the local frame (when localRootObs is enabled), joint rotations, velocities, and key body positions. The KEY_BODY_NAMES are "right_hand", "left_hand", "right_foot", and "left_foot".
Usage
Use HumanoidAMPBase as the base class for AMP humanoid tasks. Subclasses (e.g., HumanoidAMP) add task-specific rewards and goals on top of this simulation infrastructure. This class should not be instantiated directly; instead, use one of its concrete subclasses.
Code Reference
Source Location
- Repository: IsaacGymEnvs
- File: isaacgymenvs/tasks/amp/humanoid_amp_base.py
- Lines: 1-561
Signature
# Module-level constants
DOF_BODY_IDS = [1, 2, 3, 4, 6, 7, 9, 10, 11, 12, 13, 14]
DOF_OFFSETS = [0, 3, 6, 9, 10, 13, 14, 17, 18, 21, 24, 25, 28]
NUM_OBS = 13 + 52 + 28 + 12 # root_h, root_rot, root_vel, root_ang_vel, dof_pos, dof_vel, key_body_pos
NUM_ACTIONS = 28
KEY_BODY_NAMES = ["right_hand", "left_hand", "right_foot", "left_foot"]
class HumanoidAMPBase(VecTask):
def __init__(self, config, rl_device, sim_device, graphics_device_id,
headless, virtual_screen_capture, force_render):
"""Initialize humanoid simulation with MJCF asset and AMP observation buffers."""
def create_sim(self):
"""Create simulation with ground plane and configured physics parameters."""
def _create_envs(self, num_envs, spacing, num_per_row):
"""Load humanoid MJCF, set DOF properties, create parallel environments."""
def post_physics_step(self):
"""Refresh tensors, compute obs/rewards, check termination, handle resets."""
def _compute_observations(self, env_ids=None):
"""Build observation: root state, DOF positions/velocities, key body positions."""
def _compute_amp_observations(self, env_ids=None):
"""Compute AMP-specific observations for the discriminator."""
def _build_amp_obs_demo(self, motion_ids, motion_times):
"""Build AMP observations from demonstration motion data."""
def _init_amp_obs_ref(self, motion_ids, motion_times, env_ids):
"""Initialize AMP observation reference buffer from motion clips."""
def _reset_envs(self, env_ids):
"""Reset humanoid state in specified environments."""
Import
from isaacgymenvs.tasks.amp.humanoid_amp_base import HumanoidAMPBase
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config | dict | Yes | Task configuration with env.pdControl, env.powerScale, env.episodeLength, env.localRootObs, env.contactBodies, env.terminationHeight, env.enableEarlyTermination, env.plane friction/restitution |
| rl_device | str | Yes | Device for RL computations (e.g., "cuda:0") |
| sim_device | str | Yes | Device for physics simulation (e.g., "cuda:0") |
| graphics_device_id | int | Yes | GPU ID for rendering (-1 for headless) |
| headless | bool | Yes | Whether to run without visualization |
Outputs
| Name | Type | Description |
|---|---|---|
| obs_buf | Tensor | Observation tensor of shape (num_envs, 105) with root state, DOF state, and key body positions |
| rew_buf | Tensor | Per-environment scalar rewards (defined by subclasses) |
| reset_buf | Tensor | Boolean tensor indicating terminated environments |
| extras | dict | Additional info including AMP observations and termination flags |
| amp_obs | Tensor | AMP observation buffer for discriminator input |
Usage Examples
# HumanoidAMPBase is not used directly. Use a subclass like HumanoidAMP:
from isaacgymenvs.tasks.amp.humanoid_amp import HumanoidAMP
# Or create a custom AMP task:
from isaacgymenvs.tasks.amp.humanoid_amp_base import HumanoidAMPBase
class HumanoidAMPStrike(HumanoidAMPBase):
def __init__(self, config, rl_device, sim_device, graphics_device_id,
headless, virtual_screen_capture, force_render):
super().__init__(config, rl_device, sim_device, graphics_device_id,
headless, virtual_screen_capture, force_render)
# Add strike target setup
def _compute_reward(self, actions):
# Combine AMP style reward with strike task reward
pass
def _compute_amp_observations(self, env_ids=None):
# Use base implementation for standard humanoid AMP obs
super()._compute_amp_observations(env_ids)