### Install xacrodoc from source Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Installation method for building the package directly from the source repository. ```sh git clone --recurse-submodules https://github.com/adamheins/xacrodoc cd xacrodoc pip install . ``` -------------------------------- ### Install xacrodoc via uv Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Recommended method for installing the command-line tool into an isolated environment. ```sh uv tool install xacrodoc # for conversion to MJCF files, use: uv tool install "xacrodoc[mujoco]" ``` -------------------------------- ### Install xacrodoc library via pip Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Standard installation method for using xacrodoc as a Python library. ```sh pip install xacrodoc # or to also include conversion to MJCF files: pip install "xacrodoc[mujoco]" ``` -------------------------------- ### Install xacrodoc via pipx Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Alternative method for installing the command-line tool into an isolated environment. ```sh pipx install xacrodoc # or pipx install "xacrodoc[mujoco]" ``` -------------------------------- ### xacrodoc Command Line Examples Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/index.md Common command line operations for compiling XACRO files, managing package directories, and converting to MJCF format. ```sh # compile and print to stdout xacrodoc input.urdf.xacro # compile and output to provided output file xacrodoc input.urdf.xacro -o output.urdf # provide directories in which to look for packages referenced in # input.urdf.xacro (the -d (--pkg-dir) flag is needed before each one to # disambiguate from substitution arguments); a common use-case would be # providing the path to catkin workspaces xacrodoc input.urdf.xacro -d ~/my_pkg_dir -d ~/my_other_pkg_dir # alternatively, package name/path mappings can be directly supplied using the # -p (--pkg-path) flag; := is used to separate the name and path: xacrodoc input.urdf.xacro -p my_pkg:=~/path/to/my_pkg -p other_pkg:=/home/foo/packages/other_pkg # substitution arguments also use := notation, like xacro xacrodoc input.urdf.xacro mass:=1 # you can also remove file:// protocols prefixed to asset paths with # -s (--strip-protocols) or convert paths from absolute to relative using # -r (--relative-paths) xacrodoc input.urdf.xacro -s -r output.urdf # alternatively, convert to MJCF (requires Mujoco) # the -c (--copy-assets-to) option with a directory name is required when # converting to MJCF; it copies all assets to that directory and updates their # file paths (-c is optional when converting to URDF) # relative file paths are always used when converting to MJCF xacrodoc input.urdf.xacro --mjcf -c assets -o output.xml ``` -------------------------------- ### Build Documentation Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Generates HTML documentation using Sphinx. ```bash make html ``` -------------------------------- ### xacrodoc.packages.walk_up_from Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Configures the package finder to search for packages by walking up the directory tree from a specified path. ```APIDOC ## xacrodoc.packages.walk_up_from(path, priority=0) ### Description Look for packages by walking up the directory tree from `path`. ### Parameters - **path** (str or pathlib.Path) - Required - The path at which to start looking for packages. - **priority** (int) - Optional - Priority for the search: lower means the package is looked for using this method earlier. ``` -------------------------------- ### Initialize Git Submodules Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Required to clone additional submodules needed for the test suite. ```bash git submodule update --init --recursive ``` -------------------------------- ### to_urdf_file(path, compare_existing=True, use_protocols=True, relative_paths=False, verbose=False) Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Writes the URDF to a file with various configuration options. ```APIDOC ## to_urdf_file(path, compare_existing=True, use_protocols=True, relative_paths=False, verbose=False) ### Description Write the URDF to a file. ### Parameters - **path** (str or Path) - Required - The path to the URDF file to be written. - **compare_existing** (bool) - Optional - If True, only write if the parsed URDF is different than existing file content. - **use_protocols** (bool) - Optional - If True, prepends file:// protocol to asset filenames. - **relative_paths** (bool) - Optional - If True, convert asset filenames to be relative to the output path. - **verbose** (bool) - Optional - Set to True to print information about xacro compilation. ``` -------------------------------- ### Convert Xacro to MJCF Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Demonstrates converting a Xacro document to an MJCF file or string, including options for asset path handling and localization. ```python from xacrodoc import XacroDoc doc = XacroDoc.from_file("input.urdf.xacro") # keep absolute paths to assets doc.to_mjcf_file("output.xml", strippath="false") # copy all the referenced assets to the directory `assets` before conversion # name collisions between assets with the same filename are automatically # resolved by appending numbers as needed doc.localize_assets("assets") doc.to_mjcf_file("output.xml", strippath="true", meshdir="assets") # if desired, one can also just produce an MJCF string: xml = doc.to_mjcf_string() ``` -------------------------------- ### xacrodoc.packages.look_in Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Adds additional directories to the search path for finding ROS packages. ```APIDOC ## xacrodoc.packages.look_in(paths, priority=0) ### Description Add additional directories to search for packages. ### Parameters - **paths** (Iterable) - Required - A list of paths in which to search for packages. - **priority** (int) - Optional - Priority for the search: lower means the package is looked for using this method earlier. ``` -------------------------------- ### to_mjcf_file(path, **kwargs) Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Converts and writes the document to a Mujoco MJCF XML file. Requires the mujoco module. ```APIDOC ## to_mjcf_file(path, **kwargs) ### Description Convert and write to a Mujoco MJCF XML file. This requires the mujoco module to be installed. ### Parameters - **path** (str or Path) - Required - The path to the MJCF XML file to be written. - ****kwargs** (dict) - Optional - All keyword arguments are passed as Mujoco compiler options. ``` -------------------------------- ### Run Tests with Specific Python Version Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Uses uv to run tests against a specific Python version with optional dependencies. ```bash # for example uv run --locked --isolated --extra mujoco --python=3.9 pytest ``` -------------------------------- ### Compose multiple xacro files Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Building a URDF programmatically by combining multiple xacro files, optionally using $(find) directives. ```python import xacrodoc as xd # setup where to look for packages, if needed; for example: xd.packages.look_in(["somewhere/I/keep/packages"]) # specify files to compose (using xacro include directives) includes = ["robot_base.urdf.xacro", "robot_arm.urdf.xacro", "tool.urdf.xacro"] doc = xd.XacroDoc.from_includes(includes) # includes can also use $(find ...) directives: includes = [ "$(find my_ros_package)/urdf/robot_base.urdf.xacro", "$(find another_ros_package)/urdf/robot_arm.urdf.xacro", "tool.urdf.xacro" ] doc = xd.XacroDoc.from_includes(includes) ``` -------------------------------- ### Compile URDF from xacro Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Basic usage for loading xacro files and converting them to URDF strings or files, including temporary file management. ```python import os from xacrodoc import XacroDoc doc = XacroDoc.from_file("robot.urdf.xacro") # or relative to a ROS package # e.g., for a file located at some_ros_package/urdf/robot.urdf.xacro: doc = XacroDoc.from_package_file("some_ros_package", "urdf/robot.urdf.xacro") # convert to a string of URDF urdf_str = doc.to_urdf_string() # or write to a file doc.to_urdf_file("robot.urdf") # or just work with a temp file # this is useful for working with libraries that expect a URDF *file* (rather # than a string) with doc.temp_urdf_file_path() as path: # do stuff with URDF file located at `path`... # file is cleaned up once context manager is exited # you can also manage the temp file yourself if you don't want to clean it up # right away path = doc.to_temp_urdf_file() # ...do stuff with path... # manually delete the temp file os.remove(path) ``` -------------------------------- ### Use temporary URDF file path as context manager Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Utilize the context manager to handle the lifecycle of a temporary URDF file automatically. ```python with doc.temp_urdf_file_path() as path: load_file_from_path(path) ``` -------------------------------- ### xacrodoc.packages.get_path Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Attempts to resolve the filesystem path of a given ROS package. ```APIDOC ## xacrodoc.packages.get_path(pkg) ### Description Attempt to get the path of a package. ### Parameters - **pkg** (str) - Required - The name of the package. ### Returns - **str** - The path to the package. ### Raises - **PackageNotFoundError** - If the package could not be found. ``` -------------------------------- ### XacroDoc.from_file Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Loads a URDF document from a specified xacro or plain URDF file path. ```APIDOC ## classmethod from_file(path, walk_up=True, **kwargs) ### Description Loads the URDF document from a xacro or plain URDF file. ### Parameters - **path** (str or Path) - Required - The path to the xacro file. - **walk_up** (bool) - Optional - If True, look for packages by walking up the directory tree from path. - **kwargs** (dict) - Optional - Additional keyword arguments passed to the .from_string constructor method. ``` -------------------------------- ### Pass substitution arguments Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Providing arguments to xacro files programmatically using the subargs parameter. ```python from xacrodoc import XacroDoc doc = XacroDoc.from_file("robot.urdf.xacro", subargs={"mass": "2"}) ``` -------------------------------- ### to_urdf_string(use_protocols=True, paths_relative_to=None, pretty=True) Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Returns the URDF as a formatted string. ```APIDOC ## to_urdf_string(use_protocols=True, paths_relative_to=None, pretty=True) ### Description Get the URDF as a string. ### Parameters - **use_protocols** (bool) - Optional - If True, prepends file:// protocol to asset filenames. - **paths_relative_to** (str or Path or None) - Optional - If set, makes asset filenames relative to this path. - **pretty** (bool) - Optional - Set True to format the string for human readability. ### Returns - **str** - The URDF represented as a string. ``` -------------------------------- ### XacroDoc.localize_assets Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Copies all referenced assets to a local directory and updates the document paths. ```APIDOC ## localize_assets(asset_dir, exist_ok=True) ### Description Copy all assets to a local directory and update all filenames in the document accordingly. This is useful when converting to MJCF format. ### Parameters - **asset_dir** (str or Path) - Required - The path to the local directory where assets should be copied. - **exist_ok** (bool) - Optional - If False, an error will be raised if asset_dir already exists. ``` -------------------------------- ### Configure ROS package resolution Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Methods for managing how xacrodoc finds ROS packages, including automatic directory walking and manual path configuration. ```python import xacrodoc as xd # `from_file` automatically resolves packages by looking in each parent # directory of the given path to check for required ROS packages (as marked by # a package.xml file) doc = xd.XacroDoc.from_file("robot.urdf.xacro") # if you want to disable this, pass `walk_up=False`: doc = xd.XacroDoc.from_file("robot.urdf.xacro", walk_up=False) # we can also tell xacrodoc to walk up a directory tree manually xd.packages.walk_up_from("some/other/path") # or we can give paths to directories to search for packages # packages can be located multiple levels deep from the specified directories, # just like in a ROS workspace - the same package search logic is used (since # we actually use rospkg under the hood) xd.packages.look_in(["somewhere/I/keep/packages", "another/directory/with/packages"]) # you can bypass ROS conventions entirely by directly providing a dict of # package names and paths; no package.xml is required to identify packages in # this case xd.packages.update_package_cache({"my_package": "path/to/my_package"}) ``` -------------------------------- ### xacrodoc.packages.reset Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Resets the package finder configuration to default look-up methods. ```APIDOC ## xacrodoc.packages.reset() ### Description Reset the package finder to the default look-up methods. ``` -------------------------------- ### Compile and Convert URDF/Xacro via CLI Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Use the xacrodoc command to compile Xacro files, specify package paths, strip protocols, or convert to MJCF format. ```sh # compile and print to stdout xacrodoc input.urdf.xacro # compile and output to provided output file xacrodoc input.urdf.xacro -o output.urdf # provide directories in which to look for packages referenced in # input.urdf.xacro (the -d (--pkg-dir) flag is needed before each one to # disambiguate from substitution arguments); a common use-case would be # providing the path to catkin workspaces xacrodoc input.urdf.xacro -d ~/my_pkg_dir -d ~/my_other_pkg_dir # alternatively, package name/path mappings can be directly supplied using the # -p (--pkg-path) flag; := is used to separate the name and path: xacrodoc input.urdf.xacro -p my_pkg:=~/path/to/my_pkg -p other_pkg:=/home/foo/packages/other_pkg # substitution arguments also use := notation, like xacro xacrodoc input.urdf.xacro mass:=1 # you can also remove file:// protocols prefixed to asset paths with # -s (--strip-protocols) or convert paths from absolute to relative using # -r (--relative-paths) xacrodoc input.urdf.xacro -s -r output.urdf # alternatively, convert to MJCF (requires Mujoco) # the -c (--copy-assets-to) option with a directory name is required when # converting to MJCF; it copies all assets to that directory and updates their # file paths (-c is optional when converting to URDF) # relative file paths are always used when converting to MJCF xacrodoc input.urdf.xacro --mjcf -c assets -o output.xml ``` -------------------------------- ### Run Tests with Pytest Source: https://github.com/adamheins/xacrodoc/blob/main/README.md Executes the test suite located in the tests directory. ```bash cd tests pytest . ``` -------------------------------- ### to_temp_urdf_file(verbose=False) Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Writes the URDF to a temporary file. ```APIDOC ## to_temp_urdf_file(verbose=False) ### Description Write the URDF to a temporary file. Clean-up is left to the user. ### Parameters - **verbose** (bool) - Optional - Set to True to print information about xacro compilation. ### Returns - **str** - The path to the temporary URDF file. ``` -------------------------------- ### XacroDoc.from_string Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Compiles a xacro string into a URDF document. ```APIDOC ## classmethod from_string(text, subargs=None, max_runs=10, resolve_packages=True, rootdir=None) ### Description Load the URDF document from a xacro or plain URDF string. ### Parameters - **text** (str) - Required - The xacro text to compile into a URDF document. - **subargs** (dict or None) - Optional - Optional dict of substitution arguments. - **max_runs** (int) - Optional - Maximum number of times compilation will be performed to reach a fixed point. - **resolve_packages** (bool) - Optional - If True, resolve package protocol URIs in the compiled URDF. - **rootdir** (str or Path or None) - Optional - Root directory to resolve relative asset filenames. ``` -------------------------------- ### to_mjcf_string(**kwargs) Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Converts the document to a string in Mujoco MJCF XML format. ```APIDOC ## to_mjcf_string(**kwargs) ### Description Convert to a string in Mujoco MJCF XML format. Requires the mujoco module. ### Parameters - ****kwargs** (dict) - Optional - All keyword arguments are passed as Mujoco compiler options. ### Returns - **str** - The string of XML. ``` -------------------------------- ### xacrodoc.packages.get_file_path Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Retrieves the absolute path to a specific file located within a ROS package. ```APIDOC ## xacrodoc.packages.get_file_path(pkg, relative_path) ### Description Get the path to a file within a ROS package. ### Parameters - **pkg** (str) - Required - The name of the ROS package. - **relative_path** (str or Path) - Required - The path of the file relative to the package root. ### Returns - **str** - The file path. ``` -------------------------------- ### xacrodoc.packages.update_package_cache Source: https://github.com/adamheins/xacrodoc/blob/main/docs/src/reference.md Manually updates the package cache with a mapping of package names to filesystem paths. ```APIDOC ## xacrodoc.packages.update_package_cache(pkgpaths) ### Description Update the package cache. This allows the user to manually specify the location of packages on the filesystem. ### Parameters - **pkgpaths** (dict) - Required - Map from package names to package paths. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.