Files
bizhang_-obav/Tools/sitl_run.sh

149 lines
3.1 KiB
Bash
Raw Normal View History

#!/bin/bash
2015-10-24 10:57:46 -04:00
set -e
echo args: $@
sitl_bin=$1
rc_script=$2
debugger=$3
program=$4
model=$5
src_path=$6
build_path=$7
2015-10-24 10:57:46 -04:00
echo SITL ARGS
echo sitl_bin: $sitl_bin
2015-10-24 10:57:46 -04:00
echo rc_script: $rc_script
echo debugger: $debugger
echo program: $program
echo model: $model
echo src_path: $src_path
2015-10-25 19:25:18 -04:00
echo build_path: $build_path
2015-10-24 10:57:46 -04:00
working_dir=`pwd`
sitl_bin=$build_path/src/firmware/posix/px4
2016-04-05 09:21:26 +02:00
2015-12-22 09:48:11 +01:00
if [ "$chroot" == "1" ]
then
chroot_enabled=-c
sudo_enabled=sudo
else
chroot_enabled=""
sudo_enabled=""
fi
if [ "$model" == "" ] || [ "$model" == "none" ]
2015-10-24 10:57:46 -04:00
then
echo "empty model, setting iris as default"
model="iris"
fi
if [ "$#" -lt 5 ]
then
echo usage: sitl_run.sh rc_script debugger program model devel_path
echo ""
2015-10-24 10:57:46 -04:00
exit 1
fi
command_exists () {
type "$1" &> /dev/null ;
}
# kill process names that might stil
# be running from last time
pgrep gazebo && pkill gazebo
pgrep px4 && pkill px4
if command_exists jps
2015-10-25 12:33:48 -04:00
then
jmavsim_pid=`jps | grep Simulator | cut -d" " -f1`
if [ -n "$jmavsim_pid" ]
then
kill $jmavsim_pid
fi
2015-10-25 12:33:48 -04:00
fi
cp $src_path/Tools/posix_lldbinit $working_dir/.lldbinit
cp $src_path/Tools/posix.gdbinit $working_dir/.gdbinit
2015-10-23 23:58:28 +02:00
SIM_PID=0
2016-04-24 18:48:56 -04:00
if [ "$program" == "jmavsim" ] && [ ! -n "$no_sim" ]
2015-10-17 17:41:57 +02:00
then
cd $src_path/Tools/jMAVSim
2016-04-01 19:01:41 +02:00
ant create_run_jar copy_res
cd out/production
java -Djava.ext.dirs= -jar jmavsim_run.jar -udp 127.0.0.1:14560 &
2015-10-26 16:03:22 -04:00
SIM_PID=`echo $!`
2016-04-01 19:01:41 +02:00
cd ../..
2016-04-24 18:48:56 -04:00
elif [ "$program" == "gazebo" ] && [ ! -n "$no_sim" ]
then
if [ -x "$(command -v gazebo)" ]
then
2015-10-25 18:25:37 +01:00
# Set the plugin path so Gazebo finds our model and sim
source /usr/share/gazebo/setup.sh
source $src_path/integrationtests/setup_gazebo_ros.bash ${src_path} ${build_path}
gzserver --verbose worlds/${model}.world &
2015-10-25 12:25:15 -04:00
SIM_PID=`echo $!`
2016-04-24 18:48:56 -04:00
if [[ -n "$HEADLESS" ]]; then
echo "not running gazebo gui"
else
gzclient --verbose &
GUI_PID=`echo $!`
fi
else
echo "You need to have gazebo simulator installed!"
exit 1
fi
2016-04-24 18:48:56 -04:00
elif [ "$program" == "replay" ] && [ ! -n "$no_sim" ]
2016-01-28 22:28:36 +01:00
then
echo "Replaying logfile: $logfile"
# This is not a simulator, but a log file to replay
# Check if we need to creat a param file to allow user to change parameters
if ! [ -f "$rootfs/replay_params.txt" ]
then
touch $rootfs/replay_params.txt
fi
2015-10-17 17:41:57 +02:00
fi
2016-01-28 22:28:36 +01:00
cd $working_dir
2016-01-28 22:28:36 +01:00
if [ "$logfile" != "" ]
then
cp $logfile $rootfs/replay.px4log
2016-01-28 22:28:36 +01:00
fi
# Do not exit on failure now from here on because we want the complete cleanup
set +e
2015-10-17 17:41:57 +02:00
# Start Java simulator
2015-10-24 10:57:46 -04:00
if [ "$debugger" == "lldb" ]
2015-09-20 12:54:22 +02:00
then
lldb -- $sitl_bin $src_path $src_path/${rc_script}_${program}_${model}
2015-10-24 10:57:46 -04:00
elif [ "$debugger" == "gdb" ]
2015-09-20 12:54:22 +02:00
then
gdb --args $sitl_bin $src_path $src_path/${rc_script}_${program}_${model}
2015-11-06 21:11:54 -05:00
elif [ "$debugger" == "ddd" ]
then
ddd --debugger gdb --args px4 $src_path $src_path/${rc_script}_${program}_${model}
2015-11-06 21:11:54 -05:00
elif [ "$debugger" == "valgrind" ]
then
valgrind $sitl_bin $src_path $src_path/${rc_script}_${program}_${model}
2015-09-20 12:54:22 +02:00
else
$sudo_enabled $sitl_bin $chroot_enabled $src_path $src_path/${rc_script}_${program}_${model}
2015-09-20 12:54:22 +02:00
fi
2015-10-23 23:58:28 +02:00
if [ "$program" == "jmavsim" ]
2015-10-23 23:58:28 +02:00
then
kill -9 $SIM_PID
elif [ "$program" == "gazebo" ]
2015-10-23 23:58:28 +02:00
then
kill -9 $SIM_PID
2016-04-24 18:48:56 -04:00
if [[ ! -n "$HEADLESS" ]]; then
kill -9 $GUI_PID
fi
2015-10-23 23:58:28 +02:00
fi