petercorke / robotics-toolbox-python

Robotics Toolbox for Python
MIT License
1.99k stars 420 forks source link

Adding Custom URDF Robot Models #291

Open pranshumalik14 opened 2 years ago

pranshumalik14 commented 2 years ago

Describe the bug Adding new URDF models (that refer to stl files) needs a relative path to the XACRO path in rtbdata.

ValueError: file xacro/stl/braccio_base.stl not found locally or in rtbdata

Any help on how to do this properly will be highly appreciated. Here's a snapshot of the code we have written:

class Braccio(rtb.ERobot):

    def __init__(self):

        links, name, urdf_string, urdf_filepath = self.URDF_read(
            rtb.rtb_path_to_datafile("../urdf/braccio.urdf.xacro", local=True)
        )

        super().__init__(
            links,
            name=name,
            manufacturer="Arduino",
            gripper_links=links[12],
            urdf_string=urdf_string,
            urdf_filepath=urdf_filepath,
        )

We would like to keep the URDF model information local to our project than to move it to our installation folders. The code that parses xacro files seems to look for geometry files relative to the XACRO directory.

Version information

Did you install it from PyPI or GitHub? Latest Github version (pulled) Commit hash: 51aa8bbb3663a7c815f9880d538d61e7c85bc470

Environment (please complete the following information):

pranshumalik14 commented 2 years ago

This was despite setting the top-level directory to the project folder. Seemed like that information was not passed into the geometry parser/loadstr for the URDF.

petercorke commented 2 years ago

The behaviour we should have is that if an abs path is given it should use that, rather than the package relative one.

@pranshumalik14 would that work for you?

pranshumalik14 commented 2 years ago

Yes absolutely, that should fix it, thank you!

olmerg commented 2 years ago

I use os.chdir(os.path.dirname(file)) to solve the problem about absolute path.

https://github.com/olmerg/rtb_serial_robot/blob/main/planar_3dof/Planar3DOF.py

pranshumalik14 commented 2 years ago

Thanks so much @olmerg! Followed your setup step-by-step and got it to work! But a direct fix for it would still be helpful in general.