通过 ros2 pkg create
在 Python 中, 需要在 setup.py中加入data_files, 然后colcon 识别到 launch文件.
点击(此处)折叠或打开
-
import os
-
from glob import glob
-
from setuptools import setup
-
-
package_name = 'my_package'
-
-
setup(
-
# Other parameters ...
-
data_files=[
-
# ... Other data files
-
# Include all launch files. This is the most important line
-
(os.path.join('share', package_name), glob('launch/*.launch.py'))
-
]
- )
点击(此处)折叠或打开 my_script.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', executable='talker', output='screen',
-
name=[launch.substitutions.LaunchConfiguration('node_prefix'), 'talker']),
- ])