px4-firmware/Tools/sitl_run.sh

176 lines
3.6 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`
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 -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" ]
then
if [ -x "$(command -v gazebo)" ]
then
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
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
cd $working_dir
# 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
if [[ -n "$DONT_RUN" ]]
then
echo "Not running simulation (\$DONT_RUN is set)."
2015-10-17 12:41:57 -03:00
# Start Java simulator
elif [ "$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 [[ -z "$DONT_RUN" ]]
2015-10-23 18:58:28 -03:00
then
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