| | |
| | |
| | |
| | |
| |
|
| | """Launch Isaac Sim Simulator first.""" |
| |
|
| | from isaaclab.app import AppLauncher |
| |
|
| | |
| | simulation_app = AppLauncher(headless=True).app |
| |
|
| | """Rest everything follows.""" |
| |
|
| |
|
| | import pytest |
| |
|
| | from isaacsim.core.api.simulation_context import SimulationContext |
| | from pxr import Usd |
| |
|
| | import isaaclab.sim as sim_utils |
| | from isaaclab.sim.spawners.sensors.sensors import CUSTOM_FISHEYE_CAMERA_ATTRIBUTES, CUSTOM_PINHOLE_CAMERA_ATTRIBUTES |
| | from isaaclab.utils.string import to_camel_case |
| |
|
| |
|
| | @pytest.fixture |
| | def sim(): |
| | """Create a simulation context.""" |
| | sim_utils.create_new_stage() |
| | dt = 0.1 |
| | sim = SimulationContext(physics_dt=dt, rendering_dt=dt, backend="numpy") |
| | sim_utils.update_stage() |
| | yield sim |
| | sim.stop() |
| | sim.clear() |
| | sim.clear_all_callbacks() |
| | sim.clear_instance() |
| |
|
| |
|
| | """ |
| | Basic spawning. |
| | """ |
| |
|
| |
|
| | def test_spawn_pinhole_camera(sim): |
| | """Test spawning a pinhole camera.""" |
| | cfg = sim_utils.PinholeCameraCfg( |
| | focal_length=5.0, f_stop=10.0, clipping_range=(0.1, 1000.0), horizontal_aperture=10.0 |
| | ) |
| | prim = cfg.func("/World/pinhole_camera", cfg) |
| | |
| | assert prim.IsValid() |
| | assert sim.stage.GetPrimAtPath("/World/pinhole_camera").IsValid() |
| | assert prim.GetPrimTypeInfo().GetTypeName() == "Camera" |
| | |
| | _validate_properties_on_prim(prim, cfg, CUSTOM_PINHOLE_CAMERA_ATTRIBUTES) |
| |
|
| |
|
| | def test_spawn_fisheye_camera(sim): |
| | """Test spawning a fisheye camera.""" |
| | cfg = sim_utils.FisheyeCameraCfg( |
| | projection_type="fisheyePolynomial", |
| | focal_length=5.0, |
| | f_stop=10.0, |
| | clipping_range=(0.1, 1000.0), |
| | horizontal_aperture=10.0, |
| | ) |
| | |
| | |
| | prim = cfg.func("/World/fisheye_camera", cfg) |
| | |
| | assert prim.IsValid() |
| | assert sim.stage.GetPrimAtPath("/World/fisheye_camera").IsValid() |
| | assert prim.GetPrimTypeInfo().GetTypeName() == "Camera" |
| | |
| | _validate_properties_on_prim(prim, cfg, CUSTOM_FISHEYE_CAMERA_ATTRIBUTES) |
| |
|
| |
|
| | """ |
| | Helper functions. |
| | """ |
| |
|
| |
|
| | def _validate_properties_on_prim(prim: Usd.Prim, cfg: object, custom_attr: dict): |
| | """Validate the properties on the prim. |
| | |
| | Args: |
| | prim: The prim. |
| | cfg: The configuration object. |
| | custom_attr: The custom attributes for sensor. |
| | """ |
| | |
| | non_usd_cfg_param_names = [ |
| | "func", |
| | "copy_from_source", |
| | "lock_camera", |
| | "visible", |
| | "semantic_tags", |
| | "from_intrinsic_matrix", |
| | ] |
| | |
| | for attr_name, attr_value in cfg.__dict__.items(): |
| | |
| | if attr_name in non_usd_cfg_param_names or attr_value is None: |
| | continue |
| | |
| | if attr_name in custom_attr: |
| | |
| | prim_prop_name = custom_attr[attr_name][0] |
| | else: |
| | |
| | prim_prop_name = to_camel_case(attr_name, to="cC") |
| | |
| | assert prim.GetAttribute(prim_prop_name).Get() == pytest.approx(attr_value, rel=1e-5) |
| |
|