ROS2入门教程-使用 Launch启动监控多个节点
说明:
- 介绍如何使用Launch启动监控多个节点
步骤:
- 创建ROS2包
ros2 launchros2 pkg create <pkg-name> --dependencies [deps]launch
- 修改setup.py文件
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 here!
(os.path.join('share', package_name), glob('launch/*.launch.py'))
]
)
- 在CMakeLists.txt添加以下内容
# Install launch files.
install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}/
)
在launch目录中,创建.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']),
])
- 启动文件
ros2 launch my_package script.launch.py
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号