fishbotics / urchin

Python parser for URDFs
http://urdfpy.readthedocs.io/
MIT License
32 stars 15 forks source link

Older style transmission type causes an AttributeError: 'NoneType'... #9

Closed BuildingAtom closed 8 months ago

BuildingAtom commented 1 year ago

When using urchin to load a URDF with older-style transmission tags, Urchin crashes with:

...
  File ".../site-packages/urchin/urdf.py", line 2078, in _from_xml
    kwargs["trans_type"] = node.find("type").text
                           ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'text'

This appears to be caused by the assumption that type must be an element, most likely based on the current ROS page, but this causes a crash for some files as the type is an attribute of the node instead (some examples can be found in this discussion regarding the transmission tag linked by that ROS page).

One possible fix for that that I'm using at the moment is to check the node attributes first. I expand and edit line 2078 of urdf.py so that the surrounding function now looks like:

    @classmethod
    def _from_xml(cls, node, path):
        kwargs = cls._parse(node, path)
        try:
            trans_type = node.attrib.get('type')
            if trans_type is None:
                trans_type = node.find("type").text
            kwargs["trans_type"] = trans_type
        except AttributeError:
            kwargs["trans_type"] = ''
        return Transmission(**kwargs)

Though, this also makes the type optional (since it seems like it might not be required anyway?).

fishbotics commented 1 year ago

Hey @BuildingAtom , sorry I missed this issue! Can you file a PR with your changes? We should definitely support this use case

BuildingAtom commented 1 year ago

@fishbotics Sure thing! I just filed the PR.

fishbotics commented 8 months ago

Should be fixed by https://github.com/fishbotics/urchin/pull/14. Let me know if it's an issue.

Thanks for contributing!