| |
| |
| |
| |
|
|
| """Launch Isaac Sim Simulator first.""" |
|
|
| from isaaclab.app import AppLauncher |
|
|
| |
| simulation_app = AppLauncher(headless=True).app |
|
|
| """Rest everything follows.""" |
|
|
| from collections.abc import Generator |
|
|
| import numpy as np |
| import pytest |
|
|
| import omni.physx |
|
|
| import isaaclab.sim as sim_utils |
| from isaaclab.sim import SimulationCfg, SimulationContext |
|
|
|
|
| @pytest.fixture(autouse=True) |
| def test_setup_teardown(): |
| """Setup and teardown for each test.""" |
| |
| SimulationContext.clear_instance() |
|
|
| |
| yield |
|
|
| |
| SimulationContext.clear_instance() |
|
|
|
|
| @pytest.fixture |
| def sim_with_stage_in_memory() -> Generator[SimulationContext, None, None]: |
| """Create a simulation context with stage in memory.""" |
| |
| cfg = SimulationCfg(create_stage_in_memory=True) |
| sim = SimulationContext(cfg=cfg) |
| |
| sim_utils.update_stage() |
| |
| yield sim |
| |
| omni.physx.get_physx_simulation_interface().detach_stage() |
| sim.stop() |
| |
| sim.clear() |
| sim.clear_all_callbacks() |
| sim.clear_instance() |
|
|
|
|
| @pytest.mark.isaacsim_ci |
| def test_singleton(): |
| """Tests that the singleton is working.""" |
| sim1 = SimulationContext() |
| sim2 = SimulationContext() |
| assert sim1 is sim2 |
|
|
| |
| sim2.clear_instance() |
| assert sim1.instance() is None |
| |
| sim4 = SimulationContext() |
| assert sim1 is not sim4 |
| assert sim1.instance() is sim4.instance() |
|
|
|
|
| @pytest.mark.isaacsim_ci |
| def test_initialization(): |
| """Test the simulation config.""" |
| cfg = SimulationCfg(physics_prim_path="/Physics/PhysX", render_interval=5, gravity=(0.0, -0.5, -0.5)) |
| sim = SimulationContext(cfg) |
| |
| |
| |
|
|
| |
| assert sim.get_physics_dt() == cfg.dt |
| assert sim.get_rendering_dt() == cfg.dt * cfg.render_interval |
| assert not sim.has_rtx_sensors() |
| |
| assert sim.stage.GetPrimAtPath("/Physics/PhysX").IsValid() |
| assert sim.stage.GetPrimAtPath("/Physics/PhysX/defaultMaterial").IsValid() |
| |
| gravity_dir, gravity_mag = sim.get_physics_context().get_gravity() |
| gravity = np.array(gravity_dir) * gravity_mag |
| np.testing.assert_almost_equal(gravity, cfg.gravity) |
|
|
|
|
| @pytest.mark.isaacsim_ci |
| def test_sim_version(): |
| """Test obtaining the version.""" |
| sim = SimulationContext() |
| version = sim.get_version() |
| assert len(version) > 0 |
| assert version[0] >= 4 |
|
|
|
|
| @pytest.mark.isaacsim_ci |
| def test_carb_setting(): |
| """Test setting carb settings.""" |
| sim = SimulationContext() |
| |
| sim.set_setting("/physics/physxDispatcher", False) |
| assert sim.get_setting("/physics/physxDispatcher") is False |
| |
| sim.set_setting("/myExt/using_omniverse_version", sim.get_version()) |
| assert tuple(sim.get_setting("/myExt/using_omniverse_version")) == tuple(sim.get_version()) |
|
|
|
|
| @pytest.mark.isaacsim_ci |
| def test_headless_mode(): |
| """Test that render mode is headless since we are running in headless mode.""" |
| sim = SimulationContext() |
| |
| assert sim.render_mode == sim.RenderMode.NO_GUI_OR_RENDERING |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| @pytest.mark.isaacsim_ci |
| def test_zero_gravity(): |
| """Test that gravity can be properly disabled.""" |
| cfg = SimulationCfg(gravity=(0.0, 0.0, 0.0)) |
|
|
| sim = SimulationContext(cfg) |
|
|
| gravity_dir, gravity_mag = sim.get_physics_context().get_gravity() |
| gravity = np.array(gravity_dir) * gravity_mag |
| np.testing.assert_almost_equal(gravity, cfg.gravity) |
|
|