Skip to content

Commit 59493b8

Browse files
author
David Hoeller
authored
Fixes the rendering logic inside the environment classes (#515)
Fixes #476 The parameter substeps in the Simulation config had no influence on the rendering frequency. Additionally, app.update was not properly called when initializing the stage due to the render method overload. This led to problems when modifying the render interval. - Merged physics stepping and rendering inside the step method in the simulation config. - Renamed substeps to render_interval in the simulation config. - Updated all the tasks ## Type of change - Breaking change (fix or feature that would cause existing functionality to not work as expected) ## 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 run all the tests with `./isaaclab.sh --test` and they pass - [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
1 parent 030d0bf commit 59493b8

File tree

43 files changed

+181
-103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+181
-103
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.17.13"
4+
version = "0.18.0"
55

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

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

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

4+
0.18.0 (2024-06-13)
5+
~~~~~~~~~~~~~~~~~~~~
6+
7+
Fixed
8+
^^^^^
9+
10+
* Fixed the rendering logic to render at the specified interval. Earlier, the substep parameter had no effect and rendering
11+
would happen once every env.step() when active.
12+
13+
Changed
14+
^^^^^^^
15+
16+
* Renamed :attr:`omni.isaac.lab.sim.SimulationCfg.substeps` to :attr:`omni.isaac.lab.sim.SimulationCfg.render_interval`.
17+
The render logic is now integrated in the decimation loop of the environment.
18+
19+
420
0.17.13 (2024-06-13)
521
~~~~~~~~~~~~~~~~~~~~
622

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from collections.abc import Sequence
1717
from typing import Any, ClassVar
1818

19+
import carb
1920
import omni.isaac.core.utils.torch as torch_utils
2021
import omni.kit.app
2122
from omni.isaac.version import get_version
@@ -91,11 +92,19 @@ def __init__(self, cfg: DirectRLEnvCfg, render_mode: str | None = None, **kwargs
9192
print("[INFO]: Base environment:")
9293
print(f"\tEnvironment device : {self.device}")
9394
print(f"\tPhysics step-size : {self.physics_dt}")
94-
print(f"\tRendering step-size : {self.physics_dt * self.cfg.sim.substeps}")
95+
print(f"\tRendering step-size : {self.physics_dt * self.cfg.sim.render_interval}")
9596
print(f"\tEnvironment step-size : {self.step_dt}")
9697
print(f"\tPhysics GPU pipeline : {self.cfg.sim.use_gpu_pipeline}")
9798
print(f"\tPhysics GPU simulation: {self.cfg.sim.physx.use_gpu}")
9899

100+
if self.cfg.sim.render_interval < self.cfg.decimation:
101+
msg = (
102+
f"The render interval ({self.cfg.sim.render_interval}) is smaller than the decimation "
103+
f"({self.cfg.decimation}). Multiple multiple render calls will happen for each environment step."
104+
"If this is not intended, set the render interval to be equal to the decimation."
105+
)
106+
carb.log_warn(msg)
107+
99108
# generate scene
100109
with Timer("[INFO]: Time taken for scene creation"):
101110
self.scene = InteractiveScene(self.cfg.scene)
@@ -146,6 +155,8 @@ def __init__(self, cfg: DirectRLEnvCfg, render_mode: str | None = None, **kwargs
146155
self.extras = {}
147156

148157
# initialize data and constants
158+
# -- counter for simulation steps
159+
self._sim_step_counter = 0
149160
# -- counter for curriculum
150161
self.common_step_counter = 0
151162
# -- init buffers
@@ -270,17 +281,18 @@ def step(self, action: torch.Tensor) -> VecEnvStepReturn:
270281
self._pre_physics_step(action)
271282
# perform physics stepping
272283
for _ in range(self.cfg.decimation):
284+
self._sim_step_counter += 1
273285
# set actions into buffers
274286
self._apply_action()
275287
# set actions into simulator
276288
self.scene.write_data_to_sim()
289+
render = self._sim_step_counter % self.cfg.sim.render_interval == 0 and (
290+
self.sim.has_gui() or self.sim.has_rtx_sensors()
291+
)
277292
# simulate
278-
self.sim.step(render=False)
293+
self.sim.step(render=render)
279294
# update buffers at sim dt
280295
self.scene.update(dt=self.physics_dt)
281-
# perform rendering if gui is enabled
282-
if self.sim.has_gui() or self.sim.has_rtx_sensors():
283-
self.sim.render()
284296

285297
# post-step:
286298
# -- update env counters (used for curriculum generation)

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,22 @@ def __init__(self, cfg: ManagerBasedEnvCfg):
8787
print("[INFO]: Base environment:")
8888
print(f"\tEnvironment device : {self.device}")
8989
print(f"\tPhysics step-size : {self.physics_dt}")
90-
print(f"\tRendering step-size : {self.physics_dt * self.cfg.sim.substeps}")
90+
print(f"\tRendering step-size : {self.physics_dt * self.cfg.sim.render_interval}")
9191
print(f"\tEnvironment step-size : {self.step_dt}")
9292
print(f"\tPhysics GPU pipeline : {self.cfg.sim.use_gpu_pipeline}")
9393
print(f"\tPhysics GPU simulation: {self.cfg.sim.physx.use_gpu}")
9494

95+
if self.cfg.sim.render_interval < self.cfg.decimation:
96+
msg = (
97+
f"The render interval ({self.cfg.sim.render_interval}) is smaller than the decimation "
98+
f"({self.cfg.decimation}). Multiple multiple render calls will happen for each environment step. "
99+
"If this is not intended, set the render interval to be equal to the decimation."
100+
)
101+
carb.log_warn(msg)
102+
103+
# counter for simulation steps
104+
self._sim_step_counter = 0
105+
95106
# generate scene
96107
with Timer("[INFO]: Time taken for scene creation"):
97108
self.scene = InteractiveScene(self.cfg.scene)
@@ -253,17 +264,18 @@ def step(self, action: torch.Tensor) -> tuple[VecEnvObs, dict]:
253264
self.action_manager.process_action(action)
254265
# perform physics stepping
255266
for _ in range(self.cfg.decimation):
267+
self._sim_step_counter += 1
256268
# set actions into buffers
257269
self.action_manager.apply_action()
258270
# set actions into simulator
259271
self.scene.write_data_to_sim()
272+
render = self._sim_step_counter % self.cfg.sim.render_interval == 0 and (
273+
self.sim.has_gui() or self.sim.has_rtx_sensors()
274+
)
260275
# simulate
261-
self.sim.step(render=False)
276+
self.sim.step(render=render)
262277
# update buffers at sim dt
263278
self.scene.update(dt=self.physics_dt)
264-
# perform rendering if gui is enabled
265-
if self.sim.has_gui() or self.sim.has_rtx_sensors():
266-
self.sim.render()
267279

268280
# post-step: step interval event
269281
if "interval" in self.event_manager.available_modes:

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,18 @@ def step(self, action: torch.Tensor) -> VecEnvStepReturn:
154154
self.action_manager.process_action(action)
155155
# perform physics stepping
156156
for _ in range(self.cfg.decimation):
157+
self._sim_step_counter += 1
157158
# set actions into buffers
158159
self.action_manager.apply_action()
159160
# set actions into simulator
160161
self.scene.write_data_to_sim()
162+
render = self._sim_step_counter % self.cfg.sim.render_interval == 0 and (
163+
self.sim.has_gui() or self.sim.has_rtx_sensors()
164+
)
161165
# simulate
162-
self.sim.step(render=False)
166+
self.sim.step(render=render)
163167
# update buffers at sim dt
164168
self.scene.update(dt=self.physics_dt)
165-
# perform rendering if gui is enabled
166-
if self.sim.has_gui() or self.sim.has_rtx_sensors():
167-
self.sim.render()
168169

169170
# post-step:
170171
# -- update env counters (used for curriculum generation)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class SimulationCfg:
168168
dt: float = 1.0 / 60.0
169169
"""The physics simulation time-step (in seconds). Default is 0.0167 seconds."""
170170

171-
substeps: int = 1
171+
render_interval: int = 1
172172
"""The number of physics simulation steps per rendering step. Default is 1."""
173173

174174
gravity: tuple[float, float, float] = (0.0, 0.0, -9.81)

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def __init__(self, cfg: SimulationCfg | None = None):
214214
super().__init__(
215215
stage_units_in_meters=1.0,
216216
physics_dt=self.cfg.dt,
217-
rendering_dt=self.cfg.dt * self.cfg.substeps,
217+
rendering_dt=self.cfg.dt * self.cfg.render_interval,
218218
backend="torch",
219219
sim_params=sim_params,
220220
physics_prim_path=self.cfg.physics_prim_path,
@@ -384,14 +384,14 @@ def reset(self, soft: bool = False):
384384
self.render()
385385

386386
def step(self, render: bool = True):
387-
"""Steps the physics simulation with the pre-defined time-step.
387+
"""Steps the simulation.
388388
389389
.. note::
390390
This function blocks if the timeline is paused. It only returns when the timeline is playing.
391391
392392
Args:
393393
render: Whether to render the scene after stepping the physics simulation.
394-
If set to False, the scene is not rendered and only the physics simulation is stepped.
394+
If set to False, the scene is not rendered and only the physics simulation is stepped.
395395
"""
396396
# check if the simulation timeline is paused. in that case keep stepping until it is playing
397397
if not self.is_playing():
@@ -467,6 +467,11 @@ async def reset_async(self, soft: bool = False):
467467

468468
def _init_stage(self, *args, **kwargs) -> Usd.Stage:
469469
_ = super()._init_stage(*args, **kwargs)
470+
# a stage update here is needed for the case when physics_dt != rendering_dt, otherwise the app crashes
471+
# when in headless mode
472+
self.set_setting("/app/player/playSimulations", False)
473+
self._app.update()
474+
self.set_setting("/app/player/playSimulations", True)
470475
# set additional physx parameters and bind material
471476
self._set_additional_physx_params()
472477
# load flatcache/fabric interface

source/extensions/omni.isaac.lab/test/assets/check_fixed_base_assets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def main():
144144
"""Main function."""
145145

146146
# Initialize the simulation context
147-
sim = sim_utils.SimulationContext(sim_utils.SimulationCfg(dt=0.01, substeps=1))
147+
sim = sim_utils.SimulationContext(sim_utils.SimulationCfg(dt=0.01))
148148
# Set main camera
149149
sim.set_camera_view(eye=[2.5, 2.5, 2.5], target=[0.0, 0.0, 0.0])
150150
# design scene

source/extensions/omni.isaac.lab/test/markers/check_markers_visibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def main():
128128
"""Main function."""
129129

130130
# Initialize the simulation context
131-
sim_cfg = sim_utils.SimulationCfg(dt=0.005, substeps=1)
131+
sim_cfg = sim_utils.SimulationCfg(dt=0.005)
132132
sim = sim_utils.SimulationContext(sim_cfg)
133133
# Set main camera
134134
sim.set_camera_view(eye=[3.5, 3.5, 3.5], target=[0.0, 0.0, 0.0])

source/extensions/omni.isaac.lab/test/sensors/test_contact_sensor.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

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

12-
HEADLESS = True
13-
1412
# launch omniverse app
15-
app_launcher = AppLauncher(headless=HEADLESS)
13+
app_launcher = AppLauncher(headless=True)
1614
simulation_app = app_launcher.app
1715

1816
"""Rest everything follows."""
@@ -467,7 +465,7 @@ def _perform_sim_step(self) -> None:
467465
# write data to simulation
468466
self.scene.write_data_to_sim()
469467
# simulate
470-
self.sim.step(render=not HEADLESS)
468+
self.sim.step(render=False)
471469
# update buffers at sim dt
472470
self.scene.update(dt=self.sim_dt)
473471

0 commit comments

Comments
 (0)