Skip to content

Commit 2887955

Browse files
author
Yize Wang
committed
Adapt quadcopter.py For Dual Backends
Signed-off-by: Yize Wang <yizew@nvidia.com>
1 parent c97bedd commit 2887955

3 files changed

Lines changed: 47 additions & 10 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
2+
# All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
"""Default physics backend presets for the demo scripts."""
7+
8+
from isaaclab_newton.physics import NewtonCfg
9+
from isaaclab_physx.physics import PhysxCfg
10+
11+
from isaaclab.utils.configclass import configclass
12+
from isaaclab_tasks.utils.hydra import PresetCfg
13+
14+
15+
@configclass
16+
class DefaultPhysicsCfgs(PresetCfg):
17+
"""Default physics backend presets for the demo scripts."""
18+
19+
default: PhysxCfg = PhysxCfg()
20+
physx: PhysxCfg = PhysxCfg()
21+
newton_mjwarp: NewtonCfg = NewtonCfg()

scripts/demos/quadcopter.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,29 @@
1111
# Usage
1212
./isaaclab.sh -p scripts/demos/quadcopter.py
1313
14+
# Run with the Newton backend
15+
./isaaclab.sh -p scripts/demos/quadcopter.py physics=newton_mjwarp -visualizer=newton
16+
1417
"""
1518

16-
"""Launch Isaac Sim Simulator first."""
19+
"""Parse command line arguments."""
1720

1821
import argparse
19-
22+
import sys
2023
from isaaclab.app import AppLauncher
2124

25+
from isaaclab_tasks.utils import add_launcher_args,fold_preset_tokens,launch_simulation,setup_preset_cli
26+
2227
# add argparse arguments
2328
parser = argparse.ArgumentParser(description="This script demonstrates how to simulate a quadcopter.")
2429
# append AppLauncher cli args
25-
AppLauncher.add_app_launcher_args(parser)
30+
add_launcher_args(parser)
2631
# demos should open Kit visualizer by default
2732
parser.set_defaults(visualizer=["kit"])
2833
# parse the arguments
29-
args_cli = parser.parse_args()
34+
args_cli, hydra_args = setup_preset_cli(parser)
35+
sys.argv = [sys.argv[0]] + fold_preset_tokens(hydra_args)
36+
3037

3138
# launch omniverse app
3239
app_launcher = AppLauncher(args_cli)
@@ -39,18 +46,24 @@
3946
import isaaclab.sim as sim_utils
4047
from isaaclab.assets import Articulation
4148
from isaaclab.sim import SimulationContext
49+
from isaaclab_tasks.utils.hydra import collect_presets, parse_overrides, resolve_presets
50+
from default_physics_cfg import DefaultPhysicsCfgs
4251

4352
##
4453
# Pre-defined configs
4554
##
4655
from isaaclab_assets import CRAZYFLIE_CFG # isort:skip
4756

4857

49-
def main():
50-
"""Main function."""
51-
# Load kit helper
52-
sim_cfg = sim_utils.SimulationCfg(dt=0.005, device=args_cli.device)
58+
def main() -> None:
59+
"""Run the quadcopter demo."""
60+
sim_cfg = sim_utils.SimulationCfg(dt=0.005, device=args_cli.device, physics=DefaultPhysicsCfgs())
61+
global_presets, preset_sel, *_ = parse_overrides(sys.argv[1:], {"env": collect_presets(sim_cfg)})
62+
sim_cfg = resolve_presets(sim_cfg, {*global_presets, *(name for _, _, name in preset_sel)})
63+
5364
sim = SimulationContext(sim_cfg)
65+
# launch_simulation(sim, args_cli)
66+
5467
# Set main camera
5568
sim.set_camera_view(eye=[0.5, 0.5, 1.0], target=[0.0, 0.0, 0.5])
5669

@@ -74,7 +87,7 @@ def main():
7487

7588
# Fetch relevant parameters to make the quadcopter hover in place
7689
prop_body_ids = robot.find_bodies("m.*_prop")[0]
77-
robot_mass = robot.root_view.get_masses().sum()
90+
robot_mass = robot.data.body_mass.torch[0].sum()
7891
gravity = torch.tensor(sim.cfg.gravity, device=sim.device).norm()
7992

8093
# Now we are ready!
@@ -85,7 +98,7 @@ def main():
8598
sim_time = 0.0
8699
count = 0
87100
# Simulate physics
88-
while simulation_app.is_running():
101+
while sim.has_alive_visualizers():
89102
# reset
90103
if count % 2000 == 0:
91104
# reset counters

source/isaaclab/isaaclab/sim/simulation_context.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,9 @@ def _predicate(prim: Usd.Prim) -> bool:
898898

899899
sim_utils.clear_stage(predicate=_predicate)
900900

901+
def has_alive_visualizers(self) -> bool:
902+
"""Return True if there are any alive visualizers."""
903+
return any(viz.is_running() and not viz.is_closed for viz in self._visualizers)
901904

902905
@contextmanager
903906
def build_simulation_context(

0 commit comments

Comments
 (0)