I want to build and run ros2 launch project, but I don't know how to do it.

asked 2019-10-10 02:51:07 -0500

BattlePants gravatar image

hi

I followed this tutorial https://index.ros.org/doc/ros2/Tutori...

But it end up with error like this

file 'test.launch.py' was not found in the share directory of package 'launch_test' which is at '/home/<username>/workspace/install/launch_test/share/launch_test'

Here is directory structure

launch_test
    launch
        test.launch.py
    package.xml
    setup.cfg
    setup.py

Here is my code

test.launch.py

import launch
import launch.actions
import launch.substitutions
import launch_ros.actions


def generate_launch_description():
    return launch.LaunchDescription([
        launch.actions.DeclareLaunchArgument(
            'node_prefix',
            default_value=[launch.substitutions.EnvironmentVariable('USER'), '_'],
            description='Prefix for node names'),
        launch_ros.actions.Node(
            package='demo_nodes_cpp', node_executable='talker', output='screen',
            node_name=[launch.substitutions.LaunchConfiguration('node_prefix'), 'talker']),
    ])

package.xml

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>launch_test</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email=""></maintainer>
  <license>TODO: License declaration</license>

  <exec_depend>rclpy</exec_depend>
  <exec_depend>std_msgs</exec_depend>

  <export>
    <build_type>ament_python</build_type>
  </export>
</package>

setup.cfg

[develop]
script-dir=$base/lib/launch_test
[install]
install-scripts=$base/lib/launch_test

setup.py

from setuptools import setup, find_packages
import os
from glob import glob
from setuptools import setup


package_name = 'launch_test'

setup(
    name=package_name,
    version='0.0.0',
    packages=find_packages(exclude=[]),
    install_requires=['setuptools'],
    zip_safe=True,
    author='Louis Lee',
    author_email="sdd2023@clobot.co.kr",
    maintainer='Louis Lee',
    maintainer_email="sdd2023@clobot.co.kr",
    keywords=['ROS', 'ROS2'],
    classifiers=[
        'Intended Audience :: Developers',
        'License :: OSI Approved :: Apache Software License',
        'Programming Language :: Python',
        'Topic :: Software Development',
    ],
    description=(
        'Communication manager for Mobile robot framework'
    ),
    license='Apache License, Version 2.0',
    tests_require=['pytest'],
    data_files=[
        (os.path.join('share', package_name, 'launch'), glob('*.launch.py'))
    ]
)

Could you tell me where the problem is?

Or could I get another example about ros2 launch, please?

edit retag flag offensive close merge delete

Comments

I don't see anything obvious that's wrong. Did you remember to run colcon build and re-source the workspace?

mlanting gravatar imagemlanting ( 2019-10-10 13:23:48 -0500 )edit

You could look at the demos repository. The composition and lifecycle packages use launch files. https://github.com/ros2/demos

mlanting gravatar imagemlanting ( 2019-10-10 13:27:03 -0500 )edit

Yes, I run colcon build and sourced workplace, and there was no error in that process. I think there is something wrong with the code. thank you for the comment. I will check the link.

BattlePants gravatar imageBattlePants ( 2019-10-10 20:31:25 -0500 )edit