Unit 3 Topics Quiz - Launch file doesn't seem to be working

I’m currently working on the Unit 3 topics quiz and my launch file doesn’t seem to be working. Currently, I’ve tried removing the Build/ and Install/ paths and rebuilding them.

Here is a snippet of my Launch and Setup scripts

topics_quiz.launch.py:

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='topics_quiz',
            executable='topics_quiz_node',
            output='screen'),
    ])

setup.py:

from setuptools import setup

package_name = 'exercise31_pkg'

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']),
    ],
    install_requires=['setuptools'],
    zip_safe=True,
    maintainer='user',
    maintainer_email='user@todo.todo',
    description='TODO: Package description',
    license='TODO: License declaration',
    tests_require=['pytest'],
    entry_points={
        'console_scripts': [
            'exercise31 = exercise31_pkg.exercise31:main'
        ],
    },
)

Please let me know what I am doing wrong.

Thank you in advance.

Do you want to try in launch file executable=‘exercise31’?

No, sorry I meant

package_name = 'topics_quiz'

I’ve been messing around in an attempt to get something to work.

I also meant

entry_points={
        'console_scripts': [
            'topics_quiz_node = topics_quiz.topics_quiz_node:main'

Do you want to post your setup.py again?

Here it is,

from setuptools import setup

package_name = 'topics_quiz'

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']),
    ],
    install_requires=['setuptools'],
    zip_safe=True,
    maintainer='user',
    maintainer_email='user@todo.todo',
    description='TODO: Package description',
    license='TODO: License declaration',
    tests_require=['pytest'],
    entry_points={
        'console_scripts': [
            'topics_quiz_node = topics_quiz.topics_quiz_node:main'
        ],
    },
)

default setup.py needs to be modified like following. I don’t know why they didn’t make default as this.

from setuptools import setup
import os
from glob import glob

package_name = ‘topics_quiz’

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/*.launch.py’))
],

Thank you for this, it has solved my issue. :slight_smile:

Hi @ljiang ,

This is not the default setting and it should not be the default.

Let me explain why:
You add the paths to setup.py file only when you make directories like launch, config, params, etc.
By default, when you create a ROS2 package with ament_python, you do not get the package created with the above-mentioned directories.
Hence it is the programmer’s task to add these directories into setup.py file to mark those files as dependencies.

You require these two imports:

import os
from glob import glob

Just to include the following line of code:

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

into your setup.py file.

Hence, it SHOULD NOT be the default and cannot be made default.
Most packages do not come with launch directory. One of the many reasons why your code block cannot be made default.

I hope you understand.

Regards,
Girish

Hi @Nick_Summer ,

Welcome to this Community!

Glad to know that you have fixed the problem.

The problem in your case was just the executable name mismatch.
What @ljiang gave you as a solution is not exactly the solution in your case.

Of course, you need to do the modifications to the setup.py file if you want to launch your program from a launch file, but if you want to use ros2 run ..., then the solution is not exactly true.

Just clearing this up so that you do not get confused.

Regards,
Girish

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.