2015-06-15 13:51:07 -03:00
|
|
|
#!/bin/bash
|
2015-10-24 11:57:46 -03:00
|
|
|
|
2016-08-25 16:47:45 -03:00
|
|
|
set -e
|
|
|
|
|
|
|
|
echo args: $@
|
|
|
|
|
|
|
|
sitl_bin=$1
|
2016-09-01 05:59:26 -03:00
|
|
|
rcS_dir=$2
|
2016-08-25 16:47:45 -03:00
|
|
|
debugger=$3
|
|
|
|
program=$4
|
|
|
|
model=$5
|
|
|
|
src_path=$6
|
|
|
|
build_path=$7
|
2015-10-24 11:57:46 -03:00
|
|
|
|
|
|
|
echo SITL ARGS
|
2016-08-25 16:47:45 -03:00
|
|
|
|
|
|
|
echo sitl_bin: $sitl_bin
|
2016-09-01 05:59:26 -03:00
|
|
|
echo rcS_dir: $rcS_dir
|
2015-10-24 11:57:46 -03:00
|
|
|
echo debugger: $debugger
|
|
|
|
echo program: $program
|
2015-10-29 06:35:35 -03:00
|
|
|
echo model: $model
|
2016-08-25 16:47:45 -03:00
|
|
|
echo src_path: $src_path
|
2015-10-25 20:25:18 -03:00
|
|
|
echo build_path: $build_path
|
2015-10-24 11:57:46 -03:00
|
|
|
|
2016-08-25 16:47:45 -03:00
|
|
|
working_dir=`pwd`
|
2016-09-29 05:07:00 -03:00
|
|
|
rootfs=$build_path/tmp/rootfs
|
2016-04-05 04:21:26 -03:00
|
|
|
|
2015-12-22 04:48:11 -04:00
|
|
|
if [ "$chroot" == "1" ]
|
|
|
|
then
|
|
|
|
chroot_enabled=-c
|
|
|
|
sudo_enabled=sudo
|
|
|
|
else
|
|
|
|
chroot_enabled=""
|
|
|
|
sudo_enabled=""
|
|
|
|
fi
|
|
|
|
|
2016-11-25 12:04:12 -04:00
|
|
|
# To disable user input
|
|
|
|
if [[ -n "$NO_PXH" ]]; then
|
|
|
|
no_pxh=-d
|
|
|
|
else
|
|
|
|
no_pxh=""
|
|
|
|
fi
|
|
|
|
|
2015-10-29 06:35:35 -03:00
|
|
|
if [ "$model" == "" ] || [ "$model" == "none" ]
|
2015-10-24 11:57:46 -03:00
|
|
|
then
|
2015-10-29 06:35:35 -03:00
|
|
|
echo "empty model, setting iris as default"
|
|
|
|
model="iris"
|
|
|
|
fi
|
|
|
|
|
2017-03-01 09:41:04 -04:00
|
|
|
# check replay mode
|
|
|
|
if [ "$replay_mode" == "ekf2" ]
|
|
|
|
then
|
|
|
|
model="iris_replay"
|
|
|
|
# create the publisher rules
|
|
|
|
mkdir -p $rootfs
|
|
|
|
publisher_rules_file="$rootfs/orb_publisher.rules"
|
|
|
|
cat <<EOF > "$publisher_rules_file"
|
|
|
|
restrict_topics: sensor_combined, vehicle_gps_position, vehicle_land_detected
|
|
|
|
module: replay
|
|
|
|
ignore_others: false
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2016-09-01 05:59:26 -03:00
|
|
|
if [ "$#" -lt 7 ]
|
2015-10-29 06:35:35 -03:00
|
|
|
then
|
2016-09-01 05:59:26 -03:00
|
|
|
echo usage: sitl_run.sh rc_script rcS_dir debugger program model src_path build_path
|
2015-10-29 06:35:35 -03:00
|
|
|
echo ""
|
2015-10-24 11:57:46 -03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-10-25 11:57:24 -03:00
|
|
|
# kill process names that might stil
|
|
|
|
# be running from last time
|
2017-01-18 05:16:34 -04:00
|
|
|
pkill -x gazebo || true
|
|
|
|
pkill -x px4 || true
|
|
|
|
pkill -x px4_$model || true
|
|
|
|
|
2016-08-24 12:07:14 -03:00
|
|
|
jmavsim_pid=`ps aux | grep java | grep Simulator | cut -d" " -f1`
|
2016-08-05 16:29:49 -03:00
|
|
|
if [ -n "$jmavsim_pid" ]
|
2015-10-25 13:33:48 -03:00
|
|
|
then
|
2016-08-05 16:29:49 -03:00
|
|
|
kill $jmavsim_pid
|
2015-10-25 13:33:48 -03:00
|
|
|
fi
|
2015-10-25 11:57:24 -03:00
|
|
|
|
2016-08-25 16:47:45 -03:00
|
|
|
cp $src_path/Tools/posix_lldbinit $working_dir/.lldbinit
|
|
|
|
cp $src_path/Tools/posix.gdbinit $working_dir/.gdbinit
|
2015-10-23 18:58:28 -03:00
|
|
|
|
|
|
|
SIM_PID=0
|
|
|
|
|
2016-04-24 19:48:56 -03:00
|
|
|
if [ "$program" == "jmavsim" ] && [ ! -n "$no_sim" ]
|
2015-10-17 12:41:57 -03:00
|
|
|
then
|
2017-08-01 07:11:01 -03:00
|
|
|
$src_path/Tools/jmavsim_run.sh -r 500 &
|
2015-10-26 17:03:22 -03:00
|
|
|
SIM_PID=`echo $!`
|
2016-04-01 14:01:41 -03:00
|
|
|
cd ../..
|
2016-04-24 19:48:56 -03:00
|
|
|
elif [ "$program" == "gazebo" ] && [ ! -n "$no_sim" ]
|
2015-10-22 11:30:23 -03:00
|
|
|
then
|
|
|
|
if [ -x "$(command -v gazebo)" ]
|
|
|
|
then
|
2017-09-14 06:51:02 -03:00
|
|
|
if [[ -z "$DONT_RUN" ]]
|
|
|
|
then
|
|
|
|
# Set the plugin path so Gazebo finds our model and sim
|
|
|
|
source $src_path/Tools/setup_gazebo.bash ${src_path} ${build_path}
|
|
|
|
|
|
|
|
gzserver --verbose ${src_path}/Tools/sitl_gazebo/worlds/${model}.world &
|
|
|
|
SIM_PID=`echo $!`
|
|
|
|
|
|
|
|
if [[ -n "$HEADLESS" ]]; then
|
|
|
|
echo "not running gazebo gui"
|
|
|
|
else
|
|
|
|
# gzserver needs to be running to avoid a race. Since the launch
|
|
|
|
# is putting it into the background we need to avoid it by backing off
|
|
|
|
sleep 3
|
|
|
|
nice -n 20 gzclient --verbose &
|
|
|
|
GUI_PID=`echo $!`
|
|
|
|
fi
|
2016-04-24 19:48:56 -03:00
|
|
|
fi
|
2015-10-22 11:30:23 -03:00
|
|
|
else
|
|
|
|
echo "You need to have gazebo simulator installed!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-10-17 12:41:57 -03:00
|
|
|
fi
|
2016-01-28 17:28:36 -04:00
|
|
|
|
2016-08-25 16:47:45 -03:00
|
|
|
cd $working_dir
|
2015-11-23 08:51:18 -04:00
|
|
|
|
|
|
|
# Do not exit on failure now from here on because we want the complete cleanup
|
|
|
|
set +e
|
|
|
|
|
2016-11-25 12:04:12 -04:00
|
|
|
sitl_command="$sudo_enabled $sitl_bin $no_pxh $chroot_enabled $src_path $src_path/${rcS_dir}/${model}"
|
2016-08-25 16:47:45 -03:00
|
|
|
|
|
|
|
echo SITL COMMAND: $sitl_command
|
|
|
|
|
2017-09-14 06:51:02 -03:00
|
|
|
if [[ -n "$DONT_RUN" ]]
|
|
|
|
then
|
|
|
|
echo "Not running simulation (\$DONT_RUN is set)."
|
2015-10-17 12:41:57 -03:00
|
|
|
# Start Java simulator
|
2017-09-14 06:51:02 -03:00
|
|
|
elif [ "$debugger" == "lldb" ]
|
2015-09-20 07:54:22 -03:00
|
|
|
then
|
2016-08-25 16:47:45 -03:00
|
|
|
lldb -- $sitl_command
|
2015-10-24 11:57:46 -03:00
|
|
|
elif [ "$debugger" == "gdb" ]
|
2015-09-20 07:54:22 -03:00
|
|
|
then
|
2016-08-25 16:47:45 -03:00
|
|
|
gdb --args $sitl_command
|
2015-11-06 22:11:54 -04:00
|
|
|
elif [ "$debugger" == "ddd" ]
|
|
|
|
then
|
2016-08-25 16:47:45 -03:00
|
|
|
ddd --debugger gdb --args $sitl_command
|
2015-11-06 22:11:54 -04:00
|
|
|
elif [ "$debugger" == "valgrind" ]
|
|
|
|
then
|
2017-02-17 13:36:52 -04:00
|
|
|
valgrind --track-origins=yes --leak-check=full -v $sitl_command
|
|
|
|
elif [ "$debugger" == "callgrind" ]
|
|
|
|
then
|
|
|
|
valgrind --tool=callgrind -v $sitl_command
|
2016-12-08 00:41:46 -04:00
|
|
|
elif [ "$debugger" == "ide" ]
|
|
|
|
then
|
|
|
|
echo "######################################################################"
|
|
|
|
echo
|
|
|
|
echo "PX4 simulator not started, use your IDE to start PX4_${model} target."
|
|
|
|
echo "Hit enter to quit..."
|
|
|
|
echo
|
|
|
|
echo "######################################################################"
|
|
|
|
read
|
2015-09-20 07:54:22 -03:00
|
|
|
else
|
2016-08-25 16:47:45 -03:00
|
|
|
$sitl_command
|
2015-09-20 07:54:22 -03:00
|
|
|
fi
|
2015-10-23 18:58:28 -03:00
|
|
|
|
2017-09-14 06:51:02 -03:00
|
|
|
if [[ -z "$DONT_RUN" ]]
|
2015-10-23 18:58:28 -03:00
|
|
|
then
|
2017-09-14 06:51:02 -03:00
|
|
|
if [ "$program" == "jmavsim" ]
|
|
|
|
then
|
|
|
|
pkill -9 -P $SIM_PID
|
|
|
|
kill -9 $SIM_PID
|
|
|
|
elif [ "$program" == "gazebo" ]
|
|
|
|
then
|
|
|
|
kill -9 $SIM_PID
|
|
|
|
if [[ ! -n "$HEADLESS" ]]; then
|
|
|
|
kill -9 $GUI_PID
|
|
|
|
fi
|
2016-04-24 19:48:56 -03:00
|
|
|
fi
|
2015-10-23 18:58:28 -03:00
|
|
|
fi
|