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

How to create a ros2 package that can be found by cli?

asked 2019-06-16 16:03:43 -0500

ssnover95 gravatar image

I've been trying to get caught up on the latest and greatest now that an LTS release of ROS2 has come out. I'm currently trying to create a package in a ros2 overlay workspace and I'm having trouble getting the launch file up and running.

I'm used to ROS1 where I had a launch directory in my package which contained XML .launch files and as long as the package was built I could run roslaunch package_name launch_file.launch. I'm finding it to be not that straightforward in ROS2.

My package's structure is as follows where I have a containing folder called asar and in it:

├── CMakeLists.txt
├── image_capture
│   ├── CMakeLists.txt
│   ├── include
│   │   └── image_capture
│   ├── launch
│   │   └──
│   ├── package.xml
│   └── src
│       └── run_publish_images.cpp
└── vision_pipeline
    ├── CMakeLists.txt
    └── package.xml

So there are two packages in this folder and I'm focusing on the image_capture package right now.

I can call colcon build at the top of my workspace and it builds everything fine. If I run the resulting executable manually it publishes correctly (just having it publish strings as a proof of concept). However when I run ros2 launch image_capture I get an error back:

ssnover@styrka:~/dashing$ ros2 launch image_capture
Package 'image_capture' not found: "package 'image_capture' not found, searching: ['/home/ssnover/dashing/install/opencv_tests', '/home/ssnover/dashing/install/vision_opencv', '/home/ssnover/dashing/install/image_geometry', '/home/ssnover/dashing/install/examples_rclcpp_minimal_subscriber', '/home/ssnover/dashing/install/cv_bridge', '/opt/ros/dashing']"

Alright, so it's searching my workspace's install directories, and that list is generated by source /home/ssnover/dashing/install/local_setup.bash which is in bashrc file. I can see when I check in the install directory that a directory has been made called asar and there I can find the executable built by colcon under asar/lib/image_capture as well as some other shell files under asar. So colcon appears to be treating my package similarly to the others, but ros2 CLI can't find it.

Am I missing a step? Is my package file structure incorrect?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-06-16 20:08:05 -0500

ssnover95 gravatar image

The problem lies in my addition of a CMakeLists.txt file to the top level of the asar directory. This was causing a directory asar to be created underneath my install folder. When I took that out, it was no longer created and image_capture was created directly under this folder instead. I'm now able to auto-complete the command ros2 launch image_capture without a problem!

I believe that what I was doing (having a top level CMake file with a few calls to add_subdirectory) was allowed in ROS1, but it appears that this causes problems when the src directory is parsed under colcon and ros2.

edit flag offensive delete link more


An unfortunate side-effect I've just realized is that CLion will have problems loading multiple packages into a single project, as it uses CMake files to parse the project.

ssnover95 gravatar image ssnover95  ( 2019-06-16 20:09:58 -0500 )edit

I think there is an assumption in colcon that once a package is found it will not contain more packages in its subfolders. It looks like the intention is two packages: image_capture and vision_pipeline, but the cmake file outside of both is tricking colon into thinking there is one plain cmake package in the asar folder.

Interestingly, looks like AWS Robomaker had the same experience:

sloretz gravatar image sloretz  ( 2019-06-17 11:13:20 -0500 )edit

Question Tools



Asked: 2019-06-16 16:03:43 -0500

Seen: 797 times

Last updated: Jun 16 '19