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

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

  • rosrun与roslaunch的区别

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

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

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

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

      mkdir launch
      cd launch
      touch test.launch
      
    • 填写内容

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

      roslaunch test.launch
      
  • 方式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
      
    • 使用上面的.launch文件内容

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

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

    <launch>
    </launch>
    
  • 3.2 条目

    组group
    节点node

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

    • 属性

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

      remap – 映射关系,调整话题topic?输入与输出
      	from – 原始topic
      	to – 新的topic
      
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>
    

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

created by shuaixio, 2022.11.06

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值