Skip to content

Commit

Permalink
Fixes minor bugs in RayCasterCamera and BaseEnvWindow (isaac-sim#1308)
Browse files Browse the repository at this point in the history
# Description

* Fixes a bug in RayCasterCamera's print function that was accessing
`RayCaster.meshes` instead of `self.meshes`
* Fixes a bug in BaseEnvWindow that was trying to access attributes from
undefined configs when building UI elements for action and command terms


## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
  • Loading branch information
kellyguo11 authored Oct 28, 2024
1 parent 6b826b1 commit e971d64
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 24 deletions.
2 changes: 1 addition & 1 deletion source/extensions/omni.isaac.lab/config/extension.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

# Note: Semantic Versioning is used: https://semver.org/
version = "0.27.5"
version = "0.27.6"

# Description
title = "Isaac Lab framework for Robot Learning"
Expand Down
10 changes: 10 additions & 0 deletions source/extensions/omni.isaac.lab/docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Changelog
---------

0.27.6 (2024-10-25)
~~~~~~~~~~~~~~~~~~~

Fixed
^^^^^

* Fixed usage of ``meshes`` property in :class:`omni.isaac.lab.sensors.RayCasterCamera` to use ``self.meshes`` instead of the undefined ``RayCaster.meshes``.
* Fixed issue in :class:`omni.isaac.lab.envs.ui.BaseEnvWindow` where undefined configs were being accessed when creating debug visualization elements in UI.


0.27.5 (2024-10-25)
~~~~~~~~~~~~~~~~~~~

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def _create_debug_vis_ui_element(self, name: str, elem: object):
self.ui_window_elements[f"{name}_cb"] = SimpleCheckBox(
model=omni.ui.SimpleBoolModel(),
enabled=elem.has_debug_vis_implementation,
checked=elem.cfg.debug_vis,
checked=elem.cfg.debug_vis if elem.cfg else False,
on_checked_fn=lambda value, e=weakref.proxy(elem): e.set_debug_vis(value),
)
omni.isaac.ui.ui_utils.add_line_rect_flourish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __str__(self) -> str:
f"Ray-Caster-Camera @ '{self.cfg.prim_path}': \n"
f"\tview type : {self._view.__class__}\n"
f"\tupdate period (s) : {self.cfg.update_period}\n"
f"\tnumber of meshes : {len(RayCaster.meshes)}\n"
f"\tnumber of meshes : {len(self.meshes)}\n"
f"\tnumber of sensors : {self._view.count}\n"
f"\tnumber of rays/sensor: {self.num_rays}\n"
f"\ttotal number of rays : {self.num_rays * self._view.count}\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Copyright (c) 2022-2024, The Isaac Lab Project Developers.
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause

# ignore private usage of variables warning
# pyright: reportPrivateUsage=none

from __future__ import annotations

"""Launch Isaac Sim Simulator first."""

from omni.isaac.lab.app import AppLauncher, run_tests

# Can set this to False to see the GUI for debugging
HEADLESS = True

# launch omniverse app
app_launcher = AppLauncher(headless=HEADLESS, enable_cameras=True)
simulation_app = app_launcher.app

"""Rest everything follows."""

import unittest

import carb
import omni.usd
from omni.isaac.core.utils.extensions import enable_extension

from omni.isaac.lab.envs import ManagerBasedRLEnv, ManagerBasedRLEnvCfg
from omni.isaac.lab.envs.ui import ManagerBasedRLEnvWindow
from omni.isaac.lab.scene import InteractiveSceneCfg
from omni.isaac.lab.utils import configclass

enable_extension("omni.isaac.ui")


@configclass
class EmptyManagerCfg:
"""Empty manager specifications for the environment."""

pass


@configclass
class EmptySceneCfg(InteractiveSceneCfg):
"""Configuration for an empty scene."""

pass


def get_empty_base_env_cfg(device: str = "cuda:0", num_envs: int = 1, env_spacing: float = 1.0):
"""Generate base environment config based on device"""

@configclass
class EmptyEnvCfg(ManagerBasedRLEnvCfg):
"""Configuration for the empty test environment."""

# Scene settings
scene: EmptySceneCfg = EmptySceneCfg(num_envs=num_envs, env_spacing=env_spacing)
# Basic settings
actions: EmptyManagerCfg = EmptyManagerCfg()
observations: EmptyManagerCfg = EmptyManagerCfg()
rewards: EmptyManagerCfg = EmptyManagerCfg()
terminations: EmptyManagerCfg = EmptyManagerCfg()
# Define window
ui_window_class_type: ManagerBasedRLEnvWindow = ManagerBasedRLEnvWindow

def __post_init__(self):
"""Post initialization."""
# step settings
self.decimation = 4 # env step every 4 sim steps: 200Hz / 4 = 50Hz
# simulation settings
self.sim.dt = 0.005 # sim step every 5ms: 200Hz
self.sim.render_interval = self.decimation # render every 4 sim steps
# pass device down from test
self.sim.device = device
# episode length
self.episode_length_s = 5.0

return EmptyEnvCfg()


class TestManagerBasedRLEnvUI(unittest.TestCase):
"""Test for manager-based RL env class UI"""

"""
Tests
"""

def test_ui_window(self):
device = "cuda:0"
# override sim setting to enable UI
carb.settings.get_settings().set_bool("/app/window/enabled", True)
# create a new stage
omni.usd.get_context().new_stage()
# create environment
env = ManagerBasedRLEnv(cfg=get_empty_base_env_cfg(device=device))
# close the environment
env.close()


if __name__ == "__main__":
run_tests()
9 changes: 9 additions & 0 deletions source/extensions/omni.isaac.lab/test/sensors/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,15 @@ def test_throughput(self):
for im_data in camera.data.output.values():
self.assertEqual(im_data.shape, (1, camera_cfg.height, camera_cfg.width, 1))

def test_sensor_print(self):
"""Test sensor print is working correctly."""
# Create sensor
sensor = Camera(cfg=self.camera_cfg)
# Play sim
self.sim.reset()
# print info
print(sensor)

"""
Helper functions.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,27 @@ def test_cube_stack_contact_filtering(self):
contact_sensor_2.data.force_matrix_w[:, :, 0], contact_sensor.data.force_matrix_w[:, :, 0]
)

def test_sensor_print(self):
"""Test sensor print is working correctly."""
with build_simulation_context(device="cuda:0", dt=self.sim_dt, add_lighting=False) as sim:
# Spawn things into stage
scene_cfg = ContactSensorSceneCfg(num_envs=1, env_spacing=1.0, lazy_sensor_update=False)
scene_cfg.terrain = FLAT_TERRAIN_CFG.replace(prim_path="/World/ground")
scene_cfg.shape = CUBE_CFG
scene_cfg.contact_sensor = ContactSensorCfg(
prim_path=scene_cfg.shape.prim_path,
track_pose=True,
debug_vis=False,
update_period=0.0,
track_air_time=True,
history_length=3,
)
scene = InteractiveScene(scene_cfg)
# Play the simulator
sim.reset()
# print info
print(scene.sensors["contact_sensor"])

"""
Internal helpers.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,25 @@ def test_frame_transformer_all_bodies(self):
torch.testing.assert_close(bodies_pos_source_tf[:, index], body_pos_b)
torch.testing.assert_close(bodies_quat_source_tf[:, index], body_quat_b)

def test_sensor_print(self):
"""Test sensor print is working correctly."""
# Spawn things into stage
scene_cfg = MySceneCfg(num_envs=2, env_spacing=5.0, lazy_sensor_update=False)
scene_cfg.frame_transformer = FrameTransformerCfg(
prim_path="{ENV_REGEX_NS}/Robot/base",
target_frames=[
FrameTransformerCfg.FrameCfg(
prim_path="{ENV_REGEX_NS}/Robot/.*",
),
],
)
scene = InteractiveScene(scene_cfg)

# Play the simulator
self.sim.reset()
# print info
print(scene.sensors["frame_transformer"])


if __name__ == "__main__":
run_tests()
48 changes: 27 additions & 21 deletions source/extensions/omni.isaac.lab/test/sensors/test_imu.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,34 +498,40 @@ def test_offset_calculation(self):
atol=1e-4,
)

