isaac-sim / IsaacLab

Unified framework for robot learning built on NVIDIA Isaac Sim
https://isaac-sim.github.io/IsaacLab
Other
2.12k stars 859 forks source link

[Question] How can I add several assets in the InteractiveSceneCfg with a For Loop? #880

Open jbt-cmu opened 2 months ago

jbt-cmu commented 2 months ago

Question

I would like to add several object assets like so:

    # object_1 = AssetBaseCfg(
    #     prim_path="{ENV_REGEX_NS}/Object_1",
    #     spawn=sim_utils.CuboidCfg(size=[0.3, 0.3, 0.3], visual_material=sim_utils.PreviewSurfaceCfg(diffuse_color=(0.0, 0.9, 0.0))),
    #     init_state=AssetBaseCfg.InitialStateCfg(pos=[3.5, 4.5, 0.95]))

    # object_2 = AssetBaseCfg(
    #     prim_path="{ENV_REGEX_NS}/Object_2",
    #     spawn=sim_utils.CuboidCfg(size=[0.3, 0.3, 0.3], visual_material=sim_utils.PreviewSurfaceCfg(diffuse_color=(0.0, 0.9, 0.0))),
    #     init_state=AssetBaseCfg.InitialStateCfg(pos=[4.3, 4.5, 0.95]))

    # object_3 = AssetBaseCfg(
    #     prim_path="{ENV_REGEX_NS}/Object_3",
    #     spawn=sim_utils.CuboidCfg(size=[0.3, 0.3, 0.3], visual_material=sim_utils.PreviewSurfaceCfg(diffuse_color=(0.0, 0.9, 0.0))),
    #     init_state=AssetBaseCfg.InitialStateCfg(pos=[4.8, 4.5, 0.95]))

using a for loop, like so:

objects = []

# Base position values
base_x = 3.5
y_pos = 4.5
z_pos = 0.95

# Create 9 objects with an offset of 0.3 meters on the x-axis
for i in range(9):
    obj = AssetBaseCfg(
        prim_path=f"/World/Object_{i+1}",  # Replace "/World" with your desired namespace
        spawn=sim_utils.CuboidCfg(size=[0.3, 0.3, 0.3], visual_material=sim_utils.PreviewSurfaceCfg(diffuse_color=(0.0, 0.9, 0.0))),
        init_state=AssetBaseCfg.InitialStateCfg(pos=[base_x + i*0.3, y_pos, z_pos])
    )
    objects.append(obj)

However, this provides the following error:

Traceback (most recent call last):
  File "C:\Users\Owner\Documents\GitHub\IsaacLab\source\standalone\demos\ada\ada.py", line 349, in <module>
    main()
  File "C:\Users\Owner\Documents\GitHub\IsaacLab\source\standalone\demos\ada\ada.py", line 326, in main
    env = CameraAgentEnv()
  File "C:\Users\Owner\Documents\GitHub\IsaacLab\source\standalone\demos\ada\ada.py", line 234, in __init__
    self.scene = self.create_scene()
  File "C:\Users\Owner\Documents\GitHub\IsaacLab\source\standalone\demos\ada\ada.py", line 256, in create_scene
    scene = InteractiveScene(scene_cfg)
  File "c:\users\owner\documents\github\isaaclab\source\extensions\omni.isaac.lab\omni\isaac\lab\scene\interactive_scene.py", line 145, in __init__
    self._add_entities_from_cfg()
  File "c:\users\owner\documents\github\isaaclab\source\extensions\omni.isaac.lab\omni\isaac\lab\scene\interactive_scene.py", line 444, in _add_entities_from_cfg
    asset_cfg.prim_path = asset_cfg.prim_path.format(ENV_REGEX_NS=self.env_regex_ns)
AttributeError: 'list' object has no attribute 'prim_path'

How can I do this properly?

Mayankm96 commented 2 months ago

You can potentially do this operation inside the __init__ of the InteractiveSceneCfg.