#!/bin/bash # home location lat, lon, alt, heading LOCATION="CMAC" TRACKER_LOCATION="CMAC_PILOTSBOX" VEHICLE="" BUILD_TARGET="sitl" FRAME="" NUM_PROCS=1 SPEEDUP="1" # check the instance number to allow for multiple copies of the sim running at once INSTANCE=0 USE_VALGRIND=0 USE_GDB=0 USE_GDB_STOPPED=0 DEBUG_BUILD=0 USE_MAVLINK_GIMBAL=0 CLEAN_BUILD=0 START_ANTENNA_TRACKER=0 WIPE_EEPROM=0 REVERSE_THROTTLE=0 NO_REBUILD=0 START_HIL=0 TRACKER_ARGS="" EXTERNAL_SIM=0 MODEL="" BREAKPOINT="" usage() { cat <&2 usage exit 1 esac done shift $((OPTIND-1)) # kill existing copy if this is the '0' instance only kill_tasks() { [ "$INSTANCE" -eq "0" ] && { for pname in JSBSim lt-JSBSim ArduPlane.elf ArduCopter.elf APMrover2.elf AntennaTracker.elf JSBSIm.exe MAVProxy.exe; do pkill "$pname" done pkill -f runsim.py pkill -f sim_tracker.py } } if [ $START_HIL == 0 ]; then kill_tasks fi trap kill_tasks SIGINT # setup ports for this instance MAVLINK_PORT="tcp:127.0.0.1:"$((5760+10*$INSTANCE)) SIMIN_PORT="127.0.0.1:"$((5502+10*$INSTANCE)) SIMOUT_PORT="127.0.0.1:"$((5501+10*$INSTANCE)) FG_PORT="127.0.0.1:"$((5503+10*$INSTANCE)) [ -z "$VEHICLE" ] && { VEHICLE=$(basename $PWD) } [ -z "$FRAME" -a "$VEHICLE" = "APMrover2" ] && { FRAME="rover" } [ -z "$FRAME" -a "$VEHICLE" = "ArduPlane" ] && { FRAME="jsbsim" } [ -z "$FRAME" -a "$VEHICLE" = "ArduCopter" ] && { FRAME="quad" } EXTRA_PARM="" EXTRA_SIM="" [ "$SPEEDUP" != "1" ] && { EXTRA_SIM="$EXTRA_SIM --speedup=$SPEEDUP" } check_jsbsim_version() { jsbsim_version=$(JSBSim --version) if [[ $jsbsim_version != *"ArduPilot"* ]] then cat <> $tfile fi echo r >> $tfile } $autotest/run_in_terminal_window.sh "ardupilot (gdb)" gdb -x $tfile --args $cmd || exit 1 else $autotest/run_in_terminal_window.sh "ardupilot" $cmd || exit 1 fi fi trap kill_tasks SIGINT echo "RUNSIM: $RUNSIM" if [ -n "$RUNSIM" -o "$EXTERNAL_SIM" == 1 ]; then sleep 2 rm -f $tfile if [ $EXTERNAL_SIM == 0 ]; then $autotest/run_in_terminal_window.sh "Simulator" $RUNSIM || { echo "Failed to start simulator: $RUNSIM" exit 1 } sleep 2 else echo "Using external ROS simulator" RUNSIM="$autotest/ROS/runsim.py --simin=$SIMIN_PORT --simout=$SIMOUT_PORT --fgout=$FG_PORT $EXTRA_SIM" $autotest/run_in_terminal_window.sh "ROS Simulator" $RUNSIM || { echo "Failed to start simulator: $RUNSIM" exit 1 } sleep 2 fi else echo "not running external simulator" fi # mavproxy.py --master tcp:127.0.0.1:5760 --sitl 127.0.0.1:5501 --out 127.0.0.1:14550 --out 127.0.0.1:14551 options="" if [ $START_HIL == 0 ]; then options="--master $MAVLINK_PORT --sitl $SIMOUT_PORT" fi # If running inside of a vagrant guest, then we probably want to forward our mavlink out to the containing host OS if [ $USER == "vagrant" ]; then options="$options --out 10.0.2.2:14550" fi options="$options --out 127.0.0.1:14550 --out 127.0.0.1:14551" extra_cmd1="" if [ $WIPE_EEPROM == 1 ]; then extra_cmd="param forceload $autotest/$PARMS; $EXTRA_PARM; param fetch" fi if [ $START_ANTENNA_TRACKER == 1 ]; then options="$options --load-module=tracker" extra_cmd="$extra_cmd module load map; tracker set port $TRACKER_UARTA; tracker start;" fi if [ $START_HIL == 1 ]; then options="$options --load-module=HIL" fi if [ $USE_MAVLINK_GIMBAL == 1 ]; then options="$options --load-module=gimbal" fi if [ -f /usr/bin/cygstart ]; then cygstart -w "/cygdrive/c/Program Files (x86)/MAVProxy/mavproxy.exe" $options --cmd="$extra_cmd" $* else mavproxy.py $options --cmd="$extra_cmd" $* fi if [ $START_HIL == 0 ]; then kill_tasks fi