|
| 1 | +# Copyright (c) 2022-2025, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: BSD-3-Clause |
| 5 | + |
| 6 | +"""Test texture randomization in the cartpole scene using pytest.""" |
| 7 | + |
| 8 | +from isaaclab.app import AppLauncher |
| 9 | + |
| 10 | +# launch omniverse app |
| 11 | +simulation_app = AppLauncher(headless=True, enable_cameras=True).app |
| 12 | + |
| 13 | +import gymnasium as gym |
| 14 | +import numpy as np |
| 15 | + |
| 16 | +import omni.usd |
| 17 | +import pytest |
| 18 | + |
| 19 | +from isaaclab.envs import ManagerBasedRLEnv |
| 20 | + |
| 21 | +from isaaclab_tasks.manager_based.classic.cartpole.cartpole_camera_env_cfg import ( |
| 22 | + CartpoleDepthCameraEnvCfg, |
| 23 | + CartpoleRGBCameraEnvCfg, |
| 24 | +) |
| 25 | +from isaaclab_tasks.manager_based.locomotion.velocity.config.anymal_c.rough_env_cfg import AnymalCRoughEnvCfg |
| 26 | + |
| 27 | + |
| 28 | +@pytest.mark.parametrize( |
| 29 | + "env_cfg_cls", |
| 30 | + [CartpoleRGBCameraEnvCfg, CartpoleDepthCameraEnvCfg, AnymalCRoughEnvCfg], |
| 31 | + ids=["RGB", "Depth", "RayCaster"], |
| 32 | +) |
| 33 | +@pytest.mark.parametrize("device", ["cpu", "cuda"]) |
| 34 | +def test_obs_space_follows_clip_contraint(env_cfg_cls, device): |
| 35 | + """Ensure curriculum terms apply correctly after the fallback and replacement.""" |
| 36 | + # new USD stage |
| 37 | + omni.usd.get_context().new_stage() |
| 38 | + |
| 39 | + # configure the cartpole env |
| 40 | + env_cfg = env_cfg_cls() |
| 41 | + env_cfg.scene.num_envs = 2 # keep num_envs small for testing |
| 42 | + env_cfg.observations.policy.concatenate_terms = False |
| 43 | + env_cfg.sim.device = device |
| 44 | + |
| 45 | + env = ManagerBasedRLEnv(cfg=env_cfg) |
| 46 | + for group_name, group_space in env.observation_space.spaces.items(): |
| 47 | + for term_name, term_space in group_space.spaces.items(): |
| 48 | + term_cfg = getattr(getattr(env_cfg.observations, group_name), term_name) |
| 49 | + low = -np.inf if term_cfg.clip is None else term_cfg.clip[0] |
| 50 | + high = np.inf if term_cfg.clip is None else term_cfg.clip[1] |
| 51 | + assert isinstance( |
| 52 | + term_space, gym.spaces.Box |
| 53 | + ), f"Expected Box space for {term_name} in {group_name}, got {type(term_space)}" |
| 54 | + assert np.all(term_space.low == low) |
| 55 | + assert np.all(term_space.high == high) |
| 56 | + |
| 57 | + env.close() |
0 commit comments