[Question] Randomize number of spawned objects on reset #2834
Unanswered
hritik-roy-chowdhury
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Thank you for posting this. It is a great question for our Discussions section. I'll move the post there for follow up. Here is a summary to consider. To randomize the number of spawned objects, pre-spawn a fixed maximum number of cubes and dynamically activate/deactivate subsets via events. This avoids adding/removing objects during simulation (see #1783) but achieves variability through state toggling. Implementation ExampleScene Configuration (pre-spawn maximum cubes): from omni.isaac.lab.assets import RigidObjectCfg
from omni.isaac.lab.managers import SceneEntityCfg
MAX_CUBES = 10 # Maximum cubes per env
cube_cfg = RigidObjectCfg(
prim_path="/World/envs/env_.*/Cube_.*",
spawn=usd_utils.FileUsdCfg(usd_path="/path/to/cube.usd"),
init_state=RigidObjectCfg.InitialStateCfg(pos=(0.0, 0.0, 0.1)),
)
scene_cfg = {"cubes": SceneEntityCfg(cube_cfg, count=MAX_CUBES)} Event Configuration (randomize active cubes per reset): from omni.isaac.lab.managers import EventTermCfg
import torch
def randomize_cube_count(env):
# Randomly select active cubes (0 to MAX_CUBES)
num_active = torch.randint(0, MAX_CUBES+1, (env.num_envs,))
for env_idx in range(env.num_envs):
for cube_idx in range(MAX_CUBES):
# Toggle visibility/collision based on active count
active = cube_idx < num_active[env_idx]
env.scene["cubes"].set_visibility(env_idx, cube_idx, active)
env.scene["cubes"].set_collision_enabled(env_idx, cube_idx, active)
env_cfg.events.randomize_count = EventTermCfg(
func=randomize_cube_count,
mode="reset",
params={}
) Key Details
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to randomize the number of, e.g, spawned cubes on a table on event reset? For instance, using the manager-based workflow, typically the first step is to initialize the configurations and spawn methods of each entity in the scene in a separate scene configuration class. However, only these entities are ever interacted with and from what I can see, it is not possible to replicate them.
Beta Was this translation helpful? Give feedback.
All reactions