Commit 05669ea4 authored by cosmith-nvidia's avatar cosmith-nvidia Committed by Kelly Guo

Checks if XR anchor already exists on creation (#292)

# Description

Don't attempt to recreate the XR anchor if one already exists.

This fixes an error that occurs when multiple XR devices are created,
because each one tries to create a prim at the same path so the second
one fails.

## 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`
- [x] 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
- [ ] 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
parent b70aa11f
......@@ -21,7 +21,7 @@ with contextlib.suppress(ModuleNotFoundError):
from . import teleop_command
import isaacsim.core.utils.prims as prim_utils
from isaacsim.core.prims import SingleXFormPrim
from isaaclab.markers import VisualizationMarkers
from isaaclab.markers.config import FRAME_MARKER_CFG
......@@ -94,11 +94,9 @@ class Se3HandTracking(DeviceBase):
self._goal_marker = VisualizationMarkers(self._frame_marker_cfg.replace(prim_path="/Visuals/ee_goal"))
# Specify the placement of the simulation when viewed in an XR device using a prim.
prim_utils.create_prim(
"/XRAnchor", "Xform", position=self._xr_cfg.anchor_pos, orientation=self._xr_cfg.anchor_rot
)
xr_anchor = SingleXFormPrim("/XRAnchor", position=self._xr_cfg.anchor_pos, orientation=self._xr_cfg.anchor_rot)
carb.settings.get_settings().set_string("/persistent/xr/profile/ar/anchorMode", "custom anchor")
carb.settings.get_settings().set_string("/xrstage/profile/ar/customAnchor", "/XRAnchor")
carb.settings.get_settings().set_string("/xrstage/profile/ar/customAnchor", xr_anchor.prim_path)
def __del__(self):
return
......
......@@ -114,6 +114,32 @@ class TestSe3HandTracking(unittest.TestCase):
device.reset()
env.close()
def test_xr_anchor_multiple_devices(self):
env_cfg = EmptyEnvCfg()
# Create a new stage.
omni.usd.get_context().new_stage()
# Create environment.
env = ManagerBasedEnv(cfg=env_cfg)
device_1 = Se3HandTracking(None, OpenXRSpec.XrHandEXT.XR_HAND_LEFT_EXT)
device_2 = Se3HandTracking(None, OpenXRSpec.XrHandEXT.XR_HAND_RIGHT_EXT)
# Check that the xr anchor prim is created with the correct default pose.
xr_anchor_prim = XFormPrim("/XRAnchor")
self.assertTrue(xr_anchor_prim.is_valid())
position, orientation = xr_anchor_prim.get_world_poses()
np.testing.assert_almost_equal(position.tolist(), [[0, 0, 0]])
np.testing.assert_almost_equal(orientation.tolist(), [[1, 0, 0, 0]])
# Check that xr anchor mode and custom anchor are set correctly.
self.assertEqual(carb.settings.get_settings().get("/persistent/xr/profile/ar/anchorMode"), "custom anchor")
self.assertEqual(carb.settings.get_settings().get("/xrstage/profile/ar/customAnchor"), "/XRAnchor")
device_1.reset()
device_2.reset()
env.close()
if __name__ == "__main__":
run_tests()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment