pxmlw6n2f/Gazebo_Distributed_MPI/mpi_run/MPI_Gazebo_launch.sh

105 lines
3.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#####################################################################################################################################
# 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
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
ssh -f -n ${hosts[0]} "cd ~/Git/Gazebo_Distributed_MPI/mpi_run;
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]}++++++++++++;
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
sleep 5m
#登入各节点kill相关进程以结束仿真1.目前方式比较暴力后续改进2.cd ~/MPI 还要进行灵活性优化)
for((i=0;i<host_count;i++))
do
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