ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In ROS 2 packages are found using the .ament resource index (design doc here). First there needs to be a marker file in the packages folder.

Second, I assume you're doing an isolated build with colcon (which is the default), in which case your package's install prefix is install/package_name. Add another share and package_name and the URI package://package_name/meshes/file.stl should resolve to install/package_name/share/package_name/meshes/file.stl, which means it should have been installed to share/package_name/meshes.

How it works:

The package resource_retriever is used by other packages to resolve package:// URIs. It calls ament_index_cpp::get_package_share_directory(). That's implemented here. In short, it returns a string like <package prefix>/share/<package_name>.

In your example I assume you're doing an isolated build with colcon (which is the default), in which case your package's install prefix is install/package_name. Add another share and package_name and the URI package://package_name/meshes/file.stl should resolve to install/package_name/share/package_name/meshes/file.stl, which means it should have been installed to share/package_name/meshes.

How to create a marker file

How to create a marker file depends on the build type in the package.xml

  <export>
    <build_type>...</build_type>
  </export>

Build type: ament_cmake

ament_cmake packages automatically install the marker file. You only need to call ament_package(). It happens inside ament_package(), but not in a straightforward way. It invokes extensions, which calls an extension ament_cmake_index_package_hook() because ament_cmake_core registered it with itself, which ultimately calls ament_index_register_package(). I don't know why ament_package() goes through the extensions instead of calling ament_index_register_package() directly.

Build type: cmake

I don't know of a plain CMake package example to link to, but this should work.

