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

[ROS2] Using colcon doesn't create any file inside the install/<package>/share directory

asked 2022-05-25 05:43:42 -0500

Andromeda gravatar image

updated 2022-05-25 08:04:48 -0500

My package structure is very simple:

workspace/
           src/
           example/
                        launch/
                        resource/
                        test/
                        example/
                        setup.cfg
                        setup.py
                        package.xml

the problem is that I have defined a launch file inside the launch directory in my package. But running: colcon build --packages-select example (where example is just the name of the package) is doesn't move/create/copy the launch file from the launch directory into the install directory. So install/example/share/example/contains no launch file, which should be there even according to the tutorial about launch files here. In fact, the line:

(os.path.join('share', package_name), glob('launch/*.launch.py'))

from the tutorial above, suggests that the launch.py file should be found inside the share directory of the package. And this is not the case for me. I deleted the build and install directory many times. I run colcon build only, but it doesn't create any launch file inside the share directory. So I can only use absolute path inside my launch file or move manually the launch file inside the share directory. There is a reason for that? Or is the tutorial assuming that you move manually your launch file inside the share directory?

I'm using foxy on Ubuntu 20.04

UPDATE: My setup.py file contains the following code:

from setuptools import setup
from glob       import glob

import os

package_name = 'example'

setup(
    name=package_name,
    version='0.0.0',
    packages=[package_name],
    data_files=[
        ('share/ament_index/resource_index/packages', ['resource/' + package_name]),
        ('share/' + package_name, ['package.xml']),
        (os.path.join("share", package_name), glob("*launch.py")),
    ],
    install_requires=['setuptools'],
    zip_safe=True,
    maintainer='Max Muller',
    maintainer_email='max@infromtik.ca',
    description='Test',
    license='GPL',
    tests_require=['pytest'],
    entry_points={
        'console_scripts': [ 'test = example.robot_prog:main',
        ],
    },
)

Again, I understood the tutorials and the explanation. But or our example, with package name my_python_pkg, this will install all launch files from the launch folder, into ~/ros2_ws/install/my_python_pkg/share/my_python_pkg/launch/ is exactly what it is not doing!!! It creates the launch folder inside the package directory inside the install directory: yes It creates/move the launch file inside the launch directory created inside the package directory in the install directory: no

And I don't know, what's wrong with it. Evening following the tutorial I get the folder launch but no launch files, are inside it

edit retag flag offensive close merge delete

Comments

1

You need to actually install the launch folder to your share directory. This is done in the setup.py file. Could you edit this question to include a copy of your setup.py file?

Joe28965 gravatar image Joe28965  ( 2022-05-25 06:26:23 -0500 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2022-05-25 08:08:42 -0500

Andromeda gravatar image

I could fix the problem after realising that my launch.py file was inside a launch directory in the src folder of my package. I realized that the glob function was not looking inside that directory but a directory above. So changing this line of code

(os.path.join('share', package_name, 'launch'), glob('*launch.py')),

to

(os.path.join('share', package_name, 'launch'), glob('launch/*launch.py')), # Note the launch before /*launch.py

did fix the problem

edit flag offensive delete link more
2

answered 2022-05-25 07:16:27 -0500

ljaniec gravatar image

updated 2022-05-25 07:19:28 -0500

As @Joe28965 mentioned, you need to install other files in a ROS2 Python package (e.g. launch files etc.).

You can use this step-by-step tutorial for it:

https://roboticsbackend.com/create-a-...

Especially part with:

Launch files

Create a launch/ folder at the root of your package. You’ll put all your launch files inside this folder.

cd ~/ros2_ws/src/my_python_pkg/
mkdir launch

Now, to install those launch files, you need to modify setup.py.

import os
from glob import glob
from setuptools import setup
...
data_files=[
    ('share/ament_index/resource_index/packages',
        ['resource/' + package_name]),
    ('share/' + package_name, ['package.xml']),
    (os.path.join('share', package_name, 'launch'),
    glob('launch/*.launch.py')),
 ],
...

For our example, with package name my_python_pkg, this will install all launch files from the launch/ folder, into ~/ros2_ws/install/my_python_pkg/share/my_python_pkg/launch/.

Note: you only need to modify setup.py once. After that, every time you add a launch file you’ll just need to compile your package so that the file is installed, that’s it.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-05-25 05:43:42 -0500

Seen: 1,876 times

Last updated: May 25 '22