跳到主要内容

003.使用launch文件一次启动多个节点

我们可以通过.launch文件(实际上就是.xml格式的配置文件)

来实现一次启动多个节点

需要的操作如下

  1. 在包目录下新建launch文件夹, 然后再在这个文件夹里面创建xxx.launch配置文件(名称随意)
ssr_pkg
├── CMakeLists.txt
├── include
│   └── ssr_pkg
├── launch
│   └── run_all.launch # .launch 文件
├── package.xml
└── src
└── chao_node.cpp
sh
  1. 写入以下内容
<launch>
<node pkg="ssr_pkg" type="chao_node" name="chao_node" output="screen" launch-prefix="konsole -e"/>
<node pkg="ma_pkg" type="ma_node" name="ma_node" output="screen" launch-prefix="konsole -e"/>
</launch>
xml

意思如下,

  • .launch文件的配置需要被<launch>包裹

  • node表示需要启动的结点

  • pkg是包名, type是结点, name是名字

  • output="screen": 表示显示到屏蔽上

  • launch-prefix="konsole -e": 表示使用新建一个konsole控制台作为这个节点的输出

  1. 运行.launch
roslaunch <> <xxx.launch>
sh

注:

  • 不需要roscore了, roslaunch 会自动运行roscore.

  • <包>: 即xxx.launch放在哪个包下面了

如:

roslaunch ssr_pkg run_all.launch
sh
请作者喝奶茶:
Alipay IconQR Code
Alipay IconQR Code
本文遵循 CC CC 4.0 BY-SA 版权协议, 转载请标明出处
Loading Comments...