一、编写启动脚本
新建一个后缀为a.sh(名称任取,后缀为.sh即可)的脚本,内容按照如下格式填写,其中每个
gnome-terminal -- bash -c "cd /home/mobot/catkin_ws1;source devel/setup.bash;roslaunch rslidar_sdk start.launch"
中的双引号里面对应启动一个launch文件,为了防止一个launch还没启动完就启动了另一个launch导致启动失败,通过sleep 10 wait等待10秒钟(具体等待多久合适可以自己测试一下,一般要不了10秒)再启动下一个launch.每次执行一个ros的节点或者launch文件时,需要cd到对应工作空间下,执行
source devel/setup.bash
再启动相应的程序,即使已经在.bashrc中source过也要这么做。
#! /bin/bash
#根据系统启动相应版本的roscore
sudo chmod 777 /dev/ttyTHS0
gnome-terminal -- bash -c "cd /home/mobot/catkin_ws1;source devel/setup.bash;roslaunch rslidar_sdk start.launch"
sleep 10
wait
gnome-terminal -- bash -c "cd /home/mobot/pcl_ws;source devel/setup.bash;roslaunch pcl_test pcl_test.launch"
sleep 10
wait
gnome-terminal -- bash -c "cd /home/mobot/pcl_ws;source devel/setup.bash;roslaunch euclidean_cluster euclidean_cluster.launch"
sleep 10
wait
gnome-terminal -- bash -c "cd /home/mobot/serial_ws;source devel/setup.bash;rosrun serial_test1 serial_test1"
sleep 10
wait
exit 0
二、添加到自启动
搜索并打开"启动应用程序"(如果是英文系统则搜索“startup applications”)
点击"添加"