前言
有问题可以随时联系我,看到我会回复的 ——ICE
此外,本文的 Launch 文件均采用 python 文件
1 参数解释
package 功能包名
executable 可执行文件名
name 节点名,就是在构造节点时候,传进去的那个节点
2 模板
from launch import LaunchDescription
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory
def generate_launch_description():
YOLOv5_Azure_Kinect_dir = get_package_share_directory(
'YOLOv5_Azure_Kinect')
yaml_path = YOLOv5_Azure_Kinect_dir + '/configs/config.yaml'
IMG_Processor_pkg_share_dir = get_package_share_directory(
'IMG_Processor')
return LaunchDescription([
Node(
package='IMG_Processor',
executable='IMG_Processor',
name='IMG_Processor',
output='screen',
parameters=[
IMG_Processor_pkg_share_dir + '/configs/config.yaml',
],
),
])
3 节点
from launch import LaunchDescription
from launch_ros.actions import Node
Node(
package='IMG_Processor', //功能包名
executable='IMG_Processor', //可执行文件名
name='IMG_Processor', //节点名
output='screen',
parameters=[
IMG_Processor_pkg_share_dir + '/configs/config.yaml',
],
),
4 bag
from launch.actions import ExecuteProcess
ExecuteProcess(
cmd=['ros2', 'bag', 'play', './bag/KF/KF_03', '-l'],
output='screen'
),
5 rviz2
Node(
package='rviz2',
executable='rviz2',
name='rviz2_node',
output='screen'
),
6 rqt
Node(
package='rqt_gui',
executable='rqt_gui',
output='screen',
# arguments=['--standalone',
# 'rqt_reconfigure.param_plugin.ParamPlugin'
# 'rqt_publisher.publisher.Publisher'
# ],
),
- launch 启动 rqt,若没有 arguments 这个参数,则默认的启动 rqt,如果有这个参数,添上对应的参数,就启动了特定的插件,我这套模板只能加入一个参数,也就是只能启动一个插件,想启动两个插件能,需要写两个 Node
rqt 的插件很多,使用这个命令可以查看rqt --list-plugins
,这些里面有些无法使用,这里我之前测试的结果没有保存,所以不能阐述出来了
ice@ice:~$ rqt --list-plugins
rqt_action.action_plugin.ActionPlugin
rqt_console.console.Console
rqt_graph.ros_graph.RosGraph
rqt_image_view/ImageView
rqt_msg.messages.Messages
rqt_plot.plot.Plot
rqt_publisher.publisher.Publisher
rqt_py_console.py_console.PyConsole
rqt_reconfigure.param_plugin.ParamPlugin
rqt_service_caller.service_caller.ServiceCaller
rqt_shell.shell.Shell
rqt_srv.services.Services
rqt_top.top_plugin.Top
rqt_topic.topic.Topic
QFileSystemWatcher::removePaths: list is empty
QFileSystemWatcher::removePaths: list is empty
我最常用的是这两个插件,一个是 rqt_reconfigure.param_plugin.ParamPlugin
动态调参利器,一个是
rqt_publisher.publisher.Publisher
手动发布话题
7 获得另一个包的路径
from ament_index_python.packages import get_package_share_directory
pkg_share_dir = get_package_share_directory('YOLOv5_Azure_Kinect')
yaml_path = pkg_share_dir + '/configs/config.yaml'
8 启动另外一个launch文件
8.1 第一种,功能包名加其下路径(推荐)
这个写法比下面的那种简单
import os
from launch.launch_description_sources import PythonLaunchDescriptionSource
IncludeLaunchDescription(
launch_description_source=PythonLaunchDescriptionSource(
launch_file_path=os.path.join(
get_package_share_directory("ICE"),
"launch",
"ICE_launch.py"
)
)
),
8.2 第二种,绝对/相对路径
这里的路径填写可以填写为包的路径加其下的路径,或者绝对路径,获得包的路径在文章的上面
from launch.launch_description_sources import AnyLaunchDescriptionSource
from launch.actions import IncludeLaunchDescription
IncludeLaunchDescription(
AnyLaunchDescriptionSource(
'/home/ICE/launch/launch.py'),
# condition=IfCondition(LaunchConfiguration('param_name')),
),
9 Param
parameters=[
Template_pkg_share_dir + '/configs/config.yaml',
'/home/ice/Template_ICE/src/Template/configs/config.yaml',
{
"param_01": 567,
"use_sim_time": False,
}
],