def test_env_ids_propogation(self):
"""Test that env_ids argument propagates through update and reset methods"""
self.scene.reset()

def test_env_ids_propogation(self):
"""Test that env_ids argument propagates through update and reset methods"""
self.scene.reset()

for idx in range(10):
# set acceleration
self.scene.articulations["robot"].write_root_velocity_to_sim(
torch.tensor([[0.5, 0.0, 0.0, 0.0, 0.0, 0.0]], dtype=torch.float32, device=self.scene.device).repeat(
self.scene.num_envs, 1
for idx in range(10):
# set acceleration
self.scene.articulations["robot"].write_root_velocity_to_sim(
torch.tensor([[0.5, 0.0, 0.0, 0.0, 0.0, 0.0]], dtype=torch.float32, device=self.scene.device).repeat(
self.scene.num_envs, 1
)
* (idx + 1)
)
* (idx + 1)
)
# write data to sim
self.scene.write_data_to_sim()
# write data to sim
self.scene.write_data_to_sim()
# perform step
self.sim.step()
# read data from sim
self.scene.update(self.sim.get_physics_dt())

# reset scene for env 1
self.scene.reset(env_ids=[1])
# read data from sim
self.scene.update(self.sim.get_physics_dt())
# perform step
self.sim.step()
# read data from sim
self.scene.update(self.sim.get_physics_dt())

# reset scene for env 1
self.scene.reset(env_ids=[1])
# read data from sim
self.scene.update(self.sim.get_physics_dt())
# perform step
self.sim.step()
# read data from sim
self.scene.update(self.sim.get_physics_dt())
def test_sensor_print(self):
"""Test sensor print is working correctly."""
# Create sensor
sensor = self.scene.sensors["imu_ball"]
# print info
print(sensor)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,15 @@ def test_output_equal_to_usd_camera_when_intrinsics_set(self):
atol=1e-4,
)

def test_sensor_print(self):
"""Test sensor print is working correctly."""
# Create sensor
sensor = RayCasterCamera(cfg=self.camera_cfg)
# Play sim
self.sim.reset()
# print info
print(sensor)


if __name__ == "__main__":
run_tests()
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,15 @@ def test_output_equal_to_usd_camera_intrinsics(self):
del camera_tiled
del camera_usd

def test_sensor_print(self):
"""Test sensor print is working correctly."""
# Create sensor
sensor = TiledCamera(cfg=self.camera_cfg)
# Play sim
self.sim.reset()
# print info
print(sensor)

"""
Helper functions.
"""
Expand Down

0 comments on commit e971d64

Please sign in to comment.