A small utility to compile a xacro file (e.g., from a ROS package) into a URDF. This is a wrapper around xacrodoc. This utility does NOT require ROS to be installed.
- Clone the repository:
git clone <repository_url> cd <repository_name>
- Install the required Python packages:
pip install -r requirements.txt
The script can be run with the following command:
python xacro_to_urdf.py --package_dir <package_dir> \
--xacro_file <xacro_file> \
--output_urdf_file <urdf_file> \
[--resolve_paths <true|false>] \
[--args '{"key1": "value1", "key2": "value2"}']--package_dir(str): Directory of the package containing the xacro file.--xacro_file(str): Relative path to the xacro file within the package directory.--output_urdf_file(str): Path to the output URDF file.--resolve_paths(bool, optional): Whether to replacepackage://paths with absolute paths. Defaults tofalse.--args(str, optional): Extra arguments for Xacro parsing in JSON format (e.g.,'{"key1": "value1", "key2": "value2"}').
python xacro_to_urdf.py --package_dir kortex_description \
--xacro_file robots/gen3.xacro \
--output_urdf_file gen3.urdf \
--args '{"arm": "gen3", "dof": "7", "gripper": "robotiq_2f_85", "vision": "true", "sim": "false", "prefix": ""}'- Automatic
package.xmlcreation: If apackage.xmlfile is missing in the package directory, the script generates a minimal one based on the package directory name. - Xacro processing: The script uses the
xacrodoclibrary to convert the xacro file into a URDF. - Flexible path handling: Replace
package://paths with absolute paths if required. - Customizable Xacro arguments: Pass additional parameters for Xacro file parsing using the
--argsoption.
- The dependencies listed in
requirements.txt
-
Ensure the
xacro_filepath is relative to thepackage_dir. -
If
package.xmlis missing, it will be auto-generated with minimal content:<package> <name>{package_name}</name> </package>