stephane-caron / pink

Python inverse kinematics based on Pinocchio
Apache License 2.0
191 stars 12 forks source link

URDF support #7

Closed shbang91 closed 1 year ago

shbang91 commented 1 year ago

Hello,

I've noticed that pink only supports URDF in the robot_description repo. Is there any way I could use my custom URDF?

Thank you, Seung Hyeon

stephane-caron commented 1 year ago

Absolutely. Pink works directly on Pinocchio robots, so you can call Pinocchio's BuildFromURDF to load your custom URDF.

Here is some sample code that documents the Pinocchio API:


def load_urdf(urdf_path, package_dirs, root_joint=None):
    """
    Load the URDF of a robot description.

    Args:
        urdf_path: Path to the URDF file.
        package_dirs: List of directories Pinocchio can use as guesses to
            expand relative and ``package://`` paths in the URDF.
        root_joint (optional): First joint of the kinematic chain, for example
            a free flyer between the floating base of a mobile robot and an
            inertial frame. Defaults to no joint, i.e., a fixed base.

    Returns:
        Robot models for Pinocchio.
    """
    return pin.RobotWrapper.BuildFromURDF(
        filename=urdf_path,
        package_dirs=package_dirs,
        root_joint=root_joint_type(),
    )
stephane-caron commented 1 year ago

There is now a small load_custom_urdf.py example showing how to load a custom double-pendulum URDF. Hoping this helps!

shbang91 commented 1 year ago

Thank you so much for your great effort on this!