Skip to content

sample_kinematics_demo

main(random_selection=False, headless=False, short_exec=False)

Demo to use the raycasting-based sampler to load objects onTop and/or inside another Loads a cabinet, a microwave open on top of it, and two plates with apples on top, one inside and one on top of the cabinet Then loads a shelf and cracker boxes inside of it

Source code in omnigibson/examples/object_states/sample_kinematics_demo.py
def main(random_selection=False, headless=False, short_exec=False):
    """
    Demo to use the raycasting-based sampler to load objects onTop and/or inside another
    Loads a cabinet, a microwave open on top of it, and two plates with apples on top, one inside and one on top of the cabinet
    Then loads a shelf and cracker boxes inside of it
    """
    og.log.info(f"Demo {__file__}\n    " + "*" * 80 + "\n    Description:\n" + main.__doc__ + "*" * 80)

    # Create the scene config to load -- empty scene
    cfg = {
        "scene": {
            "type": "Scene",
        },
    }

    # Define objects we want to sample at runtime
    microwave_cfg = dict(
        type="DatasetObject",
        name="microwave",
        category="microwave",
        model="hjjxmi",
        bounding_box=[0.768, 0.512, 0.392],
    )

    cabinet_cfg = dict(
        type="DatasetObject",
        name="cabinet",
        category="bottom_cabinet",
        model="bamfsz",
        bounding_box=[1.075, 1.131, 1.355],
    )

    plate_cfgs = [
        dict(
            type="DatasetObject",
            name=f"plate{i}",
            category="plate",
            model="iawoof",
            bounding_box=th.tensor([0.20, 0.20, 0.05]),
        )
        for i in range(2)
    ]

    apple_cfgs = [
        dict(
            type="DatasetObject",
            name=f"apple{i}",
            category="apple",
            model="agveuv",
            bounding_box=[0.065, 0.065, 0.077],
        )
        for i in range(4)
    ]

    shelf_cfg = dict(
        type="DatasetObject",
        name=f"shelf",
        category="shelf",
        model="pkgbcp",
        bounding_box=th.tensor([1.0, 0.4, 2.0]),
    )

    box_cfgs = [
        dict(
            type="DatasetObject",
            name=f"box{i}",
            category="box_of_crackers",
            model="cmdigf",
            bounding_box=th.tensor([0.2, 0.05, 0.3]),
        )
        for i in range(5)
    ]

    # Compose objects cfg
    objects_cfg = [
        microwave_cfg,
        cabinet_cfg,
        *plate_cfgs,
        *apple_cfgs,
        shelf_cfg,
        *box_cfgs,
    ]

    # Update their spawn positions so they don't collide immediately
    for i, obj_cfg in enumerate(objects_cfg):
        obj_cfg["position"] = [100 + i, 100 + i, 100 + i]

    cfg["objects"] = objects_cfg

    # Create the environment
    env = og.Environment(configs=cfg)
    env.step([])

    # Sample microwave and boxes
    sample_boxes_on_shelf(env)
    sample_microwave_plates_apples(env)

    max_steps = 100 if short_exec else -1
    step = 0
    while step != max_steps:
        env.step(th.empty(0))
        step += 1

    # Always close environment at the end
    og.clear()