Skip to content

Commit b6a7729

Browse files
authored
Fixes outdated sensor data after reset (#1276)
# Description This change adds a call to `update_articulations_kinematic()` after performing reset in an environment to ensure that non-render sensors are updated after performing reset. ## Type of change <!-- As you go through the list, delete the ones that are not applicable. --> - 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 - [x] 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 --> --------- Signed-off-by: Kelly Guo <kellyguo123@hotmail.com> Signed-off-by: Kelly Guo <kellyg@nvidia.com>
1 parent b473b4d commit b6a7729

File tree

7 files changed

+128
-14
lines changed

7 files changed

+128
-14
lines changed

source/extensions/omni.isaac.lab/config/extension.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
# Note: Semantic Versioning is used: https://semver.org/
4-
version = "0.29.0"
4+
version = "0.29.1"
55

66
# Description
77
title = "Isaac Lab framework for Robot Learning"

source/extensions/omni.isaac.lab/docs/CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
---------
33

4+
0.29.1 (2024-12-15)
5+
~~~~~~~~~~~~~~~~~~~
6+
7+
Changed
8+
^^^^^^^
9+
10+
* Added call to update articulation kinematics after reset to ensure states are updated for non-rendering sensors. Previously, some changes in reset such as modifying joint states would not be reflected in the rigid body states immediately after reset.
11+
12+
413
0.29.0 (2024-12-15)
514
~~~~~~~~~~~~~~~~~~~
615

source/extensions/omni.isaac.lab/omni/isaac/lab/envs/direct_rl_env.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ def reset(self, seed: int | None = None, options: dict[str, Any] | None = None)
273273
indices = torch.arange(self.num_envs, dtype=torch.int64, device=self.device)
274274
self._reset_idx(indices)
275275

276+
# update articulation kinematics
277+
self.scene.write_data_to_sim()
278+
self.sim.forward()
279+
276280
# if sensors are added to the scene, make sure we render to reflect changes in reset
277281
if self.sim.has_rtx_sensors() and self.cfg.rerender_on_reset:
278282
self.sim.render()
@@ -346,6 +350,9 @@ def step(self, action: torch.Tensor) -> VecEnvStepReturn:
346350
reset_env_ids = self.reset_buf.nonzero(as_tuple=False).squeeze(-1)
347351
if len(reset_env_ids) > 0:
348352
self._reset_idx(reset_env_ids)
353+
# update articulation kinematics
354+
self.scene.write_data_to_sim()
355+
self.sim.forward()
349356
# if sensors are added to the scene, make sure we render to reflect changes in reset
350357
if self.sim.has_rtx_sensors() and self.cfg.rerender_on_reset:
351358
self.sim.render()

source/extensions/omni.isaac.lab/omni/isaac/lab/envs/manager_based_env.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,17 @@ def reset(
280280

281281
# reset state of scene
282282
self._reset_idx(env_ids)
283-
self.scene.write_data_to_sim()
284-
285-
# trigger recorder terms for post-reset calls
286-
self.recorder_manager.record_post_reset(env_ids)
287283

284+
# update articulation kinematics
285+
self.scene.write_data_to_sim()
286+
self.sim.forward()
288287
# if sensors are added to the scene, make sure we render to reflect changes in reset
289288
if self.sim.has_rtx_sensors() and self.cfg.rerender_on_reset:
290289
self.sim.render()
291290

291+
# trigger recorder terms for post-reset calls
292+
self.recorder_manager.record_post_reset(env_ids)
293+
292294
# compute observations
293295
self.obs_buf = self.observation_manager.compute()
294296

@@ -328,13 +330,16 @@ def reset_to(
328330
# set the state
329331
self.scene.reset_to(state, env_ids, is_relative=is_relative)
330332

331-
# trigger recorder terms for post-reset calls
332-
self.recorder_manager.record_post_reset(env_ids)
333+
# update articulation kinematics
334+
self.sim.forward()
333335

334336
# if sensors are added to the scene, make sure we render to reflect changes in reset
335337
if self.sim.has_rtx_sensors() and self.cfg.rerender_on_reset:
336338
self.sim.render()
337339

340+
# trigger recorder terms for post-reset calls
341+
self.recorder_manager.record_post_reset(env_ids)
342+
338343
# compute observations
339344
self.obs_buf = self.observation_manager.compute()
340345

source/extensions/omni.isaac.lab/omni/isaac/lab/envs/manager_based_rl_env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ def step(self, action: torch.Tensor) -> VecEnvStepReturn:
217217
self.recorder_manager.record_pre_reset(reset_env_ids)
218218

219219
self._reset_idx(reset_env_ids)
220-
221-
# this is needed to make joint positions set from reset events effective
220+
# update articulation kinematics
222221
self.scene.write_data_to_sim()
222+
self.sim.forward()
223223

224224
# if sensors are added to the scene, make sure we render to reflect changes in reset
225225
if self.sim.has_rtx_sensors() and self.cfg.rerender_on_reset:

source/extensions/omni.isaac.lab/omni/isaac/lab/sim/simulation_context.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,14 @@ def get_setting(self, name: str) -> Any:
416416
"""
417417
return self._settings.get(name)
418418

419+
def forward(self) -> None:
420+
"""Updates articulation kinematics and fabric for rendering."""
421+
if self._fabric_iface is not None:
422+
if self.physics_sim_view is not None and self.is_playing():
423+
# Update the articulations' link's poses before rendering
424+
self.physics_sim_view.update_articulations_kinematic()
425+
self._update_fabric(0.0, 0.0)
426+
419427
"""
420428
Operations - Override (standalone)
421429
"""
@@ -486,11 +494,7 @@ def render(self, mode: RenderMode | None = None):
486494
self.set_setting("/app/player/playSimulations", True)
487495
else:
488496
# manually flush the fabric data to update Hydra textures
489-
if self._fabric_iface is not None:
490-
if self.physics_sim_view is not None and self.is_playing():
491-
# Update the articulations' link's poses before rendering
492-
self.physics_sim_view.update_articulations_kinematic()
493-
self._update_fabric(0.0, 0.0)
497+
self.forward()
494498
# render the simulation
495499
# note: we don't call super().render() anymore because they do above operation inside
496500
# and we don't want to do it twice. We may remove it once we drop support for Isaac Sim 2022.2.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright (c) 2024, The Isaac Lab Project Developers.
2+
# All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
"""Launch Isaac Sim Simulator first."""
7+
8+
from omni.isaac.lab.app import AppLauncher, run_tests
9+
10+
# launch the simulator
11+
app_launcher = AppLauncher(headless=True, enable_cameras=True)
12+
simulation_app = app_launcher.app
13+
14+
15+
"""Rest everything follows."""
16+
17+
import gymnasium as gym
18+
import shutil
19+
import tempfile
20+
import torch
21+
import unittest
22+
23+
import carb
24+
import omni.usd
25+
26+
import omni.isaac.lab_tasks # noqa: F401
27+
from omni.isaac.lab_tasks.utils.parse_cfg import parse_env_cfg
28+
29+
30+
class TestFrameTransformerAfterReset(unittest.TestCase):
31+
"""Test cases for checking FrameTransformer values after reset."""
32+
33+
@classmethod
34+
def setUpClass(cls):
35+
# this flag is necessary to prevent a bug where the simulation gets stuck randomly when running the
36+
# test on many environments.
37+
carb_settings_iface = carb.settings.get_settings()
38+
carb_settings_iface.set_bool("/physics/cooking/ujitsoCollisionCooking", False)
39+
40+
def setUp(self):
41+
# create a temporary directory to store the test datasets
42+
self.temp_dir = tempfile.mkdtemp()
43+
44+
def tearDown(self):
45+
# delete the temporary directory after the test
46+
shutil.rmtree(self.temp_dir)
47+
48+
def test_action_state_reocrder_terms(self):
49+
"""Check FrameTransformer values after reset."""
50+
for task_name in ["Isaac-Stack-Cube-Franka-IK-Rel-v0"]:
51+
for device in ["cuda:0", "cpu"]:
52+
for num_envs in [1, 2]:
53+
with self.subTest(task_name=task_name, device=device):
54+
omni.usd.get_context().new_stage()
55+
56+
# parse configuration
57+
env_cfg = parse_env_cfg(task_name, device=device, num_envs=num_envs)
58+
59+
# create environment
60+
env = gym.make(task_name, cfg=env_cfg)
61+
62+
# disable control on stop
63+
env.unwrapped.sim._app_control_on_stop_handle = None # type: ignore
64+
65+
# reset environment
66+
obs = env.reset()[0]
67+
68+
# get the end effector position after the reset
69+
pre_reset_eef_pos = obs["policy"]["eef_pos"].clone()
70+
print(pre_reset_eef_pos)
71+
72+
# step the environment with idle actions
73+
idle_actions = torch.zeros(env.action_space.shape, device=env.unwrapped.device)
74+
obs = env.step(idle_actions)[0]
75+
76+
# get the end effector position after the first step
77+
post_reset_eef_pos = obs["policy"]["eef_pos"]
78+
print(post_reset_eef_pos)
79+
80+
# check if the end effector position is the same after the reset and the first step
81+
print(torch.all(torch.isclose(pre_reset_eef_pos, post_reset_eef_pos)))
82+
self.assertTrue(torch.all(torch.isclose(pre_reset_eef_pos, post_reset_eef_pos)))
83+
84+
# close the environment
85+
env.close()
86+
87+
88+
if __name__ == "__main__":
89+
run_tests()

0 commit comments

Comments
 (0)