clemense / yourdfpy

Python parser for URDFs
MIT License
112 stars 13 forks source link

Add `load_from_string` #54

Open amalnanavati opened 2 months ago

amalnanavati commented 2 months ago

Description: In some applications, as opposed to having a URDF file, one has the URDF as a string. it would be helpful to have a URDF.load_from_string method to handle such scenarios.

Sample Use Case: A common use case with MoveIt2 is to have the robot model as a xacro file, then convert the xacro file to a URDF string, and then pass that string as a parameter to move_group node. As a result, one can easily get the URDF string by calling the get parameter service. However, yourdfpy does not provide a way to load that string.

Workaround: I have currently worked around this with by adding the following code to my class. However, it is non-ideal because we are accessing a private member of the URDF class outside of the class. So it would be better to add the capability to the library itself.

from lxml import etree
from yourdfpy import URDF

parser = etree.XMLParser(remove_blank_text=True)
xml_root = etree.fromstring(urdf_str, parser=parser)
model = URDF(robot=URDF._parse_robot(xml_element=xml_root))
amalnanavati commented 2 months ago

As a side-note: thanks for this great library! I have opened a PR to add it to the rosdep.