ROS2-在编译类型为ament_python的包里安装launch文件方法

ROS2 setup.cfg

这个文件将告诉脚本将安装在哪里

修改setup.py以安装launch文件

关键在这一行

(os.path.join('share', package_name, 'launch'), glob('launch/*.launch.py')),
复制代码

还可以安装yaml结尾的

(os.path.join('share', package_name, 'config'), glob('config/*.yaml')),
复制代码
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')),
],
...
复制代码

ROS2的launch文件如何互相包含、互相引用呢

导入IncludeLaunchDescription

import os

from ament_index_python.packages import get_package_share_directory
from launch.actions import IncludeLaunchDescription

def generate_launch_description():
    pkg_gazebo_ros = get_package_share_directory('gazebo_ros')
    return LaunchDescription([
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(
                os.path.join(pkg_gazebo_ros, 'launch', 'gzserver.launch.py')
            ),
            launch_arguments={'world': world}.items(),
        )
    ])
复制代码

原文链接:

猜你喜欢

转载自juejin.im/post/7016899728726032420