From 3ef852c8e38fb52303bc1646dc276d026fd1a7a1 Mon Sep 17 00:00:00 2001 From: JaeyoungLim Date: Wed, 24 Jun 2020 08:23:16 +0200 Subject: [PATCH] sitl: enable spawning different vehicle types for multivehicle SITL in gazebo (#15147) This can be run with the command `Toos/gazebo_multiple_sitl_run.sh -s plane:3,iris:1 --- Tools/gazebo_sitl_multiple_run.sh | 99 ++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 33 deletions(-) diff --git a/Tools/gazebo_sitl_multiple_run.sh b/Tools/gazebo_sitl_multiple_run.sh index 92500c682d..5b8da524f1 100755 --- a/Tools/gazebo_sitl_multiple_run.sh +++ b/Tools/gazebo_sitl_multiple_run.sh @@ -11,37 +11,58 @@ function cleanup() { pkill gzclient } +function spawn_model() { + MODEL=$1 + N=$2 #Instance Number + + if [ "$MODEL" != "iris" ] && [ "$MODEL" != "plane" ] && [ "$MODEL" != "standard_vtol" ] + then + echo "Currently only the following vehicle models are supported! [iris, plane, standard_vtol]" + exit 1 + fi + + working_dir="$build_path/instance_$n" + [ ! -d "$working_dir" ] && mkdir -p "$working_dir" + + pushd "$working_dir" &>/dev/null + echo "starting instance $n in $(pwd)" + ../bin/px4 -i $n -d "$src_path/ROMFS/px4fmu_common" -w sitl_${MODEL}_${n} -s etc/init.d-posix/rcS >out.log 2>err.log & + python3 ${src_path}/Tools/sitl_gazebo/scripts/xacro.py ${src_path}/Tools/sitl_gazebo/models/rotors_description/urdf/${MODEL}_base.xacro \ + rotors_description_dir:=${src_path}/Tools/sitl_gazebo/models/rotors_description mavlink_udp_port:=$(($mavlink_udp_port+$N)) \ + mavlink_tcp_port:=$(($mavlink_tcp_port+$N)) -o /tmp/${MODEL}_${N}.urdf + + gz sdf -p /tmp/${MODEL}_${N}.urdf > /tmp/${MODEL}_${n}.sdf + echo "Spawning ${MODEL}_${N}" + + gz model --spawn-file=/tmp/${MODEL}_${N}.sdf --model-name=${MODEL}_${N} -x 0.0 -y $((3*${N})) -z 0.0 + + popd &>/dev/null + +} + if [ "$1" == "-h" ] || [ "$1" == "--help" ] then - echo "Usage: $0 [-n ] [-m ]" + echo "Usage: $0 [-n ] [-m ] [-w ] [-s