Skip to content

Bug: grasp_sim.py always loads mug.obj even when YAML specifies another object #2

@adalmases-sdk

Description

@adalmases-sdk

While running grasp_sim.py with a custom grasp file (e.g. banana.yaml), the simulator still loads mug.obj.
After debugging, I found that ObjectConfig.from_isaac_grasp_dict() overwrites the YAML object_file with the default CLI argument (objects/mug.obj) even when --object_file isn’t explicitly passed.

I solved it by modifying the scripts/graspgen/object.py file:

 def from_isaac_grasp_dict(cls, grasp_dict, grasp_file_args=None):
        # Initialize default values
        object_file = default_object_file
        object_scale = default_object_scale
        obj2usd_use_existing_usd = default_obj2usd_use_existing_usd
        obj2usd_collision_approximation = default_obj2usd_collision_approximation
        obj2usd_friction = default_obj2usd_friction

        # First, apply values from grasp file (lowest priority)
        if 'object_file' in grasp_dict:
            object_file = grasp_dict["object_file"]
        if 'object_scale' in grasp_dict:
            object_scale = grasp_dict["object_scale"]

        if 'obj2usd_use_existing_usd' in grasp_dict:
            obj2usd_use_existing_usd = grasp_dict["obj2usd_use_existing_usd"]
        if 'obj2usd_collision_approximation' in grasp_dict:
            obj2usd_collision_approximation = grasp_dict["obj2usd_collision_approximation"]
        if 'obj2usd_friction' in grasp_dict:
            obj2usd_friction = grasp_dict["obj2usd_friction"]

        # Then, override with command line arguments *only if explicitly set* (highest priority) 
        if grasp_file_args is not None:
            def arg_explicit(attr, default_val):
                """Return True if CLI arg differs from its parser default."""
                return hasattr(grasp_file_args, attr) and getattr(grasp_file_args, attr) != default_val

            if arg_explicit("object_file", default_object_file):
                object_file = grasp_file_args.object_file
            if arg_explicit("object_scale", default_object_scale):
                object_scale = grasp_file_args.object_scale
            if arg_explicit("obj2usd_use_existing_usd", default_obj2usd_use_existing_usd):
                obj2usd_use_existing_usd = grasp_file_args.obj2usd_use_existing_usd
            if arg_explicit("obj2usd_collision_approximation", default_obj2usd_collision_approximation):
                obj2usd_collision_approximation = grasp_file_args.obj2usd_collision_approximation
            if arg_explicit("obj2usd_friction", default_obj2usd_friction):
                obj2usd_friction = grasp_file_args.obj2usd_friction

        return cls(object_file=object_file, object_scale=object_scale,
                   obj2usd_use_existing_usd=obj2usd_use_existing_usd,
                   obj2usd_collision_approximation=obj2usd_collision_approximation,
                   obj2usd_friction=obj2usd_friction)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions