Skip to content

Instantly share code, notes, and snippets.

@juliangaal
Created February 6, 2024 08:54
Show Gist options
  • Save juliangaal/a15d12ade06d5c55223089f50b8b0b3e to your computer and use it in GitHub Desktop.
Save juliangaal/a15d12ade06d5c55223089f50b8b0b3e to your computer and use it in GitHub Desktop.
$(find PACKAGE)/foo/bar, but ROS2
from pathlib import Path
from ament_index_python import get_package_share_directory
def find(path_string):
assert path_string, "A non-empty path string must be provided"
assert not path_string.startswith('/'), "The path string can't start with /"
path_parts = path_string.split('/')
assert len(path_parts) > 1, "The path string must contain at least two parts"
pkg_name = path_parts[0]
pkg_share_path = Path(get_package_share_directory(pkg_name))
return str(pkg_share_path / Path(*path_parts[1:]))
def generate_launch_description():
file_path = find("package/urdf/package.urdf.xacro")
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment