pxmlw6n2f/Gazebo_Distributed_MPI/mpi_run/MPI_Gazebo_launch.sh

105 lines
3.0 KiB
Bash
Raw Normal View History

#!/bin/bash
2019-05-27 15:21:55 +08:00
#####################################################################################################################################
# Author: Zhang Shuai #
# Date: 2019-05-23 #
# Description: launch a MPI Gazebo simulation task #
# Usage: ./MPI_Gazebo_launch.sh [ros packdge's name] [launch file's name] [workspace's path] [world's path and name] [hostfile] #
#####################################################################################################################################
packdge_name=$1
launch_file_name=$2
workspace_path=$3
world_file=$4
host_file=$5
2019-05-27 16:10:02 +08:00
echo $packdge_name
echo $launch_file_name
echo $workspace_path
echo $world_file
echo $host_file
host_count=0
hosts=()
#获取hostfile文件中的host名字
while read line
do
if [ -n "$line" ]
then
temp=${line% *}
hosts[$host_count]=$temp
let host_count=$host_count+1
fi
done < $host_file
echo "host_count:$host_count"
for((i=0;i<host_count;i++))
do
echo "host_name:${hosts[$i]}"
done
#登入各节点启动roscore source还有改进空间ROS运行的工作目录应该作为参数传进来
for((i=0;i<host_count;i++))
do
ssh -f -n ${hosts[$i]} "source $workspace_path/devel/setup.bash;
roscore;
echo roscore_done!"
echo "${hosts[$i]}:roscore_good"
done
sleep 5s
#登入第一个节点启动MPI的gzserver并成为各自节点上的ROS node
2019-05-27 16:10:02 +08:00
ssh -f -n ${hosts[0]} "cd ~/Git/Gazebo_Distributed_MPI/mpi_run;
2019-05-27 15:21:55 +08:00
mpiexec -hostfile $host_file -np 1 mygzserver $world_file $workspace_path : -np 1 mygzserver $world_file $workspace_path;
echo mpiexec_done!"
echo "${hosts[0]}:mpiexec_good"
sleep 20s
#登入各节点roslaunch加载模型source还有改进空间ROS运行的工作目录应该作为参数传进来
for((i=0;i<host_count;i++))
do
ssh -f -n ${hosts[$i]} "source $workspace_path/devel/setup.bash;
echo ++++++++++${hosts[$i]}++++++++++++;
env | grep LD_LIBRARY;
echo ++++++++++${hosts[$i]}++++++++++++;
2019-05-27 15:21:55 +08:00
roslaunch $packdge_name $launch_file_name;
echo roslaunch_done!"
echo "${hosts[$i]}:roslaunch_good"
done
sleep 20s
#登入各节点开始仿真
for((i=0;i<host_count;i++))
do
ssh -f -n ${hosts[$i]} "gz world -p 0;
echo start_done!;
exit"
echo "${hosts[$i]}:start_good"
done
2019-05-30 11:33:06 +08:00
sleep 5m
#登入各节点kill相关进程以结束仿真1.目前方式比较暴力后续改进2.cd ~/MPI 还要进行灵活性优化)
for((i=0;i<host_count;i++))
do
2019-05-27 16:20:15 +08:00
ssh -f -n ${hosts[$i]} > /dev/null 2>&1 "cd ~/Git/Gazebo_Distributed_MPI/mpi_run;
./kill.sh;
./kill.sh;
./kill.sh;
./kill.sh;
./kill.sh;
./kill.sh;
./kill.sh;
./kill.sh;
./kill.sh;
exit"
echo "${hosts[$i]}:close_good"
done
echo simulation_done!
exit 0