ROS2_Foxy学习8——launch

ROS2_Foxy学习8——launch


  
The launch system in ROS 2 is responsible for helping the user describe the configuration of their system and then execute it as described. The configuration of the system includes what programs to run, where to run them, what arguments to pass them, and ROS specific conventions which make it easy to reuse components throughout the system by giving them each different configurations. It is also responsible for monitoring the state of the processes launched, and reporting and/or reacting to changes in the state of those processes.

launch文件的Python模板
项目作用项目作用项目作用
package功能包名(必须)executable可执行程序名(必须)arguments参数列表
output输出类型 screen / lognamespace名称空间name节点名
remappings重映射prefix运行命令
  1. 基础
    from launch import LaunchDescription
    from launch_ros.actions import Node
    
    def generate_launch_description():
        return LaunchDescription([
        	Node(
                package='my_package',
                executable='my_exe',
                name='my_node',
            	output='screen',
            	arguments=['39','-0.968','abc']    # 程序里面从 argv[1] 开始读取
            )
        ])
    
  2. 延伸
    1. static_tf
    2. gdb调试
    3. 重映射
    from launch import LaunchDescription
    from launch_ros.actions import Node
    
    def generate_launch_description():
        return LaunchDescription([
        	# static tf
        	# 参数列表分别是 x,y,z,x,y,z,w,parent_frame,child_frame
            Node(
                package='tf2_ros',
                executable='static_transform_publisher',
                arguments = ['0.145', '0', '0', '0', '0', '1', '0', 'base_link', 'laser']
            ),
            # gdb调试
            Node(
                package='global_map',
                executable='global_map',
                prefix='xterm -e gdb -ex run --args'
            ),
            # 重映射
            Node(
                package='turtlesim',
                executable='mimic',
                remappings=[
                    ('/input/pose', '/turtlesim1/turtle1/pose'),
                    ('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
                ]
            )
        ])
    
  3. 运行
    ros2 launch your_path_to_launch/mylaunch.py
    
参考

ROS2 创建一个launch文件