在调试ROS程序时,经常需要运行多个节点程序,如果每个都打开一个终端然后输入指令非常繁琐,可以写一个脚本文件,每次运行这个脚本就能一次运行多个节点,方便高效。方法来自于链接。其实就是利用ubuntu中的terminator小程序,安装方法如下:

sudo apt-get install terminator

安装好以后在~/.config/terminator路径下的config是它的配置文件(例如设置窗口数量、字体、窗口大小等)。如果安装terminator后没有这个文件夹那你自己新建一个就可以了。下面以启动四个窗口为例说明怎么写脚本。
  打开config文件,在terminal3下面,给command选项起个名字,例如command = COMMAND1,如下。其它的terminal同理,后面的脚本会把这个名字改成运行的指令。

[global_config]
  enabled_plugins = CustomCommandsMenu, ActivityWatch, LaunchpadCodeURLHandler, APTURLHandler, LaunchpadBugURLHandler
  suppress_multiple_term_dialog = True
[keybindings]
[layouts]
  [[default]]
    [[[child0]]]
      fullscreen = False
      last_active_term = 6465ad81-9563-4994-a9ea-4c73e642264a
      last_active_window = True
      maximised = True
      order = 0
      parent = ""
      position = 91:27
      size = 1823, 861
      title = q@ubuntu: ~
      type = Window
    [[[child1]]]
      order = 0
      parent = child0
      position = 908
      ratio = 0.499725726824
      type = HPaned
    [[[child2]]]
      order = 0
      parent = child1
      position = 427
      ratio = 0.499419279907
      type = VPaned
    [[[child5]]]
      order = 1
      parent = child1
      position = 427
      ratio = 0.499419279907
      type = VPaned
    [[[terminal3]]]
      command = COMMAND1
      order = 0
      parent = child2
      profile = default
      type = Terminal
      uuid = 6465ad81-9563-4994-a9ea-4c73e642264a
    [[[terminal4]]]
      command = COMMAND2
      order = 1
      parent = child2
      profile = default
      type = Terminal
      uuid = 40bece0b-c0b1-4510-b0d4-555a76b0df61
    [[[terminal6]]]
      command = COMMAND3
      order = 0
      parent = child5
      profile = default
      type = Terminal
      uuid = 54ebe730-2576-4963-a96f-bf5d63167da9
    [[[terminal7]]]
      command = COMMAND4
      order = 1
      parent = child5
      profile = default
      type = Terminal
      uuid = 2941b7ee-3345-4062-bfc3-cd68f3a636d4
[plugins]
[profiles]
  [[default]]
    background_image = None
    scrollback_lines = 5000

然后制作自己的脚本,以我的为例。新建script.sh文件,记事本打开然后输入以下命令。看到command1后面的指令了吧,那就是你要运行的指令,修改为你自己的指令即可,然后保存。其中的sleep指令是防止节点同时启动,因为如果同时启动会出错,所以延时一段时间以错开运行。执行脚本时,打开一个终端并输入./script.sh即可看到terminator同时启动多个窗口的过程,如下图。如果想同时关闭这多个窗口,在运行脚本的终端中按ctrl+C即可。
  如果有一天你的脚本启动不了terminator了,那就检查一下~/.config/terminator路径下的配置文件config,把它改回上面的代码即可。

#!/bin/bash

## change these to whatever you actually need
command1="cd ~/TEB;source devel/setup.bash;roslaunch teb_local_planner_tutorials robot_carlike_in_stage.launch; bash"
command2="sleep 2s;roslaunch yocs_velocity_smoother standalone.launch; bash"
command3="sleep 3s;source ~/control/devel/setup.bash; roslaunch control control.launch; bash"
command4="sleep 4s;source ~/ReedsShepp/devel/setup.bash; roslaunch steering_functions steering_functions.launch; bash"

## Modify terminator's config
sed -i.bak "s#COMMAND1#$command1#; s#COMMAND2#$command2#; s#COMMAND3#$command3#; s#COMMAND4#$command4#;" ~/.config/terminator/config

## Launch a terminator instance using the new layout
terminator -l default

## Return the original config file
mv ~/.config/terminator/config.bak ~/.config/terminator/config