px4-firmware/Tools/sitl_run.sh

184 lines
3.8 KiB
Bash
Raw Normal View History

#!/bin/bash
2015-10-24 11:57:46 -03:00
set -e
echo args: $@
sitl_bin=$1
Bug fixes, typos, indentation. Over time I made a few changes unrelated to what I'm really working on. These changes are hereby committed first. The bug fixes are related to what I'm doing in that I need them to be fixed for future commits. Tools/sitl_run.sh: rename label to rcS_dir and fix usage help. cmake/common/px4_base.cmake: Remove the check on OUT_UNPARSED_ARGUMENTS, and a few typos and indentation issues. cmake/configs/posix_sitl_replay.cmake: Set the correct variable (config_sitl_rcS_dir) to the correct directory. cmake/nuttx/px4_impl_nuttx.cmake: typos and indentation issues, and removal of a redundant FORCE (INTERNAL implies FORCE). cmake/posix/px4_impl_posix.cmake: typos and indentation issues. cmake/qurt/px4_impl_qurt.cmake: typos and indentation issues. src/modules/mavlink/mavlink_ftp.cpp : possible strict-aliasing breakage. NOTES The second argument passed to sitl_run.sh is the value of config_sitl_rcS_dir. This fact is missing from the usage help. I renamed 'label' to 'rcS_dir' to better reflect this. Also, for the 'replay' config the wrong variable was set causing the call to sitl_run.sh to skip an argument and fail (ie the debugger was passed as rcS_dir and so on). The check on OUT_UNPARSED_ARGUMENTS in px4_parse_function_args basically causes every passed IN variable to be REQUIRED and is therefore a bug. The test for the presence of the REQUIRED arguments follows directly after and is sufficient for this job. This bug went unnoticed because currently every argument to OPTIONS, ONE_VALUE, and MULTI_VALUE is actually passed to the function(s) calling px4_parse_function_args (them being REQUIRED or not). The changes in mavlink_ftp.cpp are to avoid a possible aliasing bug and (mostly) to avoid the compiler warning/error: dereferencing type- punned pointer will break strict-aliasing rules [-Werror=strict-aliasing].
2016-09-01 05:59:26 -03:00
rcS_dir=$2
debugger=$3
program=$4
model=$5
src_path=$6
build_path=$7
2015-10-24 11:57:46 -03:00
echo SITL ARGS
echo sitl_bin: $sitl_bin
Bug fixes, typos, indentation. Over time I made a few changes unrelated to what I'm really working on. These changes are hereby committed first. The bug fixes are related to what I'm doing in that I need them to be fixed for future commits. Tools/sitl_run.sh: rename label to rcS_dir and fix usage help. cmake/common/px4_base.cmake: Remove the check on OUT_UNPARSED_ARGUMENTS, and a few typos and indentation issues. cmake/configs/posix_sitl_replay.cmake: Set the correct variable (config_sitl_rcS_dir) to the correct directory. cmake/nuttx/px4_impl_nuttx.cmake: typos and indentation issues, and removal of a redundant FORCE (INTERNAL implies FORCE). cmake/posix/px4_impl_posix.cmake: typos and indentation issues. cmake/qurt/px4_impl_qurt.cmake: typos and indentation issues. src/modules/mavlink/mavlink_ftp.cpp : possible strict-aliasing breakage. NOTES The second argument passed to sitl_run.sh is the value of config_sitl_rcS_dir. This fact is missing from the usage help. I renamed 'label' to 'rcS_dir' to better reflect this. Also, for the 'replay' config the wrong variable was set causing the call to sitl_run.sh to skip an argument and fail (ie the debugger was passed as rcS_dir and so on). The check on OUT_UNPARSED_ARGUMENTS in px4_parse_function_args basically causes every passed IN variable to be REQUIRED and is therefore a bug. The test for the presence of the REQUIRED arguments follows directly after and is sufficient for this job. This bug went unnoticed because currently every argument to OPTIONS, ONE_VALUE, and MULTI_VALUE is actually passed to the function(s) calling px4_parse_function_args (them being REQUIRED or not). The changes in mavlink_ftp.cpp are to avoid a possible aliasing bug and (mostly) to avoid the compiler warning/error: dereferencing type- punned pointer will break strict-aliasing rules [-Werror=strict-aliasing].
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
echo model: $model
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
working_dir=`pwd`
sitl_bin=$build_path/src/firmware/posix/px4
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
# To disable user input
if [[ -n "$NO_PXH" ]]; then
no_pxh=-d
else
no_pxh=""
fi
if [ "$model" == "" ] || [ "$model" == "none" ]
2015-10-24 11:57:46 -03:00
then
echo "empty model, setting iris as default"
model="iris"
fi
# 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
Bug fixes, typos, indentation. Over time I made a few changes unrelated to what I'm really working on. These changes are hereby committed first. The bug fixes are related to what I'm doing in that I need them to be fixed for future commits. Tools/sitl_run.sh: rename label to rcS_dir and fix usage help. cmake/common/px4_base.cmake: Remove the check on OUT_UNPARSED_ARGUMENTS, and a few typos and indentation issues. cmake/configs/posix_sitl_replay.cmake: Set the correct variable (config_sitl_rcS_dir) to the correct directory. cmake/nuttx/px4_impl_nuttx.cmake: typos and indentation issues, and removal of a redundant FORCE (INTERNAL implies FORCE). cmake/posix/px4_impl_posix.cmake: typos and indentation issues. cmake/qurt/px4_impl_qurt.cmake: typos and indentation issues. src/modules/mavlink/mavlink_ftp.cpp : possible strict-aliasing breakage. NOTES The second argument passed to sitl_run.sh is the value of config_sitl_rcS_dir. This fact is missing from the usage help. I renamed 'label' to 'rcS_dir' to better reflect this. Also, for the 'replay' config the wrong variable was set causing the call to sitl_run.sh to skip an argument and fail (ie the debugger was passed as rcS_dir and so on). The check on OUT_UNPARSED_ARGUMENTS in px4_parse_function_args basically causes every passed IN variable to be REQUIRED and is therefore a bug. The test for the presence of the REQUIRED arguments follows directly after and is sufficient for this job. This bug went unnoticed because currently every argument to OPTIONS, ONE_VALUE, and MULTI_VALUE is actually passed to the function(s) calling px4_parse_function_args (them being REQUIRED or not). The changes in mavlink_ftp.cpp are to avoid a possible aliasing bug and (mostly) to avoid the compiler warning/error: dereferencing type- punned pointer will break strict-aliasing rules [-Werror=strict-aliasing].
2016-09-01 05:59:26 -03:00
if [ "$#" -lt 7 ]
then
Bug fixes, typos, indentation. Over time I made a few changes unrelated to what I'm really working on. These changes are hereby committed first. The bug fixes are related to what I'm doing in that I need them to be fixed for future commits. Tools/sitl_run.sh: rename label to rcS_dir and fix usage help. cmake/common/px4_base.cmake: Remove the check on OUT_UNPARSED_ARGUMENTS, and a few typos and indentation issues. cmake/configs/posix_sitl_replay.cmake: Set the correct variable (config_sitl_rcS_dir) to the correct directory. cmake/nuttx/px4_impl_nuttx.cmake: typos and indentation issues, and removal of a redundant FORCE (INTERNAL implies FORCE). cmake/posix/px4_impl_posix.cmake: typos and indentation issues. cmake/qurt/px4_impl_qurt.cmake: typos and indentation issues. src/modules/mavlink/mavlink_ftp.cpp : possible strict-aliasing breakage. NOTES The second argument passed to sitl_run.sh is the value of config_sitl_rcS_dir. This fact is missing from the usage help. I renamed 'label' to 'rcS_dir' to better reflect this. Also, for the 'replay' config the wrong variable was set causing the call to sitl_run.sh to skip an argument and fail (ie the debugger was passed as rcS_dir and so on). The check on OUT_UNPARSED_ARGUMENTS in px4_parse_function_args basically causes every passed IN variable to be REQUIRED and is therefore a bug. The test for the presence of the REQUIRED arguments follows directly after and is sufficient for this job. This bug went unnoticed because currently every argument to OPTIONS, ONE_VALUE, and MULTI_VALUE is actually passed to the function(s) calling px4_parse_function_args (them being REQUIRED or not). The changes in mavlink_ftp.cpp are to avoid a possible aliasing bug and (mostly) to avoid the compiler warning/error: dereferencing type- punned pointer will break strict-aliasing rules [-Werror=strict-aliasing].
2016-09-01 05:59:26 -03:00
echo usage: sitl_run.sh rc_script rcS_dir debugger program model src_path build_path
echo ""
2015-10-24 11:57:46 -03:00
exit 1
fi
# kill process names that might stil
# be running from last time
pkill -x gazebo || true
pkill -x px4 || true
pkill -x px4_$model || true
jmavsim_pid=`ps aux | grep java | grep Simulator | cut -d" " -f1`
if [ -n "$jmavsim_pid" ]
2015-10-25 13:33:48 -03:00
then
kill $jmavsim_pid
2015-10-25 13:33:48 -03:00
fi
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
$src_path/Tools/jmavsim_run.sh &
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" ]
then
if [ -x "$(command -v gazebo)" ]
then
2015-10-25 14:25:37 -03:00
# 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 &
2015-10-25 13:25:15 -03:00
SIM_PID=`echo $!`
2016-04-24 19:48:56 -03:00
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
2016-04-24 19:48:56 -03:00
gzclient --verbose &
GUI_PID=`echo $!`
fi
else
echo "You need to have gazebo simulator installed!"
exit 1
fi
2016-04-24 19:48:56 -03:00
elif [ "$program" == "replay" ] && [ ! -n "$no_sim" ]
2016-01-28 17:28:36 -04: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
mkdir -p $rootfs
touch $rootfs/replay_params.txt
fi
2015-10-17 12:41:57 -03:00
fi
2016-01-28 17:28:36 -04:00
cd $working_dir
2016-01-28 17:28:36 -04:00
if [ "$logfile" != "" ]
then
cp $logfile $rootfs/replay.px4log
2016-01-28 17:28:36 -04:00
fi
# Do not exit on failure now from here on because we want the complete cleanup
set +e
sitl_command="$sudo_enabled $sitl_bin $no_pxh $chroot_enabled $src_path $src_path/${rcS_dir}/${model}"
echo SITL COMMAND: $sitl_command
2015-10-17 12:41:57 -03:00
# Start Java simulator
2015-10-24 11:57:46 -03:00
if [ "$debugger" == "lldb" ]
2015-09-20 07:54:22 -03:00
then
lldb -- $sitl_command
2015-10-24 11:57:46 -03:00
elif [ "$debugger" == "gdb" ]
2015-09-20 07:54:22 -03:00
then
gdb --args $sitl_command
2015-11-06 22:11:54 -04:00
elif [ "$debugger" == "ddd" ]
then
ddd --debugger gdb --args $sitl_command
2015-11-06 22:11:54 -04:00
elif [ "$debugger" == "valgrind" ]
then
valgrind --track-origins=yes --leak-check=full -v $sitl_command
elif [ "$debugger" == "callgrind" ]
then
valgrind --tool=callgrind -v $sitl_command
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
$sitl_command
2015-09-20 07:54:22 -03:00
fi
2015-10-23 18:58:28 -03:00
if [ "$program" == "jmavsim" ]
2015-10-23 18:58:28 -03:00
then
pkill -9 -P $SIM_PID
2015-10-23 18:58:28 -03:00
kill -9 $SIM_PID
elif [ "$program" == "gazebo" ]
2015-10-23 18:58:28 -03:00
then
kill -9 $SIM_PID
2016-04-24 19:48:56 -03:00
if [[ ! -n "$HEADLESS" ]]; then
kill -9 $GUI_PID
fi
2015-10-23 18:58:28 -03:00
fi