通常是编写launch文件一次性启动多个节点,这次采用编写sh脚本控制多个launch文件启动,在任意路径下新建xxx.sh的文件,内容如下
#!/bin/bash
source ~/catkin_ws/devel/setup.bash
{
gnome-terminal -t "create pkg" -- bash -c "python /home/zxh/sdhyRos1Ws/install/share/project_launch/tools/createGpsSavePath.py;exec bash"
}&
sleep 3s
echo "create pkg success"
{
gnome-terminal -t "zed2" -- bash -c "roslaunch zed_wrapper zed2.launch;exec bash"
}&
sleep 10s
echo "project_launch starting success!"
{
gnome-terminal -t "darknet_ros" -- bash -c "roslaunch darknet_ros darknet_ros.launch;exec bash"
}&
echo "recorder_gps_pose starting success!"
gnome-terminal打开一个新的终端;exec bash,不让终端运行结束后关闭;&后台运行程序;bash -c "命令"。
多个命令可在一个终端使用:
{
gnome-terminal -x bash -c "cd ~/catkin_ws;source ./devel/setup.bash;roslaunch darknet_ros darknet_ros.launch;exec bash "
}
在终端要给xxx.sh执行权限,sudo chmod a+x xxx.sh,之后可通过./xxx.sh进行启动。
参考链接 ROS学习笔记-roslaunch文件的编写&用sh脚本控制launch文件启动顺序_TYINY的博客-CSDN博客_roslaunch脚本