Create an empty file with the same name as your package (example below assumes it's in a folder called resource adjacent to your CMakeLists.txt), then install it to share/ament_index/resource_index/packages/resource.

install(FILES resource/my_package_name
 DESTINATION share/ament_index/resource_index/packages/resource
)

Build type: ament_python

Python packages install the markerfiles themselves.

Create an empty file with the same name as your package in the repo, then install it using the data_files argument of setup().

data_files=[
    ('share/' + package_name, ['package.xml']),
    ('share/ament_index/resource_index/packages',
        ['resource/' + package_name]),
],

Related questions

q367328

In ROS 2 packages are found using the .ament resource index (design doc here). First there needs to be a marker file in the packages folder.

Second, I assume you're doing an isolated build with colcon (which is the default), in which case your package's install prefix is install/package_name. Add another share and package_name and the URI package://package_name/meshes/file.stl should resolve to install/package_name/share/package_name/meshes/file.stl, which means it should have been installed to share/package_name/meshes.

How it works:

The package resource_retriever is used by other packages to resolve package:// URIs. It calls ament_index_cpp::get_package_share_directory(). That's implemented here. In short, it returns a string like <package prefix>/share/<package_name>.

In your example I assume you're doing an isolated build with colcon (which is the default), in which case your package's install prefix is install/package_name. Add another share and package_name and the URI package://package_name/meshes/file.stl should resolve to install/package_name/share/package_name/meshes/file.stl, which means it should have been installed to share/package_name/meshes.

How to create a marker file

How to create a marker file depends on the build type in the package.xml

  <export>
    <build_type>...</build_type>
  </export>

Build type: ament_cmake

ament_cmake packages automatically install the marker file. You only need to call ament_package(). It happens inside ament_package(), but not in a straightforward way. It invokes extensions, which calls an extension ament_cmake_index_package_hook() because ament_cmake_core registered it with itself, which ultimately calls ament_index_register_package(). I don't know why ament_package() goes through the extensions instead of calling ament_index_register_package() directly.

Build type: cmake

I don't know of a plain CMake package example to link to, but this should work.

Create an empty file with the same name as your package (example below assumes it's in a folder called resource adjacent to your CMakeLists.txt), then install it to share/ament_index/resource_index/packages/resource.

install(FILES resource/my_package_name
 DESTINATION share/ament_index/resource_index/packages/resource
)

Build type: ament_python

Python packages install the markerfiles themselves.

Create an empty file with the same name as your package in the repo, then install it using the data_files argument of setup().

data_files=[
    ('share/' + package_name, ['package.xml']),
    ('share/ament_index/resource_index/packages',
        ['resource/' + package_name]),
],

Related questions

q367328

@q367328

In ROS 2 packages are found using the .ament resource index (design doc here). First there needs to be a marker file in the packages folder.

Second, I assume you're doing an isolated build with colcon (which is the default), in which case your package's install prefix is install/package_name. Add another share and package_name and the URI package://package_name/meshes/file.stl should resolve to install/package_name/share/package_name/meshes/file.stl, which means it should have been installed to share/package_name/meshes.

How it works:

The package resource_retriever is used by other packages to resolve package:// URIs. It calls ament_index_cpp::get_package_share_directory(). That's implemented here. In short, it returns a string like <package prefix>/share/<package_name>.

In your example I assume you're doing an isolated build with colcon (which is the default), in which case your package's install prefix is install/package_name. Add another share and package_name and the URI package://package_name/meshes/file.stl should resolve to install/package_name/share/package_name/meshes/file.stl, which means it should have been installed to share/package_name/meshes.

How to create a marker file

How to create a marker file depends on the build type in the package.xml

  <export>
    <build_type>...</build_type>
  </export>

Build type: ament_cmake

ament_cmake packages automatically install the marker file. You only need to call ament_package(). It happens inside ament_package(), but not in a straightforward way. It invokes extensions, which calls an extension ament_cmake_index_package_hook() because ament_cmake_core registered it with itself, which ultimately calls ament_index_register_package(). I don't know why ament_package() goes through the extensions instead of calling ament_index_register_package() directly.

Build type: cmake

I don't know of a plain CMake package example to link to, but this should work.

Create an empty file with the same name as your package (example below assumes it's in a folder called resource adjacent to your CMakeLists.txt), then install it to share/ament_index/resource_index/packages/resource.

install(FILES resource/my_package_name
 DESTINATION share/ament_index/resource_index/packages/resource
)

Build type: ament_python

Python packages install the markerfiles themselves.

Create an empty file with the same name as your package in the repo, then install it using the data_files argument of setup().

data_files=[
    ('share/' + package_name, ['package.xml']),
    ('share/ament_index/resource_index/packages',
        ['resource/' + package_name]),
],

Related questions

@q367328

q367328

In ROS 2 packages are found using the .ament resource index (design doc here). First there needs to be a marker file in the packages folder.

Second, I assume you're doing an isolated build with colcon (which is the default), in which case your package's install prefix is install/package_name. Add another share and package_name and the URI package://package_name/meshes/file.stl should resolve to install/package_name/share/package_name/meshes/file.stl, which means it should have been installed to share/package_name/meshes.

How it works:

The package resource_retriever is used by other packages to resolve package:// URIs. It calls ament_index_cpp::get_package_share_directory(). That's implemented here. In short, it returns a string like <package prefix>/share/<package_name>.

In your example I assume you're doing an isolated build with colcon (which is the default), in which case your package's install prefix is install/package_name. Add another share and package_name and the URI package://package_name/meshes/file.stl should resolve to install/package_name/share/package_name/meshes/file.stl, which means it should have been installed to share/package_name/meshes.

How to create a marker file

How to create a marker file depends on the build type in the package.xml

  <export>
    <build_type>...</build_type>
  </export>

Build type: ament_cmake

ament_cmake packages automatically install the marker file. You only need to call ament_package(). It happens inside ament_package(), but not in a straightforward way. It invokes extensions, which calls an extension ament_cmake_index_package_hook() because ament_cmake_core registered it with itself, which ultimately calls ament_index_register_package(). I don't know why ament_package() goes through the extensions instead of calling ament_index_register_package() directly.

Build type: cmake

I don't know of a plain CMake package example to link to, but this should work.

Create an empty file with the same name as your package (example below assumes it's in a folder called resource adjacent to your CMakeLists.txt), then install it to share/ament_index/resource_index/packages/resource.

install(FILES resource/my_package_name
 DESTINATION share/ament_index/resource_index/packages/resource
)

Build type: ament_python

Python packages install the markerfiles themselves.

Create an empty file with the same name as your package in the repo, then install it using the data_files argument of setup().

data_files=[
    ('share/' + package_name, ['package.xml']),
    ('share/ament_index/resource_index/packages',
        ['resource/' + package_name]),
],

Related questions

q367328

https://answers.ros.org/question/367328/