-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
255 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
# Copyright (c) 2022-2024, The Isaac Lab Project Developers. | ||
# All rights reserved. | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
"""This script demonstrates how to spawn multiple objects in multiple environments. | ||
.. code-block:: bash | ||
# Usage | ||
./isaaclab.sh -p source/standalone/demos/multi_usd_asset.py --num_envs 2048 | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
"""Launch Isaac Sim Simulator first.""" | ||
|
||
|
||
import argparse | ||
|
||
from omni.isaac.lab.app import AppLauncher | ||
|
||
# add argparse arguments | ||
parser = argparse.ArgumentParser(description="Demo on spawning different objects in multiple environments.") | ||
parser.add_argument("--num_envs", type=int, default=1024, help="Number of environments to spawn.") | ||
# append AppLauncher cli args | ||
AppLauncher.add_app_launcher_args(parser) | ||
# parse the arguments | ||
args_cli = parser.parse_args() | ||
|
||
# launch omniverse app | ||
app_launcher = AppLauncher(args_cli) | ||
simulation_app = app_launcher.app | ||
|
||
"""Rest everything follows.""" | ||
|
||
import omni.isaac.lab.sim as sim_utils | ||
from omni.isaac.lab.assets import AssetBaseCfg, ArticulationCfg | ||
from omni.isaac.lab.scene import InteractiveScene, InteractiveSceneCfg | ||
from omni.isaac.lab.sim import SimulationContext | ||
from omni.isaac.lab.utils import Timer, configclass | ||
from omni.isaac.lab.utils.assets import ISAACLAB_NUCLEUS_DIR | ||
from omni.isaac.lab.actuators import ActuatorNetLSTMCfg | ||
|
||
|
||
## | ||
# Scene Configuration | ||
## | ||
|
||
|
||
@configclass | ||
class MultiObjectSceneCfg(InteractiveSceneCfg): | ||
"""Configuration for a multi-object scene.""" | ||
|
||
# ground plane | ||
ground = AssetBaseCfg(prim_path="/World/defaultGroundPlane", spawn=sim_utils.GroundPlaneCfg()) | ||
|
||
# lights | ||
dome_light = AssetBaseCfg( | ||
prim_path="/World/Light", spawn=sim_utils.DomeLightCfg(intensity=3000.0, color=(0.75, 0.75, 0.75)) | ||
) | ||
|
||
# articulation | ||
robot: ArticulationCfg = ArticulationCfg( | ||
prim_path="/World/envs/env_.*/Robot", | ||
spawn=sim_utils.MultiUsdFileCfg( | ||
usd_path=[ | ||
f"{ISAACLAB_NUCLEUS_DIR}/Robots/ANYbotics/ANYmal-C/anymal_c.usd", | ||
f"{ISAACLAB_NUCLEUS_DIR}/Robots/ANYbotics/ANYmal-D/anymal_d.usd", | ||
], | ||
random_choice=True, | ||
rigid_props=sim_utils.RigidBodyPropertiesCfg( | ||
disable_gravity=False, | ||
retain_accelerations=False, | ||
linear_damping=0.0, | ||
angular_damping=0.0, | ||
max_linear_velocity=1000.0, | ||
max_angular_velocity=1000.0, | ||
max_depenetration_velocity=1.0, | ||
), | ||
articulation_props=sim_utils.ArticulationRootPropertiesCfg( | ||
enabled_self_collisions=True, solver_position_iteration_count=4, solver_velocity_iteration_count=0 | ||
), | ||
activate_contact_sensors=True, | ||
), | ||
init_state=ArticulationCfg.InitialStateCfg( | ||
pos=(0.0, 0.0, 0.6), | ||
joint_pos={ | ||
".*HAA": 0.0, # all HAA | ||
".*F_HFE": 0.4, # both front HFE | ||
".*H_HFE": -0.4, # both hind HFE | ||
".*F_KFE": -0.8, # both front KFE | ||
".*H_KFE": 0.8, # both hind KFE | ||
}, | ||
), | ||
actuators={ | ||
"legs": ActuatorNetLSTMCfg( | ||
joint_names_expr=[".*HAA", ".*HFE", ".*KFE"], | ||
network_file=f"{ISAACLAB_NUCLEUS_DIR}/ActuatorNets/ANYbotics/anydrive_3_lstm_jit.pt", | ||
saturation_effort=120.0, | ||
effort_limit=80.0, | ||
velocity_limit=7.5, | ||
) | ||
}, | ||
) | ||
|
||
|
||
## | ||
# Simulation Loop | ||
## | ||
|
||
|
||
def run_simulator(sim: SimulationContext, scene: InteractiveScene): | ||
"""Runs the simulation loop.""" | ||
# Extract scene entities | ||
# note: we only do this here for readability. | ||
robot = scene["robot"] | ||
# Define simulation stepping | ||
sim_dt = sim.get_physics_dt() | ||
count = 0 | ||
# Simulation loop | ||
while simulation_app.is_running(): | ||
# Reset | ||
if count % 500 == 0: | ||
# reset counter | ||
count = 0 | ||
# reset the scene entities | ||
# root state | ||
root_state = robot.data.default_root_state.clone() | ||
root_state[:, :3] += scene.env_origins | ||
robot.write_root_state_to_sim(root_state) | ||
# clear internal buffers | ||
scene.reset() | ||
print("[INFO]: Resetting robot state...") | ||
# Write data to sim | ||
scene.write_data_to_sim() | ||
# Perform step | ||
sim.step() | ||
# Increment counter | ||
count += 1 | ||
# Update buffers | ||
scene.update(sim_dt) | ||
|
||
|
||
def main(): | ||
"""Main function.""" | ||
# Load kit helper | ||
sim_cfg = sim_utils.SimulationCfg(device=args_cli.device) | ||
sim = SimulationContext(sim_cfg) | ||
# Set main camera | ||
sim.set_camera_view([2.5, 0.0, 4.0], [0.0, 0.0, 2.0]) | ||
|
||
# Design scene | ||
scene_cfg = MultiObjectSceneCfg(num_envs=args_cli.num_envs, env_spacing=1.5, replicate_physics=False) | ||
with Timer("[INFO] Time to create scene: "): | ||
scene = InteractiveScene(scene_cfg) | ||
|
||
# Play the simulator | ||
sim.reset() | ||
# Now we are ready! | ||
print("[INFO]: Setup complete...") | ||
# Run the simulator | ||
run_simulator(sim, scene) | ||
|
||
|
||
if __name__ == "__main__": | ||
# run the main execution | ||
main() | ||
# close sim app | ||
simulation_app.close() |