Scaling of pallet randomization in warehouse stage doesn't work in rep.modify.pose in Isaac Sim Script Editor interactive

I am using Isaac Sim 2022.2.1 Script Editor interactive SDG using Replicator → Start. I have this code however changing the scale from 0.01 to 0.001` didn’t help in the pallets being inside the warehouse. specifically this section of code:

def randomize_pallets():
    pallets = rep.create.from_usd(PALLET_URL, semantics=[('class', 'pallet')], count=5)
    with pallets:
        rep.physics.collider()
        rep.modify.pose(
            scale=0.01,
            position=rep.distribution.uniform((min_x + margin, min_y + margin, 0), (max_x - margin, max_y - margin, 0)),
            rotation=rep.distribution.uniform((0, 0, -90), (0, 0, 90))
        )
    return pallets

Could you please guide what part is wrong and how it should be fixed?

# problem with scaling of pallets (pallets encompass the warehouse as of 09.07.2023)
import omni.usd

import omni.replicator.core as rep
from pxr import Usd, UsdGeom, Gf
from datetime import datetime



import numpy as np

PALLET_URL = "omniverse://localhost/NVIDIA/Assets/ArchVis/Industrial/Pallets/Pallet_B1.usd"
ENV_URL ="omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/Isaac/Samples/Replicator/Stage/full_warehouse_worker_and_anim_cameras.usd"



omni.usd.get_context().open_stage(ENV_URL)

stage = omni.usd.get_context().get_stage()



#floor_prims = [x.GetPath() for x in stage.Traverse() if "SM_floor" in x.GetName() and prims_utils.get_prim_type_name(x.GetPath()) == "Xform"]
floor_prims_paths = [x.GetPath() for x in stage.Traverse() if "SM_floor" in x.GetName() ]



floor_prims = []
for floor_prim_path in floor_prims_paths:
    floor_prims.append(omni.usd.get_prim_at_path(floor_prim_path))
    

#bb_cache = bounds_utils.create_bbox_cache()

#combined_range_arr = bounds_utils.compute_combined_aabb(bb_cache, prim_paths=floor_prims)

#min_x, min_y, min_z, max_x, max_y, max_z = combined_range_arr

# bbox = omni.usd.get_context().compute_path_world_bounding_box(floor_prims[0])
# min_x, min_y, min_z, max_x, max_y, max_z = bbox

# print("bbox is: ", bbox)


def compute_bbox_with_cache(cache: UsdGeom.BBoxCache, prim: Usd.Prim) -> Gf.Range3d:
    """
    Compute Bounding Box using ComputeWorldBound at UsdGeom.BBoxCache. More efficient if used multiple times.
    See https://graphics.pixar.com/usd/dev/api/class_usd_geom_b_box_cache.html

    Args:
        cache: A cached, i.e. `UsdGeom.BBoxCache(Usd.TimeCode.Default(), ['default', 'render'])`
        prim: A prim to compute the bounding box.
    Returns:
        A range (i.e. bounding box), see more at: https://graphics.pixar.com/usd/release/api/class_gf_range3d.html

    """
    bound = cache.ComputeWorldBound(prim)
    bound_range = bound.ComputeAlignedBox()
    return bound_range


bbcache = UsdGeom.BBoxCache(Usd.TimeCode.Default(), ["default", "render"])

bb = compute_bbox_with_cache(bbcache, floor_prims[0])

max_x, max_y, max_z = bb.GetMax()

min_x_arr = []
min_y_arr = []
min_z_arr = []
max_x_arr = []
max_y_arr = []
max_z_arr = []

for floor_prim in floor_prims:
    tmp_bb = compute_bbox_with_cache(bbcache, floor_prim)
    # tmp_corners = tmp_bb.GetCorner
    tmp_min_x, tmp_min_y, tmp_min_z = tmp_bb.GetMin()
    tmp_max_x, tmp_max_y, tmp_max_z = tmp_bb.GetMax()
    min_x_arr.append(tmp_min_x)
    min_y_arr.append(tmp_min_y)
    min_z_arr.append(tmp_min_z)
    max_x_arr.append(tmp_max_x)
    max_y_arr.append(tmp_max_y)
    max_z_arr.append(tmp_max_z)
    

min_x = min(min_x_arr)
min_y = min(min_y_arr)
min_z = min(min_z_arr)

max_x = max(max_x_arr)
max_y = max(max_y_arr)
max_z = max(max_z_arr)




margin = 3


def randomize_pallets():
    pallets = rep.create.from_usd(PALLET_URL, semantics=[('class', 'pallet')], count=5)
    with pallets:
        rep.physics.collider()
        rep.modify.pose(
            scale=0.01,
            position=rep.distribution.uniform((min_x + margin, min_y + margin, 0), (max_x - margin, max_y - margin, 0)),
            rotation=rep.distribution.uniform((0, 0, -90), (0, 0, 90))
        )
    return pallets

# Register randomization

rep.randomizer.register(randomize_pallets)






# Setup camera and attach it to render product
camera = rep.create.camera(
    focus_distance=800,
    focal_length=40
    # f_stop=0.5,
    # f_stop=500,
    #focal_length=613.634
)
render_product = rep.create.render_product(camera, resolution=(1024, 1024))


timestamp = datetime.now().strftime("%Y_%m_%d-%I_%M_%S_%p")
# Initialize and attach writer
writer = rep.WriterRegistry.get("BasicWriter")
writer.initialize(output_dir="/home/mona/Desktop/Isaac_Sim_Dummy_Out/scattered_pallets_warehouse/" + timestamp , rgb=True, bounding_box_2d_tight=True)
writer.attach([render_product])

with rep.trigger.on_frame(num_frames=50):
    pallets = rep.randomizer.randomize_pallets()
    print('pallets is: ', pallets)
    print('pallets type is: ', type(pallets))
    with camera:
        rep.modify.pose(position=rep.distribution.uniform((min_x + margin, min_y + margin, 4), (max_x - margin, max_y - margin, 7)),
                        look_at=pallets)

As you see here, the pallet is encompassing the warehouse:

Hi there,

it seems I have issues running your script on my local machine, could you provide a more succinct version with the issue you are having?

This might solve the issue though, can you try using the scale as a 3d tuple instead of a scalar? scale=0.01scale=(0.01, 0.01, 0.01)

Best,
Andrei

1 Like

Thank you. The change you suggested fixed the problem.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.