Source code for urdfgenpy.exporters.urdf
#!/usr/bin/env python3
"""URDF XML exporter."""
# --- std
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from ..robot import Robot
_HEADER = '<?xml version="1.0"?>'
[docs]
class URDFExporter:
"""Converts a :class:'~urdfgenpy.Robot' to a URDF XML string."""
[docs]
def export(self, robot: Robot) -> str:
"""Render *robot* as a URDF XML string.
Args:
robot: The :class:'~urdfgenpy.Robot' to serialize.
Returns:
A complete, well-formed URDF XML string including the XML
declaration and '<robot>' root element.
"""
lines = [
_HEADER,
f'<robot name="{robot.name}">',
]
for mat in robot.materials:
lines.append(mat.to_xml(" "))
for link in robot.links:
lines.append(link.to_xml(" "))
for joint in robot.joints:
lines.append(joint.to_xml(" "))
lines.append("</robot>")
return "\n".join(lines) + "\n"