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

Using `package://` in URDF with ROS2

asked 2021-01-22 09:33:29 -0500

Felix Widmaier gravatar image

How is package:// in an URDF file resolved in ROS 2, i.e. what do I need to put there so that the files are found?


Some context:

With ROS 1 I was using package://package_name/meshes/file.stl in the URDF file with a directory "meshes" at the root of the package. This was working fine using the devel space.

Now with ROS 2, I am installing the meshes with

install(DIRECTORY meshes DESTINATION share/${PROJECT_NAME})

so they end up in install/package_name/share/package_name/meshes.

Unfortunately, when loading the URDF, they are not found. I assume, I need to adjust the package://... part. I already tried package://package_name/share/package_name/meshes without success.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-01-22 17:00:54 -0500

sloretz gravatar image

updated 2021-01-22 17:03:26 -0500

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

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

edit flag offensive delete link more

Comments

Thanks for your elaborate answer! So apparently I was already doing everything correctly. And indeed, after doing a clean rebuilt, it is not working without further changes... I have no idea what the problem was last week.

Felix Widmaier gravatar image Felix Widmaier  ( 2021-01-25 02:02:30 -0500 )edit
1

In my case, adding <gazebo_ros gazebo_model_path="${prefix}/.."/> to my package.xml similar to the turtlebot3-description-reduced-mesh package fixed the issue.

concaveros gravatar image concaveros  ( 2021-08-28 22:01:19 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-01-22 09:33:29 -0500

Seen: 2,437 times

Last updated: Jan 22 '21