Skip to content

Commit a90ddb9

Browse files
nvcyckellyguo11
authored andcommitted
Adds support to record additional steps in record_demos.py (#224)
Adds support to record additional steps after task success is detected in record_demos.py. This helps record demos with sufficient lengths to be used for training. <!-- As you go through the list, delete the ones that are not applicable. --> - Bug fix (non-breaking change which fixes an issue) - [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 - [ ] 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 <!-- 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 -->
1 parent fe8c263 commit a90ddb9

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

scripts/tools/record_demos.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
--dataset_file File path to export recorded demos. (default: "./datasets/dataset.hdf5")
2020
--step_hz Environment stepping rate in Hz. (default: 30)
2121
--num_demos Number of demonstrations to record. (default: 0)
22+
--num_success_steps Number of continuous steps with task success for concluding a demo as successful. (default: 10)
2223
"""
2324

2425
"""Launch Isaac Sim Simulator first."""
@@ -39,6 +40,12 @@
3940
parser.add_argument(
4041
"--num_demos", type=int, default=0, help="Number of demonstrations to record. Set to 0 for infinite."
4142
)
43+
parser.add_argument(
44+
"--num_success_steps",
45+
type=int,
46+
default=10,
47+
help="Number of continuous steps with task success for concluding a demo as successful. Default is 10.",
48+
)
4249
# append AppLauncher cli args
4350
AppLauncher.add_app_launcher_args(parser)
4451
# parse the arguments
@@ -58,6 +65,8 @@
5865
import time
5966
import torch
6067

68+
import omni.log
69+
6170
from isaaclab.devices import Se3HandTracking, Se3Keyboard, Se3SpaceMouse
6271
from isaaclab.envs import ViewerCfg
6372
from isaaclab.envs.mdp.recorders.recorders_cfg import ActionStateRecorderManagerCfg
@@ -127,8 +136,19 @@ def main():
127136
env_cfg = parse_env_cfg(args_cli.task, device=args_cli.device, num_envs=1)
128137
env_cfg.env_name = args_cli.task
129138

130-
# modify configuration such that the environment runs indefinitely
131-
# until goal is reached
139+
# extract success checking function to invoke in the main loop
140+
success_term = None
141+
if hasattr(env_cfg.terminations, "success"):
142+
success_term = env_cfg.terminations.success
143+
env_cfg.terminations.success = None
144+
else:
145+
omni.log.warn(
146+
"No success termination term was found in the environment."
147+
" Will not be able to mark recorded demos as successful."
148+
)
149+
150+
# modify configuration such that the environment runs indefinitely until
151+
# the goal is reached or other termination conditions are met
132152
env_cfg.terminations.time_out = None
133153

134154
env_cfg.observations.policy.concatenate_terms = False
@@ -173,6 +193,7 @@ def reset_recording_instance():
173193

174194
# simulate environment -- run everything in inference mode
175195
current_recorded_demo_count = 0
196+
success_step_count = 0
176197
with contextlib.suppress(KeyboardInterrupt) and torch.inference_mode():
177198
while True:
178199
# get keyboard command
@@ -187,15 +208,29 @@ def reset_recording_instance():
187208
# perform action on environment
188209
env.step(actions)
189210

211+
if success_term is not None:
212+
if bool(success_term.func(env, **success_term.params)[0]):
213+
success_step_count += 1
214+
if success_step_count >= args_cli.num_success_steps:
215+
env.recorder_manager.record_pre_reset([0], force_export_or_skip=False)
216+
env.recorder_manager.set_success_to_episodes(
217+
[0], torch.tensor([[True]], dtype=torch.bool, device=env.unwrapped.device)
218+
)
219+
env.recorder_manager.export_episodes([0])
220+
should_reset_recording_instance = True
221+
else:
222+
success_step_count = 0
223+
190224
if should_reset_recording_instance:
191225
env.unwrapped.recorder_manager.reset()
192226
env.reset()
193227
should_reset_recording_instance = False
228+
success_step_count = 0
194229

195230
# print out the current demo count if it has changed
196231
if env.unwrapped.recorder_manager.exported_successful_episode_count > current_recorded_demo_count:
197232
current_recorded_demo_count = env.unwrapped.recorder_manager.exported_successful_episode_count
198-
print(f"Recorded {current_recorded_demo_count} demonstrations.")
233+
print(f"Recorded {current_recorded_demo_count} successful demonstrations.")
199234

200235
if (
201236
args_cli.num_demos > 0

source/isaaclab/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.33.6"
4+
version = "0.33.7"
55

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

source/isaaclab/docs/CHANGELOG.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Changelog
22
---------
33

4-
0.33.6 (2025-01-30)
4+
0.33.7 (2025-01-30)
55
~~~~~~~~~~~~~~~~~~~
66

77
Fixed
@@ -12,7 +12,7 @@ Fixed
1212
to the event being triggered at the wrong time after the reset.
1313

1414

15-
0.33.5 (2025-01-17)
15+
0.33.6 (2025-01-17)
1616
~~~~~~~~~~~~~~~~~~~
1717

1818
Fixed
@@ -42,7 +42,7 @@ Fixed
4242
the :class:`omni.isaac.lab.assets.RigidObjectCollection` class.
4343

4444

45-
0.33.4 (2025-01-14)
45+
0.33.5 (2025-01-14)
4646
~~~~~~~~~~~~~~~~~~~
4747

4848
Fixed
@@ -51,6 +51,16 @@ Fixed
5151
* Fixed the respawn of only wrong object samples in :func:`repeated_objects_terrain` of :mod:`omni.isaac.lab.terrains.trimesh` module. Previously, the function was respawning all objects in the scene instead of only the wrong object samples, which in worst case could lead to infinite respawn loop.
5252

5353

54+
0.33.4 (2025-01-10)
55+
~~~~~~~~~~~~~~~~~~~
56+
57+
Changed
58+
^^^^^^^
59+
60+
* Added an optional parameter in the :meth:`record_pre_reset` method in
61+
:class:`~isaaclab.managers.RecorderManager` to override the export config upon invoking.
62+
63+
5464
0.33.3 (2025-01-08)
5565
~~~~~~~~~~~~~~~~~~~
5666

source/isaaclab/isaaclab/managers/recorder_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def record_post_step(self) -> None:
359359
key, value = term.record_post_step()
360360
self.add_to_episodes(key, value)
361361

362-
def record_pre_reset(self, env_ids: Sequence[int] | None) -> None:
362+
def record_pre_reset(self, env_ids: Sequence[int] | None, force_export_or_skip=None) -> None:
363363
"""Trigger recorder terms for pre-reset functions.
364364
365365
Args:
@@ -385,7 +385,7 @@ def record_pre_reset(self, env_ids: Sequence[int] | None) -> None:
385385
success_results |= self._env.termination_manager.get_term("success")[env_ids]
386386
self.set_success_to_episodes(env_ids, success_results)
387387

388-
if self.cfg.export_in_record_pre_reset:
388+
if force_export_or_skip or (force_export_or_skip is None and self.cfg.export_in_record_pre_reset):
389389
self.export_episodes(env_ids)
390390

391391
def record_post_reset(self, env_ids: Sequence[int] | None) -> None:

0 commit comments

Comments
 (0)