Add "kill.sh" "MPI_Gazebo_launch.sh" "mygzserver" three scripts to launch MPI_simulation task automatically under ROS-Gazebo framework

This commit is contained in:
zhangshuai 2019-05-23 15:42:20 +08:00
parent 6d92a1b9e7
commit 8df672a460
9 changed files with 198 additions and 2099267 deletions

View File

@ -0,0 +1,93 @@
#!/bin/bash
#########################################################################
# Author: Zhang Shuai #
# Date: 2019-05-23 #
# Description: launch a MPI Gazebo simulation task #
# Usage: ./MPI_Gazebo_launch.sh [hostfile] [world's path and name] #
#########################################################################
host_file=$1
world_file=$2
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 ~/catkin_ws/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 ~/MPI;
mpiexec -hostfile hostfile -np 1 mygzserver $world_file : -np 1 mygzserver $world_file;
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 ~/catkin_ws/devel/setup.bash;
roslaunch hector_quadrotor_gazebo hector_2_single_gazebo_mpi_spawn_test.launch;
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 ~/MPI;
./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

View File

@ -1,4 +1,4 @@
zhangshuai-Desktop slots=1
#anwen slots=2
zhangshuai-Laptop slots=1
anwen slots=1
zhangshuai-ThinkPad-X250 slots=1

View File

@ -0,0 +1,27 @@
#!/bin/bash
pid=$(ps aux | grep roscore | grep -v grep | awk '{print $2}' | sort -n | head -n 1) # 获取进程号
echo "roscore command is running, pid:${pid}"
kill ${pid} && echo "roscore command is complete"
pid=$(ps aux | grep roslaunch | grep -v grep | awk '{print $2}' | sort -n | head -n 1) # 获取进程号
echo "roslaunch command is running, pid:${pid}"
kill ${pid} && echo "roslaunch command is complete"
pid=$(ps aux | grep mpiexec | grep -v grep | awk '{print $2}' | sort -n | head -n 1) # 获取进程号
echo "mpiexec command is running, pid:${pid}"
kill ${pid} && echo "mpiexec command is complete"
pid=$(ps aux | grep gzserver | grep -v grep | awk '{print $2}' | sort -n | head -n 1) # 获取进程号
echo "gzserver command is running, pid:${pid}"
kill ${pid} && echo "gzserver command is complete"
exit 0

View File

@ -0,0 +1,63 @@
<?xml version="1.0" ?>
<sdf version="1.4">
<world name="default">
<!-- A global light source -->
<include>
<uri>model://sun</uri>
</include>
<include>
<uri>model://kunming_airport</uri>
<pose>0 0 0 0 0 0</pose>
</include>
<scene>
<ambient>0.68 0.68 0.68 1.0</ambient>
<sky>
<sunrise/>
<clouds>
<speed>0</speed>
</clouds>
</sky>
</scene>
<!-- For distributed simulation -->
<distribution flag=0>
<gazebo_id num=0>
<model_name>bebop_0</model_name>
</gazebo_id>
<gazebo_id num=1>
<model_name>bebop_1</model_name>
</gazebo_id>
</distribution>
<physics type="ode" name="ode">
<real_time_update_rate>0</real_time_update_rate>
<max_step_size>0.001</max_step_size>
<real_time_factor>0</real_time_factor>
<!-- <ode>
<solver>
<thread_position_correction>0</thread_position_correction>
<island_threads>8</island_threads>
</solver>
</ode> -->
</physics>
<model name="bebop_0">
<pose>0 5 0.186 0 0 0</pose>
<include>
<uri>model://quadrotor</uri>
</include>
<plugin name="takeoff" filename="/home/zhangshuai/gazebo_plugin_tutorial/takeoff/build/libtakeoff.so"/>
</model>
<model name="bebop_1">
<pose>0 -5 0.186 0 0 0</pose>
<include>
<uri>model://quadrotor</uri>
</include>
<plugin name="takeoff" filename="/home/zhangshuai/gazebo_plugin_tutorial/takeoff/build/libtakeoff.so"/>
</model>
</world>
</sdf>

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +0,0 @@
localhost slots=2

View File

