How to change articulation root by python code script

Hi,

I am working on a code that uses the URDF Importer to load a robot into the stage. Below is the code I am using.

class HuskyURDFImporter:

    def __init__(self, world, urdf_path=HUSKY_URDF_PATH):
        self.world = world
        self.urdf_path = urdf_path
        self.robot_prim_path = None
    
    def _load_robot_urdf(self):
        """
        Load the robot URDF file and configure the importing settings.
        Wrapping the robot prim with Robot class for applying Articulation control
        """
        _, import_config = execute("URDFCreateImportConfig")
        import_config.merge_fixed_joints = False
        import_config.fix_base = False
        import_config.make_default_prim = False
        import_config.create_physics_scene = True

        # Import Robot URDF as USD
        _, robot_prim_path = execute("URDFParseAndImportFile",
                                     urdf_path = self.urdf_path, 
                                     import_config=import_config)
        
        stage = omni.usd.get_context().get_stage()
        scene = UsdPhysics.Scene.Define(stage, Sdf.Path("/physicsScene"))
        scene.CreateGravityDirectionAttr().Set(Gf.Vec3f(0.0, 0.0, -1.0))
        scene.CreateGravityMagnitudeAttr().Set(9.81)

    
    def _set_robot_drives_config(self):
        stage = omni.usd.get_context().get_stage()

        PhysxSchema.PhysxArticulationAPI.Get(stage, "/World/husky").CreateSolverPositionIterationCountAttr(64)
        PhysxSchema.PhysxArticulationAPI.Get(stage, "/World/husky").CreateSolverVelocityIterationCountAttr(64)

        # Set robot joint properties
        joint_1 = UsdPhysics.DriveAPI.Get(stage.GetPrimAtPath("/World/husky/base_link/front_left_wheel"), "angular")
        joint_2 = UsdPhysics.DriveAPI.Get(stage.GetPrimAtPath("/World/husky/base_link/front_right_wheel"), "angular")
        joint_3 = UsdPhysics.DriveAPI.Get(stage.GetPrimAtPath("/World/husky/base_link/rear_left_wheel"), "angular")
        joint_4 = UsdPhysics.DriveAPI.Get(stage.GetPrimAtPath("/World/husky/base_link/rear_right_wheel"), "angular")

        set_drive_parameters(joint_1, "velocity", 0.0, 0.0, 1e7)
        set_drive_parameters(joint_2, "velocity", 0.0, 0.0, 1e7)
        set_drive_parameters(joint_3, "velocity", 0.0, 0.0, 1e7)
        set_drive_parameters(joint_4, "velocity", 0.0, 0.0, 1e7)

    def _apply_transform(self, translate, orient, scale):
        stage = omni.usd.get_context().get_stage()
        prim = stage.GetPrimAtPath(self._get_prim_path())

        if prim.IsValid():
            xform = UsdGeom.XformCommonAPI(prim)
            xform.SetTranslate(translate)
            xform.SetRotate(Gf.Vec3f(*orient))
            xform.SetScale(scale)

    def _get_controller(self):
        return ExtendedDifferentialController()
    
    def _get_prim_path(self):
        return "/World/husky"

I use _load_robot_urdf and _set_robot_drives_config to load the robot into the stage, and the articulation root is set to husky/base_link.

I want to move this to the husky prim.

From what I understand, using omni.isaac.dynamic_control, it is possible to move the articulation using get_articulation when the simulation is played. However, I want to move the articulation root using Python code without pressing the play button.

How can I achieve this?

Thank you in advance for your help!

Universal Scene Description: UsdPhysicsArticulationRootAPI Class Reference (openusd.org)
You can try import pxr; pxr. UsdPhysics.ArticulationRootAPI.Apply(prim);

Could you tell me how to delete the wrong articulation root?

You should be able to do:

prim.RemoveAPI(UsdPhysics.ArticulationRootAPI)

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