用shell脚本在Tmux中多窗口运行ROS程序

参考:https://blog.csdn.net/To_ChaRiver/article/details/119431775

目录

  • 目标
  • 环境
  • 脚本示例
  • 说明

目标

编写一个shell script,用来启动Tmux,创建一个会话(Session)并将窗口(Window)分割为四个窗格(Pane),在每个窗格内分别运行不同的ROS程序。

环境

Ubuntu 16.04
Tmux 2.1
ROS Kinetic

脚本示例

  1. 创建脚本文件test.sh
$ touch test.sh
  1. 编辑脚本
$ gedit test.sh

shell脚本内容为

#!/bin/bash

uid=$(whoami)

## Clear ROS logs.
rm -rf /home/$uid/.ros/log

## Go to the destination directory.
cd /home/$uid/catkin_ws/install/

echo "Start a Tmux session."

## Create a Tmux session "mywork" in a window "window0" started in the background.
tmux new -d -s mywork -n window0

## Split the window to 4 panes.
tmux split-window -h -t mywork:window0
tmux split-window -v -t mywork:window0.0
tmux split-window -v -t mywork:window0.1

## Run the ROS programs sequentially.
tmux send -t mywork:window0.0 "source setup.bash && roslaunch prog1 p1.launch" ENTER
tmux send -t mywork:window0.1 "source setup.bash && roslaunch prog2 p2.launch" ENTER
tmux send -t mywork:window0.2 "source setup.bash && roslaunch prog3 p3.launch" ENTER
tmux send -t mywork:window0.3 "source setup.bash && roslaunch prog4 p4.launch" ENTER

## Attach the Tmux session to the front.
tmux a -t mywork
  1. 赋权
$ sudo chmod +x test.sh
  1. 运行脚本
$ source test.sh

说明

本文展示了用shell脚本建立Tmux复用终端并运行ROS程序的方式,便于有需求的读者套用。
Tmux的命令行操作语句可以查询相关手册或博客。

你可能感兴趣的:(方法,自动驾驶,shell)