• 【工作向/ros】roslaunch节点启动与重启


    1. roslaunch介绍
    • roslaunch是一个工具,可以启动多个本地或远程ros节点。启动文件以.launch为后缀,启动文件是xml格式,一般把启动文件存在名为launch的目录

    • rosrun与roslaunch的区别

      • rosrun一次只能启动一个节点,如果要启动多个节点需要多次运行rosrun命令

        rosrun package_name executable_file 		# 即 rosrun 包名 可执行文件
        
        • 1
      • roslauch用来启动定义在launch文件中的多个节点,采用xml格式对要运行的节点进行描述

    2. roslaunch的启动方式
    • 方式1:直接launch文件启动。roslaunch path/to/your/xxx.launch

      • 简单创建一个.launch文件,保存并运行

        mkdir launch
        cd launch
        touch test.launch
        
        • 1
        • 2
        • 3
      • 填写内容

        <launch>
        	<node pkg = "package_name" type = "executable_file" name = "ros_node_name" output = "screen"/>
        </launch>
        
        • 1
        • 2
        • 3
      • 在终端直行

        roslaunch test.launch
        
        • 1
    • 方式2:工程包方式启动。roslaunch package_name file_name.launch

      • 用于ros工程中统一的功能包管理,实际项目中比较推荐这种方式

        cd ~/catkin_ws/src
        catkin_create_pkg test_launch
        cd test_launch
        mkdir launch
        cd launch
        touch test.launch
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
      • 使用上面的.launch文件内容

        cd ~/catkin_ws/src
        catkin_make	# 编译各个package
        source devel/setup.bash
        
        • 1
        • 2
        • 3
      • 然后以工程包方式启动节点

        roslaunch test_launch test.launch
        
        • 1
    3. roslaunch常用语法
    <launch>
    	<node pkg = "package_name" type = "executable_file" name = "ros_node_name" output = "screen"/>
    </launch>
    
    • 1
    • 2
    • 3
    • 3.1 文件属性

      <launch>
      </launch>
      
      • 1
      • 2
    • 3.2 条目

      组group
      节点node

      <group ns = “group_name”>
      </group>
      
      // ns = namespace命名空间,用来区分组group
      
      • 1
      • 2
      • 3
      • 4
    • 3.3 节点

      • 属性

        pkg – 功能包的名字
        type – 使用的功能包中的节点类型,可执行文件名
        name – ros::init起的节点名字
        output – 节点的输出定向到哪,默认是日志文件;通过output = “screen”输出到控制台
        respawn – 当设置为true时,节点停止后roslaunch会重新启动该节点,比如因为某些条件触发的coredump导致节点挂掉时,可以通过该参数立即重启该节点
        
        • 1
        • 2
        • 3
        • 4
        • 5
      • 条目

        remap – 映射关系,调整话题topic?输入与输出
        	from – 原始topic
        	to – 新的topic
        
        • 1
        • 2
        • 3
    4. roslaunch启动与重启
    • 启动多个节点,并设置节点掉线立即重启

      <launch>
          <node pkg="apollo" type="perception_bin" name="perception_node" respawn = "true" output="screen" />
          <node pkg="apollo" type="prediction_bin" name="prediction_node" respawn ="true" output="screen" />
      </launch>
      
      • 1
      • 2
      • 3
      • 4

    【参考文章】
    roslaunch核心语法
    启动roslaunch的两种方式
    catkin_create_pkg命令使用
    process has died, exit -6报错
    roslaunch节点关系图

    created by shuaixio, 2022.11.06

  • 相关阅读:
    14. Longest Common Prefix
    ThreadX笔记
    关于DDD的贫血模型和充血模型到底是什么区别?
    JVM复习
    Thread类的基本操作(JAVA多线程)
    面试时一些不能说的离职原因
    英国博士后招聘|约克大学—核磁共振监测催化
    Android gradle dependency tree change(依赖树变化)监控实现
    微信小程序 - - - input和键盘一起上弹如何实现?
    Django教程
  • 原文地址:https://blog.csdn.net/baidu_35692628/article/details/127716661