| |
| |
| |
| |
|
|
| """This script demonstrates how to use the interactive scene interface to setup a scene with multiple prims. |
| |
| .. code-block:: bash |
| |
| # Usage |
| ./isaaclab.sh -p scripts/tutorials/02_scene/create_scene.py --num_envs 32 |
| |
| """ |
|
|
| """Launch Isaac Sim Simulator first.""" |
|
|
|
|
| import argparse |
|
|
| from isaaclab.app import AppLauncher |
|
|
| |
| parser = argparse.ArgumentParser(description="Tutorial on using the interactive scene interface.") |
| parser.add_argument("--num_envs", type=int, default=2, help="Number of environments to spawn.") |
| |
| AppLauncher.add_app_launcher_args(parser) |
| |
| args_cli = parser.parse_args() |
|
|
| |
| app_launcher = AppLauncher(args_cli) |
| simulation_app = app_launcher.app |
|
|
| """Rest everything follows.""" |
|
|
| import torch |
|
|
| import isaaclab.sim as sim_utils |
| from isaaclab.assets import ArticulationCfg, AssetBaseCfg |
| from isaaclab.scene import InteractiveScene, InteractiveSceneCfg |
| from isaaclab.sim import SimulationContext |
| from isaaclab.utils import configclass |
|
|
| |
| |
| |
| from isaaclab_assets import CARTPOLE_CFG |
|
|
|
|
| @configclass |
| class CartpoleSceneCfg(InteractiveSceneCfg): |
| """Configuration for a cart-pole scene.""" |
|
|
| |
| ground = AssetBaseCfg(prim_path="/World/defaultGroundPlane", spawn=sim_utils.GroundPlaneCfg()) |
|
|
| |
| dome_light = AssetBaseCfg( |
| prim_path="/World/Light", spawn=sim_utils.DomeLightCfg(intensity=3000.0, color=(0.75, 0.75, 0.75)) |
| ) |
|
|
| |
| cartpole: ArticulationCfg = CARTPOLE_CFG.replace(prim_path="{ENV_REGEX_NS}/Robot") |
|
|
|
|
| def run_simulator(sim: sim_utils.SimulationContext, scene: InteractiveScene): |
| """Runs the simulation loop.""" |
| |
| |
| robot = scene["cartpole"] |
| |
| sim_dt = sim.get_physics_dt() |
| count = 0 |
| |
| while simulation_app.is_running(): |
| |
| if count % 500 == 0: |
| |
| count = 0 |
| |
| |
| |
| |
| root_state = robot.data.default_root_state.clone() |
| root_state[:, :3] += scene.env_origins |
| robot.write_root_pose_to_sim(root_state[:, :7]) |
| robot.write_root_velocity_to_sim(root_state[:, 7:]) |
| |
| joint_pos, joint_vel = robot.data.default_joint_pos.clone(), robot.data.default_joint_vel.clone() |
| joint_pos += torch.rand_like(joint_pos) * 0.1 |
| robot.write_joint_state_to_sim(joint_pos, joint_vel) |
| |
| scene.reset() |
| print("[INFO]: Resetting robot state...") |
| |
| |
| efforts = torch.randn_like(robot.data.joint_pos) * 5.0 |
| |
| robot.set_joint_effort_target(efforts) |
| |
| scene.write_data_to_sim() |
| |
| sim.step() |
| |
| count += 1 |
| |
| scene.update(sim_dt) |
|
|
|
|
| def main(): |
| """Main function.""" |
| |
| sim_cfg = sim_utils.SimulationCfg(device=args_cli.device) |
| sim = SimulationContext(sim_cfg) |
| |
| sim.set_camera_view([2.5, 0.0, 4.0], [0.0, 0.0, 2.0]) |
| |
| scene_cfg = CartpoleSceneCfg(num_envs=args_cli.num_envs, env_spacing=2.0) |
| scene = InteractiveScene(scene_cfg) |
| |
| sim.reset() |
| |
| print("[INFO]: Setup complete...") |
| |
| run_simulator(sim, scene) |
|
|
|
|
| if __name__ == "__main__": |
| |
| main() |
| |
| simulation_app.close() |
|
|