Unverified Commit 52ef373d authored by Kelly Guo's avatar Kelly Guo Committed by GitHub

Fixes to re-enable backwards compatibility (#577)

# Description

Some fixes for running latest Isaac Lab updates with Isaac Sim 4.5.

## 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
- [ ] 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
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->
parent 9fb2e925
......@@ -1274,6 +1274,11 @@ class Articulation(AssetBase):
spatial_tendon_ids: The tendon indices to set the stiffness for. Defaults to None (all spatial tendons).
env_ids: The environment indices to set the stiffness for. Defaults to None (all environments).
"""
if int(get_version()[2]) < 5:
omni.log.warn(
"Spatial tendons are not supported in Isaac Sim < 5.0. Please update to Isaac Sim 5.0 or later."
)
return
# resolve indices
if env_ids is None:
env_ids = slice(None)
......@@ -1300,6 +1305,11 @@ class Articulation(AssetBase):
spatial_tendon_ids: The tendon indices to set the damping for. Defaults to None (all spatial tendons).
env_ids: The environment indices to set the damping for. Defaults to None (all environments).
"""
if int(get_version()[2]) < 5:
omni.log.warn(
"Spatial tendons are not supported in Isaac Sim < 5.0. Please update to Isaac Sim 5.0 or later."
)
return
# resolve indices
if env_ids is None:
env_ids = slice(None)
......@@ -1326,6 +1336,11 @@ class Articulation(AssetBase):
spatial_tendon_ids: The tendon indices to set the limit stiffness for. Defaults to None (all spatial tendons).
env_ids: The environment indices to set the limit stiffness for. Defaults to None (all environments).
"""
if int(get_version()[2]) < 5:
omni.log.warn(
"Spatial tendons are not supported in Isaac Sim < 5.0. Please update to Isaac Sim 5.0 or later."
)
return
# resolve indices
if env_ids is None:
env_ids = slice(None)
......@@ -1352,6 +1367,11 @@ class Articulation(AssetBase):
spatial_tendon_ids: The tendon indices to set the offset for. Defaults to None (all spatial tendons).
env_ids: The environment indices to set the offset for. Defaults to None (all environments).
"""
if int(get_version()[2]) < 5:
omni.log.warn(
"Spatial tendons are not supported in Isaac Sim < 5.0. Please update to Isaac Sim 5.0 or later."
)
return
# resolve indices
if env_ids is None:
env_ids = slice(None)
......@@ -1504,8 +1524,8 @@ class Articulation(AssetBase):
self._data.default_joint_friction_coeff = (
self.root_physx_view.get_dof_friction_coefficients().to(self.device).clone()
)
self._data.default_joint_dynamic_friction_coeff = None
self._data.default_joint_viscous_friction_coeff = None
self._data.default_joint_dynamic_friction_coeff = torch.zeros_like(self._data.default_joint_friction_coeff)
self._data.default_joint_viscous_friction_coeff = torch.zeros_like(self._data.default_joint_friction_coeff)
else:
friction_props = self.root_physx_view.get_dof_friction_properties()
self._data.default_joint_friction_coeff = friction_props[:, :, 0].to(self.device).clone()
......@@ -1519,12 +1539,8 @@ class Articulation(AssetBase):
self._data.joint_damping = self._data.default_joint_damping.clone()
self._data.joint_armature = self._data.default_joint_armature.clone()
self._data.joint_friction_coeff = self._data.default_joint_friction_coeff.clone()
if int(get_version()[2]) < 5:
self._data.joint_dynamic_friction_coeff = None
self._data.joint_viscous_friction_coeff = None
else:
self._data.joint_dynamic_friction_coeff = self._data.default_joint_dynamic_friction_coeff.clone()
self._data.joint_viscous_friction_coeff = self._data.default_joint_viscous_friction_coeff.clone()
self._data.joint_dynamic_friction_coeff = self._data.default_joint_dynamic_friction_coeff.clone()
self._data.joint_viscous_friction_coeff = self._data.default_joint_viscous_friction_coeff.clone()
# -- body properties
self._data.default_mass = self.root_physx_view.get_masses().clone()
......
......@@ -140,6 +140,10 @@ class SimulationContext(_SimulationContext):
# acquire settings interface
self.carb_settings = carb.settings.get_settings()
# read isaac sim version (this includes build tag, release tag etc.)
# note: we do it once here because it reads the VERSION file from disk and is not expected to change.
self._isaacsim_version = get_version()
# apply carb physics settings
self._apply_physics_settings()
......@@ -217,9 +221,6 @@ class SimulationContext(_SimulationContext):
# ref: https://docs.omniverse.nvidia.com/prod_extensions/prod_extensions/ext_physics.html
# note: need to do this here because super().__init__ calls render and this variable is needed
self._fabric_iface = None
# read isaac sim version (this includes build tag, release tag etc.)
# note: we do it once here because it reads the VERSION file from disk and is not expected to change.
self._isaacsim_version = get_version()
# create a tensor for gravity
# note: this line is needed to create a "tensor" in the device to avoid issues with torch 2.1 onwards.
......@@ -344,8 +345,11 @@ class SimulationContext(_SimulationContext):
)
# parse preset file
repo_path = os.path.join(carb.tokens.get_tokens_interface().resolve("${app}"), "..")
preset_filename = os.path.join(repo_path, f"apps/rendering_modes/{rendering_mode}.kit")
# check if using isaac sim 4.5 and adjust path accordingly
repo_path = os.path.join(carb.tokens.get_tokens_interface().resolve("${app}"))
if self._isaacsim_version[0] == 4 and self._isaacsim_version[1] == 5:
repo_path = os.path.join(repo_path, "isaacsim_4_5")
preset_filename = os.path.join(repo_path, f"rendering_modes/{rendering_mode}.kit")
with open(preset_filename) as file:
preset_dict = toml.load(file)
preset_dict = dict(flatdict.FlatDict(preset_dict, delimiter="."))
......
......@@ -22,6 +22,7 @@ import torch
import isaacsim.core.utils.prims as prim_utils
import pytest
from isaacsim.core.version import get_version
import isaaclab.sim as sim_utils
import isaaclab.utils.math as math_utils
......@@ -1866,6 +1867,10 @@ def test_spatial_tendons(sim, num_articulations, device):
num_articulations: Number of articulations to test
device: The device to run the simulation on
"""
# skip test if Isaac Sim version is less than 5.0
if int(get_version()[2]) < 5:
pytest.skip("Spatial tendons are not supported in Isaac Sim < 5.0. Please update to Isaac Sim 5.0 or later.")
return
articulation_cfg = generate_articulation_cfg(articulation_type="spatial_tendon_test_asset")
articulation, _ = generate_articulation(articulation_cfg, num_articulations, device=device)
......@@ -1922,8 +1927,9 @@ def test_write_joint_frictions_to_sim(sim, num_articulations, device, add_ground
dynamic_friction = torch.rand(num_articulations, articulation.num_joints, device=device)
viscous_friction = torch.rand(num_articulations, articulation.num_joints, device=device)
friction = torch.rand(num_articulations, articulation.num_joints, device=device)
articulation.write_joint_dynamic_friction_coefficient_to_sim(dynamic_friction)
articulation.write_joint_viscous_friction_coefficient_to_sim(viscous_friction)
if int(get_version()[2]) >= 5:
articulation.write_joint_dynamic_friction_coefficient_to_sim(dynamic_friction)
articulation.write_joint_viscous_friction_coefficient_to_sim(viscous_friction)
articulation.write_joint_friction_coefficient_to_sim(friction)
articulation.write_data_to_sim()
......@@ -1933,8 +1939,9 @@ def test_write_joint_frictions_to_sim(sim, num_articulations, device, add_ground
# update buffers
articulation.update(sim.cfg.dt)
assert torch.allclose(articulation.data.joint_dynamic_friction_coeff, dynamic_friction)
assert torch.allclose(articulation.data.joint_viscous_friction_coeff, viscous_friction)
if int(get_version()[2]) >= 5:
assert torch.allclose(articulation.data.joint_dynamic_friction_coeff, dynamic_friction)
assert torch.allclose(articulation.data.joint_viscous_friction_coeff, viscous_friction)
assert torch.allclose(articulation.data.joint_friction_coeff, friction)
......
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