@ -17,4 +17,6 @@ mpiexec -np 1 -x GAZEBO_MASTER_URI=http://localhost:11346 gazebo -u -e ode --ver
mpiexec -np 1 -x GAZEBO_MASTER_URI=http://localhost:11346 gzserver -u -e ode --verbose /home/zhangshuai/Git/Gazebo_Hector_Test/src/hector_quadrotor/hector_quadrotor_gazebo/worlds/kunming_airport_distribution_2hector_mpi_test.world -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_paths_plugin.so -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_api_plugin.so __name:=xxx : -np 1 -x GAZEBO_MASTER_URI=http://localhost:11347 gzserver -u -e ode --verbose /home/zhangshuai/Git/Gazebo_Hector_Test/src/hector_quadrotor/hector_quadrotor_gazebo/worlds/kunming_airport_distribution_2hector_mpi_test.world -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_paths_plugin.so -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_api_plugin.so __name:=yyy
mpiexec -hostfile hostfile -np 1 -x GAZEBO_MASTER_URI=http://localhost:11346 gazebo -u -e ode --verbose /home/zhangshuai/Git/Gazebo_Hector_Test/src/hector_quadrotor/hector_quadrotor_gazebo/worlds/kunming_airport_distribution_2hector_mpi_test.world -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_paths_plugin.so -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_api_plugin.so __name:=xxx : -np 1 -x GAZEBO_MASTER_URI=http://localhost:11347 gazebo -u -e ode --verbose /home/zhangshuai/Git/Gazebo_Hector_Test/src/hector_quadrotor/hector_quadrotor_gazebo/worlds/kunming_airport_distribution_2hector_mpi_test.world -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_paths_plugin.so -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_api_plugin.so __name:=yyy
mpiexec -hostfile hostfile -np 1 -x GAZEBO_MASTER_URI=http://localhost:11346 gazebo -u -e ode --verbose /home/zhangshuai/Git/Gazebo_Hector_Test/src/hector_quadrotor/hector_quadrotor_gazebo/worlds/kunming_airport_distribution_2hector_mpi_test.world -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_paths_plugin.so -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_api_plugin.so __name:=xxx : -np 1 -x GAZEBO_MASTER_URI=http://localhost:11347 gazebo -u -e ode --verbose /home/zhangshuai/Git/Gazebo_Hector_Test/src/hector_quadrotor/hector_quadrotor_gazebo/worlds/kunming_airport_distribution_2hector_mpi_test.world -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_paths_plugin.so -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_api_plugin.so __name:=yyy
mpiexec -hostfile hostfile -np 1 gazebo -u -e ode --verbose /home/zhangshuai/Git/Gazebo_Hector_Test/src/hector_quadrotor/hector_quadrotor_gazebo/worlds/kunming_airport_distribution_2hector_mpi_test.world -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_paths_plugin.so -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_api_plugin.so __name:=xxx : -np 1 gazebo -u -e ode --verbose /home/zhangshuai/Git/Gazebo_Hector_Test/src/hector_quadrotor/hector_quadrotor_gazebo/worlds/kunming_airport_distribution_2hector_mpi_test.world -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_paths_plugin.so -s /home/zhangshuai/catkin_ws/devel/lib/libgazebo_ros_api_plugin.so __name:=yyy

View File

@ -0,0 +1,9 @@
#!/bin/bash
#echo ++++++++$1
source /opt/ros/kinetic/setup.bash
source ~/catkin_ws/devel/setup.bash
export DISPLAY=:0.0
gzserver -u -e ode --verbose $1 -s /opt/ros/kinetic/lib/libgazebo_ros_paths_plugin.so -s /opt/ros/kinetic/lib/libgazebo_ros_api_plugin.so

View File

@ -1,3 +0,0 @@
#!/bin/sh
mpiexec -hostfile hostfile -np 1 -x GAZEBO_MASTER_URI=http://localhost:11346 gazebo --verbose /home/zhangshuai/Git/Gazebo_Distributed_MPI/mpi_run/kunming_airport_distribution_30hector_mpi_test.world : -np 1 -x GAZEBO_MASTER_URI=http://localhost:11347 gzserver --verbose /home/zhangshuai/Git/Gazebo_Distributed_MPI/mpi_run/kunming_airport_distribution_30hector_mpi_test.world