003.使用launch文件一次启动多个节点
我们可以通过.launch文件(实际上就是.xml格式的配置文件)
来实现一次启动多个节点
需要的操作如下
- 在包目录下新建
launch文件夹, 然后再在这个文件夹里面创建xxx.launch配置文件(名称随意)
ssr_pkg
├── CMakeLists.txt
├── include
│ └── ssr_pkg
├── launch
│ └── run_all.launch # .launch 文件
├── package.xml
└── src
└── chao_node.cpp
- 写入以下内容
<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>
意思如下,
-
.launch文件的配置需要被<launch>包裹 -
node表示需要启动的结点 -
pkg是包名,type是结点,name是名字 -
output="screen": 表示显示到屏蔽上 -
launch-prefix="konsole -e": 表示使用新建一个konsole控制台作为这个节点的输出
- 运行
.launch
roslaunch <包> <xxx.launch>
注:
-
不需要
roscore了, roslaunch 会自动运行roscore. -
<包>: 即
xxx.launch放在哪个包下面了
如:
roslaunch ssr_pkg run_all.launch

